src/share/vm/gc_implementation/g1/g1MonitoringSupport.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1MonitoringSupport.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,269 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
    1.30 +
    1.31 +#include "gc_implementation/shared/hSpaceCounters.hpp"
    1.32 +
    1.33 +class G1CollectedHeap;
    1.34 +
    1.35 +// Class for monitoring logical spaces in G1. It provides data for
    1.36 +// both G1's jstat counters as well as G1's memory pools.
    1.37 +//
    1.38 +// G1 splits the heap into heap regions and each heap region belongs
    1.39 +// to one of the following categories:
    1.40 +//
    1.41 +// * eden      : regions that have been allocated since the last GC
    1.42 +// * survivors : regions with objects that survived the last few GCs
    1.43 +// * old       : long-lived non-humongous regions
    1.44 +// * humongous : humongous regions
    1.45 +// * free      : free regions
    1.46 +//
    1.47 +// The combination of eden and survivor regions form the equivalent of
    1.48 +// the young generation in the other GCs. The combination of old and
    1.49 +// humongous regions form the equivalent of the old generation in the
    1.50 +// other GCs. Free regions do not have a good equivalent in the other
    1.51 +// GCs given that they can be allocated as any of the other region types.
    1.52 +//
    1.53 +// The monitoring tools expect the heap to contain a number of
    1.54 +// generations (young, old, perm) and each generation to contain a
    1.55 +// number of spaces (young: eden, survivors, old). Given that G1 does
    1.56 +// not maintain those spaces physically (e.g., the set of
    1.57 +// non-contiguous eden regions can be considered as a "logical"
    1.58 +// space), we'll provide the illusion that those generations and
    1.59 +// spaces exist. In reality, each generation and space refers to a set
    1.60 +// of heap regions that are potentially non-contiguous.
    1.61 +//
    1.62 +// This class provides interfaces to access the min, current, and max
    1.63 +// capacity and current occupancy for each of G1's logical spaces and
    1.64 +// generations we expose to the monitoring tools. Also provided are
    1.65 +// counters for G1 concurrent collections and stop-the-world full heap
    1.66 +// collections.
    1.67 +//
    1.68 +// Below is a description of how the various sizes are calculated.
    1.69 +//
    1.70 +// * Current Capacity
    1.71 +//
    1.72 +//    - heap_capacity = current heap capacity (e.g., current committed size)
    1.73 +//    - young_gen_capacity = current max young gen target capacity
    1.74 +//          (i.e., young gen target capacity + max allowed expansion capacity)
    1.75 +//    - survivor_capacity = current survivor region capacity
    1.76 +//    - eden_capacity = young_gen_capacity - survivor_capacity
    1.77 +//    - old_capacity = heap_capacity - young_gen_capacity
    1.78 +//
    1.79 +//    What we do in the above is to distribute the free regions among
    1.80 +//    eden_capacity and old_capacity.
    1.81 +//
    1.82 +// * Occupancy
    1.83 +//
    1.84 +//    - young_gen_used = current young region capacity
    1.85 +//    - survivor_used = survivor_capacity
    1.86 +//    - eden_used = young_gen_used - survivor_used
    1.87 +//    - old_used = overall_used - young_gen_used
    1.88 +//
    1.89 +//    Unfortunately, we currently only keep track of the number of
    1.90 +//    currently allocated young and survivor regions + the overall used
    1.91 +//    bytes in the heap, so the above can be a little inaccurate.
    1.92 +//
    1.93 +// * Min Capacity
    1.94 +//
    1.95 +//    We set this to 0 for all spaces.
    1.96 +//
    1.97 +// * Max Capacity
    1.98 +//
    1.99 +//    For jstat, we set the max capacity of all spaces to heap_capacity,
   1.100 +//    given that we don't always have a reasonable upper bound on how big
   1.101 +//    each space can grow. For the memory pools, we make the max
   1.102 +//    capacity undefined with the exception of the old memory pool for
   1.103 +//    which we make the max capacity same as the max heap capacity.
   1.104 +//
   1.105 +// If we had more accurate occupancy / capacity information per
   1.106 +// region set the above calculations would be greatly simplified and
   1.107 +// be made more accurate.
   1.108 +//
   1.109 +// We update all the above synchronously and we store the results in
   1.110 +// fields so that we just read said fields when needed. A subtle point
   1.111 +// is that all the above sizes need to be recalculated when the old
   1.112 +// gen changes capacity (after a GC or after a humongous allocation)
   1.113 +// but only the eden occupancy changes when a new eden region is
   1.114 +// allocated. So, in the latter case we have minimal recalcuation to
   1.115 +// do which is important as we want to keep the eden region allocation
   1.116 +// path as low-overhead as possible.
   1.117 +
   1.118 +class G1MonitoringSupport : public CHeapObj<mtGC> {
   1.119 +  friend class VMStructs;
   1.120 +
   1.121 +  G1CollectedHeap* _g1h;
   1.122 +
   1.123 +  // jstat performance counters
   1.124 +  //  incremental collections both young and mixed
   1.125 +  CollectorCounters*   _incremental_collection_counters;
   1.126 +  //  full stop-the-world collections
   1.127 +  CollectorCounters*   _full_collection_counters;
   1.128 +  //  young collection set counters.  The _eden_counters,
   1.129 +  // _from_counters, and _to_counters are associated with
   1.130 +  // this "generational" counter.
   1.131 +  GenerationCounters*  _young_collection_counters;
   1.132 +  //  old collection set counters. The _old_space_counters
   1.133 +  // below are associated with this "generational" counter.
   1.134 +  GenerationCounters*  _old_collection_counters;
   1.135 +  // Counters for the capacity and used for
   1.136 +  //   the whole heap
   1.137 +  HSpaceCounters*      _old_space_counters;
   1.138 +  //   the young collection
   1.139 +  HSpaceCounters*      _eden_counters;
   1.140 +  //   the survivor collection (only one, _to_counters, is actively used)
   1.141 +  HSpaceCounters*      _from_counters;
   1.142 +  HSpaceCounters*      _to_counters;
   1.143 +
   1.144 +  // When it's appropriate to recalculate the various sizes (at the
   1.145 +  // end of a GC, when a new eden region is allocated, etc.) we store
   1.146 +  // them here so that we can easily report them when needed and not
   1.147 +  // have to recalculate them every time.
   1.148 +
   1.149 +  size_t _overall_reserved;
   1.150 +  size_t _overall_committed;
   1.151 +  size_t _overall_used;
   1.152 +
   1.153 +  uint   _young_region_num;
   1.154 +  size_t _young_gen_committed;
   1.155 +  size_t _eden_committed;
   1.156 +  size_t _eden_used;
   1.157 +  size_t _survivor_committed;
   1.158 +  size_t _survivor_used;
   1.159 +
   1.160 +  size_t _old_committed;
   1.161 +  size_t _old_used;
   1.162 +
   1.163 +  G1CollectedHeap* g1h() { return _g1h; }
   1.164 +
   1.165 +  // It returns x - y if x > y, 0 otherwise.
   1.166 +  // As described in the comment above, some of the inputs to the
   1.167 +  // calculations we have to do are obtained concurrently and hence
   1.168 +  // may be inconsistent with each other. So, this provides a
   1.169 +  // defensive way of performing the subtraction and avoids the value
   1.170 +  // going negative (which would mean a very large result, given that
   1.171 +  // the parameter are size_t).
   1.172 +  static size_t subtract_up_to_zero(size_t x, size_t y) {
   1.173 +    if (x > y) {
   1.174 +      return x - y;
   1.175 +    } else {
   1.176 +      return 0;
   1.177 +    }
   1.178 +  }
   1.179 +
   1.180 +  // Recalculate all the sizes.
   1.181 +  void recalculate_sizes();
   1.182 +  // Recalculate only what's necessary when a new eden region is allocated.
   1.183 +  void recalculate_eden_size();
   1.184 +
   1.185 + public:
   1.186 +  G1MonitoringSupport(G1CollectedHeap* g1h);
   1.187 +
   1.188 +  // Unfortunately, the jstat tool assumes that no space has 0
   1.189 +  // capacity. In our case, given that each space is logical, it's
   1.190 +  // possible that no regions will be allocated to it, hence to have 0
   1.191 +  // capacity (e.g., if there are no survivor regions, the survivor
   1.192 +  // space has 0 capacity). The way we deal with this is to always pad
   1.193 +  // each capacity value we report to jstat by a very small amount to
   1.194 +  // make sure that it's never zero. Given that we sometimes have to
   1.195 +  // report a capacity of a generation that contains several spaces
   1.196 +  // (e.g., young gen includes one eden, two survivor spaces), the
   1.197 +  // mult parameter is provided in order to adding the appropriate
   1.198 +  // padding multiple times so that the capacities add up correctly.
   1.199 +  static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
   1.200 +    return size_bytes + MinObjAlignmentInBytes * mult;
   1.201 +  }
   1.202 +
   1.203 +  // Recalculate all the sizes from scratch and update all the jstat
   1.204 +  // counters accordingly.
   1.205 +  void update_sizes();
   1.206 +  // Recalculate only what's necessary when a new eden region is
   1.207 +  // allocated and update any jstat counters that need to be updated.
   1.208 +  void update_eden_size();
   1.209 +
   1.210 +  CollectorCounters* incremental_collection_counters() {
   1.211 +    return _incremental_collection_counters;
   1.212 +  }
   1.213 +  CollectorCounters* full_collection_counters() {
   1.214 +    return _full_collection_counters;
   1.215 +  }
   1.216 +  GenerationCounters* young_collection_counters() {
   1.217 +    return _young_collection_counters;
   1.218 +  }
   1.219 +  GenerationCounters* old_collection_counters() {
   1.220 +    return _old_collection_counters;
   1.221 +  }
   1.222 +  HSpaceCounters*      old_space_counters() { return _old_space_counters; }
   1.223 +  HSpaceCounters*      eden_counters() { return _eden_counters; }
   1.224 +  HSpaceCounters*      from_counters() { return _from_counters; }
   1.225 +  HSpaceCounters*      to_counters() { return _to_counters; }
   1.226 +
   1.227 +  // Monitoring support used by
   1.228 +  //   MemoryService
   1.229 +  //   jstat counters
   1.230 +  //   Tracing
   1.231 +
   1.232 +  size_t overall_reserved()           { return _overall_reserved;     }
   1.233 +  size_t overall_committed()          { return _overall_committed;    }
   1.234 +  size_t overall_used()               { return _overall_used;         }
   1.235 +
   1.236 +  size_t young_gen_committed()        { return _young_gen_committed;  }
   1.237 +  size_t young_gen_max()              { return overall_reserved();    }
   1.238 +  size_t eden_space_committed()       { return _eden_committed;       }
   1.239 +  size_t eden_space_used()            { return _eden_used;            }
   1.240 +  size_t survivor_space_committed()   { return _survivor_committed;   }
   1.241 +  size_t survivor_space_used()        { return _survivor_used;        }
   1.242 +
   1.243 +  size_t old_gen_committed()          { return old_space_committed(); }
   1.244 +  size_t old_gen_max()                { return overall_reserved();    }
   1.245 +  size_t old_space_committed()        { return _old_committed;        }
   1.246 +  size_t old_space_used()             { return _old_used;             }
   1.247 +};
   1.248 +
   1.249 +class G1GenerationCounters: public GenerationCounters {
   1.250 +protected:
   1.251 +  G1MonitoringSupport* _g1mm;
   1.252 +
   1.253 +public:
   1.254 +  G1GenerationCounters(G1MonitoringSupport* g1mm,
   1.255 +                       const char* name, int ordinal, int spaces,
   1.256 +                       size_t min_capacity, size_t max_capacity,
   1.257 +                       size_t curr_capacity);
   1.258 +};
   1.259 +
   1.260 +class G1YoungGenerationCounters: public G1GenerationCounters {
   1.261 +public:
   1.262 +  G1YoungGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
   1.263 +  virtual void update_all();
   1.264 +};
   1.265 +
   1.266 +class G1OldGenerationCounters: public G1GenerationCounters {
   1.267 +public:
   1.268 +  G1OldGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
   1.269 +  virtual void update_all();
   1.270 +};
   1.271 +
   1.272 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP

mercurial