< prev index next >

src/share/vm/gc/shared/adaptiveSizePolicy.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/adaptiveSizePolicy.hpp"
  27 #include "gc/shared/collectorPolicy.hpp"
  28 #include "gc/shared/gcCause.hpp"
  29 #include "gc/shared/workgroup.hpp"

  30 #include "runtime/timer.hpp"
  31 #include "utilities/ostream.hpp"
  32 elapsedTimer AdaptiveSizePolicy::_minor_timer;
  33 elapsedTimer AdaptiveSizePolicy::_major_timer;
  34 bool AdaptiveSizePolicy::_debug_perturbation = false;
  35 
  36 // The throughput goal is implemented as
  37 //      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
  38 // gc_cost_ratio is the ratio
  39 //      application cost / gc cost
  40 // For example a gc_cost_ratio of 4 translates into a
  41 // throughput goal of .80
  42 
  43 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
  44                                        size_t init_promo_size,
  45                                        size_t init_survivor_size,
  46                                        double gc_pause_goal_sec,
  47                                        uint gc_cost_ratio) :
  48     _eden_size(init_eden_size),
  49     _promo_size(init_promo_size),


 149   if (ForceDynamicNumberOfGCThreads) {
 150     // Assume this is debugging and jiggle the number of GC threads.
 151     if (new_active_workers == prev_active_workers) {
 152       if (new_active_workers < total_workers) {
 153         new_active_workers++;
 154       } else if (new_active_workers > min_workers) {
 155         new_active_workers--;
 156       }
 157     }
 158     if (new_active_workers == total_workers) {
 159       if (_debug_perturbation) {
 160         new_active_workers =  min_workers;
 161       }
 162       _debug_perturbation = !_debug_perturbation;
 163     }
 164     assert((new_active_workers <= ParallelGCThreads) &&
 165            (new_active_workers >= min_workers),
 166       "Jiggled active workers too much");
 167   }
 168 
 169   if (TraceDynamicGCThreads) {
 170      gclog_or_tty->print_cr("GCTaskManager::calc_default_active_workers() : "
 171        "active_workers(): " UINTX_FORMAT "  new_active_workers: " UINTX_FORMAT "  "
 172        "prev_active_workers: " UINTX_FORMAT "\n"
 173        " active_workers_by_JT: " UINTX_FORMAT "  active_workers_by_heap_size: " UINTX_FORMAT,
 174        active_workers, new_active_workers, prev_active_workers,
 175        active_workers_by_JT, active_workers_by_heap_size);
 176   }
 177   assert(new_active_workers > 0, "Always need at least 1");
 178   return new_active_workers;
 179 }
 180 
 181 uint AdaptiveSizePolicy::calc_active_workers(uintx total_workers,
 182                                              uintx active_workers,
 183                                              uintx application_workers) {
 184   // If the user has specifically set the number of
 185   // GC threads, use them.
 186 
 187   // If the user has turned off using a dynamic number of GC threads
 188   // or the users has requested a specific number, set the active
 189   // number of workers to all the workers.
 190 
 191   uint new_active_workers;
 192   if (!UseDynamicNumberOfGCThreads ||
 193      (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) {
 194     new_active_workers = total_workers;
 195   } else {
 196     uintx min_workers = (total_workers == 1) ? 1 : 2;


 258         (minor_pause_in_seconds > 0.0)) {
 259       double interval_in_seconds =
 260         _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
 261       collection_cost =
 262         minor_pause_in_seconds / interval_in_seconds;
 263       _avg_minor_gc_cost->sample(collection_cost);
 264       // Sample for performance counter
 265       _avg_minor_interval->sample(interval_in_seconds);
 266     }
 267 
 268     // The policy does not have enough data until at least some
 269     // young collections have been done.
 270     _young_gen_policy_is_ready =
 271       (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
 272 
 273     // Calculate variables used to estimate pause time vs. gen sizes
 274     double eden_size_in_mbytes = ((double)_eden_size) / ((double)M);
 275     update_minor_pause_young_estimator(minor_pause_in_ms);
 276     update_minor_pause_old_estimator(minor_pause_in_ms);
 277 
 278     if (PrintAdaptiveSizePolicy && Verbose) {
 279       gclog_or_tty->print("AdaptiveSizePolicy::minor_collection_end: "
 280                           "minor gc cost: %f  average: %f", collection_cost,
 281                           _avg_minor_gc_cost->average());
 282       gclog_or_tty->print_cr("  minor pause: %f minor period %f",
 283                              minor_pause_in_ms,
 284                              _latest_minor_mutator_interval_seconds * MILLIUNITS);
 285     }
 286 
 287     // Calculate variable used to estimate collection cost vs. gen sizes
 288     assert(collection_cost >= 0.0, "Expected to be non-negative");
 289     _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
 290   }
 291 
 292   // Interval times use this timer to measure the mutator time.
 293   // Reset the timer after the GC pause.
 294   _minor_timer.reset();
 295   _minor_timer.start();
 296 }
 297 
 298 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden, uint percent_change) {
 299   size_t eden_heap_delta;
 300   eden_heap_delta = cur_eden / 100 * percent_change;
 301   return eden_heap_delta;
 302 }
 303 
 304 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
 305   return eden_increment(cur_eden, YoungGenerationSizeIncrement);


 371 // small.  Use the decaying gc cost only to decide whether to
 372 // adjust for throughput.  Using it also to determine the adjustment
 373 // to be made for throughput also seems reasonable but there is
 374 // no test case to use to decide if it is the right thing to do
 375 // don't do it yet.
 376 
 377 double AdaptiveSizePolicy::decaying_gc_cost() const {
 378   double decayed_major_gc_cost = major_gc_cost();
 379   double avg_major_interval = major_gc_interval_average_for_decay();
 380   if (UseAdaptiveSizeDecayMajorGCCost &&
 381       (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
 382       (avg_major_interval > 0.00)) {
 383     double time_since_last_major_gc = time_since_major_gc();
 384 
 385     // Decay the major gc cost?
 386     if (time_since_last_major_gc >
 387         ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
 388 
 389       // Decay using the time-since-last-major-gc
 390       decayed_major_gc_cost = decaying_major_gc_cost();
 391       if (PrintGCDetails && Verbose) {
 392         gclog_or_tty->print_cr("\ndecaying_gc_cost: major interval average:"
 393           " %f  time since last major gc: %f",
 394           avg_major_interval, time_since_last_major_gc);
 395         gclog_or_tty->print_cr("  major gc cost: %f  decayed major gc cost: %f",
 396           major_gc_cost(), decayed_major_gc_cost);
 397       }
 398     }
 399   }
 400   double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
 401   return result;
 402 }
 403 
 404 
 405 void AdaptiveSizePolicy::clear_generation_free_space_flags() {
 406   set_change_young_gen_for_min_pauses(0);
 407   set_change_old_gen_for_maj_pauses(0);
 408 
 409   set_change_old_gen_for_throughput(0);
 410   set_change_young_gen_for_throughput(0);
 411   set_decrease_for_footprint(0);
 412   set_decide_at_full_gc(0);
 413 }
 414 
 415 void AdaptiveSizePolicy::check_gc_overhead_limit(
 416                                           size_t young_live,
 417                                           size_t eden_live,
 418                                           size_t max_old_gen_size,
 419                                           size_t max_eden_size,


 444   // space has suddenly jumped up).  If the current is much
 445   // higher than the average, use the average since it represents
 446   // the longer term behavior.
 447   const size_t live_in_eden =
 448     MIN2(eden_live, (size_t) avg_eden_live()->average());
 449   const size_t free_in_eden = max_eden_size > live_in_eden ?
 450     max_eden_size - live_in_eden : 0;
 451   const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
 452   const size_t total_free_limit = free_in_old_gen + free_in_eden;
 453   const size_t total_mem = max_old_gen_size + max_eden_size;
 454   const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0);
 455   const double mem_free_old_limit = max_old_gen_size * (GCHeapFreeLimit/100.0);
 456   const double mem_free_eden_limit = max_eden_size * (GCHeapFreeLimit/100.0);
 457   const double gc_cost_limit = GCTimeLimit/100.0;
 458   size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average());
 459   // But don't force a promo size below the current promo size. Otherwise,
 460   // the promo size will shrink for no good reason.
 461   promo_limit = MAX2(promo_limit, _promo_size);
 462 
 463 
 464   if (PrintAdaptiveSizePolicy && (Verbose ||
 465       (free_in_old_gen < (size_t) mem_free_old_limit &&
 466        free_in_eden < (size_t) mem_free_eden_limit))) {
 467     gclog_or_tty->print_cr(
 468           "PSAdaptiveSizePolicy::check_gc_overhead_limit:"
 469           " promo_limit: " SIZE_FORMAT
 470           " max_eden_size: " SIZE_FORMAT
 471           " total_free_limit: " SIZE_FORMAT
 472           " max_old_gen_size: " SIZE_FORMAT
 473           " max_eden_size: " SIZE_FORMAT
 474           " mem_free_limit: " SIZE_FORMAT,
 475           promo_limit, max_eden_size, total_free_limit,
 476           max_old_gen_size, max_eden_size,
 477           (size_t) mem_free_limit);
 478   }
 479 
 480   bool print_gc_overhead_limit_would_be_exceeded = false;
 481   if (is_full_gc) {
 482     if (gc_cost() > gc_cost_limit &&
 483       free_in_old_gen < (size_t) mem_free_old_limit &&
 484       free_in_eden < (size_t) mem_free_eden_limit) {
 485       // Collections, on average, are taking too much time, and
 486       //      gc_cost() > gc_cost_limit
 487       // we have too little space available after a full gc.
 488       //      total_free_limit < mem_free_limit
 489       // where
 490       //   total_free_limit is the free space available in
 491       //     both generations
 492       //   total_mem is the total space available for allocation
 493       //     in both generations (survivor spaces are not included
 494       //     just as they are not included in eden_limit).
 495       //   mem_free_limit is a fraction of total_mem judged to be an
 496       //     acceptable amount that is still unused.
 497       // The heap can ask for the value of this variable when deciding
 498       // whether to thrown an OutOfMemory error.


 504       // At this point the GC overhead limit is being exceeded.
 505       inc_gc_overhead_limit_count();
 506       if (UseGCOverheadLimit) {
 507         if (gc_overhead_limit_count() >=
 508             AdaptiveSizePolicyGCTimeLimitThreshold){
 509           // All conditions have been met for throwing an out-of-memory
 510           set_gc_overhead_limit_exceeded(true);
 511           // Avoid consecutive OOM due to the gc time limit by resetting
 512           // the counter.
 513           reset_gc_overhead_limit_count();
 514         } else {
 515           // The required consecutive collections which exceed the
 516           // GC time limit may or may not have been reached. We
 517           // are approaching that condition and so as not to
 518           // throw an out-of-memory before all SoftRef's have been
 519           // cleared, set _should_clear_all_soft_refs in CollectorPolicy.
 520           // The clearing will be done on the next GC.
 521           bool near_limit = gc_overhead_limit_near();
 522           if (near_limit) {
 523             collector_policy->set_should_clear_all_soft_refs(true);
 524             if (PrintGCDetails && Verbose) {
 525               gclog_or_tty->print_cr("  Nearing GC overhead limit, "
 526                 "will be clearing all SoftReference");
 527             }
 528           }
 529         }
 530       }
 531       // Set this even when the overhead limit will not
 532       // cause an out-of-memory.  Diagnostic message indicating
 533       // that the overhead limit is being exceeded is sometimes
 534       // printed.
 535       print_gc_overhead_limit_would_be_exceeded = true;
 536 
 537     } else {
 538       // Did not exceed overhead limits
 539       reset_gc_overhead_limit_count();
 540     }
 541   }
 542 
 543   if (UseGCOverheadLimit && PrintGCDetails && Verbose) {
 544     if (gc_overhead_limit_exceeded()) {
 545       gclog_or_tty->print_cr("      GC is exceeding overhead limit "
 546         "of " UINTX_FORMAT "%%", GCTimeLimit);
 547       reset_gc_overhead_limit_count();
 548     } else if (print_gc_overhead_limit_would_be_exceeded) {
 549       assert(gc_overhead_limit_count() > 0, "Should not be printing");
 550       gclog_or_tty->print_cr("      GC would exceed overhead limit "
 551         "of " UINTX_FORMAT "%% %d consecutive time(s)",
 552         GCTimeLimit, gc_overhead_limit_count());
 553     }
 554   }
 555 }
 556 // Printing
 557 
 558 bool AdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st) const {

 559 
 560   //  Should only be used with adaptive size policy turned on.
 561   // Otherwise, there may be variables that are undefined.
 562   if (!UseAdaptiveSizePolicy) return false;
 563 
 564   // Print goal for which action is needed.
 565   char* action = NULL;
 566   bool change_for_pause = false;
 567   if ((change_old_gen_for_maj_pauses() ==
 568          decrease_old_gen_for_maj_pauses_true) ||
 569       (change_young_gen_for_min_pauses() ==
 570          decrease_young_gen_for_min_pauses_true)) {
 571     action = (char*) " *** pause time goal ***";
 572     change_for_pause = true;
 573   } else if ((change_old_gen_for_throughput() ==
 574                increase_old_gen_for_throughput_true) ||
 575             (change_young_gen_for_throughput() ==
 576                increase_young_gen_for_througput_true)) {
 577     action = (char*) " *** throughput goal ***";
 578   } else if (decrease_for_footprint()) {
 579     action = (char*) " *** reduced footprint ***";
 580   } else {
 581     // No actions were taken.  This can legitimately be the
 582     // situation if not enough data has been gathered to make


 610   if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
 611     assert(change_young_gen_for_throughput() ==
 612            increase_young_gen_for_througput_true,
 613            "Both generations should be growing");
 614     young_gen_action = grow_msg;
 615     tenured_gen_action = grow_msg;
 616   } else if (change_young_gen_for_throughput() ==
 617              increase_young_gen_for_througput_true) {
 618     // Only the young generation may grow at start up (before
 619     // enough full collections have been done to grow the old generation).
 620     young_gen_action = grow_msg;
 621     tenured_gen_action = no_change_msg;
 622   }
 623 
 624   // Minimum footprint
 625   if (decrease_for_footprint() != 0) {
 626     young_gen_action = shrink_msg;
 627     tenured_gen_action = shrink_msg;
 628   }
 629 
 630   st->print_cr("    UseAdaptiveSizePolicy actions to meet %s", action);
 631   st->print_cr("                       GC overhead (%%)");
 632   st->print_cr("    Young generation:     %7.2f\t  %s",
 633     100.0 * avg_minor_gc_cost()->average(),
 634     young_gen_action);
 635   st->print_cr("    Tenured generation:   %7.2f\t  %s",
 636     100.0 * avg_major_gc_cost()->average(),
 637     tenured_gen_action);
 638   return true;
 639 }
 640 
 641 bool AdaptiveSizePolicy::print_adaptive_size_policy_on(
 642                                             outputStream* st,
 643                                             uint tenuring_threshold_arg) const {
 644   if (!AdaptiveSizePolicy::print_adaptive_size_policy_on(st)) {
 645     return false;
 646   }
 647 
 648   // Tenuring threshold
 649   bool tenuring_threshold_changed = true;
 650   if (decrement_tenuring_threshold_for_survivor_limit()) {
 651     st->print("    Tenuring threshold:    (attempted to decrease to avoid"
 652               " survivor space overflow) = ");
 653   } else if (decrement_tenuring_threshold_for_gc_cost()) {
 654     st->print("    Tenuring threshold:    (attempted to decrease to balance"
 655               " GC costs) = ");
 656   } else if (increment_tenuring_threshold_for_gc_cost()) {
 657     st->print("    Tenuring threshold:    (attempted to increase to balance"
 658               " GC costs) = ");
 659   } else {
 660     tenuring_threshold_changed = false;
 661     assert(!tenuring_threshold_change(), "(no change was attempted)");
 662   }
 663   if (tenuring_threshold_changed) {
 664     st->print_cr("%u", tenuring_threshold_arg);
 665   }
 666   return true;
 667 }


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/adaptiveSizePolicy.hpp"
  27 #include "gc/shared/collectorPolicy.hpp"
  28 #include "gc/shared/gcCause.hpp"
  29 #include "gc/shared/workgroup.hpp"
  30 #include "logging/log.hpp"
  31 #include "runtime/timer.hpp"
  32 #include "utilities/ostream.hpp"
  33 elapsedTimer AdaptiveSizePolicy::_minor_timer;
  34 elapsedTimer AdaptiveSizePolicy::_major_timer;
  35 bool AdaptiveSizePolicy::_debug_perturbation = false;
  36 
  37 // The throughput goal is implemented as
  38 //      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
  39 // gc_cost_ratio is the ratio
  40 //      application cost / gc cost
  41 // For example a gc_cost_ratio of 4 translates into a
  42 // throughput goal of .80
  43 
  44 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
  45                                        size_t init_promo_size,
  46                                        size_t init_survivor_size,
  47                                        double gc_pause_goal_sec,
  48                                        uint gc_cost_ratio) :
  49     _eden_size(init_eden_size),
  50     _promo_size(init_promo_size),


 150   if (ForceDynamicNumberOfGCThreads) {
 151     // Assume this is debugging and jiggle the number of GC threads.
 152     if (new_active_workers == prev_active_workers) {
 153       if (new_active_workers < total_workers) {
 154         new_active_workers++;
 155       } else if (new_active_workers > min_workers) {
 156         new_active_workers--;
 157       }
 158     }
 159     if (new_active_workers == total_workers) {
 160       if (_debug_perturbation) {
 161         new_active_workers =  min_workers;
 162       }
 163       _debug_perturbation = !_debug_perturbation;
 164     }
 165     assert((new_active_workers <= ParallelGCThreads) &&
 166            (new_active_workers >= min_workers),
 167       "Jiggled active workers too much");
 168   }
 169 
 170    log_trace(gc, task)("GCTaskManager::calc_default_active_workers() : "

 171      "active_workers(): " UINTX_FORMAT "  new_active_workers: " UINTX_FORMAT "  "
 172      "prev_active_workers: " UINTX_FORMAT "\n"
 173      " active_workers_by_JT: " UINTX_FORMAT "  active_workers_by_heap_size: " UINTX_FORMAT,
 174      active_workers, new_active_workers, prev_active_workers,
 175      active_workers_by_JT, active_workers_by_heap_size);

 176   assert(new_active_workers > 0, "Always need at least 1");
 177   return new_active_workers;
 178 }
 179 
 180 uint AdaptiveSizePolicy::calc_active_workers(uintx total_workers,
 181                                              uintx active_workers,
 182                                              uintx application_workers) {
 183   // If the user has specifically set the number of
 184   // GC threads, use them.
 185 
 186   // If the user has turned off using a dynamic number of GC threads
 187   // or the users has requested a specific number, set the active
 188   // number of workers to all the workers.
 189 
 190   uint new_active_workers;
 191   if (!UseDynamicNumberOfGCThreads ||
 192      (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) {
 193     new_active_workers = total_workers;
 194   } else {
 195     uintx min_workers = (total_workers == 1) ? 1 : 2;


 257         (minor_pause_in_seconds > 0.0)) {
 258       double interval_in_seconds =
 259         _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
 260       collection_cost =
 261         minor_pause_in_seconds / interval_in_seconds;
 262       _avg_minor_gc_cost->sample(collection_cost);
 263       // Sample for performance counter
 264       _avg_minor_interval->sample(interval_in_seconds);
 265     }
 266 
 267     // The policy does not have enough data until at least some
 268     // young collections have been done.
 269     _young_gen_policy_is_ready =
 270       (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
 271 
 272     // Calculate variables used to estimate pause time vs. gen sizes
 273     double eden_size_in_mbytes = ((double)_eden_size) / ((double)M);
 274     update_minor_pause_young_estimator(minor_pause_in_ms);
 275     update_minor_pause_old_estimator(minor_pause_in_ms);
 276 
 277     log_trace(gc, ergo)("AdaptiveSizePolicy::minor_collection_end: minor gc cost: %f  average: %f",
 278                         collection_cost, _avg_minor_gc_cost->average());
 279     log_trace(gc, ergo)("  minor pause: %f minor period %f",
 280                         minor_pause_in_ms, _latest_minor_mutator_interval_seconds * MILLIUNITS);




 281 
 282     // Calculate variable used to estimate collection cost vs. gen sizes
 283     assert(collection_cost >= 0.0, "Expected to be non-negative");
 284     _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
 285   }
 286 
 287   // Interval times use this timer to measure the mutator time.
 288   // Reset the timer after the GC pause.
 289   _minor_timer.reset();
 290   _minor_timer.start();
 291 }
 292 
 293 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden, uint percent_change) {
 294   size_t eden_heap_delta;
 295   eden_heap_delta = cur_eden / 100 * percent_change;
 296   return eden_heap_delta;
 297 }
 298 
 299 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
 300   return eden_increment(cur_eden, YoungGenerationSizeIncrement);


 366 // small.  Use the decaying gc cost only to decide whether to
 367 // adjust for throughput.  Using it also to determine the adjustment
 368 // to be made for throughput also seems reasonable but there is
 369 // no test case to use to decide if it is the right thing to do
 370 // don't do it yet.
 371 
 372 double AdaptiveSizePolicy::decaying_gc_cost() const {
 373   double decayed_major_gc_cost = major_gc_cost();
 374   double avg_major_interval = major_gc_interval_average_for_decay();
 375   if (UseAdaptiveSizeDecayMajorGCCost &&
 376       (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
 377       (avg_major_interval > 0.00)) {
 378     double time_since_last_major_gc = time_since_major_gc();
 379 
 380     // Decay the major gc cost?
 381     if (time_since_last_major_gc >
 382         ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
 383 
 384       // Decay using the time-since-last-major-gc
 385       decayed_major_gc_cost = decaying_major_gc_cost();
 386       log_trace(gc, ergo)("decaying_gc_cost: major interval average: %f  time since last major gc: %f",


 387                     avg_major_interval, time_since_last_major_gc);
 388       log_trace(gc, ergo)("  major gc cost: %f  decayed major gc cost: %f",
 389                     major_gc_cost(), decayed_major_gc_cost);
 390     }
 391   }

 392   double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
 393   return result;
 394 }
 395 
 396 
 397 void AdaptiveSizePolicy::clear_generation_free_space_flags() {
 398   set_change_young_gen_for_min_pauses(0);
 399   set_change_old_gen_for_maj_pauses(0);
 400 
 401   set_change_old_gen_for_throughput(0);
 402   set_change_young_gen_for_throughput(0);
 403   set_decrease_for_footprint(0);
 404   set_decide_at_full_gc(0);
 405 }
 406 
 407 void AdaptiveSizePolicy::check_gc_overhead_limit(
 408                                           size_t young_live,
 409                                           size_t eden_live,
 410                                           size_t max_old_gen_size,
 411                                           size_t max_eden_size,


 436   // space has suddenly jumped up).  If the current is much
 437   // higher than the average, use the average since it represents
 438   // the longer term behavior.
 439   const size_t live_in_eden =
 440     MIN2(eden_live, (size_t) avg_eden_live()->average());
 441   const size_t free_in_eden = max_eden_size > live_in_eden ?
 442     max_eden_size - live_in_eden : 0;
 443   const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
 444   const size_t total_free_limit = free_in_old_gen + free_in_eden;
 445   const size_t total_mem = max_old_gen_size + max_eden_size;
 446   const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0);
 447   const double mem_free_old_limit = max_old_gen_size * (GCHeapFreeLimit/100.0);
 448   const double mem_free_eden_limit = max_eden_size * (GCHeapFreeLimit/100.0);
 449   const double gc_cost_limit = GCTimeLimit/100.0;
 450   size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average());
 451   // But don't force a promo size below the current promo size. Otherwise,
 452   // the promo size will shrink for no good reason.
 453   promo_limit = MAX2(promo_limit, _promo_size);
 454 
 455 
 456   log_trace(gc, ergo)(



 457         "PSAdaptiveSizePolicy::check_gc_overhead_limit:"
 458         " promo_limit: " SIZE_FORMAT
 459         " max_eden_size: " SIZE_FORMAT
 460         " total_free_limit: " SIZE_FORMAT
 461         " max_old_gen_size: " SIZE_FORMAT
 462         " max_eden_size: " SIZE_FORMAT
 463         " mem_free_limit: " SIZE_FORMAT,
 464         promo_limit, max_eden_size, total_free_limit,
 465         max_old_gen_size, max_eden_size,
 466         (size_t) mem_free_limit);

 467 
 468   bool print_gc_overhead_limit_would_be_exceeded = false;
 469   if (is_full_gc) {
 470     if (gc_cost() > gc_cost_limit &&
 471       free_in_old_gen < (size_t) mem_free_old_limit &&
 472       free_in_eden < (size_t) mem_free_eden_limit) {
 473       // Collections, on average, are taking too much time, and
 474       //      gc_cost() > gc_cost_limit
 475       // we have too little space available after a full gc.
 476       //      total_free_limit < mem_free_limit
 477       // where
 478       //   total_free_limit is the free space available in
 479       //     both generations
 480       //   total_mem is the total space available for allocation
 481       //     in both generations (survivor spaces are not included
 482       //     just as they are not included in eden_limit).
 483       //   mem_free_limit is a fraction of total_mem judged to be an
 484       //     acceptable amount that is still unused.
 485       // The heap can ask for the value of this variable when deciding
 486       // whether to thrown an OutOfMemory error.


 492       // At this point the GC overhead limit is being exceeded.
 493       inc_gc_overhead_limit_count();
 494       if (UseGCOverheadLimit) {
 495         if (gc_overhead_limit_count() >=
 496             AdaptiveSizePolicyGCTimeLimitThreshold){
 497           // All conditions have been met for throwing an out-of-memory
 498           set_gc_overhead_limit_exceeded(true);
 499           // Avoid consecutive OOM due to the gc time limit by resetting
 500           // the counter.
 501           reset_gc_overhead_limit_count();
 502         } else {
 503           // The required consecutive collections which exceed the
 504           // GC time limit may or may not have been reached. We
 505           // are approaching that condition and so as not to
 506           // throw an out-of-memory before all SoftRef's have been
 507           // cleared, set _should_clear_all_soft_refs in CollectorPolicy.
 508           // The clearing will be done on the next GC.
 509           bool near_limit = gc_overhead_limit_near();
 510           if (near_limit) {
 511             collector_policy->set_should_clear_all_soft_refs(true);
 512             log_trace(gc, ergo)("Nearing GC overhead limit, will be clearing all SoftReference");



 513           }
 514         }
 515       }
 516       // Set this even when the overhead limit will not
 517       // cause an out-of-memory.  Diagnostic message indicating
 518       // that the overhead limit is being exceeded is sometimes
 519       // printed.
 520       print_gc_overhead_limit_would_be_exceeded = true;
 521 
 522     } else {
 523       // Did not exceed overhead limits
 524       reset_gc_overhead_limit_count();
 525     }
 526   }
 527 
 528   if (UseGCOverheadLimit) {
 529     if (gc_overhead_limit_exceeded()) {
 530       log_trace(gc, ergo)("GC is exceeding overhead limit of " UINTX_FORMAT "%%", GCTimeLimit);

 531       reset_gc_overhead_limit_count();
 532     } else if (print_gc_overhead_limit_would_be_exceeded) {
 533       assert(gc_overhead_limit_count() > 0, "Should not be printing");
 534       log_trace(gc, ergo)("GC would exceed overhead limit of " UINTX_FORMAT "%% %d consecutive time(s)",

 535                           GCTimeLimit, gc_overhead_limit_count());
 536     }
 537   }
 538 }
 539 // Printing
 540 
 541 bool AdaptiveSizePolicy::print() const {
 542   assert(UseAdaptiveSizePolicy, "UseAdaptiveSizePolicy need to be enabled.");
 543 
 544   if (!Log<LOG_TAGS(gc, ergo)>::is_debug()) {
 545     return false;
 546   }
 547 
 548   // Print goal for which action is needed.
 549   char* action = NULL;
 550   bool change_for_pause = false;
 551   if ((change_old_gen_for_maj_pauses() ==
 552          decrease_old_gen_for_maj_pauses_true) ||
 553       (change_young_gen_for_min_pauses() ==
 554          decrease_young_gen_for_min_pauses_true)) {
 555     action = (char*) " *** pause time goal ***";
 556     change_for_pause = true;
 557   } else if ((change_old_gen_for_throughput() ==
 558                increase_old_gen_for_throughput_true) ||
 559             (change_young_gen_for_throughput() ==
 560                increase_young_gen_for_througput_true)) {
 561     action = (char*) " *** throughput goal ***";
 562   } else if (decrease_for_footprint()) {
 563     action = (char*) " *** reduced footprint ***";
 564   } else {
 565     // No actions were taken.  This can legitimately be the
 566     // situation if not enough data has been gathered to make


 594   if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
 595     assert(change_young_gen_for_throughput() ==
 596            increase_young_gen_for_througput_true,
 597            "Both generations should be growing");
 598     young_gen_action = grow_msg;
 599     tenured_gen_action = grow_msg;
 600   } else if (change_young_gen_for_throughput() ==
 601              increase_young_gen_for_througput_true) {
 602     // Only the young generation may grow at start up (before
 603     // enough full collections have been done to grow the old generation).
 604     young_gen_action = grow_msg;
 605     tenured_gen_action = no_change_msg;
 606   }
 607 
 608   // Minimum footprint
 609   if (decrease_for_footprint() != 0) {
 610     young_gen_action = shrink_msg;
 611     tenured_gen_action = shrink_msg;
 612   }
 613 
 614   log_debug(gc, ergo)("UseAdaptiveSizePolicy actions to meet %s", action);
 615   log_debug(gc, ergo)("                       GC overhead (%%)");
 616   log_debug(gc, ergo)("    Young generation:     %7.2f\t  %s",
 617                       100.0 * avg_minor_gc_cost()->average(), young_gen_action);
 618   log_debug(gc, ergo)("    Tenured generation:   %7.2f\t  %s",
 619                       100.0 * avg_major_gc_cost()->average(), tenured_gen_action);


 620   return true;
 621 }
 622 
 623 void AdaptiveSizePolicy::print_tenuring_threshold( uint new_tenuring_threshold_arg) const {






 624   // Tenuring threshold

 625   if (decrement_tenuring_threshold_for_survivor_limit()) {
 626     log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to avoid survivor space overflow) = %u", new_tenuring_threshold_arg);

 627   } else if (decrement_tenuring_threshold_for_gc_cost()) {
 628     log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to balance GC costs) = %u", new_tenuring_threshold_arg);

 629   } else if (increment_tenuring_threshold_for_gc_cost()) {
 630     log_debug(gc, ergo)("Tenuring threshold: (attempted to increase to balance GC costs) = %u", new_tenuring_threshold_arg);

 631   } else {

 632     assert(!tenuring_threshold_change(), "(no change was attempted)");
 633   }




 634 }
< prev index next >