--- a/hotspot/src/share/vm/code/nmethod.cpp Mon Jan 30 16:04:22 2017 +0300
+++ b/hotspot/src/share/vm/code/nmethod.cpp Tue Jan 31 01:11:40 2017 +0300
@@ -1146,6 +1146,14 @@
assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
assert(!is_zombie(), "should not already be a zombie");
+ if (_state == state) {
+ // Avoid taking the lock if already in required state.
+ // This is safe from races because the state is an end-state,
+ // which the nmethod cannot back out of once entered.
+ // No need for fencing either.
+ return false;
+ }
+
// Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
nmethodLocker nml(this);
methodHandle the_method(method());