8329994: Zap alignment padding bits for ArrayOops in non-release builds

Reviewed-by: ayang, sjohanss
This commit is contained in:
Axel Boldt-Christmas 2024-06-24 06:06:45 +00:00
parent a4582a8957
commit 863b2a991d
3 changed files with 18 additions and 0 deletions

View File

@ -388,6 +388,7 @@ oop ObjArrayAllocator::initialize(HeapWord* mem) const {
assert(_length >= 0, "length should be non-negative");
if (_do_zero) {
mem_clear(mem);
mem_zap_start_padding(mem);
mem_zap_end_padding(mem);
}
arrayOopDesc::set_length(mem, _length);
@ -395,6 +396,20 @@ oop ObjArrayAllocator::initialize(HeapWord* mem) const {
}
#ifndef PRODUCT
void ObjArrayAllocator::mem_zap_start_padding(HeapWord* mem) const {
const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
const size_t header_size_in_bytes = arrayOopDesc::header_size_in_bytes();
const address base = reinterpret_cast<address>(mem) + base_offset_in_bytes;
const address header_end = reinterpret_cast<address>(mem) + header_size_in_bytes;
if (header_end < base) {
const size_t padding_in_bytes = base - header_end;
Copy::fill_to_bytes(header_end, padding_in_bytes, heapPaddingByteVal);
}
}
void ObjArrayAllocator::mem_zap_end_padding(HeapWord* mem) const {
const size_t length_in_bytes = static_cast<size_t>(_length) << ArrayKlass::cast(_klass)->log2_element_size();
const BasicType element_type = ArrayKlass::cast(_klass)->element_type();

View File

@ -94,6 +94,7 @@ protected:
const int _length;
const bool _do_zero;
void mem_zap_start_padding(HeapWord* mem) const PRODUCT_RETURN;
void mem_zap_end_padding(HeapWord* mem) const PRODUCT_RETURN;
public:

View File

@ -139,6 +139,8 @@ oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
return true;
};
mem_zap_start_padding(mem);
if (!initialize_memory()) {
// Re-color with 11 remset bits if we got intercepted by a GC safepoint
const bool result = initialize_memory();