RFR: 8299684: (bf) JNI direct buffer functions with large capacity behave unexpectedly [v2]
David Holmes
dholmes at openjdk.org
Fri Jan 6 06:54:49 UTC 2023
On Thu, 5 Jan 2023 23:42:11 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: Enhance message in IAE caused by NewDirectByteBuffer passing up a capacity which overflows int range
I think it will look strange to update the JNI spec to say that although the function takes a jlong as the requested capacity, it will throw IAE if the capacity is larger than a jint! The mismatch between the JNI and Java code made me dig into the history here to see what JSR-51 had to say about this, but unfortunately it didn't say much. What I did find in
https://bugs.openjdk.org/browse/JDK-4496703
was a very definitive comment about only supporting 32-bit (ie int) based direct buffers, but with a glimmer of hope
> "A future revision of the specification is likely to address this problem".
So perhaps the JNI side was prepared for this unrealized future? But even so it should have specified what happens if the jlong capacity exceeds the value of a jint
I thought perhaps a special OutOfMemoryError (akin to the "Requested array size exceeds VM limit" OOME) could be thrown - and that would not require a JNI spec change - but it is a stretch. Though also note that if this requires a JNI spec change then it cannot be backported without jumping through some serious JCP Maintenance Release hoops.
-------------
PR: https://git.openjdk.org/jdk/pull/11873
More information about the hotspot-dev
mailing list