Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8289004

investigate if SharedRuntime::get_java_tid parameter should be a JavaThread*

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 20
    • 20
    • hotspot
    • b18

    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.

      Attachments

        Issue Links

          Activity

            People

              rehn Robbin Ehn
              dcubed Daniel Daugherty
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: