< prev index next > src/hotspot/share/runtime/javaThread.cpp
Print this page
#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"
// 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
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());
}
_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),
_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),
// 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);)
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) {
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");
}
#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);
_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;
}
#endif // PRODUCT
void JavaThread::inc_held_monitor_count(intx i, bool jni) {
#ifdef SUPPORT_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;
}
}
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);
if (jni) {
_jni_monitor_count -= i;
assert(_jni_monitor_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _jni_monitor_count);
}
#endif
}
void JavaThread::dec_held_monitor_count(intx i, bool jni) {
#ifdef SUPPORT_MONITOR_COUNT
_held_monitor_count -= i;
! 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
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 >