changeset 37143:345ad6728be3

8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser Reviewed-by: jmasa, tschatzl
author mgerdin
date Fri, 11 Mar 2016 11:22:56 +0100
parents 5389598424cc
children b7ae74d4d5d8
files hotspot/src/share/vm/gc/g1/collectionSetChooser.cpp hotspot/src/share/vm/gc/g1/collectionSetChooser.hpp hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp
diffstat 4 files changed, 71 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/gc/g1/collectionSetChooser.cpp	Fri Mar 18 03:46:02 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/collectionSetChooser.cpp	Fri Mar 11 11:22:56 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -145,7 +145,6 @@
   verify();
 }
 
-
 void CollectionSetChooser::add_region(HeapRegion* hr) {
   assert(!hr->is_pinned(),
          "Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index());
@@ -210,4 +209,67 @@
   _front = 0;
   _end = 0;
   _remaining_reclaimable_bytes = 0;
+}
+
+class ParKnownGarbageHRClosure: public HeapRegionClosure {
+  G1CollectedHeap* _g1h;
+  CSetChooserParUpdater _cset_updater;
+
+public:
+  ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
+                           uint chunk_size) :
+    _g1h(G1CollectedHeap::heap()),
+    _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
+
+  bool doHeapRegion(HeapRegion* r) {
+    // Do we have any marking information for this region?
+    if (r->is_marked()) {
+      // We will skip any region that's currently used as an old GC
+      // alloc region (we should not consider those for collection
+      // before we fill them up).
+      if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
+        _cset_updater.add_region(r);
+      }
+    }
+    return false;
+  }
 };
+
+class ParKnownGarbageTask: public AbstractGangTask {
+  CollectionSetChooser* _hrSorted;
+  uint _chunk_size;
+  G1CollectedHeap* _g1;
+  HeapRegionClaimer _hrclaimer;
+
+public:
+  ParKnownGarbageTask(CollectionSetChooser* hrSorted, uint chunk_size, uint n_workers) :
+      AbstractGangTask("ParKnownGarbageTask"),
+      _hrSorted(hrSorted), _chunk_size(chunk_size),
+      _g1(G1CollectedHeap::heap()), _hrclaimer(n_workers) {}
+
+  void work(uint worker_id) {
+    ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
+    _g1->heap_region_par_iterate(&parKnownGarbageCl, worker_id, &_hrclaimer);
+  }
+};
+
+uint CollectionSetChooser::calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const {
+  assert(n_workers > 0, "Active gc workers should be greater than 0");
+  const uint overpartition_factor = 4;
+  const uint min_chunk_size = MAX2(n_regions / n_workers, 1U);
+  return MAX2(n_regions / (n_workers * overpartition_factor), min_chunk_size);
+}
+
+void CollectionSetChooser::rebuild(WorkGang* workers, uint n_regions) {
+  clear();
+
+  uint n_workers = workers->active_workers();
+
+  uint chunk_size = calculate_parallel_work_chunk_size(n_workers, n_regions);
+  prepare_for_par_region_addition(n_workers, n_regions, chunk_size);
+
+  ParKnownGarbageTask par_known_garbage_task(this, chunk_size, n_workers);
+  workers->run_task(&par_known_garbage_task);
+
+  sort_regions();
+}
--- a/hotspot/src/share/vm/gc/g1/collectionSetChooser.hpp	Fri Mar 18 03:46:02 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/collectionSetChooser.hpp	Fri Mar 11 11:22:56 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,6 +65,9 @@
   // The sum of reclaimable bytes over all the regions in the CSet chooser.
   size_t _remaining_reclaimable_bytes;
 
+  // Calculate and return chunk size (in number of regions) for parallel
+  // addition of regions
+  uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
 public:
 
   // Return the current candidate region to be considered for
@@ -132,6 +135,8 @@
 
   void clear();
 
+  void rebuild(WorkGang* workers, uint n_regions);
+
   // Return the number of candidate regions that remain to be collected.
   uint remaining_regions() { return _end - _front; }
 
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp	Fri Mar 18 03:46:02 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp	Fri Mar 11 11:22:56 2016 +0100
@@ -1285,68 +1285,8 @@
   }
 }
 
-class ParKnownGarbageHRClosure: public HeapRegionClosure {
-  G1CollectedHeap* _g1h;
-  CSetChooserParUpdater _cset_updater;
-
-public:
-  ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
-                           uint chunk_size) :
-    _g1h(G1CollectedHeap::heap()),
-    _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
-
-  bool doHeapRegion(HeapRegion* r) {
-    // Do we have any marking information for this region?
-    if (r->is_marked()) {
-      // We will skip any region that's currently used as an old GC
-      // alloc region (we should not consider those for collection
-      // before we fill them up).
-      if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
-        _cset_updater.add_region(r);
-      }
-    }
-    return false;
-  }
-};
-
-class ParKnownGarbageTask: public AbstractGangTask {
-  CollectionSetChooser* _hrSorted;
-  uint _chunk_size;
-  G1CollectedHeap* _g1;
-  HeapRegionClaimer _hrclaimer;
-
-public:
-  ParKnownGarbageTask(CollectionSetChooser* hrSorted, uint chunk_size, uint n_workers) :
-      AbstractGangTask("ParKnownGarbageTask"),
-      _hrSorted(hrSorted), _chunk_size(chunk_size),
-      _g1(G1CollectedHeap::heap()), _hrclaimer(n_workers) {}
-
-  void work(uint worker_id) {
-    ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
-    _g1->heap_region_par_iterate(&parKnownGarbageCl, worker_id, &_hrclaimer);
-  }
-};
-
-uint G1CollectorPolicy::calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const {
-  assert(n_workers > 0, "Active gc workers should be greater than 0");
-  const uint overpartition_factor = 4;
-  const uint min_chunk_size = MAX2(n_regions / n_workers, 1U);
-  return MAX2(n_regions / (n_workers * overpartition_factor), min_chunk_size);
-}
-
 void G1CollectorPolicy::record_concurrent_mark_cleanup_end() {
-  cset_chooser()->clear();
-
-  WorkGang* workers = _g1->workers();
-  uint n_workers = workers->active_workers();
-
-  uint n_regions = _g1->num_regions();
-  uint chunk_size = calculate_parallel_work_chunk_size(n_workers, n_regions);
-  cset_chooser()->prepare_for_par_region_addition(n_workers, n_regions, chunk_size);
-  ParKnownGarbageTask par_known_garbage_task(cset_chooser(), chunk_size, n_workers);
-  workers->run_task(&par_known_garbage_task);
-
-  cset_chooser()->sort_regions();
+  cset_chooser()->rebuild(_g1->workers(), _g1->num_regions());
 
   double end_sec = os::elapsedTime();
   double elapsed_time_ms = (end_sec - _mark_cleanup_start_sec) * 1000.0;
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp	Fri Mar 18 03:46:02 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp	Fri Mar 11 11:22:56 2016 +0100
@@ -255,10 +255,6 @@
   void update_rs_lengths_prediction();
   void update_rs_lengths_prediction(size_t prediction);
 
-  // Calculate and return chunk size (in number of regions) for parallel
-  // concurrent mark cleanup.
-  uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
-
   // Check whether a given young length (young_length) fits into the
   // given target pause time and whether the prediction for the amount
   // of objects to be copied for the given length will fit into the