1 /*
   2  * Copyright (c) 2016, 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 #ifndef SHARE_GC_G1_G1ANALYTICS_HPP
  26 #define SHARE_GC_G1_G1ANALYTICS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 class TruncatedSeq;
  32 class G1Predictions;
  33 
  34 class G1Analytics: public CHeapObj<mtGC> {
  35   const static int TruncatedSeqLength = 10;
  36   const static int NumPrevPausesForHeuristics = 10;
  37   const G1Predictions* _predictor;
  38 
  39   // These exclude marking times.
  40   TruncatedSeq* _recent_gc_times_ms;
  41 
  42   TruncatedSeq* _concurrent_mark_remark_times_ms;
  43   TruncatedSeq* _concurrent_mark_cleanup_times_ms;
  44 
  45   TruncatedSeq* _alloc_rate_ms_seq;
  46   double        _prev_collection_pause_end_ms;
  47 
  48   TruncatedSeq* _rs_length_diff_seq;
  49   TruncatedSeq* _cost_per_logged_card_ms_seq;
  50   TruncatedSeq* _cost_scan_hcc_seq;
  51   TruncatedSeq* _young_cards_per_entry_ratio_seq;
  52   TruncatedSeq* _mixed_cards_per_entry_ratio_seq;
  53   TruncatedSeq* _young_only_cost_per_remset_card_ms_seq;
  54   TruncatedSeq* _mixed_cost_per_remset_card_ms_seq;
  55   TruncatedSeq* _cost_per_byte_ms_seq;
  56   TruncatedSeq* _constant_other_time_ms_seq;
  57   TruncatedSeq* _young_other_cost_per_region_ms_seq;
  58   TruncatedSeq* _non_young_other_cost_per_region_ms_seq;
  59 
  60   TruncatedSeq* _pending_cards_seq;
  61   TruncatedSeq* _rs_length_seq;
  62 
  63   TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
  64 
  65   // Statistics kept per GC stoppage, pause or full.
  66   TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec;
  67 
  68   // The ratio of gc time to elapsed time, computed over recent pauses,
  69   // and the ratio for just the last pause.
  70   double _recent_avg_pause_time_ratio;
  71   double _last_pause_time_ratio;
  72 
  73   double get_new_prediction(TruncatedSeq const* seq) const;
  74   size_t get_new_size_prediction(TruncatedSeq const* seq) const;
  75 
  76 public:
  77   G1Analytics(const G1Predictions* predictor);
  78 
  79   double prev_collection_pause_end_ms() const {
  80     return _prev_collection_pause_end_ms;
  81   }
  82 
  83   double recent_avg_pause_time_ratio() const {
  84     return _recent_avg_pause_time_ratio;
  85   }
  86 
  87   double last_pause_time_ratio() const {
  88     return _last_pause_time_ratio;
  89   }
  90 
  91   uint number_of_recorded_pause_times() const {
  92     return NumPrevPausesForHeuristics;
  93   }
  94 
  95   void append_prev_collection_pause_end_ms(double ms) {
  96     _prev_collection_pause_end_ms += ms;
  97   }
  98 
  99   void report_concurrent_mark_remark_times_ms(double ms);
 100   void report_concurrent_mark_cleanup_times_ms(double ms);
 101   void report_alloc_rate_ms(double alloc_rate);
 102   void report_cost_per_logged_card_ms(double cost_per_logged_card_ms);
 103   void report_cost_scan_hcc(double cost_scan_hcc);
 104   void report_cost_per_remset_card_ms(double cost_per_remset_card_ms, bool for_young_gc);
 105   void report_cards_per_entry_ratio(double cards_per_entry_ratio, bool for_young_gc);
 106   void report_rs_length_diff(double rs_length_diff);
 107   void report_cost_per_byte_ms(double cost_per_byte_ms, bool mark_or_rebuild_in_progress);
 108   void report_young_other_cost_per_region_ms(double other_cost_per_region_ms);
 109   void report_non_young_other_cost_per_region_ms(double other_cost_per_region_ms);
 110   void report_constant_other_time_ms(double constant_other_time_ms);
 111   void report_pending_cards(double pending_cards);
 112   void report_rs_length(double rs_length);
 113 
 114   size_t predict_rs_length_diff() const;
 115 
 116   double predict_alloc_rate_ms() const;
 117   int num_alloc_rate_ms() const;
 118 
 119   double predict_cost_per_logged_card_ms() const;
 120 
 121   double predict_scan_hcc_ms() const;
 122 
 123   double predict_rs_update_time_ms(size_t pending_cards) const;
 124 
 125   double predict_young_cards_per_entry_ratio() const;
 126 
 127   double predict_mixed_cards_per_entry_ratio() const;
 128 
 129   size_t predict_card_num(size_t rs_length, bool for_young_gc) const;
 130 
 131   double predict_rs_scan_time_ms(size_t card_num, bool for_young_gc) const;
 132 
 133   double predict_mixed_rs_scan_time_ms(size_t card_num) const;
 134 
 135   double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const;
 136 
 137   double predict_object_copy_time_ms(size_t bytes_to_copy, bool during_concurrent_mark) const;
 138 
 139   double predict_constant_other_time_ms() const;
 140 
 141   double predict_young_other_time_ms(size_t young_num) const;
 142 
 143   double predict_non_young_other_time_ms(size_t non_young_num) const;
 144 
 145   double predict_remark_time_ms() const;
 146 
 147   double predict_cleanup_time_ms() const;
 148 
 149   size_t predict_rs_length() const;
 150   size_t predict_pending_cards() const;
 151 
 152   double predict_cost_per_byte_ms() const;
 153 
 154   // Add a new GC of the given duration and end time to the record.
 155   void update_recent_gc_times(double end_time_sec, double elapsed_ms);
 156   void compute_pause_time_ratio(double interval_ms, double pause_time_ms);
 157 
 158   double last_known_gc_end_time_sec() const;
 159 };
 160 
 161 #endif // SHARE_GC_G1_G1ANALYTICS_HPP