RFR: 8357601: Checked version of JNI Release<type>ArrayElements needs to filter out known wrapped arrays

Coleen Phillimore coleenp at openjdk.org
Mon Jun 30 01:41:55 UTC 2025


On Mon, 26 May 2025 08:56:09 GMT, David Holmes <dholmes at openjdk.org> wrote:

> The checked version of `Get`/`Release<type>ArrayElements` uses `GuardedMemory` to perform error checking. When releasing the array the code needs to check for the known array tags from the other JNI APIs and report an error.
> 
> We also expand `GuardedMemory` to allow for a second tag word so that we can discriminate additional allocation sites i.e. identifying use of `Get`/`SetPrimitiveArrayCritical`. And add further robustness to guard verification by using `SafeFetch`.

So tag is STRING_TAG and STRING_UTF_TAG and the purpose of tag2 is CRITICAL_TAG?  Maybe just call it critical_tag()?

src/hotspot/share/memory/guardedMemory.hpp line 249:

> 247:   void* get_tag() const { return get_head_guard()->get_tag(); }
> 248: 
> 249:     /**

Extra whitespace.  Why these blocky comments?  That say the same thing twice in 5 lines.

src/hotspot/share/prims/jniCheck.cpp line 357:

> 355: 
> 356: // Arbitrary (but well-known) tag for GetStringUTFChars
> 357: const void* STRING_UTF_TAG = (void*) 0x48124812;

Why is this well-known?  This ending in 12 could be an address, do you not want to make this a possible address?

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

PR Review: https://git.openjdk.org/jdk/pull/25444#pullrequestreview-2872732848
PR Review Comment: https://git.openjdk.org/jdk/pull/25444#discussion_r2110303265
PR Review Comment: https://git.openjdk.org/jdk/pull/25444#discussion_r2110306715


More information about the hotspot-dev mailing list