@@ -590,26 +590,25 @@ void Method::build_profiling_method_data(const methodHandle& method, TRAPS) {
590
590
return ;
591
591
}
592
592
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
+ }
604
600
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.
613
612
}
614
613
}
615
614
0 commit comments