RFR: 8299089: Instrument global jni handles with tag to make them distinguishable

Axel Boldt-Christmas aboldtch at openjdk.org
Tue Jan 10 10:08:52 UTC 2023


On Tue, 10 Jan 2023 09:46:18 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>>> All the tags are mutually exclusive.
>> 
>> I see; could those tags be implemented using enum then? Sth like:
>> 
>> 
>> enum Tag {
>>   local = 0b00,
>>   jweak = 0b01,
>>   global = 0b10,
>>   mask = 0b11,
>> }
>> 
>> bool is_tagged_with(Handle h, Tag t) {
>>   return (h & mask) == t.
>> }
>> 
>> 
>> This makes the "mutual exclusiveness" more explicit and can probaly remove some redundancy in `assert(is_jweak); assert(!is_global);`.
>> 
>> 
>>> But we will get handles from the JNI external interface, and we want to check that the storage is correct in conjunction with checking that the tags are correct.
>> 
>> I don't know much about JNI; I thought all handles must be constructed using JNI APIs -- so, they must be correctly tagged.
>
> That is probably clearer. Will take a look at it.
> 
> That is how it should be used and I think the effort is that if you do something bad you get a ReportJNIFatalError with some message instead of maybe crashing in the VM. But probably cleaner and more accurate if the code which checks the storage is move to `jniCheck::validate_handle` and have the handle checks just use the tag.

Looking at `validate_handle` it does check the storage and it would reach `ShouldNotReachHere();` if the handle has bad storage. So just checking the tag should be fine. (And assert the storage)

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

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


More information about the hotspot-dev mailing list