--- old/src/share/vm/code/nmethod.cpp 2017-01-30 16:06:33.000000000 +0300 +++ new/src/share/vm/code/nmethod.cpp 2017-01-30 16:06:32.000000000 +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());