On 30.04.2015 14:17, Philip Martin wrote:
> Branko Čibej <brane_at_wandisco.com> writes:
>
>> The more important part of this change was the addition of
>> POP_AND_RETURN_NOTHING at the end of the function (that you don't
>> quote), because that actually destroys ("pops") the current local JNI
>> frame and cleans up any remaining local references within it. We were
>> leaking a whole frame, not just the single object reference in the loop,
>> and that was affecting other code that happened to be in proximity to
>> the call sites of this function.
> I have to relearn this JNI stuff every time I look at it. The local
> refs are cleaned up automatically on return from the native code because
> the JVM wraps the native call in PushLocalFrame/PopLocalFrame. We use
> DeleteLocalRef to control the number of local refs during the native
> call.
Yes. And add our own push/pop pairs where that's reasonable, for
example, in callbacks from native to Java and in several other places.
> The problem in this case was a missing PopLocalFrame which I guess means
> that the JVM is not tracking the stack depth to automatically pop any
> frames pushed by the native code. I think that means we may still have
> a problem in this function with the bare returns:
>
>>>> if (JNIUtil::isJavaExceptionThrown())
>>>> return;
>>>>
Not really. Once an exception is thrown, we'll return from the loop and
the containing function will detect the exception, pop the local frame
that it created (thus removing any remaining references within that
frame) and return.
-- Brane
Received on 2015-04-30 14:27:08 CEST