238 }
239
240 _top = new_top;
241
242 return ZAddress::good(addr);
243 }
244
245 inline uintptr_t ZPage::alloc_object_atomic(size_t size) {
246 assert(is_allocating(), "Invalid state");
247
248 const size_t aligned_size = align_up(size, object_alignment());
249 uintptr_t addr = top();
250
251 for (;;) {
252 const uintptr_t new_top = addr + aligned_size;
253 if (new_top > end()) {
254 // Not enough space left
255 return 0;
256 }
257
258 const uintptr_t prev_top = Atomic::cmpxchg(new_top, &_top, addr);
259 if (prev_top == addr) {
260 // Success
261 return ZAddress::good(addr);
262 }
263
264 // Retry
265 addr = prev_top;
266 }
267 }
268
269 inline bool ZPage::undo_alloc_object(uintptr_t addr, size_t size) {
270 assert(is_allocating(), "Invalid state");
271
272 const uintptr_t offset = ZAddress::offset(addr);
273 const size_t aligned_size = align_up(size, object_alignment());
274 const uintptr_t old_top = top();
275 const uintptr_t new_top = old_top - aligned_size;
276
277 if (new_top != offset) {
278 // Failed to undo allocation, not the last allocated object
282 _top = new_top;
283
284 // Success
285 return true;
286 }
287
288 inline bool ZPage::undo_alloc_object_atomic(uintptr_t addr, size_t size) {
289 assert(is_allocating(), "Invalid state");
290
291 const uintptr_t offset = ZAddress::offset(addr);
292 const size_t aligned_size = align_up(size, object_alignment());
293 uintptr_t old_top = top();
294
295 for (;;) {
296 const uintptr_t new_top = old_top - aligned_size;
297 if (new_top != offset) {
298 // Failed to undo allocation, not the last allocated object
299 return false;
300 }
301
302 const uintptr_t prev_top = Atomic::cmpxchg(new_top, &_top, old_top);
303 if (prev_top == old_top) {
304 // Success
305 return true;
306 }
307
308 // Retry
309 old_top = prev_top;
310 }
311 }
312
313 #endif // SHARE_GC_Z_ZPAGE_INLINE_HPP
|
238 }
239
240 _top = new_top;
241
242 return ZAddress::good(addr);
243 }
244
245 inline uintptr_t ZPage::alloc_object_atomic(size_t size) {
246 assert(is_allocating(), "Invalid state");
247
248 const size_t aligned_size = align_up(size, object_alignment());
249 uintptr_t addr = top();
250
251 for (;;) {
252 const uintptr_t new_top = addr + aligned_size;
253 if (new_top > end()) {
254 // Not enough space left
255 return 0;
256 }
257
258 const uintptr_t prev_top = Atomic::cmpxchg(&_top, addr, new_top);
259 if (prev_top == addr) {
260 // Success
261 return ZAddress::good(addr);
262 }
263
264 // Retry
265 addr = prev_top;
266 }
267 }
268
269 inline bool ZPage::undo_alloc_object(uintptr_t addr, size_t size) {
270 assert(is_allocating(), "Invalid state");
271
272 const uintptr_t offset = ZAddress::offset(addr);
273 const size_t aligned_size = align_up(size, object_alignment());
274 const uintptr_t old_top = top();
275 const uintptr_t new_top = old_top - aligned_size;
276
277 if (new_top != offset) {
278 // Failed to undo allocation, not the last allocated object
282 _top = new_top;
283
284 // Success
285 return true;
286 }
287
288 inline bool ZPage::undo_alloc_object_atomic(uintptr_t addr, size_t size) {
289 assert(is_allocating(), "Invalid state");
290
291 const uintptr_t offset = ZAddress::offset(addr);
292 const size_t aligned_size = align_up(size, object_alignment());
293 uintptr_t old_top = top();
294
295 for (;;) {
296 const uintptr_t new_top = old_top - aligned_size;
297 if (new_top != offset) {
298 // Failed to undo allocation, not the last allocated object
299 return false;
300 }
301
302 const uintptr_t prev_top = Atomic::cmpxchg(&_top, old_top, new_top);
303 if (prev_top == old_top) {
304 // Success
305 return true;
306 }
307
308 // Retry
309 old_top = prev_top;
310 }
311 }
312
313 #endif // SHARE_GC_Z_ZPAGE_INLINE_HPP
|