8041468: Field nmethod::_lock_count should be declared volatile
authoranoll
Thu, 24 Apr 2014 09:47:34 +0200
changeset 24309 fc2950805050
parent 24090 196e4bd91543
child 24310 1cc31246af03
child 24311 40cf14732ddc
8041468: Field nmethod::_lock_count should be declared volatile Summary: The jint field nmethod::_lock_count which is used in nmethodLocker::lock_nmethod and nmethodLocker::unlock_nmethod should be declared volatile (see also signature of Atomic::inc) Reviewed-by: kvn, roland Contributed-by: Tobias Hartmann <tobias.hartmann@oracle.com>
hotspot/src/share/vm/code/nmethod.cpp
hotspot/src/share/vm/code/nmethod.hpp
hotspot/src/share/vm/runtime/vmStructs.cpp
--- a/hotspot/src/share/vm/code/nmethod.cpp	Tue Apr 22 17:45:56 2014 -0700
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Thu Apr 24 09:47:34 2014 +0200
@@ -2284,13 +2284,13 @@
 void nmethodLocker::lock_nmethod(nmethod* nm, bool zombie_ok) {
   if (nm == NULL)  return;
   Atomic::inc(&nm->_lock_count);
-  guarantee(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method");
+  assert(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method");
 }
 
 void nmethodLocker::unlock_nmethod(nmethod* nm) {
   if (nm == NULL)  return;
   Atomic::dec(&nm->_lock_count);
-  guarantee(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
+  assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
 }
 
 
--- a/hotspot/src/share/vm/code/nmethod.hpp	Tue Apr 22 17:45:56 2014 -0700
+++ b/hotspot/src/share/vm/code/nmethod.hpp	Thu Apr 24 09:47:34 2014 +0200
@@ -203,7 +203,7 @@
   // and is not made into a zombie. However, once the nmethod is made into
   // a zombie, it will be locked one final time if CompiledMethodUnload
   // event processing needs to be done.
-  jint  _lock_count;
+  volatile jint _lock_count;
 
   // not_entrant method removal. Each mark_sweep pass will update
   // this mark to current sweep invocation count if it is seen on the
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Tue Apr 22 17:45:56 2014 -0700
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Thu Apr 24 09:47:34 2014 +0200
@@ -878,7 +878,7 @@
   nonstatic_field(nmethod,             _entry_point,                                  address)                               \
   nonstatic_field(nmethod,             _verified_entry_point,                         address)                               \
   nonstatic_field(nmethod,             _osr_entry_point,                              address)                               \
-  nonstatic_field(nmethod,             _lock_count,                                   jint)                                  \
+  volatile_nonstatic_field(nmethod,    _lock_count,                                   jint)                                  \
   nonstatic_field(nmethod,             _stack_traversal_mark,                         long)                                  \
   nonstatic_field(nmethod,             _compile_id,                                   int)                                   \
   nonstatic_field(nmethod,             _comp_level,                                   int)                                   \