JDK-8289004 : investigate if SharedRuntime::get_java_tid parameter should be a JavaThread*
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-22
  • Updated: 2022-10-10
  • Resolved: 2022-10-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b18Fixed
Related Reports
Relates :  
Description
In the code review for:
    JDK-8288139 JavaThread touches oop after GC barrier is detached

this topic came up:
    https://github.com/openjdk/jdk19/pull/21#discussion_r898482607

Here's [~dholmes]' comment:

> Additional RFE: can we not declare this to take JavaThread and so avoid the checks and casts below?

Here's the relevant code in JDK20:

src/hotspot/share/runtime/sharedRuntime.cpp

jlong SharedRuntime::get_java_tid(Thread* thread) {
  if (thread != NULL && thread->is_Java_thread()) {
    Thread* current = Thread::current();
    guarantee(current != thread || JavaThread::cast(thread)->is_oop_safe(),
              "current cannot touch oops after its GC barrier is detached.");
    oop obj = JavaThread::cast(thread)->threadObj();
    return (obj == NULL) ? 0 : java_lang_Thread::thread_id(obj);
  }
  return 0;
}

In the current implementation, if 'thread' is NULL or not a JavaThread,
then the API returns a 0. However, if this API is only ever called on a
JavaThread, then we could change the parameter from 'Thread*' to
'JavaThread*' and do some cleanup.
Comments
Changeset: 979efd41 Author: Robbin Ehn <rehn@openjdk.org> Date: 2022-10-05 12:44:20 +0000 URL: https://git.openjdk.org/jdk/commit/979efd4174968802f0c170e768671507a11e118e
05-10-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10532 Date: 2022-10-03 12:59:21 +0000
03-10-2022