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