diff --git a/src/hotspot/share/gc/shared/barrierSetNMethod.cpp b/src/hotspot/share/gc/shared/barrierSetNMethod.cpp index 2d7b3513f0b..79d8a3f85b9 100644 --- a/src/hotspot/share/gc/shared/barrierSetNMethod.cpp +++ b/src/hotspot/share/gc/shared/barrierSetNMethod.cpp @@ -83,7 +83,10 @@ void BarrierSetNMethod::arm_with(nmethod* nm, int value) { if (is_not_entrant(nm)) { value |= not_entrant; } - set_guard_value(nm, value); + if (guard_value(nm) != value) { + // Patch the code only if needed. + set_guard_value(nm, value); + } } bool BarrierSetNMethod::is_armed(nmethod* nm) { diff --git a/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp b/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp index 5754d208a4f..52412ef1fcc 100644 --- a/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp +++ b/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp @@ -113,7 +113,10 @@ void ZBarrierSetNMethod::arm_with(nmethod* nm, int value) { if (is_not_entrant(nm)) { value |= not_entrant; } - set_guard_value(nm, value); + if (guard_value(nm) != value) { + // Patch the code only if needed. + set_guard_value(nm, value); + } } bool ZBarrierSetNMethod::is_armed(nmethod* nm) {