void CompactibleSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) { Space::initialize(mr, clear_space, mangle_space); set_compaction_top(bottom()); _next_compaction_space = NULL; }
void PSMarkSweepDecorator::precompact() { // Reset our own compact top. set_compaction_top(space()->bottom()); /* We allow some amount of garbage towards the bottom of the space, so * we don't start compacting before there is a significant gain to be made. * Occasionally, we want to ensure a full compaction, which is determined * by the MarkSweepAlwaysCompactCount parameter. This is a significant * performance improvement! */ bool skip_dead = ((PSMarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0); size_t allowed_deadspace = 0; if (skip_dead) { const size_t ratio = allowed_dead_ratio(); allowed_deadspace = space()->capacity_in_words() * ratio / 100; } // Fetch the current destination decorator PSMarkSweepDecorator* dest = destination_decorator(); ObjectStartArray* start_array = dest->start_array(); HeapWord* compact_top = dest->compaction_top(); HeapWord* compact_end = dest->space()->end(); HeapWord* q = space()->bottom(); HeapWord* t = space()->top(); HeapWord* end_of_live= q; /* One byte beyond the last byte of the last live object. */ HeapWord* first_dead = space()->end(); /* The first dead object. */ LiveRange* liveRange = NULL; /* The current live range, recorded in the first header of preceding free area. */ _first_dead = first_dead; const intx interval = PrefetchScanIntervalInBytes; while (q < t) { assert(oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() || oop(q)->mark()->has_bias_pattern(), "these are the only valid states during a mark sweep"); if (oop(q)->is_gc_marked()) { /* prefetch beyond q */ Prefetch::write(q, interval); size_t size = oop(q)->size(); size_t compaction_max_size = pointer_delta(compact_end, compact_top); // This should only happen if a space in the young gen overflows the // old gen. If that should happen, we null out the start_array, because // the young spaces are not covered by one. while(size > compaction_max_size) { // First record the last compact_top dest->set_compaction_top(compact_top); // Advance to the next compaction decorator advance_destination_decorator(); dest = destination_decorator(); // Update compaction info start_array = dest->start_array(); compact_top = dest->compaction_top(); compact_end = dest->space()->end(); assert(compact_top == dest->space()->bottom(), "Advanced to space already in use"); assert(compact_end > compact_top, "Must always be space remaining"); compaction_max_size = pointer_delta(compact_end, compact_top); } // store the forwarding pointer into the mark word if (q != compact_top) { oop(q)->forward_to(oop(compact_top)); assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark"); } else { // if the object isn't moving we can just set the mark to the default // mark and handle it specially later on. oop(q)->init_mark(); assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL"); } // Update object start array if (start_array) { start_array->allocate_block(compact_top); } VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(oop(q), size)); compact_top += size; assert(compact_top <= dest->space()->end(), "Exceeding space in destination"); q += size; end_of_live = q; } else { /* run over all the contiguous dead objects */ HeapWord* end = q; do { /* prefetch beyond end */ Prefetch::write(end, interval); end += oop(end)->size(); } while (end < t && (!oop(end)->is_gc_marked())); /* see if we might want to pretend this object is alive so that * we don't have to compact quite as often. */ if (allowed_deadspace > 0 && q == compact_top) { size_t sz = pointer_delta(end, q); if (insert_deadspace(allowed_deadspace, q, sz)) { size_t compaction_max_size = pointer_delta(compact_end, compact_top); // This should only happen if a space in the young gen overflows the // old gen. If that should happen, we null out the start_array, because // the young spaces are not covered by one. while (sz > compaction_max_size) { // First record the last compact_top dest->set_compaction_top(compact_top); // Advance to the next compaction decorator advance_destination_decorator(); dest = destination_decorator(); // Update compaction info start_array = dest->start_array(); compact_top = dest->compaction_top(); compact_end = dest->space()->end(); assert(compact_top == dest->space()->bottom(), "Advanced to space already in use"); assert(compact_end > compact_top, "Must always be space remaining"); compaction_max_size = pointer_delta(compact_end, compact_top); } // store the forwarding pointer into the mark word if (q != compact_top) { oop(q)->forward_to(oop(compact_top)); assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark"); } else { // if the object isn't moving we can just set the mark to the default // mark and handle it specially later on. oop(q)->init_mark(); assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL"); } // Update object start array if (start_array) { start_array->allocate_block(compact_top); } VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(oop(q), sz)); compact_top += sz; assert(compact_top <= dest->space()->end(), "Exceeding space in destination"); q = end; end_of_live = end; continue; } } /* for the previous LiveRange, record the end of the live objects. */ if (liveRange) { liveRange->set_end(q); } /* record the current LiveRange object. * liveRange->start() is overlaid on the mark word. */ liveRange = (LiveRange*)q; liveRange->set_start(end); liveRange->set_end(end); /* see if this is the first dead region. */ if (q < first_dead) { first_dead = q; } /* move on to the next object */ q = end; } } assert(q == t, "just checking"); if (liveRange != NULL) { liveRange->set_end(q); } _end_of_live = end_of_live; if (end_of_live < first_dead) { first_dead = end_of_live; } _first_dead = first_dead; // Update compaction top dest->set_compaction_top(compact_top); }