From 83cd98426ed97e14aa1521d7253bc0f88aa502e8 Mon Sep 17 00:00:00 2001 From: Xiaolong Peng Date: Fri, 8 May 2026 22:06:14 +0000 Subject: [PATCH] 8383861: Shenandoah: Use int[] as filling class for compressed oop array allocation Reviewed-by: shade, kdnilsen --- .../gc/shenandoah/shenandoahObjArrayAllocator.cpp | 13 +++++-------- .../jtreg/gc/shenandoah/TestLargeArrayInit.java | 12 ++++++++++++ .../gc/shenandoah/TestLargeArrayInitGCStress.java | 12 ++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahObjArrayAllocator.cpp b/src/hotspot/share/gc/shenandoah/shenandoahObjArrayAllocator.cpp index e2215ea58ef..dc9fef16cf6 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahObjArrayAllocator.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahObjArrayAllocator.cpp @@ -71,16 +71,14 @@ oop ShenandoahObjArrayAllocator::initialize(HeapWord* mem) const { // Always initialize the mem with primitive array first so GC won't look into the elements in the array. // For obj array, the header will be corrected to object array after clearing the memory. Klass* filling_klass = _klass; - int filling_array_length = _length; - const bool is_ref_type = is_reference_type(element_type, true); + const bool is_ref_type = is_reference_type(element_type); if (is_ref_type) { - const bool is_narrow_oop = element_type == T_NARROWOOP; - size_t filling_element_byte_size = is_narrow_oop ? T_INT_aelem_bytes : T_LONG_aelem_bytes; - filling_klass = is_narrow_oop ? Universe::intArrayKlass() : Universe::longArrayKlass(); - filling_array_length = (int) ((process_size << LogBytesPerWord) / filling_element_byte_size); + filling_klass = LP64_ONLY(UseCompressedOops ? Universe::intArrayKlass() : Universe::longArrayKlass()) NOT_LP64(Universe::intArrayKlass()); + assert(type2aelembytes(ArrayKlass::cast(filling_klass)->element_type()) == type2aelembytes(element_type), "filling element size must match ref size"); } - ObjArrayAllocator filling_array_allocator(filling_klass, _word_size, filling_array_length , /* do_zero */ false); + // Use _length directly: it matches the ref count, and the filling element size equals the ref size. + ObjArrayAllocator filling_array_allocator(filling_klass, _word_size, _length, /* do_zero */ false); filling_array_allocator.initialize(mem); // Invisible roots will be scanned and marked at the end of marking. @@ -106,7 +104,6 @@ oop ShenandoahObjArrayAllocator::initialize(HeapWord* mem) const { // reference array, header need to be overridden to its own. if (is_ref_type) { - arrayOopDesc::set_length(mem, _length); finish(mem); // zap paddings after setting correct klass mem_zap_start_padding(mem); diff --git a/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInit.java b/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInit.java index 9ce254ff845..83c74866a95 100644 --- a/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInit.java +++ b/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInit.java @@ -68,6 +68,18 @@ * TestLargeArrayInit */ +/* + * @test id=compressed-oops-off + * @summary Verify zero-initialization completeness for large arrays with compressed oops disabled + * @requires vm.gc.Shenandoah + * @library /test/lib + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m -Xms512m + * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive + * -XX:-UseCompressedOops + * TestLargeArrayInit + */ + /** * * Allocates large byte[], int[], long[], and Object[] arrays whose sizes span diff --git a/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInitGCStress.java b/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInitGCStress.java index 34f3b70197a..6dfd250e3cc 100644 --- a/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInitGCStress.java +++ b/test/hotspot/jtreg/gc/shenandoah/TestLargeArrayInitGCStress.java @@ -69,6 +69,18 @@ * TestLargeArrayInitGCStress */ +/* + * @test id=compressed-oops-off + * @summary Verify correct object metadata for large arrays with compressed oops disabled under GC stress + * @requires vm.gc.Shenandoah + * @library /test/lib + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx256m -Xms256m + * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive + * -XX:-UseCompressedOops + * TestLargeArrayInitGCStress + */ + /** * * Allocates large arrays of various types under GC stress (aggressive heuristics,