| 1 | /* |
| 2 | * Copyright (c) 2013, 2018, Red Hat, Inc. All rights reserved. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 11 | * version 2 for more details (a copy is included in the LICENSE file that |
| 12 | * accompanied this code). |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License version |
| 15 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 19 | * or visit www.oracle.com if you need additional information or have any |
| 20 | * questions. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "precompiled.hpp" |
| 25 | |
| 26 | #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" |
| 27 | #include "gc/shenandoah/shenandoahHeap.inline.hpp" |
| 28 | #include "runtime/os.hpp" |
| 29 | |
| 30 | ShenandoahCollectorPolicy::ShenandoahCollectorPolicy() : |
| 31 | _success_concurrent_gcs(0), |
| 32 | _success_degenerated_gcs(0), |
| 33 | _success_full_gcs(0), |
| 34 | _alloc_failure_degenerated(0), |
| 35 | _alloc_failure_degenerated_upgrade_to_full(0), |
| 36 | _alloc_failure_full(0), |
| 37 | _explicit_concurrent(0), |
| 38 | _explicit_full(0), |
| 39 | _implicit_concurrent(0), |
| 40 | _implicit_full(0), |
| 41 | _cycle_counter(0) { |
| 42 | |
| 43 | Copy::zero_to_bytes(_degen_points, sizeof(size_t) * ShenandoahHeap::_DEGENERATED_LIMIT); |
| 44 | |
| 45 | _tracer = new (ResourceObj::C_HEAP, mtGC) ShenandoahTracer(); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | void ShenandoahCollectorPolicy::record_explicit_to_concurrent() { |
| 50 | _explicit_concurrent++; |
| 51 | } |
| 52 | |
| 53 | void ShenandoahCollectorPolicy::record_explicit_to_full() { |
| 54 | _explicit_full++; |
| 55 | } |
| 56 | |
| 57 | void ShenandoahCollectorPolicy::record_implicit_to_concurrent() { |
| 58 | _implicit_concurrent++; |
| 59 | } |
| 60 | |
| 61 | void ShenandoahCollectorPolicy::record_implicit_to_full() { |
| 62 | _implicit_full++; |
| 63 | } |
| 64 | |
| 65 | void ShenandoahCollectorPolicy::record_alloc_failure_to_full() { |
| 66 | _alloc_failure_full++; |
| 67 | } |
| 68 | |
| 69 | void ShenandoahCollectorPolicy::record_alloc_failure_to_degenerated(ShenandoahHeap::ShenandoahDegenPoint point) { |
| 70 | assert(point < ShenandoahHeap::_DEGENERATED_LIMIT, "sanity" ); |
| 71 | _alloc_failure_degenerated++; |
| 72 | _degen_points[point]++; |
| 73 | } |
| 74 | |
| 75 | void ShenandoahCollectorPolicy::record_degenerated_upgrade_to_full() { |
| 76 | _alloc_failure_degenerated_upgrade_to_full++; |
| 77 | } |
| 78 | |
| 79 | void ShenandoahCollectorPolicy::record_success_concurrent() { |
| 80 | _success_concurrent_gcs++; |
| 81 | } |
| 82 | |
| 83 | void ShenandoahCollectorPolicy::record_success_degenerated() { |
| 84 | _success_degenerated_gcs++; |
| 85 | } |
| 86 | |
| 87 | void ShenandoahCollectorPolicy::record_success_full() { |
| 88 | _success_full_gcs++; |
| 89 | } |
| 90 | |
| 91 | size_t ShenandoahCollectorPolicy::cycle_counter() const { |
| 92 | return _cycle_counter; |
| 93 | } |
| 94 | |
| 95 | void ShenandoahCollectorPolicy::record_cycle_start() { |
| 96 | _cycle_counter++; |
| 97 | } |
| 98 | |
| 99 | void ShenandoahCollectorPolicy::record_shutdown() { |
| 100 | _in_shutdown.set(); |
| 101 | } |
| 102 | |
| 103 | bool ShenandoahCollectorPolicy::is_at_shutdown() { |
| 104 | return _in_shutdown.is_set(); |
| 105 | } |
| 106 | |
| 107 | void ShenandoahCollectorPolicy::print_gc_stats(outputStream* out) const { |
| 108 | out->print_cr("Under allocation pressure, concurrent cycles may cancel, and either continue cycle" ); |
| 109 | out->print_cr("under stop-the-world pause or result in stop-the-world Full GC. Increase heap size," ); |
| 110 | out->print_cr("tune GC heuristics, set more aggressive pacing delay, or lower allocation rate" ); |
| 111 | out->print_cr("to avoid Degenerated and Full GC cycles." ); |
| 112 | out->cr(); |
| 113 | |
| 114 | out->print_cr(SIZE_FORMAT_W(5) " successful concurrent GCs" , _success_concurrent_gcs); |
| 115 | out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly" , _explicit_concurrent); |
| 116 | out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly" , _implicit_concurrent); |
| 117 | out->cr(); |
| 118 | |
| 119 | out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs" , _success_degenerated_gcs); |
| 120 | out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure" , _alloc_failure_degenerated); |
| 121 | for (int c = 0; c < ShenandoahHeap::_DEGENERATED_LIMIT; c++) { |
| 122 | if (_degen_points[c] > 0) { |
| 123 | const char* desc = ShenandoahHeap::degen_point_to_string((ShenandoahHeap::ShenandoahDegenPoint)c); |
| 124 | out->print_cr(" " SIZE_FORMAT_W(5) " happened at %s" , _degen_points[c], desc); |
| 125 | } |
| 126 | } |
| 127 | out->print_cr(" " SIZE_FORMAT_W(5) " upgraded to Full GC" , _alloc_failure_degenerated_upgrade_to_full); |
| 128 | out->cr(); |
| 129 | |
| 130 | out->print_cr(SIZE_FORMAT_W(5) " Full GCs" , _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full); |
| 131 | out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly" , _explicit_full); |
| 132 | out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly" , _implicit_full); |
| 133 | out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure" , _alloc_failure_full); |
| 134 | out->print_cr(" " SIZE_FORMAT_W(5) " upgraded from Degenerated GC" , _alloc_failure_degenerated_upgrade_to_full); |
| 135 | } |
| 136 | |