< prev index next >

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Print this page
rev 57997 : [mq]: 8238854-remove-superfluous-alloc-checks
rev 57998 : [mq]: softmaxheapsize2

@@ -369,11 +369,11 @@
       // the heap. Alternatively we could do a defragmentation GC.
       log_debug(gc, ergo, heap)("Attempt heap expansion (humongous allocation request failed). Allocation request: " SIZE_FORMAT "B",
                                     word_size * HeapWordSize);
 
       _hrm->expand_at(first, obj_regions, workers());
-      policy()->record_new_heap_size(num_regions());
+      update_heap_target_size();
 
 #ifdef ASSERT
       for (uint i = first; i < first + obj_regions; ++i) {
         HeapRegion* hr = region_at(i);
         assert(hr->is_free(), "sanity");

@@ -1369,11 +1369,11 @@
   }
 
   if (expanded_by > 0) {
     size_t actual_expand_bytes = expanded_by * HeapRegion::GrainBytes;
     assert(actual_expand_bytes <= aligned_expand_bytes, "post-condition");
-    policy()->record_new_heap_size(num_regions());
+    update_heap_target_size();
   } else {
     log_debug(gc, ergo, heap)("Did not expand the heap (heap expansion operation failed)");
 
     // The expansion of the virtual storage space was unsuccessful.
     // Let's see if it was because we ran out of swap.

@@ -1393,11 +1393,11 @@
     assert(is_maximal_no_gc(), "Should be no regions left, available: %u", _hrm->available());
     log_debug(gc, ergo, heap)("Did not expand the heap (heap already fully expanded)");
     return false;
   }
 
-  policy()->record_new_heap_size(num_regions());
+  update_heap_target_size();
   return true;
 }
 
 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) {
   size_t aligned_shrink_bytes =

@@ -1410,11 +1410,11 @@
   size_t shrunk_bytes = num_regions_removed * HeapRegion::GrainBytes;
 
   log_debug(gc, ergo, heap)("Shrink the heap. requested shrinking amount: " SIZE_FORMAT "B aligned shrinking amount: " SIZE_FORMAT "B attempted shrinking amount: " SIZE_FORMAT "B",
                             shrink_bytes, aligned_shrink_bytes, shrunk_bytes);
   if (num_regions_removed > 0) {
-    policy()->record_new_heap_size(num_regions());
+    update_heap_target_size();
   } else {
     log_debug(gc, ergo, heap)("Did not expand the heap (heap shrinking operation failed)");
   }
 }
 

@@ -1435,10 +1435,16 @@
 
   _hrm->verify_optional();
   _verifier->verify_region_sets_optional();
 }
 
+void G1CollectedHeap::update_heap_target_size() {
+  uint soft_goal_num_regions = (soft_max_capacity() + HeapRegion::GrainBytes - 1) / HeapRegion::GrainBytes;
+
+  _policy->update_heap_target_size(num_regions(), soft_goal_num_regions);
+}
+
 class OldRegionSetChecker : public HeapRegionSetChecker {
 public:
   void check_mt_safety() {
     // Master Old Set MT safety protocol:
     // (a) If we're at a safepoint, operations on the master old set

@@ -2418,10 +2424,14 @@
 
 size_t G1CollectedHeap::max_reserved_capacity() const {
   return _hrm->max_length() * HeapRegion::GrainBytes;
 }
 
+size_t G1CollectedHeap::soft_max_capacity() const {
+  return clamp(align_up(SoftMaxHeapSize, HeapAlignment), MinHeapSize, max_capacity());
+}
+
 jlong G1CollectedHeap::millis_since_last_gc() {
   // See the notes in GenCollectedHeap::millis_since_last_gc()
   // for more information about the implementation.
   jlong ret_val = (os::javaTimeNanos() / NANOSECS_PER_MILLISEC) -
                   _policy->collection_pause_end_millis();

@@ -3009,10 +3019,12 @@
   trace_heap_before_gc(_gc_tracer_stw);
 
   _verifier->verify_region_sets_optional();
   _verifier->verify_dirty_young_regions();
 
+  update_heap_target_size();
+
   // We should not be doing initial mark unless the conc mark thread is running
   if (!_cm_thread->should_terminate()) {
     // This call will decide whether this pause is an initial-mark
     // pause. If it is, in_initial_mark_gc() will return true
     // for the duration of this pause.
< prev index next >