RFR (S): 8022683 : JNI GetStringUTFChars should return NULL on allocation failure not abort the VM

David Holmes david.holmes at oracle.com
Sun Aug 18 20:51:17 PDT 2013


Hi David,

On 17/08/2013 12:45 AM, David Simms wrote:
> Hello all,
>
> Need reviewers on a JDK8 fix for:
> http://bugs.sun.com/view_bug.do?bug_id=8022683
>
> Found the following functions need to return NULL as suggested by the
> JNI spec
> (http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html):
>
>   * GetStringChars()
>   * GetStringUTFChars()
>   * Get<PrimitiveType>ArrayElements() family of array getters (same
>     generating macro).
>
> Although the specification suggests OOME may be thrown by certain
> functions, the documentation on the aforementioned functions does not
> suggest "throws". So they return NULL now without aborting the JVM as
> before.

There is always come contention with the JNI spec as to whether the 
intent is as defined by the original JNI spec book, or whether it is 
reflected in what is considered the "official spec". :)

> It was assumed the meaning of "isCopy" is undefined given a NULL result,
> in keeping with the rest of jni.cpp.

Even so I think it preferable to not set it unless the operation succeeds.

> Also discovered allocation.hpp macros missing proper argument bracketing
> (e.g. size passed in NEW_C_HEAP_ARRAY_RETURN_NULL()), fixed them up
> since I was there (and they caused trouble).

I can only see size causing a problem because it is used in an 
expression. The rest seems somewhat overkill.

> Webrev:
>
> http://cr.openjdk.java.net/~dsimms/8022683/
> <http://cr.openjdk.java.net/%7Edsimms/8022683/>

One concern I have is in how the dtrace probes will handle things if 
buf/result is NULL?

Thanks,
David

> Testing:
>
> Attached "unit test" to bug, naive test program to trigger OOM. It is
> not suitable for automated testing. Ideally require hooks into the JVM
> to simulate OOM during JNI calls.
>
> Cheers
> /David Simms


More information about the hotspot-runtime-dev mailing list