--- old/src/share/vm/gc/shared/space.inline.hpp 2016-04-13 16:51:58.699402212 +0200 +++ new/src/share/vm/gc/shared/space.inline.hpp 2016-04-13 16:51:58.555402206 +0200 @@ -79,7 +79,6 @@ inline void CompactibleSpace::scan_and_forward(SpaceType* space, CompactPoint* cp) { // Compute the new addresses for the live objects and store it in the mark // Used by universe::mark_sweep_phase2() - HeapWord* compact_top; // This is where we are currently compacting to. // We're sure to be here before any objects are compacted into this // space, so this is a good time to initialize this: @@ -90,13 +89,12 @@ assert(cp->threshold == NULL, "just checking"); assert(cp->gen->first_compaction_space() == space, "just checking"); cp->space = cp->gen->first_compaction_space(); - compact_top = cp->space->bottom(); - cp->space->set_compaction_top(compact_top); cp->threshold = cp->space->initialize_threshold(); - } else { - compact_top = cp->space->compaction_top(); + cp->space->set_compaction_top(cp->space->bottom()); } + HeapWord* compact_top = cp->space->compaction_top(); // This is where we are currently compacting to. + // 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 @@ -110,43 +108,43 @@ allowed_deadspace = (space->capacity() * ratio / 100) / HeapWordSize; } - HeapWord* q = space->bottom(); - HeapWord* t = space->scan_limit(); - - 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. + HeapWord* end_of_live = space->bottom(); // One byte beyond the last byte of the last live object. + HeapWord* first_dead = NULL; // The first dead object. const intx interval = PrefetchScanIntervalInBytes; - while (q < t) { - assert(!space->scanned_block_is_obj(q) || - oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() || - oop(q)->mark()->has_bias_pattern(), + HeapWord* cur_obj = space->bottom(); + HeapWord* scan_limit = space->scan_limit(); + + while (cur_obj < scan_limit) { + assert(!space->scanned_block_is_obj(cur_obj) || + oop(cur_obj)->mark()->is_marked() || oop(cur_obj)->mark()->is_unlocked() || + oop(cur_obj)->mark()->has_bias_pattern(), "these are the only valid states during a mark sweep"); - if (space->scanned_block_is_obj(q) && oop(q)->is_gc_marked()) { + if (space->scanned_block_is_obj(cur_obj) && oop(cur_obj)->is_gc_marked()) { // prefetch beyond q - Prefetch::write(q, interval); - size_t size = space->scanned_block_size(q); - compact_top = cp->space->forward(oop(q), size, cp, compact_top); - q += size; - end_of_live = q; + Prefetch::write(cur_obj, interval); + size_t size = space->scanned_block_size(cur_obj); + compact_top = cp->space->forward(oop(cur_obj), size, cp, compact_top); + cur_obj += size; + end_of_live = cur_obj; } else { // run over all the contiguous dead objects - HeapWord* end = q; + HeapWord* end = cur_obj; do { // prefetch beyond end Prefetch::write(end, interval); end += space->scanned_block_size(end); - } while (end < t && (!space->scanned_block_is_obj(end) || !oop(end)->is_gc_marked())); + } while (end < scan_limit && (!space->scanned_block_is_obj(end) || !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 (space->insert_deadspace(allowed_deadspace, q, sz)) { - compact_top = cp->space->forward(oop(q), sz, cp, compact_top); - q = end; + if (allowed_deadspace > 0 && cur_obj == compact_top) { + assert(!UseG1GC, "G1 should not be allowing dead space"); + size_t sz = pointer_delta(end, cur_obj); + if (space->insert_deadspace(allowed_deadspace, cur_obj, sz)) { + compact_top = cp->space->forward(oop(cur_obj), sz, cp, compact_top); + cur_obj = end; end_of_live = end; continue; } @@ -154,25 +152,26 @@ // otherwise, it really is a free region. - // q is a pointer to a dead object. Use this dead memory to store a pointer to the next live object. - (*(HeapWord**)q) = end; + // cur_obj is a pointer to a dead object. Use this dead memory to store a pointer to the next live object. + *(HeapWord**)cur_obj = end; // see if this is the first dead region. - if (q < first_dead) { - first_dead = q; + if (first_dead == NULL) { + first_dead = cur_obj; } // move on to the next object - q = end; + cur_obj = end; } } - assert(q == t, "just checking"); + assert(cur_obj == scan_limit, "just checking"); space->_end_of_live = end_of_live; - if (end_of_live < first_dead) { - first_dead = end_of_live; + if (first_dead != NULL) { + space->_first_dead = first_dead; + } else { + space->_first_dead = end_of_live; } - space->_first_dead = first_dead; // save the compaction_top of the compaction space. cp->space->set_compaction_top(compact_top);