537 assert(Heap_lock->owned_by_self() ||
538 (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()),
539 "not locked");
540 HeapWord* obj = top();
541 if (pointer_delta(end(), obj) >= size) {
542 HeapWord* new_top = obj + size;
543 set_top(new_top);
544 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
545 return obj;
546 } else {
547 return NULL;
548 }
549 }
550
551 // This version is lock-free.
552 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
553 do {
554 HeapWord* obj = top();
555 if (pointer_delta(end(), obj) >= size) {
556 HeapWord* new_top = obj + size;
557 HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
558 // result can be one of two:
559 // the old top value: the exchange succeeded
560 // otherwise: the new value of the top is returned.
561 if (result == obj) {
562 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
563 return obj;
564 }
565 } else {
566 return NULL;
567 }
568 } while (true);
569 }
570
571 HeapWord* ContiguousSpace::allocate_aligned(size_t size) {
572 assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()), "not locked");
573 HeapWord* end_value = end();
574
575 HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end_value, SurvivorAlignmentInBytes);
576 if (obj == NULL) {
577 return NULL;
|
537 assert(Heap_lock->owned_by_self() ||
538 (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()),
539 "not locked");
540 HeapWord* obj = top();
541 if (pointer_delta(end(), obj) >= size) {
542 HeapWord* new_top = obj + size;
543 set_top(new_top);
544 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
545 return obj;
546 } else {
547 return NULL;
548 }
549 }
550
551 // This version is lock-free.
552 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
553 do {
554 HeapWord* obj = top();
555 if (pointer_delta(end(), obj) >= size) {
556 HeapWord* new_top = obj + size;
557 HeapWord* result = Atomic::cmpxchg(top_addr(), obj, new_top);
558 // result can be one of two:
559 // the old top value: the exchange succeeded
560 // otherwise: the new value of the top is returned.
561 if (result == obj) {
562 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
563 return obj;
564 }
565 } else {
566 return NULL;
567 }
568 } while (true);
569 }
570
571 HeapWord* ContiguousSpace::allocate_aligned(size_t size) {
572 assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()), "not locked");
573 HeapWord* end_value = end();
574
575 HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end_value, SurvivorAlignmentInBytes);
576 if (obj == NULL) {
577 return NULL;
|