1 /*
   2  * Copyright (c) 2016, 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_G1POLICY_HPP
  26 #define SHARE_VM_GC_G1_G1POLICY_HPP
  27 
  28 #include "gc/g1/g1CollectorState.hpp"
  29 #include "gc/g1/g1GCPhaseTimes.hpp"
  30 #include "gc/g1/g1InCSetState.hpp"
  31 #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp"
  32 #include "gc/g1/g1MMUTracker.hpp"
  33 #include "gc/g1/g1Predictions.hpp"
  34 #include "gc/g1/g1YoungGenSizer.hpp"
  35 #include "gc/shared/gcCause.hpp"
  36 #include "utilities/pair.hpp"
  37 
  38 // A G1Policy makes policy decisions that determine the
  39 // characteristics of the collector.  Examples include:
  40 //   * choice of collection set.
  41 //   * when to collect.
  42 
  43 class HeapRegion;
  44 class G1CollectionSet;
  45 class CollectionSetChooser;
  46 class G1IHOPControl;
  47 class G1Analytics;
  48 class G1YoungGenSizer;
  49 
  50 class G1Policy: public CHeapObj<mtGC> {
  51 public:
  52   virtual const G1Predictions& predictor() const = 0;
  53   virtual const G1Analytics* analytics()   const = 0;
  54 
  55   // Add the given number of bytes to the total number of allocated bytes in the old gen.
  56   virtual void add_bytes_allocated_in_old_since_last_gc(size_t bytes) = 0;
  57 
  58   // Accessors
  59 
  60   virtual void set_region_eden(HeapRegion* hr, int young_index_in_cset) = 0;
  61   virtual void set_region_survivor(HeapRegion* hr, int young_index_in_cset) = 0;
  62 
  63   virtual void record_max_rs_lengths(size_t rs_lengths) = 0;
  64 
  65   virtual double predict_base_elapsed_time_ms(size_t pending_cards) const = 0;
  66   virtual double predict_base_elapsed_time_ms(size_t pending_cards,
  67                                               size_t scanned_cards) const = 0;
  68 
  69   virtual double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc) const = 0;
  70 
  71   virtual void cset_regions_freed() = 0;
  72 
  73   virtual G1MMUTracker* mmu_tracker() = 0;
  74 
  75   virtual const G1MMUTracker* mmu_tracker() const = 0;
  76 
  77   virtual double max_pause_time_ms() const = 0;
  78 
  79   virtual size_t pending_cards() const = 0;
  80 
  81   // Calculate the minimum number of old regions we'll add to the CSet
  82   // during a mixed GC.
  83   virtual uint calc_min_old_cset_length() const = 0;
  84 
  85   // Calculate the maximum number of old regions we'll add to the CSet
  86   // during a mixed GC.
  87   virtual uint calc_max_old_cset_length() const = 0;
  88 
  89   // Returns the given amount of uncollected reclaimable space
  90   // as a percentage of the current heap capacity.
  91   virtual double reclaimable_bytes_perc(size_t reclaimable_bytes) const = 0;
  92 
  93   virtual ~G1Policy() {}
  94 
  95   virtual G1CollectorState* collector_state() const = 0;
  96 
  97   virtual G1GCPhaseTimes* phase_times() const = 0;
  98 
  99   // Check the current value of the young list RSet lengths and
 100   // compare it against the last prediction. If the current value is
 101   // higher, recalculate the young list target length prediction.
 102   virtual void revise_young_list_target_length_if_necessary(size_t rs_lengths) = 0;
 103 
 104   // This should be called after the heap is resized.
 105   virtual void record_new_heap_size(uint new_number_of_regions) = 0;
 106 
 107   virtual void init(G1CollectedHeap* g1h, G1CollectionSet* collection_set) = 0;
 108 
 109   virtual void note_gc_start() = 0;
 110 
 111   virtual bool need_to_start_conc_mark(const char* source, size_t alloc_word_size = 0) = 0;
 112 
 113   // Record the start and end of an evacuation pause.
 114   virtual void record_collection_pause_start(double start_time_sec) = 0;
 115   virtual void record_collection_pause_end(double pause_time_ms, size_t cards_scanned, size_t heap_used_bytes_before_gc) = 0;
 116 
 117   // Record the start and end of a full collection.
 118   virtual void record_full_collection_start() = 0;
 119   virtual void record_full_collection_end() = 0;
 120 
 121   // Must currently be called while the world is stopped.
 122   virtual void record_concurrent_mark_init_end(double mark_init_elapsed_time_ms) = 0;
 123 
 124   // Record start and end of remark.
 125   virtual void record_concurrent_mark_remark_start() = 0;
 126   virtual void record_concurrent_mark_remark_end() = 0;
 127 
 128   // Record start, end, and completion of cleanup.
 129   virtual void record_concurrent_mark_cleanup_start() = 0;
 130   virtual void record_concurrent_mark_cleanup_end() = 0;
 131   virtual void record_concurrent_mark_cleanup_completed() = 0;
 132 
 133   virtual void print_phases() = 0;
 134 
 135   // Record how much space we copied during a GC. This is typically
 136   // called when a GC alloc region is being retired.
 137   virtual void record_bytes_copied_during_gc(size_t bytes) = 0;
 138 
 139   // The amount of space we copied during a GC.
 140   virtual size_t bytes_copied_during_gc() const = 0;
 141 
 142   virtual void finalize_collection_set(double target_pause_time_ms) = 0;
 143 
 144   // This sets the initiate_conc_mark_if_possible() flag to start a
 145   // new cycle, as long as we are not already in one. It's best if it
 146   // is called during a safepoint when the test whether a cycle is in
 147   // progress or not is stable.
 148   virtual bool force_initial_mark_if_outside_cycle(GCCause::Cause gc_cause) = 0;
 149 
 150   // This is called at the very beginning of an evacuation pause (it
 151   // has to be the first thing that the pause does). If
 152   // initiate_conc_mark_if_possible() is true, and the concurrent
 153   // marking thread has completed its work during the previous cycle,
 154   // it will set during_initial_mark_pause() to so that the pause does
 155   // the initial-mark work and start a marking cycle.
 156   virtual void decide_on_conc_mark_initiation() = 0;
 157 
 158   // Print stats on young survival ratio
 159   virtual void print_yg_surv_rate_info() const = 0;
 160 
 161   virtual void finished_recalculating_age_indexes(bool is_survivors) = 0;
 162 
 163   virtual size_t young_list_target_length() const = 0;
 164 
 165   virtual bool should_allocate_mutator_region() const = 0;
 166 
 167   virtual bool can_expand_young_list() const = 0;
 168 
 169   virtual uint young_list_max_length() const = 0;
 170 
 171   virtual bool adaptive_young_list_length() const = 0;
 172 
 173   virtual bool should_process_references() const = 0;
 174 
 175   virtual uint tenuring_threshold() const = 0;
 176   virtual uint max_survivor_regions() = 0;
 177 
 178   virtual void note_start_adding_survivor_regions() = 0;
 179 
 180   virtual void note_stop_adding_survivor_regions() = 0;
 181 
 182   virtual void record_age_table(AgeTable* age_table) = 0;
 183 };
 184 
 185 #endif // SHARE_VM_GC_G1_G1POLICY_HPP