Skip to content

Commit 9f24a6f

Browse files
committed
8297389: resexhausted003 fails with assert(!thread->owns_locks()) failed: must release all locks when leaving VM
Reviewed-by: dholmes, rrich, dlong
1 parent fa0c599 commit 9f24a6f

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

src/hotspot/share/ci/ciReplay.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -824,20 +824,12 @@ class CompileReplay : public StackObj {
824824
/* just copied from Method, to build interpret data*/
825825

826826
// To be properly initialized, some profiling in the MDO needs the
827-
// method to be rewritten (number of arguments at a call for
828-
// instance)
827+
// method to be rewritten (number of arguments at a call for instance)
829828
method->method_holder()->link_class(CHECK);
830-
// Method::build_profiling_method_data(method, CHECK);
831-
{
832-
// Grab a lock here to prevent multiple
833-
// MethodData*s from being created.
834-
MutexLocker ml(THREAD, MethodData_lock);
835-
if (method->method_data() == NULL) {
836-
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
837-
MethodData* method_data = MethodData::allocate(loader_data, methodHandle(THREAD, method), CHECK);
838-
method->set_method_data(method_data);
839-
}
840-
}
829+
assert(method->method_data() == NULL, "Should only be initialized once");
830+
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
831+
MethodData* method_data = MethodData::allocate(loader_data, methodHandle(THREAD, method), CHECK);
832+
method->set_method_data(method_data);
841833

842834
// collect and record all the needed information for later
843835
ciMethodDataRecord* rec = new_ciMethodData(method);

src/hotspot/share/oops/method.cpp

+18-19
Original file line numberDiff line numberDiff line change
@@ -590,26 +590,25 @@ void Method::build_profiling_method_data(const methodHandle& method, TRAPS) {
590590
return;
591591
}
592592

593-
// Grab a lock here to prevent multiple
594-
// MethodData*s from being created.
595-
MutexLocker ml(THREAD, MethodData_lock);
596-
if (method->method_data() == NULL) {
597-
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
598-
MethodData* method_data = MethodData::allocate(loader_data, method, THREAD);
599-
if (HAS_PENDING_EXCEPTION) {
600-
CompileBroker::log_metaspace_failure();
601-
ClassLoaderDataGraph::set_metaspace_oom(true);
602-
return; // return the exception (which is cleared)
603-
}
593+
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
594+
MethodData* method_data = MethodData::allocate(loader_data, method, THREAD);
595+
if (HAS_PENDING_EXCEPTION) {
596+
CompileBroker::log_metaspace_failure();
597+
ClassLoaderDataGraph::set_metaspace_oom(true);
598+
return; // return the exception (which is cleared)
599+
}
604600

605-
method->set_method_data(method_data);
606-
if (PrintMethodData && (Verbose || WizardMode)) {
607-
ResourceMark rm(THREAD);
608-
tty->print("build_profiling_method_data for ");
609-
method->print_name(tty);
610-
tty->cr();
611-
// At the end of the run, the MDO, full of data, will be dumped.
612-
}
601+
if (!Atomic::replace_if_null(&method->_method_data, method_data)) {
602+
MetadataFactory::free_metadata(loader_data, method_data);
603+
return;
604+
}
605+
606+
if (PrintMethodData && (Verbose || WizardMode)) {
607+
ResourceMark rm(THREAD);
608+
tty->print("build_profiling_method_data for ");
609+
method->print_name(tty);
610+
tty->cr();
611+
// At the end of the run, the MDO, full of data, will be dumped.
613612
}
614613
}
615614

src/hotspot/share/oops/methodData.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) con
658658
// a method.
659659

660660
MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
661+
assert(!THREAD->owns_locks(), "Should not own any locks");
661662
int size = MethodData::compute_allocation_size_in_words(method);
662663

663664
return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)

src/hotspot/share/runtime/mutexLocker.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ Mutex* SymbolArena_lock = NULL;
6969
Monitor* StringDedup_lock = NULL;
7070
Mutex* StringDedupIntern_lock = NULL;
7171
Monitor* CodeCache_lock = NULL;
72-
Mutex* MethodData_lock = NULL;
7372
Mutex* TouchedMethodLog_lock = NULL;
7473
Mutex* RetData_lock = NULL;
7574
Monitor* VMOperation_lock = NULL;
@@ -297,7 +296,6 @@ void mutex_init() {
297296
def(Management_lock , PaddedMutex , safepoint); // used for JVM management
298297

299298
def(ConcurrentGCBreakpoints_lock , PaddedMonitor, safepoint, true);
300-
def(MethodData_lock , PaddedMutex , safepoint);
301299
def(TouchedMethodLog_lock , PaddedMutex , safepoint);
302300

303301
def(CompileThread_lock , PaddedMonitor, safepoint);

src/hotspot/share/runtime/mutexLocker.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ extern Mutex* SymbolArena_lock; // a lock on the symbol table a
5858
extern Monitor* StringDedup_lock; // a lock on the string deduplication facility
5959
extern Mutex* StringDedupIntern_lock; // a lock on StringTable notification of StringDedup
6060
extern Monitor* CodeCache_lock; // a lock on the CodeCache
61-
extern Mutex* MethodData_lock; // a lock on installation of method data
6261
extern Mutex* TouchedMethodLog_lock; // a lock on allocation of LogExecutedMethods info
6362
extern Mutex* RetData_lock; // a lock on installation of RetData inside method data
6463
extern Monitor* VMOperation_lock; // a lock on queue of vm_operations waiting to execute

0 commit comments

Comments
 (0)