RFR: 8299684: (bf) JNI direct buffer functions with large capacity behave unexpectedly [v5]

Alan Bateman alanb at openjdk.org
Tue Jan 10 12:04:56 UTC 2023


On Tue, 10 Jan 2023 02:20:34 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: Changes addressing reviewer comments

The update looks quite good and maybe some day this can be converted from a psvm test to a junit test.

test/jdk/java/nio/jni/NewDirectByteBuffer.java line 30:

> 28:  * @summary Verify that JNI NewDirectByteBuffer throws IllegalArgumentException
> 29:  * if the capacity is negative or greater than Integer::MAX_VALUE
> 30:  * @run main/native NewDirectByteBuffer

You may have missed the comments about @requires and wondering if this test will run on 32-bit, as it will attempt to malloc 2GB.

test/jdk/java/nio/jni/NewDirectByteBuffer.java line 50:

> 48:         (long)Integer.MAX_VALUE + 1L,
> 49:         3_000_000_000L,
> 50:         5_000_000_000L

Long.MIN_VALUE and Long.MAX_VALUE would be good to include.

test/jdk/java/nio/jni/libNewDirectByteBuffer.c line 35:

> 33:     void* addr = malloc(size);
> 34:     if (addr == NULL) {
> 35:         jclass rtExCls = (*env)->FindClass(env, "java/lang/OutOfMemoryError");

rtExCls? Does this stand for "runtime exception class", just asking because this is an Error class.

-------------

PR: https://git.openjdk.org/jdk/pull/11873


More information about the nio-dev mailing list