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 f5f5870 commit 5666863
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 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 @@ -314,18 +314,15 @@ HeapWord* MemAllocator::mem_allocate_inside_tlab_slow(Allocation& allocation) co
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
12 changes: 3 additions & 9 deletions src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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 @@ -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 @@ -777,18 +777,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
10 changes: 4 additions & 6 deletions src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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 @@ -1989,11 +1989,9 @@ void BytecodeInterpreter::run(interpreterState istate) {
size_t obj_size = ik->size_helper();
HeapWord* result = THREAD->tlab().allocate(obj_size);
if (result != nullptr) {
// 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 @@ -483,6 +483,9 @@ const int 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

1 comment on commit 5666863

@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.