RFR: 8299684: (bf) JNI direct buffer functions with large capacity behave unexpectedly [v14]
Alan Bateman
alanb at openjdk.org
Wed Jan 18 09:15:34 UTC 2023
On Wed, 18 Jan 2023 03:17:53 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> Remove cast in `JNI::NewDirectByteBuffer`of `long` capacity to `int`, modify the constructor in question to accept a `long` capacity, and verify in the constructor that the capacity does not overflow `int` range, throwing IAE If it does.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>
> 8299684: Clean up memory deallocation
test/jdk/java/nio/jni/NewDirectByteBuffer.java line 106:
> 104: (long)Integer.MAX_VALUE - 1, (long)Integer.MAX_VALUE})
> 105: void legalCapacities(long capacity) {
> 106: long addr = UNSAFE.allocateMemory(capacity);
I think David was asking for the test to continue when malloc fails. Now that the test is changed to use Unsafe.allocateMemory it means it has to catch OOME.
test/jdk/java/nio/jni/libNewDirectByteBuffer.c line 49:
> 47: (JNIEnv *env, jclass cls, jobject buf)
> 48: {
> 49: return (jlong)(*env)->GetDirectBufferAddress(env, buf);
The cast to jlong should be okay for 64-bit. For 32-bit then it will likely need a double cast, as in ((jlong)(int)( .. )) but maybe okay for now as you've restricted the test to 64-bit.
-------------
PR: https://git.openjdk.org/jdk/pull/11873
More information about the hotspot-dev
mailing list