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
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();
|
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/softRefPolicy.hpp"
31 #include "gc/shared/workgroup.hpp"
32 #include "logging/log.hpp"
33 #include "runtime/timer.hpp"
34 #include "utilities/ostream.hpp"
35
36 elapsedTimer AdaptiveSizePolicy::_minor_timer;
37 elapsedTimer AdaptiveSizePolicy::_major_timer;
38 bool AdaptiveSizePolicy::_debug_perturbation = false;
39
40 // The throughput goal is implemented as
41 // _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
42 // gc_cost_ratio is the ratio
43 // application cost / gc cost
44 // For example a gc_cost_ratio of 4 translates into a
45 // throughput goal of .80
46
47 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
48 size_t init_promo_size,
49 size_t init_survivor_size,
50 double gc_pause_goal_sec,
51 uint gc_cost_ratio) :
52 _eden_size(init_eden_size),
53 _promo_size(init_promo_size),
54 _survivor_size(init_survivor_size),
55 _gc_pause_goal_sec(gc_pause_goal_sec),
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,
412 bool is_full_gc,
413 GCCause::Cause gc_cause,
414 SoftRefPolicy* soft_ref_policy) {
415
416 // Ignore explicit GC's. Exiting here does not set the flag and
417 // does not reset the count. Updating of the averages for system
418 // GC's is still controlled by UseAdaptiveSizePolicyWithSystemGC.
419 if (GCCause::is_user_requested_gc(gc_cause) ||
420 GCCause::is_serviceability_requested_gc(gc_cause)) {
421 return;
422 }
423 // eden_limit is the upper limit on the size of eden based on
424 // the maximum size of the young generation and the sizes
425 // of the survivor space.
426 // The question being asked is whether the gc costs are high
427 // and the space being recovered by a collection is low.
428 // free_in_young_gen is the free space in the young generation
429 // after a collection and promo_live is the free space in the old
430 // generation after a collection.
431 //
432 // Use the minimum of the current value of the live in the
433 // young gen or the average of the live in the young gen.
434 // If the current value drops quickly, that should be taken
491 // tenured gen.
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 soft_ref_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();
|