hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
changeset 5343 95a5c4b89273
parent 1 489c9b5090e2
child 5547 f4b087cbb361
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp	Fri Apr 09 13:08:34 2010 -0400
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp	Tue Apr 13 13:52:10 2010 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2010 Sun Microsystems, Inc.  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
@@ -184,18 +184,19 @@
   set_change_young_gen_for_maj_pauses(0);
 }
 
-
 // If this is not a full GC, only test and modify the young generation.
 
-void PSAdaptiveSizePolicy::compute_generation_free_space(size_t young_live,
-                                               size_t eden_live,
-                                               size_t old_live,
-                                               size_t perm_live,
-                                               size_t cur_eden,
-                                               size_t max_old_gen_size,
-                                               size_t max_eden_size,
-                                               bool   is_full_gc,
-                                               GCCause::Cause gc_cause) {
+void PSAdaptiveSizePolicy::compute_generation_free_space(
+                                           size_t young_live,
+                                           size_t eden_live,
+                                           size_t old_live,
+                                           size_t perm_live,
+                                           size_t cur_eden,
+                                           size_t max_old_gen_size,
+                                           size_t max_eden_size,
+                                           bool   is_full_gc,
+                                           GCCause::Cause gc_cause,
+                                           CollectorPolicy* collector_policy) {
 
   // Update statistics
   // Time statistics are updated as we go, update footprint stats here
@@ -380,91 +381,16 @@
   // Is too much time being spent in GC?
   //   Is the heap trying to grow beyond it's limits?
 
-  const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
+  const size_t free_in_old_gen =
+    (size_t)(max_old_gen_size - avg_old_live()->average());
   if (desired_promo_size > free_in_old_gen && desired_eden_size > eden_limit) {
-
-    // eden_limit is the upper limit on the size of eden based on
-    // the maximum size of the young generation and the sizes
-    // of the survivor space.
-    // The question being asked is whether the gc costs are high
-    // and the space being recovered by a collection is low.
-    // free_in_young_gen is the free space in the young generation
-    // after a collection and promo_live is the free space in the old
-    // generation after a collection.
-    //
-    // Use the minimum of the current value of the live in the
-    // young gen or the average of the live in the young gen.
-    // If the current value drops quickly, that should be taken
-    // into account (i.e., don't trigger if the amount of free
-    // space has suddenly jumped up).  If the current is much
-    // higher than the average, use the average since it represents
-    // the longer term behavor.
-    const size_t live_in_eden = MIN2(eden_live, (size_t) avg_eden_live()->average());
-    const size_t free_in_eden = eden_limit > live_in_eden ?
-      eden_limit - live_in_eden : 0;
-    const size_t total_free_limit = free_in_old_gen + free_in_eden;
-    const size_t total_mem = max_old_gen_size + max_eden_size;
-    const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0);
-    if (PrintAdaptiveSizePolicy && (Verbose ||
-        (total_free_limit < (size_t) mem_free_limit))) {
-      gclog_or_tty->print_cr(
-            "PSAdaptiveSizePolicy::compute_generation_free_space limits:"
-            " promo_limit: " SIZE_FORMAT
-            " eden_limit: " SIZE_FORMAT
-            " total_free_limit: " SIZE_FORMAT
-            " max_old_gen_size: " SIZE_FORMAT
-            " max_eden_size: " SIZE_FORMAT
-            " mem_free_limit: " SIZE_FORMAT,
-            promo_limit, eden_limit, total_free_limit,
-            max_old_gen_size, max_eden_size,
-            (size_t) mem_free_limit);
-    }
-
-    if (is_full_gc) {
-      if (gc_cost() > gc_cost_limit &&
-        total_free_limit < (size_t) mem_free_limit) {
-        // Collections, on average, are taking too much time, and
-        //      gc_cost() > gc_cost_limit
-        // we have too little space available after a full gc.
-        //      total_free_limit < mem_free_limit
-        // where
-        //   total_free_limit is the free space available in
-        //     both generations
-        //   total_mem is the total space available for allocation
-        //     in both generations (survivor spaces are not included
-        //     just as they are not included in eden_limit).
-        //   mem_free_limit is a fraction of total_mem judged to be an
-        //     acceptable amount that is still unused.
-        // The heap can ask for the value of this variable when deciding
-        // whether to thrown an OutOfMemory error.
-        // Note that the gc time limit test only works for the collections
-        // of the young gen + tenured gen and not for collections of the
-        // permanent gen.  That is because the calculation of the space
-        // freed by the collection is the free space in the young gen +
-        // tenured gen.
-        // Ignore explicit GC's. Ignoring explicit GC's at this level
-        // is the equivalent of the GC did not happen as far as the
-        // overhead calculation is concerted (i.e., the flag is not set
-        // and the count is not affected).  Also the average will not
-        // have been updated unless UseAdaptiveSizePolicyWithSystemGC is on.
-        if (!GCCause::is_user_requested_gc(gc_cause) &&
-            !GCCause::is_serviceability_requested_gc(gc_cause)) {
-          inc_gc_time_limit_count();
-          if (UseGCOverheadLimit &&
-              (gc_time_limit_count() > AdaptiveSizePolicyGCTimeLimitThreshold)){
-            // All conditions have been met for throwing an out-of-memory
-            _gc_time_limit_exceeded = true;
-            // Avoid consecutive OOM due to the gc time limit by resetting
-            // the counter.
-            reset_gc_time_limit_count();
-          }
-          _print_gc_time_limit_would_be_exceeded = true;
-        }
-      } else {
-        // Did not exceed overhead limits
-        reset_gc_time_limit_count();
-      }
-    }
+    check_gc_overhead_limit(young_live,
+                            eden_live,
+                            max_old_gen_size,
+                            max_eden_size,
+                            is_full_gc,
+                            gc_cause,
+                            collector_policy);
   }