< 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"

@@ -223,10 +224,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

@@ -248,10 +251,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());
    }

@@ -417,11 +423,13 @@
    _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),
    _Stalled(0),
+   _on_monitorenter(false),
  
    _monitor_chunks(nullptr),
  
    _suspend_flags(0),
  

@@ -476,10 +484,14 @@
    _cont_entry(nullptr),
    _cont_fastpath(0),
    _cont_fastpath_thread_state(1),
    _held_monitor_count(0),
    _jni_monitor_count(0),
+   _preempting(false),
+   _preemption_cancelled(false),
+   _jvmti_unmount_event_pending(false),
+   DEBUG_ONLY(_obj_locker_count(0) COMMA)
  
    _handshake(this),
  
    _popframe_preserved_args(nullptr),
    _popframe_preserved_args_size(0),

@@ -884,10 +896,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);)
  

@@ -1132,10 +1145,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) {

@@ -1675,10 +1689,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");
    }

@@ -1949,11 +1964,11 @@
  
  #endif // PRODUCT
  
  void JavaThread::inc_held_monitor_count(intx i, bool jni) {
  #ifdef SUPPORT_MONITOR_COUNT
-   assert(_held_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _held_monitor_count);
+   assert(_held_monitor_count + 1 >= 0, "Must always be greater than 0: " INTX_FORMAT, _held_monitor_count + 1);
    _held_monitor_count += i;
    if (jni) {
      assert(_jni_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _jni_monitor_count);
      _jni_monitor_count += i;
    }

@@ -1961,11 +1976,11 @@
  }
  
  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 + 1 >= 0, "Must always be greater than 0: " INTX_FORMAT, _held_monitor_count + 1);
    if (jni) {
      _jni_monitor_count -= i;
      assert(_jni_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _jni_monitor_count);
    }
  #endif

@@ -2148,10 +2163,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 >