From 553d45b11460a794613651373f34c8379c11729b Mon Sep 17 00:00:00 2001 From: Fredrik Bredberg Date: Thu, 2 May 2024 13:53:45 +0000 Subject: [PATCH] 8323724: Remove potential re-inflation from FastHashCode under LM_LIGHTWEIGHT Reviewed-by: aboldtch, coleenp --- src/hotspot/share/runtime/synchronizer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/runtime/synchronizer.cpp b/src/hotspot/share/runtime/synchronizer.cpp index 356be7cba435d..f8d4b32315665 100644 --- a/src/hotspot/share/runtime/synchronizer.cpp +++ b/src/hotspot/share/runtime/synchronizer.cpp @@ -1077,9 +1077,11 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) { // Inflate the monitor to set the hash. - // An async deflation can race after the inflate() call and before we - // can update the ObjectMonitor's header with the hash value below. - monitor = inflate(current, obj, inflate_cause_hash_code); + // There's no need to inflate if the mark has already got a monitor. + // NOTE: an async deflation can race after we get the monitor and + // before we can update the ObjectMonitor's header with the hash + // value below. + monitor = mark.has_monitor() ? mark.monitor() : inflate(current, obj, inflate_cause_hash_code); // Load ObjectMonitor's header/dmw field and see if it has a hash. mark = monitor->header(); assert(mark.is_neutral(), "invariant: header=" INTPTR_FORMAT, mark.value());