614 assert(Heap_lock->owned_by_self() ||
615 (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()),
616 "not locked");
617 HeapWord* obj = top();
618 if (pointer_delta(end(), obj) >= size) {
619 HeapWord* new_top = obj + size;
620 set_top(new_top);
621 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
622 return obj;
623 } else {
624 return NULL;
625 }
626 }
627
628 // This version is lock-free.
629 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
630 do {
631 HeapWord* obj = top();
632 if (pointer_delta(end(), obj) >= size) {
633 HeapWord* new_top = obj + size;
634 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
635 // result can be one of two:
636 // the old top value: the exchange succeeded
637 // otherwise: the new value of the top is returned.
638 if (result == obj) {
639 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
640 return obj;
641 }
642 } else {
643 return NULL;
644 }
645 } while (true);
646 }
647
648 HeapWord* ContiguousSpace::allocate_aligned(size_t size) {
649 assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()), "not locked");
650 HeapWord* end_value = end();
651
652 HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end_value, SurvivorAlignmentInBytes);
653 if (obj == NULL) {
654 return NULL;
|
614 assert(Heap_lock->owned_by_self() ||
615 (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()),
616 "not locked");
617 HeapWord* obj = top();
618 if (pointer_delta(end(), obj) >= size) {
619 HeapWord* new_top = obj + size;
620 set_top(new_top);
621 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
622 return obj;
623 } else {
624 return NULL;
625 }
626 }
627
628 // This version is lock-free.
629 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
630 do {
631 HeapWord* obj = top();
632 if (pointer_delta(end(), obj) >= size) {
633 HeapWord* new_top = obj + size;
634 HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
635 // result can be one of two:
636 // the old top value: the exchange succeeded
637 // otherwise: the new value of the top is returned.
638 if (result == obj) {
639 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
640 return obj;
641 }
642 } else {
643 return NULL;
644 }
645 } while (true);
646 }
647
648 HeapWord* ContiguousSpace::allocate_aligned(size_t size) {
649 assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()), "not locked");
650 HeapWord* end_value = end();
651
652 HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end_value, SurvivorAlignmentInBytes);
653 if (obj == NULL) {
654 return NULL;
|