1 /* 2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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_implementation/g1/g1CollectedHeap.inline.hpp" 27 #include "gc_implementation/g1/g1IHOPControl.hpp" 28 #include "gc_implementation/shared/gcTrace.hpp" 29 #include "jfr/utilities/jfrLog.hpp" 30 31 G1IHOPControl::G1IHOPControl(double initial_ihop_percent) : 32 _initial_ihop_percent(initial_ihop_percent), 33 _target_occupancy(0), 34 _last_allocated_bytes(0), 35 _last_allocation_time_s(0.0) 36 { 37 assert(_initial_ihop_percent >= 0.0 && _initial_ihop_percent <= 100.0, "Initial IHOP value must be between 0 and 100."); 38 } 39 40 void G1IHOPControl::update_target_occupancy(size_t new_target_occupancy) { 41 log_debug(gc, ihop)("Target occupancy update: old: " SIZE_FORMAT "B, new: " SIZE_FORMAT "B", 42 _target_occupancy, new_target_occupancy); 43 _target_occupancy = new_target_occupancy; 44 } 45 46 void G1IHOPControl::update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) { 47 assert(allocation_time_s >= 0.0, "Allocation time must be positive."); 48 49 _last_allocation_time_s = allocation_time_s; 50 _last_allocated_bytes = allocated_bytes; 51 } 52 53 // should be defined in globalDefinitions.hpp 54 template<typename T> 55 inline double percent_of(T numerator, T denominator) { 56 return denominator != 0 ? (double)numerator / denominator * 100.0 : 0.0; 57 } 58 59 void G1IHOPControl::print() { 60 assert(_target_occupancy > 0, "Target occupancy still not updated yet."); 61 size_t cur_conc_mark_start_threshold = get_conc_mark_start_threshold(); 62 log_debug(gc, ihop)("Basic information (value update), threshold: " SIZE_FORMAT "B (%1.2f), target occupancy: " SIZE_FORMAT "B, current occupancy: " SIZE_FORMAT "B, " 63 "recent allocation size: " SIZE_FORMAT "B, recent allocation duration: %1.2fms, recent old gen allocation rate: %1.2fB/s, recent marking phase length: %1.2fms", 64 cur_conc_mark_start_threshold, 65 percent_of(cur_conc_mark_start_threshold, _target_occupancy), 66 _target_occupancy, 67 G1CollectedHeap::heap()->used(), 68 _last_allocated_bytes, 69 _last_allocation_time_s * 1000.0, 70 _last_allocation_time_s > 0.0 ? _last_allocated_bytes / _last_allocation_time_s : 0.0, 71 last_marking_length_s() * 1000.0); 72 } 73 74 void G1IHOPControl::send_trace_event(G1NewTracer* tracer) { 75 assert(_target_occupancy > 0, "Target occupancy still not updated yet."); 76 tracer->report_basic_ihop_statistics(get_conc_mark_start_threshold(), 77 _target_occupancy, 78 G1CollectedHeap::heap()->used(), 79 _last_allocated_bytes, 80 _last_allocation_time_s, 81 last_marking_length_s()); 82 } 83 84 G1StaticIHOPControl::G1StaticIHOPControl(double ihop_percent) : 85 G1IHOPControl(ihop_percent), 86 _last_marking_length_s(0.0) { 87 }