CNI invocation API proposal
Jeff Sturm
jsturm@one-point.com
Fri Apr 13 12:32:00 GMT 2001
On 2001年4月13日, Cedric Berger wrote:
> Does the GC really need to know the stack bottom?
> What I mean is that there should be *no* java object on the
> stack before a thread enters the VM when it executes it's
> first call to a java object, right?
> the GC should only need to scan the stack of a thread from
> this point to the top:
But once the thread is attached, it is free to return from the calling
function, call a java method and save the result in a stack frame below
the point where it attached.
Besides saying "don't do that" I'm not sure how to avoid it.
> I.E: JNI/CNI:CallVoidMethod could be implemented this way:
>> CallVoidMethod() {
> JavaPeer peer = getPeerOneWayOrAnother();
> if(peer.stackBottom == 0)
> peer.stackBottom = currentStack;
> reallyCallJavaMethod();
> }
Suppose your example returned a jobject instead of void. Supposing the
thread attached as a side effect of calling getPeerOnewayOrAnother() how
do you ensure the returned object is visible to GC?
JNI uses local refs to track the returned object, making it unnecessary to
conservatively scan the native stack. But unless you are diligent with
DeleteLocalRef() you introduce memory leaks that way. In JNI I found
myself frequently detaching for just that reason. So I'd like to avoid
the global/local ref stuff entirely when I am not in JNI.
Jeff
More information about the Java
mailing list