RFR: 8373839: Disable JVM TI suspension during JNI critical regions

Fredrik Bredberg fbredberg at openjdk.org
Thu Dec 18 13:44:25 UTC 2025


On Thu, 18 Dec 2025 01:24:42 GMT, David Holmes <dholmes at openjdk.org> wrote:

> To ensure JNI critical access to a raw array can't interfere with actions of the debugger, we disable JVM TI suspension whilst JNI critical access is active, as originally suggested by @fisk. We assume the debugger is being operated correctly (ie the thread using the raw array will be suspended), and that the critical section is short so as to not delay debugging too long. 
> 
> The mechanism for this already exists courtesy of the virtual thread support.
> 
> Testing:
>  - tiers 1 - 6 sanity

This is a nice fix, regardless of my opinion about pre/post-decrement. Thank you David.

src/hotspot/share/runtime/javaThread.hpp line 966:

> 964:   void exit_critical() {
> 965:     assert(Thread::current() == this, "this must be current thread");
> 966:     if (_jni_active_critical-- == 1) {

Suggestion:

    if (--_jni_active_critical == 0) {

I know my suggested line really does the same as yours, but this way I feel it's easier to see that we re-enable suspension when the number of active critical regions are down to 0. I.e. I prefer pre-decrement and compare to 0, vs. post-decrement and compare to 1.

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

Marked as reviewed by fbredberg (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28884#pullrequestreview-3593033724
PR Review Comment: https://git.openjdk.org/jdk/pull/28884#discussion_r2631125115


More information about the serviceability-dev mailing list