1 /*
2  * Copyright (c) 2003, 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 #include "precompiled.hpp"
26 #include "gc/parallel/psGCAdaptivePolicyCounters.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "runtime/arguments.hpp"
29 
30 
31 
PSGCAdaptivePolicyCounters(const char * name_arg,int collectors,int generations,PSAdaptiveSizePolicy * size_policy_arg)32 PSGCAdaptivePolicyCounters::PSGCAdaptivePolicyCounters(const char* name_arg,
33                                       int collectors,
34                                       int generations,
35                                       PSAdaptiveSizePolicy* size_policy_arg)
36         : GCAdaptivePolicyCounters(name_arg,
37                                    collectors,
38                                    generations,
39                                    size_policy_arg) {
40   if (UsePerfData) {
41     EXCEPTION_MARK;
42     ResourceMark rm;
43 
44     const char* cname;
45 
46     cname = PerfDataManager::counter_name(name_space(), "oldPromoSize");
47     _old_promo_size = PerfDataManager::create_variable(SUN_GC, cname,
48       PerfData::U_Bytes, ps_size_policy()->calculated_promo_size_in_bytes(), CHECK);
49 
50     cname = PerfDataManager::counter_name(name_space(), "oldEdenSize");
51     _old_eden_size = PerfDataManager::create_variable(SUN_GC, cname,
52       PerfData::U_Bytes, ps_size_policy()->calculated_eden_size_in_bytes(), CHECK);
53 
54     cname = PerfDataManager::counter_name(name_space(), "oldCapacity");
55     _old_capacity = PerfDataManager::create_variable(SUN_GC, cname,
56       PerfData::U_Bytes, (jlong) InitialHeapSize, CHECK);
57 
58     cname = PerfDataManager::counter_name(name_space(), "avgPromotedAvg");
59     _avg_promoted_avg_counter =
60       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
61         ps_size_policy()->calculated_promo_size_in_bytes(), CHECK);
62 
63     cname = PerfDataManager::counter_name(name_space(), "avgPromotedDev");
64     _avg_promoted_dev_counter =
65       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
66         (jlong) 0 , CHECK);
67 
68     cname = PerfDataManager::counter_name(name_space(), "avgPromotedPaddedAvg");
69     _avg_promoted_padded_avg_counter =
70       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
71         ps_size_policy()->calculated_promo_size_in_bytes(), CHECK);
72 
73     cname = PerfDataManager::counter_name(name_space(),
74       "avgPretenuredPaddedAvg");
75     _avg_pretenured_padded_avg =
76       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
77         (jlong) 0, CHECK);
78 
79 
80     cname = PerfDataManager::counter_name(name_space(),
81       "changeYoungGenForMajPauses");
82     _change_young_gen_for_maj_pauses_counter =
83       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Events,
84         (jlong)0, CHECK);
85 
86     cname = PerfDataManager::counter_name(name_space(),
87       "changeOldGenForMinPauses");
88     _change_old_gen_for_min_pauses =
89       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Events,
90         (jlong)0, CHECK);
91 
92 
93     cname = PerfDataManager::counter_name(name_space(), "avgMajorPauseTime");
94     _avg_major_pause = PerfDataManager::create_variable(SUN_GC, cname,
95       PerfData::U_Ticks, (jlong) ps_size_policy()->_avg_major_pause->average(), CHECK);
96 
97     cname = PerfDataManager::counter_name(name_space(), "avgMajorIntervalTime");
98     _avg_major_interval = PerfDataManager::create_variable(SUN_GC, cname,
99       PerfData::U_Ticks, (jlong) ps_size_policy()->_avg_major_interval->average(), CHECK);
100 
101     cname = PerfDataManager::counter_name(name_space(), "majorGcCost");
102     _major_gc_cost_counter = PerfDataManager::create_variable(SUN_GC, cname,
103        PerfData::U_Ticks, (jlong) ps_size_policy()->major_gc_cost(), CHECK);
104 
105     cname = PerfDataManager::counter_name(name_space(), "liveSpace");
106     _live_space = PerfDataManager::create_variable(SUN_GC, cname,
107       PerfData::U_Bytes, ps_size_policy()->live_space(), CHECK);
108 
109     cname = PerfDataManager::counter_name(name_space(), "freeSpace");
110     _free_space = PerfDataManager::create_variable(SUN_GC, cname,
111       PerfData::U_Bytes, ps_size_policy()->free_space(), CHECK);
112 
113     cname = PerfDataManager::counter_name(name_space(), "avgBaseFootprint");
114     _avg_base_footprint = PerfDataManager::create_variable(SUN_GC, cname,
115       PerfData::U_Bytes, (jlong) ps_size_policy()->avg_base_footprint()->average(), CHECK);
116 
117     cname = PerfDataManager::counter_name(name_space(), "liveAtLastFullGc");
118     _live_at_last_full_gc_counter =
119       PerfDataManager::create_variable(SUN_GC, cname,
120       PerfData::U_Bytes, ps_size_policy()->live_at_last_full_gc(), CHECK);
121 
122     cname = PerfDataManager::counter_name(name_space(), "majorPauseOldSlope");
123     _major_pause_old_slope = PerfDataManager::create_variable(SUN_GC, cname,
124       PerfData::U_None, (jlong) 0, CHECK);
125 
126     cname = PerfDataManager::counter_name(name_space(), "minorPauseOldSlope");
127     _minor_pause_old_slope = PerfDataManager::create_variable(SUN_GC, cname,
128       PerfData::U_None, (jlong) 0, CHECK);
129 
130     cname = PerfDataManager::counter_name(name_space(), "majorPauseYoungSlope");
131     _major_pause_young_slope = PerfDataManager::create_variable(SUN_GC, cname,
132       PerfData::U_None, (jlong) 0, CHECK);
133 
134     cname = PerfDataManager::counter_name(name_space(), "scavengeSkipped");
135     _scavenge_skipped = PerfDataManager::create_variable(SUN_GC, cname,
136       PerfData::U_Bytes, (jlong) 0, CHECK);
137 
138     cname = PerfDataManager::counter_name(name_space(), "fullFollowsScavenge");
139     _full_follows_scavenge = PerfDataManager::create_variable(SUN_GC, cname,
140       PerfData::U_Bytes, (jlong) 0, CHECK);
141 
142     _counter_time_stamp.update();
143   }
144 
145   assert(size_policy()->is_gc_ps_adaptive_size_policy(),
146     "Wrong type of size policy");
147 }
148 
update_counters_from_policy()149 void PSGCAdaptivePolicyCounters::update_counters_from_policy() {
150   if (UsePerfData) {
151     GCAdaptivePolicyCounters::update_counters_from_policy();
152     update_eden_size();
153     update_promo_size();
154     update_avg_old_live();
155     update_survivor_size_counters();
156     update_avg_promoted_avg();
157     update_avg_promoted_dev();
158     update_avg_promoted_padded_avg();
159     update_avg_pretenured_padded_avg();
160 
161     update_avg_major_pause();
162     update_avg_major_interval();
163     update_minor_gc_cost_counter();
164     update_major_gc_cost_counter();
165     update_mutator_cost_counter();
166     update_decrement_tenuring_threshold_for_gc_cost();
167     update_increment_tenuring_threshold_for_gc_cost();
168     update_decrement_tenuring_threshold_for_survivor_limit();
169     update_live_space();
170     update_free_space();
171     update_avg_base_footprint();
172 
173     update_change_old_gen_for_maj_pauses();
174     update_change_young_gen_for_maj_pauses();
175     update_change_old_gen_for_min_pauses();
176 
177     update_change_old_gen_for_throughput();
178     update_change_young_gen_for_throughput();
179 
180     update_decrease_for_footprint();
181     update_decide_at_full_gc_counter();
182 
183     update_major_pause_old_slope();
184     update_minor_pause_old_slope();
185     update_major_pause_young_slope();
186     update_minor_collection_slope_counter();
187     update_gc_overhead_limit_exceeded_counter();
188     update_live_at_last_full_gc_counter();
189   }
190 }
191 
update_counters()192 void PSGCAdaptivePolicyCounters::update_counters() {
193   if (UsePerfData) {
194     update_counters_from_policy();
195   }
196 }
197