From fbb50f5c6c2afca959c38ca8432d7b32c94d6f92 Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Thu, 30 Apr 2026 09:39:12 +0000 Subject: [PATCH] 8383564: Avoid reloading klass when transforming stack chunks Reviewed-by: stefank, tschatzl --- src/hotspot/share/gc/g1/g1ParScanThreadState.cpp | 2 +- src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp | 2 +- src/hotspot/share/gc/serial/defNewGeneration.cpp | 5 +++-- src/hotspot/share/gc/shared/continuationGCSupport.hpp | 3 +++ .../share/gc/shared/continuationGCSupport.inline.hpp | 6 +++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp index 50438c641c2..45e1b25cb95 100644 --- a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp +++ b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp @@ -444,7 +444,7 @@ void G1ParScanThreadState::do_iterate_object(oop const obj, return; } - ContinuationGCSupport::transform_stack_chunk(obj); + ContinuationGCSupport::transform_stack_chunk(obj, klass); // Check for deduplicating young Strings. if (G1StringDedup::is_candidate_from_evacuation(klass, diff --git a/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp b/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp index 47970ac25cb..4b9edeb7072 100644 --- a/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp +++ b/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp @@ -292,7 +292,7 @@ inline oop PSPromotionManager::copy_unmarked_to_survivor_space(oop o, assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj"); } - ContinuationGCSupport::transform_stack_chunk(new_obj); + ContinuationGCSupport::transform_stack_chunk(new_obj, klass); // Do the size comparison first with new_obj_size, which we // already have. Hopefully, only a few objects are larger than diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index ec3726d1dce..0a98d099744 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -698,7 +698,8 @@ void DefNewGeneration::handle_promotion_failure(oop old) { oop DefNewGeneration::copy_to_survivor_space(oop old) { assert(is_in_reserved(old) && !old->is_forwarded(), "shouldn't be scavenging this oop"); - size_t s = old->size(); + Klass* klass = old->klass(); + size_t s = old->size_given_klass(klass); oop obj = nullptr; // Try allocating obj in to-space (unless too old) @@ -725,7 +726,7 @@ oop DefNewGeneration::copy_to_survivor_space(oop old) { // Copy obj Copy::aligned_disjoint_words(cast_from_oop(old), cast_from_oop(obj), s); - ContinuationGCSupport::transform_stack_chunk(obj); + ContinuationGCSupport::transform_stack_chunk(obj, klass); if (!new_obj_is_tenured) { // Increment age if obj still in new generation diff --git a/src/hotspot/share/gc/shared/continuationGCSupport.hpp b/src/hotspot/share/gc/shared/continuationGCSupport.hpp index dda983e0bd8..8aa0245201d 100644 --- a/src/hotspot/share/gc/shared/continuationGCSupport.hpp +++ b/src/hotspot/share/gc/shared/continuationGCSupport.hpp @@ -28,6 +28,8 @@ #include "memory/allStatic.hpp" #include "oops/oopsHierarchy.hpp" +class Klass; + class ContinuationGCSupport : public AllStatic { public: // Relativize the given oop if it is a stack chunk. @@ -35,6 +37,7 @@ public: // Relativize and transform to use a bitmap for future oop iteration for the // given oop if it is a stack chunk. static void transform_stack_chunk(oop obj); + static void transform_stack_chunk(oop obj, Klass* klass); }; #endif // SHARE_GC_SHARED_CONTINUATIONGCSUPPORT_HPP diff --git a/src/hotspot/share/gc/shared/continuationGCSupport.inline.hpp b/src/hotspot/share/gc/shared/continuationGCSupport.inline.hpp index 72a828b7396..321ef51f9ae 100644 --- a/src/hotspot/share/gc/shared/continuationGCSupport.inline.hpp +++ b/src/hotspot/share/gc/shared/continuationGCSupport.inline.hpp @@ -43,7 +43,11 @@ inline bool ContinuationGCSupport::relativize_stack_chunk(oop obj) { } inline void ContinuationGCSupport::transform_stack_chunk(oop obj) { - if (!obj->is_stackChunk()) { + transform_stack_chunk(obj, obj->klass()); +} + +inline void ContinuationGCSupport::transform_stack_chunk(oop obj, Klass* klass) { + if (!klass->is_stack_chunk_instance_klass()) { return; }