Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 49355ef

Browse files
Olga MikhaltsovaYuri Nesterenko
authored andcommitted
8259271: gc/parallel/TestDynShrinkHeap.java still fails "assert(covered_region.contains(new_memregion)) failed: new region is not in covered_region"
Use load_acquire to order reads of top and end. Reviewed-by: yan Backport-of: 685c03d
1 parent 56d491c commit 49355ef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/hotspot/share/gc/parallel/mutableSpace.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ HeapWord* MutableSpace::allocate(size_t size) {
196196
// This version is lock-free.
197197
HeapWord* MutableSpace::cas_allocate(size_t size) {
198198
do {
199-
HeapWord* obj = top();
199+
// Read top before end, else the range check may pass when it shouldn't.
200+
// If end is read first, other threads may advance end and top such that
201+
// current top > old end and current top + size > current end. Then
202+
// pointer_delta underflows, allowing installation of top > current end.
203+
HeapWord* obj = OrderAccess::load_acquire(top_addr());
200204
if (pointer_delta(end(), obj) >= size) {
201205
HeapWord* new_top = obj + size;
202206
HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);

0 commit comments

Comments
 (0)