[jdk19] RFR: 8289091: move oop safety check from SharedRuntime::get_java_tid() to JavaThread::threadObj() [v3]

David Holmes dholmes at openjdk.org
Thu Jun 30 03:06:50 UTC 2022


On Wed, 29 Jun 2022 18:22:46 GMT, Daniel D. Daugherty <dcubed at openjdk.org> wrote:

>> src/hotspot/share/runtime/thread.cpp line 2153:
>> 
>>> 2151:   if (!current->is_Java_thread() || JavaThread::cast(current)->is_oop_safe()) {
>>> 2152:     // Only access threadObj() if current thread is not a JavaThread
>>> 2153:     // or if it is a JavaThread that can safely access oops.
>> 
>> How can a non-JavaThread safely access the oop? Is the only safe case the VMThread at a safepoint?
>
> The purpose of the `if (!current->is_Java_thread() ||` part of the if-statement
> is to allow the code to work as it did before for the non-JavaThread case. Before
> this fix, if a non-JavaThread called into this code, then it was allowed to execute
> this code. I've preserved that behavior and I've see no failures that indicate that
> this is a problem.
> 
> Do I know what non-JavaThreads might wander in here? No I don't.

I realise this is pre-existing behaviour. It seems odd that a non-JavaThread can touch an oop when an exiting JavaThread cannot - how are they different? Or do we just cross our fingers and hope for the best with a non-JavaThread because it is rare? Perhaps @fisk can explain?

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

PR: https://git.openjdk.org/jdk19/pull/69


More information about the hotspot-runtime-dev mailing list