RFR: 8258077: Using -Xcheck:jni can lead to a double-free after JDK-8193234

David Holmes david.holmes at oracle.com
Thu Dec 17 06:45:53 UTC 2020


Hi Mauro, Dmitry,

On 15/12/2020 6:21 pm, Mauro Lacy wrote:
> On Fri, 11 Dec 2020 08:39:58 GMT, Mauro Lacy <github.com+11656534+maurolacy at openjdk.org> wrote:
> 
>> Besides, I don't think the same is true of the other `Release` methods. This happens only with the `Critical` variant.
> 
> Sorry for the confusion. The reported double free error always mentions `ReleasePrimitiveArrayCritical`, but as Dmitry says, this ends up affecting both APIs.

Right - I'm fixing that incorrect message as well.

But after giving this a lot of thought and research (see comments in 
https://bugs.openjdk.java.net/browse/JDK-8258185) I've decided that the 
appropriate fix here is simply to modify the fix for JDK-8193234 so that 
it only affects the ReleasePrimitiveArrayCritical case. It will still be 
incorrect to call ReleasePrimitiveArrayCritical more than once per 
GetPrimitiveArrayCritical, regardless of mode, due to the fact hotspot 
never returns a copy here. This programming error will not be observed 
in normal execution, but will be detected as a side-effect of the 
additional checking done under -Xcheck:jni.

It may be possible to allow multiple calls to 
ReleasePrimitiveArrayCritical by checking if the native array is located 
in the Java heap or not, but this seems like a programming error to me 
as noted in the bug reports, and hence not something I want to 
support/encourage.

I'll be creating a PR as soon as some further sanity testing has been done.

Thanks,
David
-----

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/1697
> 


More information about the hotspot-dev mailing list