Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8325870: Zap end padding bits for ArrayOops in non-release builds #17864

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/hotspot/share/gc/shared/memAllocator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
#include "services/lowMemoryDetector.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
#include "utilities/globalDefinitions.hpp"

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

#ifndef PRODUCT
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();
const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
const size_t size_in_bytes = _word_size * BytesPerWord;

const address obj_end = reinterpret_cast<address>(mem) + size_in_bytes;
const address base = reinterpret_cast<address>(mem) + base_offset_in_bytes;
const address elements_end = base + length_in_bytes;
assert(elements_end <= obj_end, "payload must fit in object");
if (elements_end < obj_end) {
const size_t padding_in_bytes = obj_end - elements_end;
Copy::fill_to_bytes(elements_end, padding_in_bytes, heapPaddingByteVal);
}
}
#endif

oop ClassAllocator::initialize(HeapWord* mem) const {
// Set oop_size field before setting the _klass field because a
// non-null _klass field indicates that the object is parsable by
4 changes: 3 additions & 1 deletion src/hotspot/share/gc/shared/memAllocator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -98,6 +98,8 @@ class ObjArrayAllocator: public MemAllocator {
const int _length;
const bool _do_zero;

void mem_zap_end_padding(HeapWord* mem) const PRODUCT_RETURN;

public:
ObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero,
Thread* thread = Thread::current())
4 changes: 3 additions & 1 deletion src/hotspot/share/gc/z/zObjArrayAllocator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -132,6 +132,8 @@ oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
assert(result, "Array initialization should always succeed the second time");
}

mem_zap_end_padding(mem);

ZThreadLocalData::clear_invisible_root(_thread);

// Signal to the ZIterator that this is no longer an invisible root
29 changes: 15 additions & 14 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1025,19 +1025,20 @@ enum LockingMode {
//----------------------------------------------------------------------------------------------------
// Special constants for debugging

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