1 /*
2  * Copyright (c) 2004, 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_PARALLEL_GCADAPTIVEPOLICYCOUNTERS_HPP
26 #define SHARE_VM_GC_PARALLEL_GCADAPTIVEPOLICYCOUNTERS_HPP
27 
28 #include "gc/shared/adaptiveSizePolicy.hpp"
29 #include "gc/shared/gcPolicyCounters.hpp"
30 #include "utilities/macros.hpp"
31 
32 // This class keeps statistical information and computes the
33 // size of the heap.
34 
35 class GCAdaptivePolicyCounters : public GCPolicyCounters {
36  protected:
37   PerfVariable*         _eden_size_counter;
38   PerfVariable*         _promo_size_counter;
39 
40   PerfVariable*         _young_capacity_counter;
41 
42   PerfVariable*         _minor_gc_cost_counter;
43   PerfVariable*         _major_gc_cost_counter;
44   PerfVariable*         _mutator_cost_counter;
45 
46   PerfVariable*         _avg_young_live_counter;
47   PerfVariable*         _avg_old_live_counter;
48 
49   PerfVariable*         _avg_minor_pause_counter;
50   PerfVariable*         _avg_minor_interval_counter;
51 
52 #ifdef NOT_PRODUCT
53   PerfVariable*         _minor_pause_counter;
54 #endif
55 
56   PerfVariable*         _change_young_gen_for_min_pauses_counter;
57   PerfVariable*         _change_young_gen_for_throughput_counter;
58   PerfVariable*         _change_old_gen_for_maj_pauses_counter;
59   PerfVariable*         _change_old_gen_for_throughput_counter;
60   PerfVariable*         _decrease_for_footprint_counter;
61 
62   PerfVariable*         _minor_pause_young_slope_counter;
63   PerfVariable*         _major_pause_old_slope_counter;
64 
65   PerfVariable*         _decide_at_full_gc_counter;
66 
67   PerfVariable*         _survived_counter;
68   PerfVariable*         _promoted_counter;
69 
70   PerfVariable*         _avg_survived_avg_counter;
71   PerfVariable*         _avg_survived_dev_counter;
72   PerfVariable*         _avg_survived_padded_avg_counter;
73 
74   PerfVariable*         _survivor_overflowed_counter;
75   PerfVariable*         _increment_tenuring_threshold_for_gc_cost_counter;
76   PerfVariable*         _decrement_tenuring_threshold_for_gc_cost_counter;
77   PerfVariable*        _decrement_tenuring_threshold_for_survivor_limit_counter;
78 
79   PerfVariable*         _minor_collection_slope_counter;
80   PerfVariable*         _major_collection_slope_counter;
81 
82   AdaptiveSizePolicy* _size_policy;
83 
update_eden_size()84   inline void update_eden_size() {
85     size_t eden_size_in_bytes = size_policy()->calculated_eden_size_in_bytes();
86     _eden_size_counter->set_value(eden_size_in_bytes);
87   }
88 
update_promo_size()89   inline void update_promo_size() {
90     _promo_size_counter->set_value(
91       size_policy()->calculated_promo_size_in_bytes());
92   }
93 
update_avg_minor_pause_counter()94   inline void update_avg_minor_pause_counter() {
95     _avg_minor_pause_counter->set_value((jlong)
96       (size_policy()->avg_minor_pause()->average() * 1000.0));
97   }
update_avg_minor_interval_counter()98   inline void update_avg_minor_interval_counter() {
99     _avg_minor_interval_counter->set_value((jlong)
100       (size_policy()->avg_minor_interval()->average() * 1000.0));
101   }
102 
103 #ifdef NOT_PRODUCT
update_minor_pause_counter()104   inline void update_minor_pause_counter() {
105     _minor_pause_counter->set_value((jlong)
106       (size_policy()->avg_minor_pause()->last_sample() * 1000.0));
107   }
108 #endif
update_minor_gc_cost_counter()109   inline void update_minor_gc_cost_counter() {
110     _minor_gc_cost_counter->set_value((jlong)
111       (size_policy()->minor_gc_cost() * 100.0));
112   }
113 
update_avg_young_live_counter()114   inline void update_avg_young_live_counter() {
115     _avg_young_live_counter->set_value(
116       (jlong)(size_policy()->avg_young_live()->average())
117     );
118   }
119 
update_avg_survived_avg_counters()120   inline void update_avg_survived_avg_counters() {
121     _avg_survived_avg_counter->set_value(
122       (jlong)(size_policy()->_avg_survived->average())
123     );
124   }
update_avg_survived_dev_counters()125   inline void update_avg_survived_dev_counters() {
126     _avg_survived_dev_counter->set_value(
127       (jlong)(size_policy()->_avg_survived->deviation())
128     );
129   }
update_avg_survived_padded_avg_counters()130   inline void update_avg_survived_padded_avg_counters() {
131     _avg_survived_padded_avg_counter->set_value(
132       (jlong)(size_policy()->_avg_survived->padded_average())
133     );
134   }
135 
update_change_old_gen_for_throughput()136   inline void update_change_old_gen_for_throughput() {
137     _change_old_gen_for_throughput_counter->set_value(
138       size_policy()->change_old_gen_for_throughput());
139   }
update_change_young_gen_for_throughput()140   inline void update_change_young_gen_for_throughput() {
141     _change_young_gen_for_throughput_counter->set_value(
142       size_policy()->change_young_gen_for_throughput());
143   }
update_decrease_for_footprint()144   inline void update_decrease_for_footprint() {
145     _decrease_for_footprint_counter->set_value(
146       size_policy()->decrease_for_footprint());
147   }
148 
update_decide_at_full_gc_counter()149   inline void update_decide_at_full_gc_counter() {
150     _decide_at_full_gc_counter->set_value(
151       size_policy()->decide_at_full_gc());
152   }
153 
update_minor_pause_young_slope_counter()154   inline void update_minor_pause_young_slope_counter() {
155     _minor_pause_young_slope_counter->set_value(
156       (jlong)(size_policy()->minor_pause_young_slope() * 1000)
157     );
158   }
159 
160   virtual void update_counters_from_policy();
161 
162  protected:
size_policy()163   virtual AdaptiveSizePolicy* size_policy() { return _size_policy; }
164 
165  public:
166   GCAdaptivePolicyCounters(const char* name,
167                            int collectors,
168                            int generations,
169                            AdaptiveSizePolicy* size_policy);
170 
update_survived(size_t survived)171   inline void update_survived(size_t survived) {
172     _survived_counter->set_value(survived);
173   }
update_promoted(size_t promoted)174   inline void update_promoted(size_t promoted) {
175     _promoted_counter->set_value(promoted);
176   }
update_young_capacity(size_t size_in_bytes)177   inline void update_young_capacity(size_t size_in_bytes) {
178     _young_capacity_counter->set_value(size_in_bytes);
179   }
180 
181   virtual void update_counters();
182 
update_survivor_size_counters()183   inline void update_survivor_size_counters() {
184     desired_survivor_size()->set_value(
185       size_policy()->calculated_survivor_size_in_bytes());
186   }
update_survivor_overflowed(bool survivor_overflowed)187   inline void update_survivor_overflowed(bool survivor_overflowed) {
188     _survivor_overflowed_counter->set_value(survivor_overflowed);
189   }
update_tenuring_threshold(uint threshold)190   inline void update_tenuring_threshold(uint threshold) {
191     tenuring_threshold()->set_value(threshold);
192   }
update_increment_tenuring_threshold_for_gc_cost()193   inline void update_increment_tenuring_threshold_for_gc_cost() {
194     _increment_tenuring_threshold_for_gc_cost_counter->set_value(
195       size_policy()->increment_tenuring_threshold_for_gc_cost());
196   }
update_decrement_tenuring_threshold_for_gc_cost()197   inline void update_decrement_tenuring_threshold_for_gc_cost() {
198     _decrement_tenuring_threshold_for_gc_cost_counter->set_value(
199       size_policy()->decrement_tenuring_threshold_for_gc_cost());
200   }
update_decrement_tenuring_threshold_for_survivor_limit()201   inline void update_decrement_tenuring_threshold_for_survivor_limit() {
202     _decrement_tenuring_threshold_for_survivor_limit_counter->set_value(
203       size_policy()->decrement_tenuring_threshold_for_survivor_limit());
204   }
update_change_young_gen_for_min_pauses()205   inline void update_change_young_gen_for_min_pauses() {
206     _change_young_gen_for_min_pauses_counter->set_value(
207       size_policy()->change_young_gen_for_min_pauses());
208   }
update_change_old_gen_for_maj_pauses()209   inline void update_change_old_gen_for_maj_pauses() {
210     _change_old_gen_for_maj_pauses_counter->set_value(
211       size_policy()->change_old_gen_for_maj_pauses());
212   }
213 
update_minor_collection_slope_counter()214   inline void update_minor_collection_slope_counter() {
215     _minor_collection_slope_counter->set_value(
216       (jlong)(size_policy()->minor_collection_slope() * 1000)
217     );
218   }
219 
update_major_collection_slope_counter()220   inline void update_major_collection_slope_counter() {
221     _major_collection_slope_counter->set_value(
222       (jlong)(size_policy()->major_collection_slope() * 1000)
223     );
224   }
225 
set_size_policy(AdaptiveSizePolicy * v)226   void set_size_policy(AdaptiveSizePolicy* v) { _size_policy = v; }
227 
kind() const228   virtual GCPolicyCounters::Name kind() const {
229     return GCPolicyCounters::GCAdaptivePolicyCountersKind;
230   }
231 };
232 
233 #endif // SHARE_VM_GC_PARALLEL_GCADAPTIVEPOLICYCOUNTERS_HPP
234