Skip to content

Commit

Permalink
8329134: Reconsider TLAB zapping
Browse files Browse the repository at this point in the history
Backport-of: 5698f7ad29c939b7e52882ace575dd7113bf41de
  • Loading branch information
pengxiaolong authored and shipilev committed Jun 3, 2024
1 parent 33ab474 commit 09ad130
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
7 changes: 2 additions & 5 deletions src/hotspot/share/gc/shared/memAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,15 @@ HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const
PTR_FORMAT " min: " SIZE_FORMAT ", desired: " SIZE_FORMAT,
p2i(mem), min_tlab_size, new_tlab_size);

// ...and clear or zap just allocated TLAB, if needed.
if (ZeroTLAB) {
// ..and clear it.
Copy::zero_to_words(mem, allocation._allocated_tlab_size);
} else {
// ...and zap just allocated object.
#ifdef ASSERT
} else if (ZapTLAB) {
// Skip mangling the space corresponding to the object header to
// ensure that the returned space is not considered parsable by
// any concurrent GC thread.
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(mem + hdr_size, allocation._allocated_tlab_size - hdr_size, badHeapWordVal);
#endif // ASSERT
}

tlab.fill(mem, mem + _word_size, allocation._allocated_tlab_size);
Expand Down
10 changes: 2 additions & 8 deletions src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
invariants();
HeapWord* obj = top();
if (pointer_delta(end(), obj) >= size) {
// successful thread-local allocation
#ifdef ASSERT
// Skip mangling the space corresponding to the object header to
// ensure that the returned space is not considered parsable by
// any concurrent GC thread.
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal);
#endif // ASSERT
// Successful thread-local allocation.

// This addition is safe because we know that top is
// at least size below end, so the add can't wrap.
set_top(obj + size);
Expand Down
7 changes: 2 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,18 +778,15 @@ HeapWord* ShenandoahHeap::allocate_from_gclab_slow(Thread* thread, size_t size)

assert (size <= actual_size, "allocation should fit");

// ...and clear or zap just allocated TLAB, if needed.
if (ZeroTLAB) {
// ..and clear it.
Copy::zero_to_words(gclab_buf, actual_size);
} else {
// ...and zap just allocated object.
#ifdef ASSERT
} else if (ZapTLAB) {
// Skip mangling the space corresponding to the object header to
// ensure that the returned space is not considered parsable by
// any concurrent GC thread.
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(gclab_buf + hdr_size, actual_size - hdr_size, badHeapWordVal);
#endif // ASSERT
}
gclab->set_buf(gclab_buf, actual_size);
return gclab->allocate(size);
Expand Down
8 changes: 3 additions & 5 deletions src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,11 +1942,9 @@ void BytecodeInterpreter::run(interpreterState istate) {
size_t obj_size = ik->size_helper();
HeapWord* result = THREAD->tlab().allocate(obj_size);
if (result != NULL) {
// Initialize object field block:
// - if TLAB is pre-zeroed, we can skip this path
// - in debug mode, ThreadLocalAllocBuffer::allocate mangles
// this area, and we still need to initialize it
if (DEBUG_ONLY(true ||) !ZeroTLAB) {
// Initialize object field block.
if (!ZeroTLAB) {
// The TLAB was not pre-zeroed, we need to clear the memory here.
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
}
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ const intx ObjectAlignmentInBytes = 8;
develop(bool, ZapFillerObjects, trueInDebug, \
"Zap filler objects") \
\
develop(bool, ZapTLAB, trueInDebug, \
"Zap allocated TLABs") \
\
product(bool, ExecutingUnitTests, false, \
"Whether the JVM is running unit tests or not") \
\
Expand Down

0 comments on commit 09ad130

Please sign in to comment.