Skip to content

Commit

Permalink
8325870: Zap end padding bits for ArrayOops in non-release builds
Browse files Browse the repository at this point in the history
Reviewed-by: stefank, ayang
  • Loading branch information
xmas92 committed Feb 22, 2024
1 parent 0f4cd8f commit 10eafdc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
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
Expand Down Expand Up @@ -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())
Expand Down
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
Expand Down Expand Up @@ -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
Expand Down
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
Expand Down Expand Up @@ -1028,19 +1028,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
Expand Down

1 comment on commit 10eafdc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.