--- a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp Fri Sep 05 12:36:37 2014 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp Tue Sep 09 00:05:25 2014 +0200
@@ -193,76 +193,6 @@
gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
}
-class G1PrepareCompactClosure: public HeapRegionClosure {
- G1CollectedHeap* _g1h;
- ModRefBarrierSet* _mrbs;
- CompactPoint _cp;
- HeapRegionSetCount _humongous_regions_removed;
-
- bool is_cp_initialized() const {
- return _cp.space != NULL;
- }
-
- void prepare_for_compaction(HeapRegion* hr, HeapWord* end) {
- // If this is the first live region that we came across which we can compact,
- // initialize the CompactPoint.
- if (!is_cp_initialized()) {
- _cp.space = hr;
- _cp.threshold = hr->initialize_threshold();
- }
- hr->prepare_for_compaction(&_cp);
- // Also clear the part of the card table that will be unused after
- // compaction.
- _mrbs->clear(MemRegion(hr->compaction_top(), end));
- }
-
- void free_humongous_region(HeapRegion* hr) {
- HeapWord* end = hr->end();
- FreeRegionList dummy_free_list("Dummy Free List for G1MarkSweep");
-
- assert(hr->startsHumongous(),
- "Only the start of a humongous region should be freed.");
-
- hr->set_containing_set(NULL);
- _humongous_regions_removed.increment(1u, hr->capacity());
-
- _g1h->free_humongous_region(hr, &dummy_free_list, false /* par */);
- prepare_for_compaction(hr, end);
- dummy_free_list.remove_all();
- }
-
-public:
- G1PrepareCompactClosure()
- : _g1h(G1CollectedHeap::heap()),
- _mrbs(_g1h->g1_barrier_set()),
- _cp(NULL),
- _humongous_regions_removed() { }
-
- void update_sets() {
- // We'll recalculate total used bytes and recreate the free list
- // at the end of the GC, so no point in updating those values here.
- HeapRegionSetCount empty_set;
- _g1h->remove_from_old_sets(empty_set, _humongous_regions_removed);
- }
-
- bool doHeapRegion(HeapRegion* hr) {
- if (hr->isHumongous()) {
- if (hr->startsHumongous()) {
- oop obj = oop(hr->bottom());
- if (obj->is_gc_marked()) {
- obj->forward_to(obj);
- } else {
- free_humongous_region(hr);
- }
- } else {
- assert(hr->continuesHumongous(), "Invalid humongous.");
- }
- } else {
- prepare_for_compaction(hr, hr->end());
- }
- return false;
- }
-};
void G1MarkSweep::mark_sweep_phase2() {
// Now all live objects are marked, compute the new object addresses.
@@ -271,14 +201,10 @@
// phase2, phase3 and phase4, but the ValidateMarkSweep live oops
// tracking expects us to do so. See comment under phase4.
- G1CollectedHeap* g1h = G1CollectedHeap::heap();
-
GCTraceTime tm("phase 2", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
GenMarkSweep::trace("2");
- G1PrepareCompactClosure blk;
- g1h->heap_region_iterate(&blk);
- blk.update_sets();
+ prepare_compaction();
}
class G1AdjustPointersClosure: public HeapRegionClosure {
@@ -373,3 +299,68 @@
g1h->heap_region_iterate(&blk);
}
+
+void G1MarkSweep::prepare_compaction_work(G1PrepareCompactClosure* blk) {
+ G1CollectedHeap* g1h = G1CollectedHeap::heap();
+ g1h->heap_region_iterate(blk);
+ blk->update_sets();
+}
+
+void G1PrepareCompactClosure::free_humongous_region(HeapRegion* hr) {
+ HeapWord* end = hr->end();
+ FreeRegionList dummy_free_list("Dummy Free List for G1MarkSweep");
+
+ assert(hr->startsHumongous(),
+ "Only the start of a humongous region should be freed.");
+
+ hr->set_containing_set(NULL);
+ _humongous_regions_removed.increment(1u, hr->capacity());
+
+ _g1h->free_humongous_region(hr, &dummy_free_list, false /* par */);
+ prepare_for_compaction(hr, end);
+ dummy_free_list.remove_all();
+}
+
+void G1PrepareCompactClosure::prepare_for_compaction(HeapRegion* hr, HeapWord* end) {
+ // If this is the first live region that we came across which we can compact,
+ // initialize the CompactPoint.
+ if (!is_cp_initialized()) {
+ _cp.space = hr;
+ _cp.threshold = hr->initialize_threshold();
+ }
+ prepare_for_compaction_work(&_cp, hr, end);
+}
+
+void G1PrepareCompactClosure::prepare_for_compaction_work(CompactPoint* cp,
+ HeapRegion* hr,
+ HeapWord* end) {
+ hr->prepare_for_compaction(cp);
+ // Also clear the part of the card table that will be unused after
+ // compaction.
+ _mrbs->clear(MemRegion(hr->compaction_top(), end));
+}
+
+void G1PrepareCompactClosure::update_sets() {
+ // We'll recalculate total used bytes and recreate the free list
+ // at the end of the GC, so no point in updating those values here.
+ HeapRegionSetCount empty_set;
+ _g1h->remove_from_old_sets(empty_set, _humongous_regions_removed);
+}
+
+bool G1PrepareCompactClosure::doHeapRegion(HeapRegion* hr) {
+ if (hr->isHumongous()) {
+ if (hr->startsHumongous()) {
+ oop obj = oop(hr->bottom());
+ if (obj->is_gc_marked()) {
+ obj->forward_to(obj);
+ } else {
+ free_humongous_region(hr);
+ }
+ } else {
+ assert(hr->continuesHumongous(), "Invalid humongous.");
+ }
+ } else {
+ prepare_for_compaction(hr, hr->end());
+ }
+ return false;
+}