Skip to content

Commit 10eafdc

Browse files
committed
8325870: Zap end padding bits for ArrayOops in non-release builds
Reviewed-by: stefank, ayang
1 parent 0f4cd8f commit 10eafdc

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

src/hotspot/share/gc/shared/memAllocator.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
4141
#include "services/lowMemoryDetector.hpp"
4242
#include "utilities/align.hpp"
4343
#include "utilities/copy.hpp"
44+
#include "utilities/globalDefinitions.hpp"
4445

4546
class MemAllocator::Allocation: StackObj {
4647
friend class MemAllocator;
@@ -408,11 +409,30 @@ oop ObjArrayAllocator::initialize(HeapWord* mem) const {
408409
assert(_length >= 0, "length should be non-negative");
409410
if (_do_zero) {
410411
mem_clear(mem);
412+
mem_zap_end_padding(mem);
411413
}
412414
arrayOopDesc::set_length(mem, _length);
413415
return finish(mem);
414416
}
415417

418+
#ifndef PRODUCT
419+
void ObjArrayAllocator::mem_zap_end_padding(HeapWord* mem) const {
420+
const size_t length_in_bytes = static_cast<size_t>(_length) << ArrayKlass::cast(_klass)->log2_element_size();
421+
const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
422+
const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
423+
const size_t size_in_bytes = _word_size * BytesPerWord;
424+
425+
const address obj_end = reinterpret_cast<address>(mem) + size_in_bytes;
426+
const address base = reinterpret_cast<address>(mem) + base_offset_in_bytes;
427+
const address elements_end = base + length_in_bytes;
428+
assert(elements_end <= obj_end, "payload must fit in object");
429+
if (elements_end < obj_end) {
430+
const size_t padding_in_bytes = obj_end - elements_end;
431+
Copy::fill_to_bytes(elements_end, padding_in_bytes, heapPaddingByteVal);
432+
}
433+
}
434+
#endif
435+
416436
oop ClassAllocator::initialize(HeapWord* mem) const {
417437
// Set oop_size field before setting the _klass field because a
418438
// non-null _klass field indicates that the object is parsable by

src/hotspot/share/gc/shared/memAllocator.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -98,6 +98,8 @@ class ObjArrayAllocator: public MemAllocator {
9898
const int _length;
9999
const bool _do_zero;
100100

101+
void mem_zap_end_padding(HeapWord* mem) const PRODUCT_RETURN;
102+
101103
public:
102104
ObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero,
103105
Thread* thread = Thread::current())

src/hotspot/share/gc/z/zObjArrayAllocator.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -132,6 +132,8 @@ oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
132132
assert(result, "Array initialization should always succeed the second time");
133133
}
134134

135+
mem_zap_end_padding(mem);
136+
135137
ZThreadLocalData::clear_invisible_root(_thread);
136138

137139
// Signal to the ZIterator that this is no longer an invisible root

src/hotspot/share/utilities/globalDefinitions.hpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1028,19 +1028,20 @@ enum LockingMode {
10281028
//----------------------------------------------------------------------------------------------------
10291029
// Special constants for debugging
10301030

1031-
const jint badInt = -3; // generic "bad int" value
1032-
const intptr_t badAddressVal = -2; // generic "bad address" value
1033-
const intptr_t badOopVal = -1; // generic "bad oop" value
1034-
const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
1035-
const int badStackSegVal = 0xCA; // value used to zap stack segments
1036-
const int badHandleValue = 0xBC; // value used to zap vm handle area
1037-
const int badResourceValue = 0xAB; // value used to zap resource area
1038-
const int freeBlockPad = 0xBA; // value used to pad freed blocks.
1039-
const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
1040-
const juint uninitMetaWordVal= 0xf7f7f7f7; // value used to zap newly allocated metachunk
1041-
const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
1042-
const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC
1043-
const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation
1031+
const jint badInt = -3; // generic "bad int" value
1032+
const intptr_t badAddressVal = -2; // generic "bad address" value
1033+
const intptr_t badOopVal = -1; // generic "bad oop" value
1034+
const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
1035+
const int badStackSegVal = 0xCA; // value used to zap stack segments
1036+
const int badHandleValue = 0xBC; // value used to zap vm handle area
1037+
const int badResourceValue = 0xAB; // value used to zap resource area
1038+
const int freeBlockPad = 0xBA; // value used to pad freed blocks.
1039+
const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
1040+
const juint uninitMetaWordVal = 0xf7f7f7f7; // value used to zap newly allocated metachunk
1041+
const jubyte heapPaddingByteVal = 0xBD; // value used to zap object padding in the heap
1042+
const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
1043+
const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC
1044+
const int badCodeHeapNewVal = 0xCC; // value used to zap Code heap at allocation
10441045
const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation
10451046
const intptr_t badDispHeaderDeopt = 0xDE0BD000; // value to fill unused displaced header during deoptimization
10461047
const intptr_t badDispHeaderOSR = 0xDEAD05A0; // value to fill unused displaced header during OSR

0 commit comments

Comments
 (0)