hotspot/src/share/vm/oops/constantPool.cpp
changeset 27247 99db666dbe8e
parent 25624 b3bd733f04e9
child 27408 9a8090dd6ec3
--- a/hotspot/src/share/vm/oops/constantPool.cpp	Tue Oct 14 20:35:45 2014 +0000
+++ b/hotspot/src/share/vm/oops/constantPool.cpp	Thu Oct 02 10:55:36 2014 +0200
@@ -1779,11 +1779,22 @@
 
 void ConstantPool::set_on_stack(const bool value) {
   if (value) {
-    _flags |= _on_stack;
+    int old_flags = *const_cast<volatile int *>(&_flags);
+    while ((old_flags & _on_stack) == 0) {
+      int new_flags = old_flags | _on_stack;
+      int result = Atomic::cmpxchg(new_flags, &_flags, old_flags);
+
+      if (result == old_flags) {
+        // Succeeded.
+        MetadataOnStackMark::record(this, Thread::current());
+        return;
+      }
+      old_flags = result;
+    }
   } else {
+    // Clearing is done single-threadedly.
     _flags &= ~_on_stack;
   }
-  if (value) MetadataOnStackMark::record(this);
 }
 
 // JSR 292 support for patching constant pool oops after the class is linked and