[jdk19] RFR: 8289091: move oop safety check from SharedRuntime::get_java_tid() to JavaThread::threadObj() [v2]
David Holmes
dholmes at openjdk.org
Wed Jun 29 02:38:51 UTC 2022
On Tue, 28 Jun 2022 13:41:01 GMT, Daniel D. Daugherty <dcubed at openjdk.org> wrote:
>> src/hotspot/share/runtime/thread.cpp line 2151:
>>
>>> 2149: st->print("%s \"%s\"", type_name(), get_thread_name_string(buf, buflen));
>>> 2150: Thread* current = Thread::current_or_null();
>>> 2151: if (current != nullptr && (!current->is_Java_thread() || JavaThread::cast(current)->is_oop_safe())) {
>>
>> Just realized, we can't have a null current thread if we are calling this as that is checked at a higher level. But we should be using `current_or_null_safe()` here as we could be in a signal-handling context.
>
> I used `Thread::current_or_null()` just to make the code more bullet proof. In all of
> my testing I never ran into a case where `Thread::current()` returned `nullptr`.
> I'm going to switch back to `Thread::current()` and remove the extra handling for
> the `current == nullptr` case.
If the code can be invoked in the context of a signal handler, as can happen for the error reporting path, then you must use `Thread::current_or_null_safe()` or risk introducing a deadlock or secondary crash.
It occurs to me that this may mean the existing safety-check is not correct because it may end up being checked in that context too.
-------------
PR: https://git.openjdk.org/jdk19/pull/69
More information about the hotspot-runtime-dev
mailing list