src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp

Print this page




 177       " padded_average_promoted " SIZE_FORMAT
 178       " free in old gen " SIZE_FORMAT,
 179       (size_t) average_promoted_in_bytes(),
 180       (size_t) padded_average_promoted_in_bytes(),
 181       old_free_in_bytes);
 182   }
 183   return result;
 184 }
 185 
 186 void PSAdaptiveSizePolicy::clear_generation_free_space_flags() {
 187 
 188   AdaptiveSizePolicy::clear_generation_free_space_flags();
 189 
 190   set_change_old_gen_for_min_pauses(0);
 191 
 192   set_change_young_gen_for_maj_pauses(0);
 193 }
 194 
 195 // If this is not a full GC, only test and modify the young generation.
 196 
 197 void PSAdaptiveSizePolicy::compute_generation_free_space(
 198                                            size_t young_live,
 199                                            size_t eden_live,
 200                                            size_t old_live,
 201                                            size_t cur_eden,
 202                                            size_t max_old_gen_size,
 203                                            size_t max_eden_size,
 204                                            bool   is_full_gc,
 205                                            GCCause::Cause gc_cause,
 206                                            CollectorPolicy* collector_policy) {
 207 
 208   // Update statistics
 209   // Time statistics are updated as we go, update footprint stats here
 210   _avg_base_footprint->sample(BaseFootPrintEstimate);
 211   avg_young_live()->sample(young_live);
 212   avg_eden_live()->sample(eden_live);
 213   if (is_full_gc) {
 214     // old_live is only accurate after a full gc
 215     avg_old_live()->sample(old_live);
 216   }
 217 


 328         avg_major_gc_cost()->average() >= 0.0 &&
 329         avg_minor_gc_cost()->average() >= 0.0) {
 330       size_t desired_sum = desired_eden_size + desired_promo_size;
 331       desired_eden_size = adjust_eden_for_footprint(desired_eden_size,
 332                                                     desired_sum);
 333       if (is_full_gc) {
 334         set_decide_at_full_gc(decide_at_full_gc_true);
 335         desired_promo_size = adjust_promo_for_footprint(desired_promo_size,
 336                                                         desired_sum);
 337       }
 338     }
 339   }
 340 
 341   // Note we make the same tests as in the code block below;  the code
 342   // seems a little easier to read with the printing in another block.
 343   if (PrintAdaptiveSizePolicy) {
 344     if (desired_promo_size > promo_limit)  {
 345       // "free_in_old_gen" was the original value for used for promo_limit
 346       size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
 347       gclog_or_tty->print_cr(
 348             "PSAdaptiveSizePolicy::compute_generation_free_space limits:"
 349             " desired_promo_size: " SIZE_FORMAT
 350             " promo_limit: " SIZE_FORMAT
 351             " free_in_old_gen: " SIZE_FORMAT
 352             " max_old_gen_size: " SIZE_FORMAT
 353             " avg_old_live: " SIZE_FORMAT,
 354             desired_promo_size, promo_limit, free_in_old_gen,
 355             max_old_gen_size, (size_t) avg_old_live()->average());
 356     }
 357     if (desired_eden_size > eden_limit) {
 358       gclog_or_tty->print_cr(
 359             "AdaptiveSizePolicy::compute_generation_free_space limits:"
 360             " desired_eden_size: " SIZE_FORMAT
 361             " old_eden_size: " SIZE_FORMAT
 362             " eden_limit: " SIZE_FORMAT
 363             " cur_eden: " SIZE_FORMAT
 364             " max_eden_size: " SIZE_FORMAT
 365             " avg_young_live: " SIZE_FORMAT,
 366             desired_eden_size, _eden_size, eden_limit, cur_eden,
 367             max_eden_size, (size_t)avg_young_live()->average());
 368     }
 369     if (gc_cost() > gc_cost_limit) {
 370       gclog_or_tty->print_cr(
 371             "AdaptiveSizePolicy::compute_generation_free_space: gc time limit"
 372             " gc_cost: %f "
 373             " GCTimeLimit: %d",
 374             gc_cost(), GCTimeLimit);
 375     }
 376   }
 377 
 378   // Align everything and make a final limit check
 379   const size_t alignment = _intra_generation_alignment;
 380   desired_eden_size  = align_size_up(desired_eden_size, alignment);
 381   desired_eden_size  = MAX2(desired_eden_size, alignment);
 382   desired_promo_size = align_size_up(desired_promo_size, alignment);
 383   desired_promo_size = MAX2(desired_promo_size, alignment);
 384 
 385   eden_limit  = align_size_down(eden_limit, alignment);
 386   promo_limit = align_size_down(promo_limit, alignment);
 387 
 388   // Is too much time being spent in GC?
 389   //   Is the heap trying to grow beyond it's limits?
 390 
 391   const size_t free_in_old_gen =


 399                             gc_cause,
 400                             collector_policy);
 401   }
 402 
 403 
 404   // And one last limit check, now that we've aligned things.
 405   if (desired_eden_size > eden_limit) {
 406     // If the policy says to get a larger eden but
 407     // is hitting the limit, don't decrease eden.
 408     // This can lead to a general drifting down of the
 409     // eden size.  Let the tenuring calculation push more
 410     // into the old gen.
 411     desired_eden_size = MAX2(eden_limit, cur_eden);
 412   }
 413   desired_promo_size = MIN2(desired_promo_size, promo_limit);
 414 
 415 
 416   if (PrintAdaptiveSizePolicy) {
 417     // Timing stats
 418     gclog_or_tty->print(
 419                "PSAdaptiveSizePolicy::compute_generation_free_space: costs"
 420                " minor_time: %f"
 421                " major_cost: %f"
 422                " mutator_cost: %f"
 423                " throughput_goal: %f",
 424                minor_gc_cost(), major_gc_cost(), mutator_cost(),
 425                _throughput_goal);
 426 
 427     // We give more details if Verbose is set
 428     if (Verbose) {
 429       gclog_or_tty->print( " minor_pause: %f"
 430                   " major_pause: %f"
 431                   " minor_interval: %f"
 432                   " major_interval: %f"
 433                   " pause_goal: %f",
 434                   _avg_minor_pause->padded_average(),
 435                   _avg_major_pause->padded_average(),
 436                   _avg_minor_interval->average(),
 437                   _avg_major_interval->average(),
 438                   gc_pause_goal_sec());
 439     }


 590             <= AdaptiveSizePolicyInitializingSteps)) {
 591           set_change_young_gen_for_maj_pauses(
 592           increase_young_gen_for_maj_pauses_true);
 593           eden_heap_delta = eden_increment_aligned_up(*desired_eden_size_ptr);
 594           *desired_eden_size_ptr = _eden_size + eden_heap_delta;
 595           _young_gen_change_for_major_pause_count++;
 596         } else {
 597           // Record that decreasing the young gen size would decrease
 598           // the major pause
 599           set_change_young_gen_for_maj_pauses(
 600             decrease_young_gen_for_maj_pauses_true);
 601           eden_heap_delta = eden_decrement_aligned_down(*desired_eden_size_ptr);
 602           *desired_eden_size_ptr = _eden_size - eden_heap_delta;
 603         }
 604       }
 605     }
 606   }
 607 
 608   if (PrintAdaptiveSizePolicy && Verbose) {
 609     gclog_or_tty->print_cr(
 610       "AdaptiveSizePolicy::compute_generation_free_space "
 611       "adjusting gen sizes for major pause (avg %f goal %f). "
 612       "desired_promo_size " SIZE_FORMAT "desired_eden_size "
 613        SIZE_FORMAT
 614       " promo delta " SIZE_FORMAT  " eden delta " SIZE_FORMAT,
 615       _avg_major_pause->average(), gc_pause_goal_sec(),
 616       *desired_promo_size_ptr, *desired_eden_size_ptr,
 617       promo_heap_delta, eden_heap_delta);
 618   }
 619 }
 620 
 621 void PSAdaptiveSizePolicy::adjust_for_throughput(bool is_full_gc,
 622                                              size_t* desired_promo_size_ptr,
 623                                              size_t* desired_eden_size_ptr) {
 624 
 625   // Add some checks for a threshhold for a change.  For example,
 626   // a change less than the required alignment is probably not worth
 627   // attempting.
 628   if (is_full_gc) {
 629     set_decide_at_full_gc(decide_at_full_gc_true);
 630   }


 793     gclog_or_tty->print_cr(
 794         "adjusting eden for throughput (avg %f goal %f). desired_eden_size "
 795         SIZE_FORMAT " eden delta " SIZE_FORMAT "\n",
 796       mutator_cost(), _throughput_goal,
 797         *desired_eden_size_ptr, scaled_eden_heap_delta);
 798   }
 799 }
 800 
 801 size_t PSAdaptiveSizePolicy::adjust_promo_for_footprint(
 802     size_t desired_promo_size, size_t desired_sum) {
 803   assert(desired_promo_size <= desired_sum, "Inconsistent parameters");
 804   set_decrease_for_footprint(decrease_old_gen_for_footprint_true);
 805 
 806   size_t change = promo_decrement(desired_promo_size);
 807   change = scale_down(change, desired_promo_size, desired_sum);
 808 
 809   size_t reduced_size = desired_promo_size - change;
 810 
 811   if (PrintAdaptiveSizePolicy && Verbose) {
 812     gclog_or_tty->print_cr(
 813       "AdaptiveSizePolicy::compute_generation_free_space "
 814       "adjusting tenured gen for footprint. "
 815       "starting promo size " SIZE_FORMAT
 816       " reduced promo size " SIZE_FORMAT,
 817       " promo delta " SIZE_FORMAT,
 818       desired_promo_size, reduced_size, change );
 819   }
 820 
 821   assert(reduced_size <= desired_promo_size, "Inconsistent result");
 822   return reduced_size;
 823 }
 824 
 825 size_t PSAdaptiveSizePolicy::adjust_eden_for_footprint(
 826   size_t desired_eden_size, size_t desired_sum) {
 827   assert(desired_eden_size <= desired_sum, "Inconsistent parameters");
 828   set_decrease_for_footprint(decrease_young_gen_for_footprint_true);
 829 
 830   size_t change = eden_decrement(desired_eden_size);
 831   change = scale_down(change, desired_eden_size, desired_sum);
 832 
 833   size_t reduced_size = desired_eden_size - change;
 834 
 835   if (PrintAdaptiveSizePolicy && Verbose) {
 836     gclog_or_tty->print_cr(
 837       "AdaptiveSizePolicy::compute_generation_free_space "
 838       "adjusting eden for footprint. "
 839       " starting eden size " SIZE_FORMAT
 840       " reduced eden size " SIZE_FORMAT
 841       " eden delta " SIZE_FORMAT,
 842       desired_eden_size, reduced_size, change);
 843   }
 844 
 845   assert(reduced_size <= desired_eden_size, "Inconsistent result");
 846   return reduced_size;
 847 }
 848 
 849 // Scale down "change" by the factor
 850 //      part / total
 851 // Don't align the results.
 852 
 853 size_t PSAdaptiveSizePolicy::scale_down(size_t change,
 854                                         double part,
 855                                         double total) {
 856   assert(part <= total, "Inconsistent input");
 857   size_t reduced_change = change;




 177       " padded_average_promoted " SIZE_FORMAT
 178       " free in old gen " SIZE_FORMAT,
 179       (size_t) average_promoted_in_bytes(),
 180       (size_t) padded_average_promoted_in_bytes(),
 181       old_free_in_bytes);
 182   }
 183   return result;
 184 }
 185 
 186 void PSAdaptiveSizePolicy::clear_generation_free_space_flags() {
 187 
 188   AdaptiveSizePolicy::clear_generation_free_space_flags();
 189 
 190   set_change_old_gen_for_min_pauses(0);
 191 
 192   set_change_young_gen_for_maj_pauses(0);
 193 }
 194 
 195 // If this is not a full GC, only test and modify the young generation.
 196 
 197 void PSAdaptiveSizePolicy::compute_generations_free_space(
 198                                            size_t young_live,
 199                                            size_t eden_live,
 200                                            size_t old_live,
 201                                            size_t cur_eden,
 202                                            size_t max_old_gen_size,
 203                                            size_t max_eden_size,
 204                                            bool   is_full_gc,
 205                                            GCCause::Cause gc_cause,
 206                                            CollectorPolicy* collector_policy) {
 207 
 208   // Update statistics
 209   // Time statistics are updated as we go, update footprint stats here
 210   _avg_base_footprint->sample(BaseFootPrintEstimate);
 211   avg_young_live()->sample(young_live);
 212   avg_eden_live()->sample(eden_live);
 213   if (is_full_gc) {
 214     // old_live is only accurate after a full gc
 215     avg_old_live()->sample(old_live);
 216   }
 217 


 328         avg_major_gc_cost()->average() >= 0.0 &&
 329         avg_minor_gc_cost()->average() >= 0.0) {
 330       size_t desired_sum = desired_eden_size + desired_promo_size;
 331       desired_eden_size = adjust_eden_for_footprint(desired_eden_size,
 332                                                     desired_sum);
 333       if (is_full_gc) {
 334         set_decide_at_full_gc(decide_at_full_gc_true);
 335         desired_promo_size = adjust_promo_for_footprint(desired_promo_size,
 336                                                         desired_sum);
 337       }
 338     }
 339   }
 340 
 341   // Note we make the same tests as in the code block below;  the code
 342   // seems a little easier to read with the printing in another block.
 343   if (PrintAdaptiveSizePolicy) {
 344     if (desired_promo_size > promo_limit)  {
 345       // "free_in_old_gen" was the original value for used for promo_limit
 346       size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
 347       gclog_or_tty->print_cr(
 348             "PSAdaptiveSizePolicy::compute_generations_free_space limits:"
 349             " desired_promo_size: " SIZE_FORMAT
 350             " promo_limit: " SIZE_FORMAT
 351             " free_in_old_gen: " SIZE_FORMAT
 352             " max_old_gen_size: " SIZE_FORMAT
 353             " avg_old_live: " SIZE_FORMAT,
 354             desired_promo_size, promo_limit, free_in_old_gen,
 355             max_old_gen_size, (size_t) avg_old_live()->average());
 356     }
 357     if (desired_eden_size > eden_limit) {
 358       gclog_or_tty->print_cr(
 359             "AdaptiveSizePolicy::compute_generations_free_space limits:"
 360             " desired_eden_size: " SIZE_FORMAT
 361             " old_eden_size: " SIZE_FORMAT
 362             " eden_limit: " SIZE_FORMAT
 363             " cur_eden: " SIZE_FORMAT
 364             " max_eden_size: " SIZE_FORMAT
 365             " avg_young_live: " SIZE_FORMAT,
 366             desired_eden_size, _eden_size, eden_limit, cur_eden,
 367             max_eden_size, (size_t)avg_young_live()->average());
 368     }
 369     if (gc_cost() > gc_cost_limit) {
 370       gclog_or_tty->print_cr(
 371             "AdaptiveSizePolicy::compute_generations_free_space: gc time limit"
 372             " gc_cost: %f "
 373             " GCTimeLimit: %d",
 374             gc_cost(), GCTimeLimit);
 375     }
 376   }
 377 
 378   // Align everything and make a final limit check
 379   const size_t alignment = _intra_generation_alignment;
 380   desired_eden_size  = align_size_up(desired_eden_size, alignment);
 381   desired_eden_size  = MAX2(desired_eden_size, alignment);
 382   desired_promo_size = align_size_up(desired_promo_size, alignment);
 383   desired_promo_size = MAX2(desired_promo_size, alignment);
 384 
 385   eden_limit  = align_size_down(eden_limit, alignment);
 386   promo_limit = align_size_down(promo_limit, alignment);
 387 
 388   // Is too much time being spent in GC?
 389   //   Is the heap trying to grow beyond it's limits?
 390 
 391   const size_t free_in_old_gen =


 399                             gc_cause,
 400                             collector_policy);
 401   }
 402 
 403 
 404   // And one last limit check, now that we've aligned things.
 405   if (desired_eden_size > eden_limit) {
 406     // If the policy says to get a larger eden but
 407     // is hitting the limit, don't decrease eden.
 408     // This can lead to a general drifting down of the
 409     // eden size.  Let the tenuring calculation push more
 410     // into the old gen.
 411     desired_eden_size = MAX2(eden_limit, cur_eden);
 412   }
 413   desired_promo_size = MIN2(desired_promo_size, promo_limit);
 414 
 415 
 416   if (PrintAdaptiveSizePolicy) {
 417     // Timing stats
 418     gclog_or_tty->print(
 419                "PSAdaptiveSizePolicy::compute_generations_free_space: costs"
 420                " minor_time: %f"
 421                " major_cost: %f"
 422                " mutator_cost: %f"
 423                " throughput_goal: %f",
 424                minor_gc_cost(), major_gc_cost(), mutator_cost(),
 425                _throughput_goal);
 426 
 427     // We give more details if Verbose is set
 428     if (Verbose) {
 429       gclog_or_tty->print( " minor_pause: %f"
 430                   " major_pause: %f"
 431                   " minor_interval: %f"
 432                   " major_interval: %f"
 433                   " pause_goal: %f",
 434                   _avg_minor_pause->padded_average(),
 435                   _avg_major_pause->padded_average(),
 436                   _avg_minor_interval->average(),
 437                   _avg_major_interval->average(),
 438                   gc_pause_goal_sec());
 439     }


 590             <= AdaptiveSizePolicyInitializingSteps)) {
 591           set_change_young_gen_for_maj_pauses(
 592           increase_young_gen_for_maj_pauses_true);
 593           eden_heap_delta = eden_increment_aligned_up(*desired_eden_size_ptr);
 594           *desired_eden_size_ptr = _eden_size + eden_heap_delta;
 595           _young_gen_change_for_major_pause_count++;
 596         } else {
 597           // Record that decreasing the young gen size would decrease
 598           // the major pause
 599           set_change_young_gen_for_maj_pauses(
 600             decrease_young_gen_for_maj_pauses_true);
 601           eden_heap_delta = eden_decrement_aligned_down(*desired_eden_size_ptr);
 602           *desired_eden_size_ptr = _eden_size - eden_heap_delta;
 603         }
 604       }
 605     }
 606   }
 607 
 608   if (PrintAdaptiveSizePolicy && Verbose) {
 609     gclog_or_tty->print_cr(
 610       "AdaptiveSizePolicy::compute_generations_free_space "
 611       "adjusting gen sizes for major pause (avg %f goal %f). "
 612       "desired_promo_size " SIZE_FORMAT "desired_eden_size "
 613        SIZE_FORMAT
 614       " promo delta " SIZE_FORMAT  " eden delta " SIZE_FORMAT,
 615       _avg_major_pause->average(), gc_pause_goal_sec(),
 616       *desired_promo_size_ptr, *desired_eden_size_ptr,
 617       promo_heap_delta, eden_heap_delta);
 618   }
 619 }
 620 
 621 void PSAdaptiveSizePolicy::adjust_for_throughput(bool is_full_gc,
 622                                              size_t* desired_promo_size_ptr,
 623                                              size_t* desired_eden_size_ptr) {
 624 
 625   // Add some checks for a threshhold for a change.  For example,
 626   // a change less than the required alignment is probably not worth
 627   // attempting.
 628   if (is_full_gc) {
 629     set_decide_at_full_gc(decide_at_full_gc_true);
 630   }


 793     gclog_or_tty->print_cr(
 794         "adjusting eden for throughput (avg %f goal %f). desired_eden_size "
 795         SIZE_FORMAT " eden delta " SIZE_FORMAT "\n",
 796       mutator_cost(), _throughput_goal,
 797         *desired_eden_size_ptr, scaled_eden_heap_delta);
 798   }
 799 }
 800 
 801 size_t PSAdaptiveSizePolicy::adjust_promo_for_footprint(
 802     size_t desired_promo_size, size_t desired_sum) {
 803   assert(desired_promo_size <= desired_sum, "Inconsistent parameters");
 804   set_decrease_for_footprint(decrease_old_gen_for_footprint_true);
 805 
 806   size_t change = promo_decrement(desired_promo_size);
 807   change = scale_down(change, desired_promo_size, desired_sum);
 808 
 809   size_t reduced_size = desired_promo_size - change;
 810 
 811   if (PrintAdaptiveSizePolicy && Verbose) {
 812     gclog_or_tty->print_cr(
 813       "AdaptiveSizePolicy::compute_generations_free_space "
 814       "adjusting tenured gen for footprint. "
 815       "starting promo size " SIZE_FORMAT
 816       " reduced promo size " SIZE_FORMAT,
 817       " promo delta " SIZE_FORMAT,
 818       desired_promo_size, reduced_size, change );
 819   }
 820 
 821   assert(reduced_size <= desired_promo_size, "Inconsistent result");
 822   return reduced_size;
 823 }
 824 
 825 size_t PSAdaptiveSizePolicy::adjust_eden_for_footprint(
 826   size_t desired_eden_size, size_t desired_sum) {
 827   assert(desired_eden_size <= desired_sum, "Inconsistent parameters");
 828   set_decrease_for_footprint(decrease_young_gen_for_footprint_true);
 829 
 830   size_t change = eden_decrement(desired_eden_size);
 831   change = scale_down(change, desired_eden_size, desired_sum);
 832 
 833   size_t reduced_size = desired_eden_size - change;
 834 
 835   if (PrintAdaptiveSizePolicy && Verbose) {
 836     gclog_or_tty->print_cr(
 837       "AdaptiveSizePolicy::compute_generations_free_space "
 838       "adjusting eden for footprint. "
 839       " starting eden size " SIZE_FORMAT
 840       " reduced eden size " SIZE_FORMAT
 841       " eden delta " SIZE_FORMAT,
 842       desired_eden_size, reduced_size, change);
 843   }
 844 
 845   assert(reduced_size <= desired_eden_size, "Inconsistent result");
 846   return reduced_size;
 847 }
 848 
 849 // Scale down "change" by the factor
 850 //      part / total
 851 // Don't align the results.
 852 
 853 size_t PSAdaptiveSizePolicy::scale_down(size_t change,
 854                                         double part,
 855                                         double total) {
 856   assert(part <= total, "Inconsistent input");
 857   size_t reduced_change = change;