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 ShenandoahHeapRegion::setup_sizes(initial_heap_byte_size(), max_heap_byte_size()); 46 47 initialize_all(); 48 49 _tracer = new (ResourceObj::C_HEAP, mtGC) ShenandoahTracer(); 50 51 } 52 53 void ShenandoahCollectorPolicy::initialize_alignments() { 54 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing(). 55 size_t align = ShenandoahHeapRegion::region_size_bytes(); 56 if (UseLargePages) { 57 align = MAX2(align, os::large_page_size()); 58 } 59 _space_alignment = align; 60 _heap_alignment = align; 61 } 62 63 void ShenandoahCollectorPolicy::record_explicit_to_concurrent() { 64 _explicit_concurrent++; 65 } 66 67 void ShenandoahCollectorPolicy::record_explicit_to_full() { 68 _explicit_full++; 69 } 70 71 void ShenandoahCollectorPolicy::record_implicit_to_concurrent() { 72 _implicit_concurrent++; 73 } 74 75 void ShenandoahCollectorPolicy::record_implicit_to_full() { 76 _implicit_full++; 77 } 78 79 void ShenandoahCollectorPolicy::record_alloc_failure_to_full() { 80 _alloc_failure_full++; 81 } 82 83 void ShenandoahCollectorPolicy::record_alloc_failure_to_degenerated(ShenandoahHeap::ShenandoahDegenPoint point) { 84 assert(point < ShenandoahHeap::_DEGENERATED_LIMIT, "sanity"); 85 _alloc_failure_degenerated++; 86 _degen_points[point]++; 87 } 88 89 void ShenandoahCollectorPolicy::record_degenerated_upgrade_to_full() { 90 _alloc_failure_degenerated_upgrade_to_full++; 91 } 92 93 void ShenandoahCollectorPolicy::record_success_concurrent() { 94 _success_concurrent_gcs++; 95 } 96 97 void ShenandoahCollectorPolicy::record_success_degenerated() { 98 _success_degenerated_gcs++; 99 } 100 101 void ShenandoahCollectorPolicy::record_success_full() { 102 _success_full_gcs++; 103 } 104 105 size_t ShenandoahCollectorPolicy::cycle_counter() const { 106 return _cycle_counter; 107 } 108 109 void ShenandoahCollectorPolicy::record_cycle_start() { 110 _cycle_counter++; 111 } 112 113 void ShenandoahCollectorPolicy::record_shutdown() { 114 _in_shutdown.set(); 115 } 116 117 bool ShenandoahCollectorPolicy::is_at_shutdown() { 118 return _in_shutdown.is_set(); 119 } 120 121 void ShenandoahCollectorPolicy::print_gc_stats(outputStream* out) const { 122 out->print_cr("Under allocation pressure, concurrent cycles may cancel, and either continue cycle"); 123 out->print_cr("under stop-the-world pause or result in stop-the-world Full GC. Increase heap size,"); 124 out->print_cr("tune GC heuristics, set more aggressive pacing delay, or lower allocation rate"); 125 out->print_cr("to avoid Degenerated and Full GC cycles."); 126 out->cr(); 127 128 out->print_cr(SIZE_FORMAT_W(5) " successful concurrent GCs", _success_concurrent_gcs); 129 out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly", _explicit_concurrent); 130 out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly", _implicit_concurrent); 131 out->cr(); 132 133 out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs", _success_degenerated_gcs); 134 out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_degenerated); 135 for (int c = 0; c < ShenandoahHeap::_DEGENERATED_LIMIT; c++) { 136 if (_degen_points[c] > 0) { 137 const char* desc = ShenandoahHeap::degen_point_to_string((ShenandoahHeap::ShenandoahDegenPoint)c); 138 out->print_cr(" " SIZE_FORMAT_W(5) " happened at %s", _degen_points[c], desc); 139 } 140 } 141 out->print_cr(" " SIZE_FORMAT_W(5) " upgraded to Full GC", _alloc_failure_degenerated_upgrade_to_full); 142 out->cr(); 143 144 out->print_cr(SIZE_FORMAT_W(5) " Full GCs", _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full); 145 out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly", _explicit_full); 146 out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly", _implicit_full); 147 out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_full); 148 out->print_cr(" " SIZE_FORMAT_W(5) " upgraded from Degenerated GC", _alloc_failure_degenerated_upgrade_to_full); 149 }