1 /* 2 * Copyright (c) 2015, 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 #ifndef SHARE_VM_GC_G1_G1IHOPCONTROL_HPP 26 #define SHARE_VM_GC_G1_G1IHOPCONTROL_HPP 27 28 #include "memory/allocation.hpp" 29 #include "utilities/numberSeq.hpp" 30 31 class G1Predictions; 32 33 // Base class for algorithms that calculate the heap occupancy at which 34 // concurrent marking should start. This heap usage threshold should be relative 35 // to old gen size. 36 class G1IHOPControl : public CHeapObj<mtGC> { 37 protected: 38 // The initial IHOP value relative to the target occupancy. 39 double _initial_ihop_percent; 40 // The target maximum occupancy of the heap. 41 size_t _target_occupancy; 42 43 // Initialize an instance with the initial IHOP value in percent and the target 44 // occupancy. The target occupancy is the number of bytes when marking should 45 // be finished and reclaim started. 46 G1IHOPControl(double initial_ihop_percent, size_t target_occupancy); 47 public: 48 virtual ~G1IHOPControl() { } 49 50 // Get the current non-young occupancy at which concurrent marking should start. 51 virtual size_t get_conc_mark_start_threshold() = 0; 52 53 // Update information about time during which allocations in the Java heap occurred, 54 // how large these allocations were in bytes, and an additional buffer. 55 // The allocations should contain any amount of space made unusable for further 56 // allocation, e.g. any waste caused by TLAB allocation, space at the end of 57 // humongous objects that can not be used for allocation, etc. 58 // Together with the target occupancy, this additional buffer should contain the 59 // difference between old gen size and total heap size at the start of reclamation, 60 // and space required for that reclamation. 61 virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) = 0; 62 // Update the time spent in the mutator beginning from the end of initial mark to 63 // the first mixed gc. 64 virtual void update_marking_length(double marking_length_s) = 0; 65 66 virtual void print() = 0; 67 }; 68 69 // The returned concurrent mark starting occupancy threshold is a fixed value 70 // relative to the maximum heap size. 71 class G1StaticIHOPControl : public G1IHOPControl { 72 // Most recent complete mutator allocation period in seconds. 73 double _last_allocation_time_s; 74 // Amount of bytes allocated during _last_allocation_time_s. 75 size_t _last_allocated_bytes; 76 // Most recent mutator time between the end of initial mark to the start of the 77 // first mixed gc. 78 double _last_marking_length_s; 79 public: 80 G1StaticIHOPControl(double ihop_percent, size_t target_occupancy); 81 82 size_t get_conc_mark_start_threshold() { return (size_t) (_initial_ihop_percent * _target_occupancy / 100.0); } 83 84 virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) { 85 assert(allocation_time_s >= 0.0, "Allocation time must be positive but is %.3f", allocation_time_s); 86 _last_allocation_time_s = allocation_time_s; 87 _last_allocated_bytes = allocated_bytes; 88 } 89 90 virtual void update_marking_length(double marking_length_s) { 91 assert(marking_length_s > 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s); 92 _last_marking_length_s = marking_length_s; 93 } 94 95 virtual void print(); 96 #ifndef PRODUCT 97 static void test(); 98 #endif 99 }; 100 101 class G1AdaptiveIHOPControl : public G1IHOPControl { 102 G1Predictions const * _predictor; 103 104 TruncatedSeq _marking_times_s; 105 TruncatedSeq _allocation_rate_s; 106 107 size_t _last_allocation_bytes; // Most recent mutator allocation since last GC. 108 size_t _prev_unrestrained_young_size; 109 110 size_t _current_threshold; 111 112 // Updates _current_threshold according to internal state. 113 void recalculate(); 114 115 bool have_enough_data_for_prediction() const; 116 public: 117 G1AdaptiveIHOPControl(double ihop_percent, size_t initial_target_occupancy, G1Predictions const* predictor); 118 119 virtual void set_target_occupancy(size_t target_occupancy); 120 121 virtual size_t get_conc_mark_start_threshold(); 122 123 virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size); 124 virtual void update_marking_length(double marking_length_s); 125 126 virtual void print(); 127 #ifndef PRODUCT 128 static void test(); 129 #endif 130 }; 131 132 #endif // SHARE_VM_GC_G1_G1IHOPCONTROL_HPP