We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d90e06a commit 685c03dCopy full SHA for 685c03d
src/hotspot/share/gc/parallel/mutableSpace.cpp
@@ -194,7 +194,11 @@ HeapWord* MutableSpace::allocate(size_t size) {
194
// This version is lock-free.
195
HeapWord* MutableSpace::cas_allocate(size_t size) {
196
do {
197
- HeapWord* obj = top();
+ // Read top before end, else the range check may pass when it shouldn't.
198
+ // If end is read first, other threads may advance end and top such that
199
+ // current top > old end and current top + size > current end. Then
200
+ // pointer_delta underflows, allowing installation of top > current end.
201
+ HeapWord* obj = Atomic::load_acquire(top_addr());
202
if (pointer_delta(end(), obj) >= size) {
203
HeapWord* new_top = obj + size;
204
HeapWord* result = Atomic::cmpxchg(top_addr(), obj, new_top);
0 commit comments