375 assert(this == cp->space, "'this' should be current compaction space.");
376 size_t compaction_max_size = pointer_delta(end(), compact_top);
377 while (size > compaction_max_size) {
378 // switch to next compaction space
379 cp->space->set_compaction_top(compact_top);
380 cp->space = cp->space->next_compaction_space();
381 if (cp->space == NULL) {
382 cp->gen = GenCollectedHeap::heap()->young_gen();
383 assert(cp->gen != NULL, "compaction must succeed");
384 cp->space = cp->gen->first_compaction_space();
385 assert(cp->space != NULL, "generation must have a first compaction space");
386 }
387 compact_top = cp->space->bottom();
388 cp->space->set_compaction_top(compact_top);
389 cp->threshold = cp->space->initialize_threshold();
390 compaction_max_size = pointer_delta(cp->space->end(), compact_top);
391 }
392
393 // store the forwarding pointer into the mark word
394 if ((HeapWord*)q != compact_top) {
395 q->forward_to(oop(compact_top));
396 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
397 } else {
398 // if the object isn't moving we can just set the mark to the default
399 // mark and handle it specially later on.
400 q->init_mark();
401 assert(q->forwardee() == NULL, "should be forwarded to NULL");
402 }
403
404 compact_top += size;
405
406 // we need to update the offset table so that the beginnings of objects can be
407 // found during scavenge. Note that we are updating the offset table based on
408 // where the object will be once the compaction phase finishes.
409 if (compact_top > cp->threshold)
410 cp->threshold =
411 cp->space->cross_threshold(compact_top - size, compact_top);
412 return compact_top;
413 }
414
415
614 err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
615 p2i(p), p2i(bottom()), p2i(end())));
616 HeapWord* current_top = top();
617 assert(p <= current_top,
618 err_msg("p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT,
619 p2i(p), p2i(current_top)));
620 assert(p == current_top || oop(p)->is_oop(),
621 err_msg("p (" PTR_FORMAT ") is not a block start - "
622 "current_top: " PTR_FORMAT ", is_oop: %s",
623 p2i(p), p2i(current_top), BOOL_TO_STR(oop(p)->is_oop())));
624 if (p < current_top) {
625 return oop(p)->size();
626 } else {
627 assert(p == current_top, "just checking");
628 return pointer_delta(end(), (HeapWord*) p);
629 }
630 }
631
632 // This version requires locking.
633 inline HeapWord* ContiguousSpace::allocate_impl(size_t size) {
634 assert(Heap_lock->owned_by_self() ||
635 (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()),
636 "not locked");
637 HeapWord* obj = top();
638 if (pointer_delta(end(), obj) >= size) {
639 HeapWord* new_top = obj + size;
640 set_top(new_top);
641 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
642 return obj;
643 } else {
644 return NULL;
645 }
646 }
647
648 // This version is lock-free.
649 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
650 do {
651 HeapWord* obj = top();
652 if (pointer_delta(end(), obj) >= size) {
653 HeapWord* new_top = obj + size;
654 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
655 // result can be one of two:
|
375 assert(this == cp->space, "'this' should be current compaction space.");
376 size_t compaction_max_size = pointer_delta(end(), compact_top);
377 while (size > compaction_max_size) {
378 // switch to next compaction space
379 cp->space->set_compaction_top(compact_top);
380 cp->space = cp->space->next_compaction_space();
381 if (cp->space == NULL) {
382 cp->gen = GenCollectedHeap::heap()->young_gen();
383 assert(cp->gen != NULL, "compaction must succeed");
384 cp->space = cp->gen->first_compaction_space();
385 assert(cp->space != NULL, "generation must have a first compaction space");
386 }
387 compact_top = cp->space->bottom();
388 cp->space->set_compaction_top(compact_top);
389 cp->threshold = cp->space->initialize_threshold();
390 compaction_max_size = pointer_delta(cp->space->end(), compact_top);
391 }
392
393 // store the forwarding pointer into the mark word
394 if ((HeapWord*)q != compact_top) {
395 q->forward_to(compact_oop(compact_top));
396 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
397 } else {
398 // if the object isn't moving we can just set the mark to the default
399 // mark and handle it specially later on.
400 q->init_mark();
401 assert(q->forwardee() == NULL, "should be forwarded to NULL");
402 }
403
404 compact_top += size;
405
406 // we need to update the offset table so that the beginnings of objects can be
407 // found during scavenge. Note that we are updating the offset table based on
408 // where the object will be once the compaction phase finishes.
409 if (compact_top > cp->threshold)
410 cp->threshold =
411 cp->space->cross_threshold(compact_top - size, compact_top);
412 return compact_top;
413 }
414
415
614 err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
615 p2i(p), p2i(bottom()), p2i(end())));
616 HeapWord* current_top = top();
617 assert(p <= current_top,
618 err_msg("p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT,
619 p2i(p), p2i(current_top)));
620 assert(p == current_top || oop(p)->is_oop(),
621 err_msg("p (" PTR_FORMAT ") is not a block start - "
622 "current_top: " PTR_FORMAT ", is_oop: %s",
623 p2i(p), p2i(current_top), BOOL_TO_STR(oop(p)->is_oop())));
624 if (p < current_top) {
625 return oop(p)->size();
626 } else {
627 assert(p == current_top, "just checking");
628 return pointer_delta(end(), (HeapWord*) p);
629 }
630 }
631
632 // This version requires locking.
633 inline HeapWord* ContiguousSpace::allocate_impl(size_t size) {
634 // Shenandoah is currently partitioning by region so this assertion
635 // is too strong. If we move to a smaller granularity we will
636 // need to revisit this.
637 assert(Heap_lock->owned_by_self() ||
638 (SafepointSynchronize::is_at_safepoint() && (Thread::current()->is_VM_thread() || UseShenandoahGC)),
639 "not locked");
640 HeapWord* obj = top();
641 if (pointer_delta(end(), obj) >= size) {
642 HeapWord* new_top = obj + size;
643 set_top(new_top);
644 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
645 return obj;
646 } else {
647 return NULL;
648 }
649 }
650
651 // This version is lock-free.
652 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) {
653 do {
654 HeapWord* obj = top();
655 if (pointer_delta(end(), obj) >= size) {
656 HeapWord* new_top = obj + size;
657 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
658 // result can be one of two:
|