changeset 9415:bc32046eef89

8259271: gc/parallel/TestDynShrinkHeap.java still fails "assert(covered_region.contains(new_memregion)) failed: new region is not in covered_region" Summary: Use load_acquire to order reads of top and end. Reviewed-by: tschatzl, iwalulya, eosterlund
author kbarrett
date Fri, 22 Jan 2021 11:20:52 +0000
parents 6f024d171932
children a4312636c0f7
files src/share/vm/gc_implementation/shared/mutableSpace.cpp
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Thu Dec 17 14:18:00 2020 +0000
+++ b/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Fri Jan 22 11:20:52 2021 +0000
@@ -28,6 +28,7 @@
 #include "gc_implementation/shared/mutableSpace.hpp"
 #include "gc_implementation/shared/spaceDecorator.hpp"
 #include "oops/oop.inline.hpp"
+#include "runtime/orderAccess.hpp"
 #include "runtime/safepoint.hpp"
 #include "runtime/thread.hpp"
 #endif // INCLUDE_ALL_GCS
@@ -192,7 +193,11 @@
 // This version is lock-free.
 HeapWord* MutableSpace::cas_allocate(size_t size) {
   do {
-    HeapWord* obj = top();
+    // Read top before end, else the range check may pass when it shouldn't.
+    // If end is read first, other threads may advance end and top such that
+    // current top > old end and current top + size > current end.  Then
+    // pointer_delta underflows, allowing installation of top > current end.
+    HeapWord* obj = (HeapWord*)OrderAccess::load_ptr_acquire(top_addr());
     if (pointer_delta(end(), obj) >= size) {
       HeapWord* new_top = obj + size;
       HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);