8383861: Shenandoah: Use int[] as filling class for compressed oop array allocation

Reviewed-by: shade, kdnilsen
This commit is contained in:
Xiaolong Peng 2026-05-08 22:06:14 +00:00
parent 0b0a5a71a3
commit 83cd98426e
3 changed files with 29 additions and 8 deletions

View File

@ -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);

View File

@ -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

View File

@ -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,