< prev index next >

src/hotspot/share/runtime/javaThread.cpp

Print this page
@@ -81,10 +81,11 @@
  #include "runtime/serviceThread.hpp"
  #include "runtime/stackFrameStream.inline.hpp"
  #include "runtime/stackWatermarkSet.hpp"
  #include "runtime/synchronizer.hpp"
  #include "runtime/threadCritical.hpp"
+ #include "runtime/threadIdentifier.hpp"
  #include "runtime/threadSMR.inline.hpp"
  #include "runtime/threadStatisticalInfo.hpp"
  #include "runtime/threadWXSetters.inline.hpp"
  #include "runtime/timer.hpp"
  #include "runtime/timerTrace.hpp"

@@ -233,10 +234,12 @@
    // We are called from jni_AttachCurrentThread/jni_AttachCurrentThreadAsDaemon.
    // We cannot use JavaCalls::construct_new_instance because the java.lang.Thread
    // constructor calls Thread.current(), which must be set here.
    java_lang_Thread::set_thread(thread_oop(), this);
    set_threadOopHandles(thread_oop());
+   // Set the lock_id to the next thread_id temporarily while initialization runs.
+   set_lock_id(ThreadIdentifier::next());
  
    JavaValue result(T_VOID);
    if (thread_name != nullptr) {
      Handle name = java_lang_String::create_from_str(thread_name, CHECK);
      // Thread gets assigned specified name and null target

@@ -258,10 +261,13 @@
                              vmSymbols::threadgroup_runnable_void_signature(),
                              thread_group,
                              Handle(),
                              CHECK);
    }
+   // Update the lock_id with the tid value.
+   set_lock_id(java_lang_Thread::thread_id(thread_oop()));
+ 
    os::set_priority(this, NormPriority);
  
    if (daemon) {
      java_lang_Thread::set_daemon(thread_oop());
    }

@@ -427,10 +433,12 @@
    _current_pending_monitor(nullptr),
    _current_pending_monitor_is_from_java(true),
    _current_waiting_monitor(nullptr),
    _active_handles(nullptr),
    _free_handle_block(nullptr),
+   _lock_id(0),
+   _on_monitorenter(false),
  
    _suspend_flags(0),
  
    _thread_state(_thread_new),
    _saved_exception_pc(nullptr),

@@ -447,10 +455,12 @@
    _carrier_thread_suspended(false),
    _is_in_VTMS_transition(false),
    _is_in_tmp_VTMS_transition(false),
    _is_disable_suspend(false),
    _VTMS_transition_mark(false),
+   _pending_jvmti_unmount_event(false),
+   _contended_entered_monitor(nullptr),
  #ifdef ASSERT
    _is_VTMS_transition_disabler(false),
  #endif
  #endif
    _jni_attach_state(_not_attaching_via_jni),

@@ -485,10 +495,15 @@
    _cont_entry(nullptr),
    _cont_fastpath(0),
    _cont_fastpath_thread_state(1),
    _held_monitor_count(0),
    _jni_monitor_count(0),
+   _preempting(false),
+   _preemption_cancelled(false),
+   _pending_interrupted_exception(false),
+   _preempt_alternate_return(nullptr),
+   DEBUG_ONLY(_obj_locker_count(0) COMMA)
  
    _handshake(this),
  
    _popframe_preserved_args(nullptr),
    _popframe_preserved_args_size(0),

@@ -928,10 +943,11 @@
      // We would like a fatal here, but due to we never checked this before there
      // is a lot of tests which breaks, even with an error log.
      log_debug(jni)("JavaThread %s (tid: " UINTX_FORMAT ") with Objects still locked by JNI MonitorEnter.",
                     exit_type == JavaThread::normal_exit ? "exiting" : "detaching", os::current_thread_id());
    }
+   assert(obj_locker_count() == 0, "expected 0 but found: " INTX_FORMAT, obj_locker_count());
  
    // These things needs to be done while we are still a Java Thread. Make sure that thread
    // is in a consistent state, in case GC happens
    JFR_ONLY(Jfr::on_thread_exit(this);)
  

@@ -1157,10 +1173,11 @@
    Handshake::execute(&iaeh, target);
  }
  
  #if INCLUDE_JVMTI
  void JavaThread::set_is_in_VTMS_transition(bool val) {
+   assert(is_in_VTMS_transition() != val, "already %s transition", val ? "inside" : "outside");
    _is_in_VTMS_transition = val;
  }
  
  #ifdef ASSERT
  void JavaThread::set_is_VTMS_transition_disabler(bool val) {

@@ -1520,13 +1537,12 @@
    Thread::print_on(st, print_extended_info);
    // print guess for valid stack memory region (assume 4K pages); helps lock debugging
    st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
    if (thread_oop != nullptr) {
      if (is_vthread_mounted()) {
-       oop vt = vthread();
-       assert(vt != nullptr, "");
-       st->print_cr("   Carrying virtual thread #" INT64_FORMAT, (int64_t)java_lang_Thread::thread_id(vt));
+       // _lock_id is the thread ID of the mounted virtual thread
+       st->print_cr("   Carrying virtual thread #" INT64_FORMAT, lock_id());
      } else {
        st->print_cr("   java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
      }
    }
  #ifndef PRODUCT

@@ -1706,10 +1722,11 @@
    Handle thread_oop(Thread::current(),
                      JNIHandles::resolve_non_null(jni_thread));
    assert(InstanceKlass::cast(thread_oop->klass())->is_linked(),
           "must be initialized");
    set_threadOopHandles(thread_oop());
+   set_lock_id(java_lang_Thread::thread_id(thread_oop()));
  
    if (prio == NoPriority) {
      prio = java_lang_Thread::priority(thread_oop());
      assert(prio != NoPriority, "A valid priority should be present");
    }

@@ -2001,14 +2018,14 @@
  // Slow-path decrement of the held monitor counts. JNI unlocking is always
  // this slow-path.
  void JavaThread::dec_held_monitor_count(intx i, bool jni) {
  #ifdef SUPPORT_MONITOR_COUNT
    _held_monitor_count -= i;
-   assert(_held_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _held_monitor_count);
+   assert(_held_monitor_count >= 0, "Must always be non-negative: " INTX_FORMAT, _held_monitor_count);
    if (jni) {
      _jni_monitor_count -= i;
-     assert(_jni_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _jni_monitor_count);
+     assert(_jni_monitor_count >= 0, "Must always be non-negative: " INTX_FORMAT, _jni_monitor_count);
    }
    // When a thread is detaching with still owned JNI monitors, the logic that releases
    // the monitors doesn't know to set the "jni" flag and so the counts can get out of sync.
    // So we skip this assert if the thread is exiting. Once all monitors are unlocked the
    // JNI count is directly set to zero.

@@ -2194,10 +2211,11 @@
  
    java_lang_Thread::set_daemon(thread_oop());
  
    // Now bind the thread_oop to the target JavaThread.
    target->set_threadOopHandles(thread_oop());
+   target->set_lock_id(java_lang_Thread::thread_id(thread_oop()));
  
    Threads::add(target); // target is now visible for safepoint/handshake
    // Publish the JavaThread* in java.lang.Thread after the JavaThread* is
    // on a ThreadsList. We don't want to wait for the release when the
    // Theads_lock is dropped when the 'mu' destructor is run since the
< prev index next >