Name: nt126004 Date: 01/31/2002
FULL PRODUCT VERSION :
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-root-010902-18:51)
Java HotSpot(TM) Client VM (build 1.3.1, mixed mode)
FULL OPERATING SYSTEM VERSION :
This feature request is not specific to any OS (and you really should have such a setting in the bug reporter)
ADDITIONAL OPERATING SYSTEMS :
All.
A DESCRIPTION OF THE PROBLEM :
I just spent a whole bunch of time tracking down a bug in LiveConnect (in the PRESERVE_OBJECT_IDENTITY case which I re-enabled in OmniWeb's copy, if any Mozilla folks are reading) which was due to not holding on to a global ref (weak in this case) when putting a Java wrapper object in a hash table keyed off of a JS object.
The thing that made this difficult to track down was the behavior of JNI with respect to reference addresses. Local references seem to be allocated out of stack of addresses in the JVM (presumably on a per thread/JNIEnv basis).
Now, the problem was that the reference I was getting back from my hash table lookup was bad, but it wasn't obvious that it was bad since the JNI stack of local refs was used. The JNI implementation has a policy of reusing reference addresses quickly, meaning it is more likely that your stale address will point to something live, just not what it should.
Thus, it seems like it would be nice to have a -X option that is analogous to 'NSZombieEnabled' and 'NSDeallocateZombies' in Cocoa. Let's call this option '-Xzombies' for now (I don't care what it is called :).
If -Xzombies was enabled, then the following behaviors would be in effect:
- Reference addresses would never be reused (yes, very wasteful of memory, but very, very useful for debugging).
- Local refs that went out of scope would be annotated as such in the JVM.
- Global/WeakGlobal ref addresses that were deleted would be annotated as above
- The JVM would check all method receivers and object arguments for zombie-ness and would log a message like:
'Detected zombie object 0x%08x as [receiver|argument N] of className.methodSignature. Please break on _JNIZombieDetected to debug.'
It would then call _JNIZombieDetected(), an empty function that just serves as a place to stop to see where you screwed up.
Alternatively, the JVM could just call abort() after logging the information.
This option would make it extremely easy to track down bad references.
(Review ID: 137703)
======================================================================
- duplicates
-
JDK-4664556 -Xcheck:jni improvements
-
- Closed
-