RFR: 8280422: thread_from_jni_environment can never return NULL [v2]

David Holmes dholmes at openjdk.java.net
Mon Feb 21 12:43:55 UTC 2022


On Mon, 21 Feb 2022 12:29:34 GMT, Johannes Bechberger <duke at openjdk.java.net> wrote:

>> David Holmes has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Update copyright
>
> I would suggest to add a method for checking the termination status in cases where it might happen:
> 
> ```c++
>   // Returns whether current thread as indicated by the given JNIEnv
>   // is terminated.
>   // We don't assert it is Thread::current here as that is done at the
>   // external JNI entry points where the JNIEnv is passed into the VM.
>   static bool is_thread_from_jni_environment_terminated(JNIEnv* env) {
>     JavaThread* current = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
>     // We can't get here in a thread that has completed its execution and so
>     // "is_terminated", but a thread is also considered terminated if the VM
>     // has exited, so we have to check this and block in case this is a daemon
>     // thread returning to the VM (the JNI DirectBuffer entry points rely on
>     // this).
>     return current->is_terminated();
>   }

@parttimenerd �� 
> This seems to break AsyncGetCallTrace in some rare cases, as "thread_from_jni_environment can never actually return NULL" does not always hold.

Can you please provide further information. As a correctly used JNIEnv can never produce a NULL thread as the JNIEnv is a sub-object of the JavaThread instance.

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

PR: https://git.openjdk.java.net/jdk/pull/7193


More information about the hotspot-runtime-dev mailing list