changeset 13103:6aae3f3ae593

Collection policy cleanups.
author shade
date Tue, 21 Mar 2017 19:07:12 +0100
parents 555f3a32bf60
children 4975ba41d39a
files src/share/vm/gc/shenandoah/shenandoahCollectorPolicy.cpp
diffstat 1 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc/shenandoah/shenandoahCollectorPolicy.cpp	Tue Mar 21 13:29:22 2017 -0400
+++ b/src/share/vm/gc/shenandoah/shenandoahCollectorPolicy.cpp	Tue Mar 21 19:07:12 2017 +0100
@@ -52,6 +52,18 @@
     else return 0;
   }
 
+  RegionGarbage* get_region_garbage_cache(size_t num) {
+    RegionGarbage* res = _region_garbage;
+    if (res == NULL) {
+      res = NEW_C_HEAP_ARRAY(RegionGarbage, num, mtGC);
+      _region_garbage_size = num;
+    } else if (_region_garbage_size < num) {
+      REALLOC_C_HEAP_ARRAY(RegionGarbage, _region_garbage, num, mtGC);
+      _region_garbage_size = num;
+    }
+    return res;
+  }
+
   RegionGarbage* _region_garbage;
   size_t _region_garbage_size;
 
@@ -174,14 +186,7 @@
   ShenandoahHeapRegionSet* regions = heap->regions();
   size_t active = regions->active_regions();
 
-  RegionGarbage* candidates = _region_garbage;
-  if (candidates == NULL) {
-    candidates = NEW_C_HEAP_ARRAY(RegionGarbage, active, mtGC);
-    _region_garbage_size = active;
-  } else if (_region_garbage_size < active) {
-    REALLOC_C_HEAP_ARRAY(RegionGarbage, _region_garbage, active, mtGC);
-    _region_garbage_size = active;
-  }
+  RegionGarbage* candidates = get_region_garbage_cache(active);
 
   size_t cand_idx = 0;
   _bytes_in_cset = 0;
@@ -219,7 +224,7 @@
 
   if (cand_idx > 0) {
     if (needs_regions_sorted_by_garbage()) {
-      QuickSort::sort<RegionGarbage>(candidates, cand_idx, compare_by_garbage, false);
+      QuickSort::sort<RegionGarbage>(candidates, (int)cand_idx, compare_by_garbage, false);
     }
 
     for (size_t i = 0; i < cand_idx; i++) {
@@ -581,8 +586,6 @@
     _allocation_threshold_factor = 0.;
   }
 
-  virtual ~ConnectionHeuristics() {}
-
   virtual bool should_start_concurrent_mark(size_t used, size_t capacity) const {
     size_t half_gig = 64 * 1024 * 1024;
     size_t bytes_alloc = ShenandoahHeap::heap()->bytes_allocated_since_cm();
@@ -602,17 +605,18 @@
 
   virtual void choose_collection_set(ShenandoahCollectionSet* collection_set, int* connections) {
     ShenandoahHeapRegionSet* regions = ShenandoahHeap::heap()->regions();
-    size_t end = regions->active_regions();
-    RegionGarbage sorted_by_garbage[end];
-    for (size_t i = 0; i < end; i++) {
+    size_t active = regions->active_regions();
+
+    RegionGarbage* sorted_by_garbage = get_region_garbage_cache(active);
+    for (size_t i = 0; i < active; i++) {
       ShenandoahHeapRegion* r = regions->get_fast(i);
       sorted_by_garbage[i].region_number = r->region_number();
       sorted_by_garbage[i].garbage = r->garbage();
     }
 
-    QuickSort::sort<RegionGarbage>(sorted_by_garbage, end, compare_by_garbage, false);
+    QuickSort::sort<RegionGarbage>(sorted_by_garbage, (int) active, compare_by_garbage, false);
 
-    int num = ShenandoahHeap::heap()->num_regions();
+    size_t num = ShenandoahHeap::heap()->num_regions();
     // simulate write heuristics by picking best region.
     int r = 0;
     ShenandoahHeapRegion* choosenOne = regions->get(sorted_by_garbage[0].region_number);
@@ -621,28 +625,28 @@
       choosenOne = regions->get(sorted_by_garbage[++r].region_number);
     }
 
-    int region_number = choosenOne->region_number();
-    log_develop_trace(gc)("Adding choosen region %d\n", region_number);
+    size_t region_number = choosenOne->region_number();
+    log_develop_trace(gc)("Adding choosen region " SIZE_FORMAT, region_number);
 
     // Add all the regions which point to this region.
-    for (int i = 0; i < num; i++) {
+    for (size_t i = 0; i < num; i++) {
       if (connections[i * num + region_number] > 0) {
         ShenandoahHeapRegion* candidate = regions->get(sorted_by_garbage[i].region_number);
         if (maybe_add_heap_region(candidate, collection_set))
-          log_develop_trace(gc)("Adding region %d which points to the choosen region\n", i);
+          log_develop_trace(gc)("Adding region " SIZE_FORMAT " which points to the choosen region", i);
       }
     }
 
     // Add all the regions they point to.
     for (size_t ci = 0; ci < collection_set->active_regions(); ci++) {
       ShenandoahHeapRegion* cs_heap_region = collection_set->get(ci);
-      int cs_heap_region_number = cs_heap_region->region_number();
-      for (int i = 0; i < num; i++) {
+      size_t cs_heap_region_number = cs_heap_region->region_number();
+      for (size_t i = 0; i < num; i++) {
         if (connections[i * num + cs_heap_region_number] > 0) {
           ShenandoahHeapRegion* candidate = regions->get(sorted_by_garbage[i].region_number);
           if (maybe_add_heap_region(candidate, collection_set)) {
             log_develop_trace(gc)
-              ("Adding region %d which is pointed to by region %d\n", i, cs_heap_region_number);
+              ("Adding region " SIZE_FORMAT " which is pointed to by region " SIZE_FORMAT, i, cs_heap_region_number);
           }
         }
       }