1.1 --- a/src/share/vm/oops/constantPool.cpp Mon Nov 03 12:02:40 2014 -0800 1.2 +++ b/src/share/vm/oops/constantPool.cpp Thu Oct 02 10:55:36 2014 +0200 1.3 @@ -1817,11 +1817,22 @@ 1.4 1.5 void ConstantPool::set_on_stack(const bool value) { 1.6 if (value) { 1.7 - _flags |= _on_stack; 1.8 + int old_flags = *const_cast<volatile int *>(&_flags); 1.9 + while ((old_flags & _on_stack) == 0) { 1.10 + int new_flags = old_flags | _on_stack; 1.11 + int result = Atomic::cmpxchg(new_flags, &_flags, old_flags); 1.12 + 1.13 + if (result == old_flags) { 1.14 + // Succeeded. 1.15 + MetadataOnStackMark::record(this, Thread::current()); 1.16 + return; 1.17 + } 1.18 + old_flags = result; 1.19 + } 1.20 } else { 1.21 + // Clearing is done single-threadedly. 1.22 _flags &= ~_on_stack; 1.23 } 1.24 - if (value) MetadataOnStackMark::record(this); 1.25 } 1.26 1.27 // JSR 292 support for patching constant pool oops after the class is linked and