8066171: Out of order with Metaspace allocation lock
authorcoleenp
Fri, 05 Dec 2014 15:15:13 -0500
changeset 28019 a6303ff71902
parent 28017 84009002b566
child 28020 ece5ab85141e
8066171: Out of order with Metaspace allocation lock Summary: Lock resolved_references instead. Reviewed-by: twisti, sspitsyn
hotspot/src/share/vm/oops/cpCache.cpp
--- a/hotspot/src/share/vm/oops/cpCache.cpp	Thu Dec 04 15:20:09 2014 -0800
+++ b/hotspot/src/share/vm/oops/cpCache.cpp	Fri Dec 05 15:15:13 2014 -0500
@@ -287,9 +287,13 @@
   // the lock, so that when the losing writer returns, he can use the linked
   // cache entry.
 
-  // Use the lock from the metaspace for this, which cannot stop for safepoint.
-  Mutex* metaspace_lock = cpool->pool_holder()->class_loader_data()->metaspace_lock();
-  MutexLockerEx ml(metaspace_lock,  Mutex::_no_safepoint_check_flag);
+  objArrayHandle resolved_references = 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());
   if (!is_f1_null()) {
     return;
   }
@@ -336,7 +340,6 @@
   // This allows us to create fewer Methods, while keeping type safety.
   //
 
-  objArrayHandle resolved_references = cpool->resolved_references();
   // Store appendix, if any.
   if (has_appendix) {
     const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset;