7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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/gcUtil.inline.hpp"
30 #include "gc/shared/workgroup.hpp"
31 #include "logging/log.hpp"
32 #include "runtime/timer.hpp"
33 #include "utilities/ostream.hpp"
34 elapsedTimer AdaptiveSizePolicy::_minor_timer;
35 elapsedTimer AdaptiveSizePolicy::_major_timer;
36 bool AdaptiveSizePolicy::_debug_perturbation = false;
37
38 // The throughput goal is implemented as
39 // _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
40 // gc_cost_ratio is the ratio
41 // application cost / gc cost
42 // For example a gc_cost_ratio of 4 translates into a
43 // throughput goal of .80
44
45 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
46 size_t init_promo_size,
47 size_t init_survivor_size,
48 double gc_pause_goal_sec,
49 uint gc_cost_ratio) :
50 _eden_size(init_eden_size),
51 _promo_size(init_promo_size),
52 _survivor_size(init_survivor_size),
53 _gc_pause_goal_sec(gc_pause_goal_sec),
392 }
393
394
395 void AdaptiveSizePolicy::clear_generation_free_space_flags() {
396 set_change_young_gen_for_min_pauses(0);
397 set_change_old_gen_for_maj_pauses(0);
398
399 set_change_old_gen_for_throughput(0);
400 set_change_young_gen_for_throughput(0);
401 set_decrease_for_footprint(0);
402 set_decide_at_full_gc(0);
403 }
404
405 void AdaptiveSizePolicy::check_gc_overhead_limit(
406 size_t young_live,
407 size_t eden_live,
408 size_t max_old_gen_size,
409 size_t max_eden_size,
410 bool is_full_gc,
411 GCCause::Cause gc_cause,
412 CollectorPolicy* collector_policy) {
413
414 // Ignore explicit GC's. Exiting here does not set the flag and
415 // does not reset the count. Updating of the averages for system
416 // GC's is still controlled by UseAdaptiveSizePolicyWithSystemGC.
417 if (GCCause::is_user_requested_gc(gc_cause) ||
418 GCCause::is_serviceability_requested_gc(gc_cause)) {
419 return;
420 }
421 // eden_limit is the upper limit on the size of eden based on
422 // the maximum size of the young generation and the sizes
423 // of the survivor space.
424 // The question being asked is whether the gc costs are high
425 // and the space being recovered by a collection is low.
426 // free_in_young_gen is the free space in the young generation
427 // after a collection and promo_live is the free space in the old
428 // generation after a collection.
429 //
430 // Use the minimum of the current value of the live in the
431 // young gen or the average of the live in the young gen.
432 // If the current value drops quickly, that should be taken
485 // Note that the gc time limit test only works for the collections
486 // of the young gen + tenured gen and not for collections of the
487 // permanent gen. That is because the calculation of the space
488 // freed by the collection is the free space in the young gen +
489 // tenured gen.
490 // At this point the GC overhead limit is being exceeded.
491 inc_gc_overhead_limit_count();
492 if (UseGCOverheadLimit) {
493 if (gc_overhead_limit_count() >=
494 AdaptiveSizePolicyGCTimeLimitThreshold){
495 // All conditions have been met for throwing an out-of-memory
496 set_gc_overhead_limit_exceeded(true);
497 // Avoid consecutive OOM due to the gc time limit by resetting
498 // the counter.
499 reset_gc_overhead_limit_count();
500 } else {
501 // The required consecutive collections which exceed the
502 // GC time limit may or may not have been reached. We
503 // are approaching that condition and so as not to
504 // throw an out-of-memory before all SoftRef's have been
505 // cleared, set _should_clear_all_soft_refs in CollectorPolicy.
506 // The clearing will be done on the next GC.
507 bool near_limit = gc_overhead_limit_near();
508 if (near_limit) {
509 collector_policy->set_should_clear_all_soft_refs(true);
510 log_trace(gc, ergo)("Nearing GC overhead limit, will be clearing all SoftReference");
511 }
512 }
513 }
514 // Set this even when the overhead limit will not
515 // cause an out-of-memory. Diagnostic message indicating
516 // that the overhead limit is being exceeded is sometimes
517 // printed.
518 print_gc_overhead_limit_would_be_exceeded = true;
519
520 } else {
521 // Did not exceed overhead limits
522 reset_gc_overhead_limit_count();
523 }
524 }
525
526 if (UseGCOverheadLimit) {
527 if (gc_overhead_limit_exceeded()) {
528 log_trace(gc, ergo)("GC is exceeding overhead limit of " UINTX_FORMAT "%%", GCTimeLimit);
529 reset_gc_overhead_limit_count();
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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/gcCause.hpp"
28 #include "gc/shared/gcUtil.inline.hpp"
29 #include "gc/shared/softRefPolicy.hpp"
30 #include "gc/shared/workgroup.hpp"
31 #include "logging/log.hpp"
32 #include "runtime/timer.hpp"
33 #include "utilities/ostream.hpp"
34
35 elapsedTimer AdaptiveSizePolicy::_minor_timer;
36 elapsedTimer AdaptiveSizePolicy::_major_timer;
37 bool AdaptiveSizePolicy::_debug_perturbation = false;
38
39 // The throughput goal is implemented as
40 // _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
41 // gc_cost_ratio is the ratio
42 // application cost / gc cost
43 // For example a gc_cost_ratio of 4 translates into a
44 // throughput goal of .80
45
46 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
47 size_t init_promo_size,
48 size_t init_survivor_size,
49 double gc_pause_goal_sec,
50 uint gc_cost_ratio) :
51 _eden_size(init_eden_size),
52 _promo_size(init_promo_size),
53 _survivor_size(init_survivor_size),
54 _gc_pause_goal_sec(gc_pause_goal_sec),
393 }
394
395
396 void AdaptiveSizePolicy::clear_generation_free_space_flags() {
397 set_change_young_gen_for_min_pauses(0);
398 set_change_old_gen_for_maj_pauses(0);
399
400 set_change_old_gen_for_throughput(0);
401 set_change_young_gen_for_throughput(0);
402 set_decrease_for_footprint(0);
403 set_decide_at_full_gc(0);
404 }
405
406 void AdaptiveSizePolicy::check_gc_overhead_limit(
407 size_t young_live,
408 size_t eden_live,
409 size_t max_old_gen_size,
410 size_t max_eden_size,
411 bool is_full_gc,
412 GCCause::Cause gc_cause,
413 SoftRefPolicy* soft_ref_policy) {
414
415 // Ignore explicit GC's. Exiting here does not set the flag and
416 // does not reset the count. Updating of the averages for system
417 // GC's is still controlled by UseAdaptiveSizePolicyWithSystemGC.
418 if (GCCause::is_user_requested_gc(gc_cause) ||
419 GCCause::is_serviceability_requested_gc(gc_cause)) {
420 return;
421 }
422 // eden_limit is the upper limit on the size of eden based on
423 // the maximum size of the young generation and the sizes
424 // of the survivor space.
425 // The question being asked is whether the gc costs are high
426 // and the space being recovered by a collection is low.
427 // free_in_young_gen is the free space in the young generation
428 // after a collection and promo_live is the free space in the old
429 // generation after a collection.
430 //
431 // Use the minimum of the current value of the live in the
432 // young gen or the average of the live in the young gen.
433 // If the current value drops quickly, that should be taken
486 // Note that the gc time limit test only works for the collections
487 // of the young gen + tenured gen and not for collections of the
488 // permanent gen. That is because the calculation of the space
489 // freed by the collection is the free space in the young gen +
490 // tenured gen.
491 // At this point the GC overhead limit is being exceeded.
492 inc_gc_overhead_limit_count();
493 if (UseGCOverheadLimit) {
494 if (gc_overhead_limit_count() >=
495 AdaptiveSizePolicyGCTimeLimitThreshold){
496 // All conditions have been met for throwing an out-of-memory
497 set_gc_overhead_limit_exceeded(true);
498 // Avoid consecutive OOM due to the gc time limit by resetting
499 // the counter.
500 reset_gc_overhead_limit_count();
501 } else {
502 // The required consecutive collections which exceed the
503 // GC time limit may or may not have been reached. We
504 // are approaching that condition and so as not to
505 // throw an out-of-memory before all SoftRef's have been
506 // cleared, set _should_clear_all_soft_refs in SoftRefPolicy.
507 // The clearing will be done on the next GC.
508 bool near_limit = gc_overhead_limit_near();
509 if (near_limit) {
510 soft_ref_policy->set_should_clear_all_soft_refs(true);
511 log_trace(gc, ergo)("Nearing GC overhead limit, will be clearing all SoftReference");
512 }
513 }
514 }
515 // Set this even when the overhead limit will not
516 // cause an out-of-memory. Diagnostic message indicating
517 // that the overhead limit is being exceeded is sometimes
518 // printed.
519 print_gc_overhead_limit_would_be_exceeded = true;
520
521 } else {
522 // Did not exceed overhead limits
523 reset_gc_overhead_limit_count();
524 }
525 }
526
527 if (UseGCOverheadLimit) {
528 if (gc_overhead_limit_exceeded()) {
529 log_trace(gc, ergo)("GC is exceeding overhead limit of " UINTX_FORMAT "%%", GCTimeLimit);
530 reset_gc_overhead_limit_count();
|