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