8154528: Reclaim regions emptied by marking in Remark pause
authortschatzl
Wed, 18 Apr 2018 11:36:48 +0200
changeset 49804 7593b16d0d20
parent 49803 14518ac8df87
child 49805 1ccbcd88f66c
8154528: Reclaim regions emptied by marking in Remark pause Reviewed-by: shade, sjohanss
src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Wed Apr 18 11:36:48 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Wed Apr 18 11:36:48 2018 +0200
@@ -1142,6 +1142,18 @@
       log_debug(gc, remset, tracking)("Remembered Set Tracking update regions total %u, selected %u",
                                       _g1h->num_regions(), cl.num_selected_for_rebuild());
     }
+    {
+      GCTraceTime(Debug, gc, phases)("Reclaim Empty Regions");
+      reclaim_empty_regions();
+    }
+
+    // Clean out dead classes
+    if (ClassUnloadingWithConcurrentMark) {
+      GCTraceTime(Debug, gc, phases)("Purge Metaspace");
+      ClassLoaderDataGraph::purge();
+    }
+
+    compute_new_sizes();
 
     verify_during_pause(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UsePrevMarking, "Remark after");
 
@@ -1173,9 +1185,9 @@
   g1p->record_concurrent_mark_remark_end();
 }
 
-class G1CleanupTask : public AbstractGangTask {
+class G1ReclaimEmptyRegionsTask : public AbstractGangTask {
   // Per-region work during the Cleanup pause.
-  class G1CleanupRegionsClosure : public HeapRegionClosure {
+  class G1ReclaimEmptyRegionsClosure : public HeapRegionClosure {
     G1CollectedHeap* _g1h;
     size_t _freed_bytes;
     FreeRegionList* _local_cleanup_list;
@@ -1184,9 +1196,9 @@
     HRRSCleanupTask* _hrrs_cleanup_task;
 
   public:
-    G1CleanupRegionsClosure(G1CollectedHeap* g1,
-                            FreeRegionList* local_cleanup_list,
-                            HRRSCleanupTask* hrrs_cleanup_task) :
+    G1ReclaimEmptyRegionsClosure(G1CollectedHeap* g1,
+                                 FreeRegionList* local_cleanup_list,
+                                 HRRSCleanupTask* hrrs_cleanup_task) :
       _g1h(g1),
       _freed_bytes(0),
       _local_cleanup_list(local_cleanup_list),
@@ -1225,7 +1237,7 @@
   HeapRegionClaimer _hrclaimer;
 
 public:
-  G1CleanupTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) :
+  G1ReclaimEmptyRegionsTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) :
     AbstractGangTask("G1 Cleanup"),
     _g1h(g1h),
     _cleanup_list(cleanup_list),
@@ -1237,9 +1249,9 @@
   void work(uint worker_id) {
     FreeRegionList local_cleanup_list("Local Cleanup List");
     HRRSCleanupTask hrrs_cleanup_task;
-    G1CleanupRegionsClosure cl(_g1h,
-                               &local_cleanup_list,
-                               &hrrs_cleanup_task);
+    G1ReclaimEmptyRegionsClosure cl(_g1h,
+                                    &local_cleanup_list,
+                                    &hrrs_cleanup_task);
     _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hrclaimer, worker_id);
     assert(cl.is_complete(), "Shouldn't have aborted!");
 
@@ -1261,7 +1273,7 @@
   WorkGang* workers = _g1h->workers();
   FreeRegionList empty_regions_list("Empty Regions After Mark List");
 
-  G1CleanupTask cl(_g1h, &empty_regions_list, workers->active_workers());
+  G1ReclaimEmptyRegionsTask cl(_g1h, &empty_regions_list, workers->active_workers());
   workers->run_task(&cl);
 
   if (!empty_regions_list.is_empty()) {
@@ -1280,6 +1292,18 @@
   }
 }
 
+void G1ConcurrentMark::compute_new_sizes() {
+  MetaspaceGC::compute_new_size();
+
+  // Cleanup will have freed any regions completely full of garbage.
+  // Update the soft reference policy with the new heap occupancy.
+  Universe::update_heap_info_at_gc();
+
+  // We reclaimed old regions so we should calculate the sizes to make
+  // sure we update the old gen/space data.
+  _g1h->g1mm()->update_sizes();
+}
+
 void G1ConcurrentMark::cleanup() {
   assert_at_safepoint_on_vm_thread();
 
@@ -1306,26 +1330,6 @@
     _g1h->heap_region_iterate(&cl);
   }
 
-  {
-    GCTraceTime(Debug, gc, phases)("Reclaim Empty Regions");
-    reclaim_empty_regions();
-  }
-
-  // Cleanup will have freed any regions completely full of garbage.
-  // Update the soft reference policy with the new heap occupancy.
-  Universe::update_heap_info_at_gc();
-
-  // Clean out dead classes and update Metaspace sizes.
-  if (ClassUnloadingWithConcurrentMark) {
-    GCTraceTime(Debug, gc, phases)("Purge Metaspace");
-    ClassLoaderDataGraph::purge();
-  }
-  MetaspaceGC::compute_new_size();
-
-  // We reclaimed old regions so we should calculate the sizes to make
-  // sure we update the old gen/space data.
-  _g1h->g1mm()->update_sizes();
-
   verify_during_pause(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "Cleanup after");
 
   // We need to make this be a "collection" so any collection pause that
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp	Wed Apr 18 11:36:48 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp	Wed Apr 18 11:36:48 2018 +0200
@@ -373,6 +373,9 @@
 
   void reclaim_empty_regions();
 
+  // After reclaiming empty regions, update heap sizes.
+  void compute_new_sizes();
+
   // Clear statistics gathered during the concurrent cycle for the given region after
   // it has been reclaimed.
   void clear_statistics(HeapRegion* r);