Skip to content
Permalink
Browse files
8262910: Cleanup THREAD/TRAPS/naming and typing issues in ObjectMonit…
…or and related code

Reviewed-by: coleenp, pchilanomate, dcubed, cjplummer, sspitsyn
  • Loading branch information
David Holmes committed Mar 10, 2021
1 parent 57f16f9 commit c6d74bd93392790efa0af6a4fb0c350bdf9ed0d7
Show file tree
Hide file tree
Showing 18 changed files with 470 additions and 521 deletions.
@@ -546,12 +546,12 @@ void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
//
// The notify allows applications that did an untimed wait() on
// the classloader object lock to not hang.
void SystemDictionary::double_lock_wait(Thread* thread, Handle lockObject) {
void SystemDictionary::double_lock_wait(JavaThread* thread, Handle lockObject) {
assert_lock_strong(SystemDictionary_lock);

assert(lockObject() != NULL, "lockObject must be non-NULL");
bool calledholdinglock
= ObjectSynchronizer::current_thread_holds_lock(thread->as_Java_thread(), lockObject);
= ObjectSynchronizer::current_thread_holds_lock(thread, lockObject);
assert(calledholdinglock, "must hold lock for notify");
assert(!is_parallelCapable(lockObject), "lockObject must not be parallelCapable");
// These don't throw exceptions.
@@ -626,7 +626,7 @@ InstanceKlass* SystemDictionary::handle_parallel_super_load(
if (class_loader.is_null()) {
SystemDictionary_lock->wait();
} else {
double_lock_wait(THREAD, lockObject);
double_lock_wait(THREAD->as_Java_thread(), lockObject);
}
} else {
// If not in SD and not in PH, the other thread is done loading the super class
@@ -693,7 +693,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
// ParallelCapable Classloaders and the bootstrap classloader
// do not acquire lock here.
Handle lockObject = get_loader_lock_or_null(class_loader);
ObjectLocker ol(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD->as_Java_thread());

// Check again (after locking) if the class already exists in SystemDictionary
bool class_has_been_loaded = false;
@@ -777,7 +777,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
} else {
// case 4: traditional with broken classloader lock. wait on first
// requestor.
double_lock_wait(THREAD, lockObject);
double_lock_wait(THREAD->as_Java_thread(), lockObject);
}
// Check if classloading completed while we were waiting
InstanceKlass* check = dictionary->find_class(name_hash, name);
@@ -1051,7 +1051,7 @@ InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
// Classloaders that support parallelism, e.g. bootstrap classloader,
// do not acquire lock here
Handle lockObject = get_loader_lock_or_null(class_loader);
ObjectLocker ol(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD->as_Java_thread());

// Parse the stream and create a klass.
// Note that we do this even though this klass might
@@ -1339,7 +1339,7 @@ InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
{
HandleMark hm(THREAD);
Handle lockObject = get_loader_lock_or_null(class_loader);
ObjectLocker ol(lockObject, THREAD);
ObjectLocker ol(lockObject, THREAD->as_Java_thread());
// prohibited package check assumes all classes loaded from archive call
// restore_unshareable_info which calls ik->set_package()
ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
@@ -345,7 +345,7 @@ class SystemDictionary : AllStatic {
// waiting; relocks lockObject with correct recursion count
// after waiting, but before reentering SystemDictionary_lock
// to preserve lock order semantics.
static void double_lock_wait(Thread* thread, Handle lockObject);
static void double_lock_wait(JavaThread* thread, Handle lockObject);
static void define_instance_class(InstanceKlass* k, Handle class_loader, TRAPS);
static InstanceKlass* find_or_define_helper(Symbol* class_name,
Handle class_loader,
@@ -732,7 +732,7 @@ JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, Ba
Handle h_obj(thread, elem->obj());
assert(Universe::heap()->is_in_or_null(h_obj()),
"must be NULL or an object");
ObjectSynchronizer::enter(h_obj, elem->lock(), CHECK);
ObjectSynchronizer::enter(h_obj, elem->lock(), thread);
assert(Universe::heap()->is_in_or_null(elem->obj()),
"must be NULL or an object");
#ifdef ASSERT
@@ -752,7 +752,7 @@ JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
}
return;
}
ObjectSynchronizer::exit(obj, elem->lock(), Thread::current());
ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
// Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
// again at method exit or in the case of an exception.
elem->set_obj(NULL);
@@ -139,7 +139,7 @@ void JfrJavaSupport::notify_all(jobject object, TRAPS) {
HandleMark hm(THREAD);
Handle h_obj(THREAD, resolve_non_null(object));
assert(h_obj.not_null(), "invariant");
ObjectSynchronizer::jni_enter(h_obj, THREAD);
ObjectSynchronizer::jni_enter(h_obj, THREAD->as_Java_thread());
ObjectSynchronizer::notifyall(h_obj, THREAD);
ObjectSynchronizer::jni_exit(h_obj(), THREAD);
DEBUG_ONLY(check_java_thread_in_vm(THREAD));
@@ -258,7 +258,7 @@
volatile_nonstatic_field(ObjectMonitor, _recursions, intptr_t) \
volatile_nonstatic_field(ObjectMonitor, _cxq, ObjectWaiter*) \
volatile_nonstatic_field(ObjectMonitor, _EntryList, ObjectWaiter*) \
volatile_nonstatic_field(ObjectMonitor, _succ, Thread*) \
volatile_nonstatic_field(ObjectMonitor, _succ, JavaThread*) \
\
volatile_nonstatic_field(oopDesc, _mark, markWord) \
volatile_nonstatic_field(oopDesc, _metadata._klass, Klass*) \
@@ -374,13 +374,14 @@ void ConstantPoolCacheEntry::set_method_handle_common(const constantPoolHandle&
// the lock, so that when the losing writer returns, he can use the linked
// cache entry.

objArrayHandle resolved_references(Thread::current(), cpool->resolved_references());
JavaThread* current = JavaThread::current();
objArrayHandle resolved_references(current, cpool->resolved_references());
// Use the resolved_references() lock for this cpCache entry.
// resolved_references are created for all classes with Invokedynamic, MethodHandle
// or MethodType constant pool cache entries.
assert(resolved_references() != NULL,
"a resolved_references array should have been created for this class");
ObjectLocker ol(resolved_references, Thread::current());
ObjectLocker ol(resolved_references, current);
if (!is_f1_null()) {
return;
}
@@ -482,10 +483,11 @@ bool ConstantPoolCacheEntry::save_and_throw_indy_exc(
// Use the resolved_references() lock for this cpCache entry.
// resolved_references are created for all classes with Invokedynamic, MethodHandle
// or MethodType constant pool cache entries.
objArrayHandle resolved_references(Thread::current(), cpool->resolved_references());
JavaThread* current = THREAD->as_Java_thread();
objArrayHandle resolved_references(current, cpool->resolved_references());
assert(resolved_references() != NULL,
"a resolved_references array should have been created for this class");
ObjectLocker ol(resolved_references, THREAD);
ObjectLocker ol(resolved_references, current);

// if f1 is not null or the indy_resolution_failed flag is set then another
// thread either succeeded in resolving the method or got a LinkageError
@@ -807,7 +807,7 @@ void InstanceKlass::eager_initialize_impl() {
EXCEPTION_MARK;
HandleMark hm(THREAD);
Handle h_init_lock(THREAD, init_lock());
ObjectLocker ol(h_init_lock, THREAD);
ObjectLocker ol(h_init_lock, THREAD->as_Java_thread());

// abort if someone beat us to the initialization
if (!is_not_initialized()) return; // note: not equivalent to is_initialized()
@@ -943,7 +943,7 @@ bool InstanceKlass::link_class_impl(TRAPS) {
{
HandleMark hm(THREAD);
Handle h_init_lock(THREAD, init_lock());
ObjectLocker ol(h_init_lock, THREAD);
ObjectLocker ol(h_init_lock, jt);
// rewritten will have been set if loader constraint error found
// on an earlier link attempt
// don't verify or rewrite if already rewritten
@@ -1068,7 +1068,7 @@ void InstanceKlass::initialize_impl(TRAPS) {
// Step 1
{
Handle h_init_lock(THREAD, init_lock());
ObjectLocker ol(h_init_lock, THREAD);
ObjectLocker ol(h_init_lock, jt);

// Step 2
// If we were to use wait() instead of waitInterruptibly() then
@@ -1211,7 +1211,7 @@ void InstanceKlass::initialize_impl(TRAPS) {
void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
Handle h_init_lock(THREAD, init_lock());
if (h_init_lock() != NULL) {
ObjectLocker ol(h_init_lock, THREAD);
ObjectLocker ol(h_init_lock, THREAD->as_Java_thread());
set_init_thread(NULL); // reset _init_thread before changing _init_state
set_init_state(state);
fence_and_clear_init_lock();
@@ -2712,7 +2712,7 @@ JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
}

Handle obj(thread, JNIHandles::resolve_non_null(jobj));
ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR));
ObjectSynchronizer::jni_enter(obj, thread);
ret = JNI_OK;
return ret;
JNI_END
@@ -693,7 +693,7 @@ JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) {
// The phase is checked by the wrapper that called this function,
// but this thread could be racing with the thread that is
// terminating the VM so we check one more time.
Thread* THREAD = Thread::current();
JavaThread* THREAD = JavaThread::current();
HandleMark hm(THREAD);

// create the zip entry (which will open the zip file and hence
@@ -1079,13 +1079,12 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
nWait = j;
break;
}
Thread *t = mon->thread_of_waiter(waiter);
if (t != NULL && t->is_Java_thread()) {
JavaThread *wjava_thread = t->as_Java_thread();
JavaThread *w = mon->thread_of_waiter(waiter);
if (w != NULL) {
// If the thread was found on the ObjectWaiter list, then
// it has not been notified. This thread can't change the
// state of the monitor so it doesn't need to be suspended.
Handle th(current_thread, wjava_thread->threadObj());
Handle th(current_thread, w->threadObj());
ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
}

0 comments on commit c6d74bd

Please sign in to comment.