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

changeset 2821
b52782ae3880
child 3176
8229bd737950
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1MonitoringSupport.cpp	Thu Apr 21 10:23:44 2011 -0700
     1.3 @@ -0,0 +1,178 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, 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 +#include "precompiled.hpp"
    1.29 +#include "gc_implementation/g1/g1MonitoringSupport.hpp"
    1.30 +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
    1.31 +#include "gc_implementation/g1/g1CollectorPolicy.hpp"
    1.32 +
    1.33 +G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h,
    1.34 +                                         VirtualSpace* g1_storage_addr) :
    1.35 +  _g1h(g1h),
    1.36 +  _incremental_collection_counters(NULL),
    1.37 +  _full_collection_counters(NULL),
    1.38 +  _non_young_collection_counters(NULL),
    1.39 +  _old_space_counters(NULL),
    1.40 +  _young_collection_counters(NULL),
    1.41 +  _eden_counters(NULL),
    1.42 +  _from_counters(NULL),
    1.43 +  _to_counters(NULL),
    1.44 +  _g1_storage_addr(g1_storage_addr)
    1.45 +{
    1.46 +  // Counters for GC collections
    1.47 +  //
    1.48 +  //  name "collector.0".  In a generational collector this would be the
    1.49 +  // young generation collection.
    1.50 +  _incremental_collection_counters =
    1.51 +    new CollectorCounters("G1 incremental collections", 0);
    1.52 +  //   name "collector.1".  In a generational collector this would be the
    1.53 +  // old generation collection.
    1.54 +  _full_collection_counters =
    1.55 +    new CollectorCounters("G1 stop-the-world full collections", 1);
    1.56 +
    1.57 +  // timer sampling for all counters supporting sampling only update the
    1.58 +  // used value.  See the take_sample() method.  G1 requires both used and
    1.59 +  // capacity updated so sampling is not currently used.  It might
    1.60 +  // be sufficient to update all counters in take_sample() even though
    1.61 +  // take_sample() only returns "used".  When sampling was used, there
    1.62 +  // were some anomolous values emitted which may have been the consequence
    1.63 +  // of not updating all values simultaneously (i.e., see the calculation done
    1.64 +  // in eden_space_used(), is it possbile that the values used to
    1.65 +  // calculate either eden_used or survivor_used are being updated by
    1.66 +  // the collector when the sample is being done?).
    1.67 +  const bool sampled = false;
    1.68 +
    1.69 +  // "Generation" and "Space" counters.
    1.70 +  //
    1.71 +  //  name "generation.1" This is logically the old generation in
    1.72 +  // generational GC terms.  The "1, 1" parameters are for
    1.73 +  // the n-th generation (=1) with 1 space.
    1.74 +  // Counters are created from minCapacity, maxCapacity, and capacity
    1.75 +  _non_young_collection_counters =
    1.76 +    new GenerationCounters("whole heap", 1, 1, _g1_storage_addr);
    1.77 +
    1.78 +  //  name  "generation.1.space.0"
    1.79 +  // Counters are created from maxCapacity, capacity, initCapacity,
    1.80 +  // and used.
    1.81 +  _old_space_counters = new HSpaceCounters("space", 0,
    1.82 +    _g1h->max_capacity(), _g1h->capacity(), _non_young_collection_counters);
    1.83 +
    1.84 +  //   Young collection set
    1.85 +  //  name "generation.0".  This is logically the young generation.
    1.86 +  //  The "0, 3" are paremeters for the n-th genertaion (=0) with 3 spaces.
    1.87 +  // See  _non_young_collection_counters for additional counters
    1.88 +  _young_collection_counters = new GenerationCounters("young", 0, 3, NULL);
    1.89 +
    1.90 +  // Replace "max_heap_byte_size() with maximum young gen size for
    1.91 +  // g1Collectedheap
    1.92 +  //  name "generation.0.space.0"
    1.93 +  // See _old_space_counters for additional counters
    1.94 +  _eden_counters = new HSpaceCounters("eden", 0,
    1.95 +    _g1h->max_capacity(), eden_space_committed(),
    1.96 +    _young_collection_counters);
    1.97 +
    1.98 +  //  name "generation.0.space.1"
    1.99 +  // See _old_space_counters for additional counters
   1.100 +  // Set the arguments to indicate that this survivor space is not used.
   1.101 +  _from_counters = new HSpaceCounters("s0", 1, (long) 0, (long) 0,
   1.102 +    _young_collection_counters);
   1.103 +
   1.104 +  //  name "generation.0.space.2"
   1.105 +  // See _old_space_counters for additional counters
   1.106 +  _to_counters = new HSpaceCounters("s1", 2,
   1.107 +    _g1h->max_capacity(),
   1.108 +    survivor_space_committed(),
   1.109 +    _young_collection_counters);
   1.110 +}
   1.111 +
   1.112 +size_t G1MonitoringSupport::overall_committed() {
   1.113 +  return g1h()->capacity();
   1.114 +}
   1.115 +
   1.116 +size_t G1MonitoringSupport::overall_used() {
   1.117 +  return g1h()->used_unlocked();
   1.118 +}
   1.119 +
   1.120 +size_t G1MonitoringSupport::eden_space_committed() {
   1.121 +  return MAX2(eden_space_used(), (size_t) HeapRegion::GrainBytes);
   1.122 +}
   1.123 +
   1.124 +size_t G1MonitoringSupport::eden_space_used() {
   1.125 +  size_t young_list_length = g1h()->young_list()->length();
   1.126 +  size_t eden_used = young_list_length * HeapRegion::GrainBytes;
   1.127 +  size_t survivor_used = survivor_space_used();
   1.128 +  eden_used = subtract_up_to_zero(eden_used, survivor_used);
   1.129 +  return eden_used;
   1.130 +}
   1.131 +
   1.132 +size_t G1MonitoringSupport::survivor_space_committed() {
   1.133 +  return MAX2(survivor_space_used(),
   1.134 +              (size_t) HeapRegion::GrainBytes);
   1.135 +}
   1.136 +
   1.137 +size_t G1MonitoringSupport::survivor_space_used() {
   1.138 +  size_t survivor_num = g1h()->g1_policy()->recorded_survivor_regions();
   1.139 +  size_t survivor_used = survivor_num * HeapRegion::GrainBytes;
   1.140 +  return survivor_used;
   1.141 +}
   1.142 +
   1.143 +size_t G1MonitoringSupport::old_space_committed() {
   1.144 +  size_t committed = overall_committed();
   1.145 +  size_t eden_committed = eden_space_committed();
   1.146 +  size_t survivor_committed = survivor_space_committed();
   1.147 +  committed = subtract_up_to_zero(committed, eden_committed);
   1.148 +  committed = subtract_up_to_zero(committed, survivor_committed);
   1.149 +  committed = MAX2(committed, (size_t) HeapRegion::GrainBytes);
   1.150 +  return committed;
   1.151 +}
   1.152 +
   1.153 +// See the comment near the top of g1MonitoringSupport.hpp for
   1.154 +// an explanation of these calculations for "used" and "capacity".
   1.155 +size_t G1MonitoringSupport::old_space_used() {
   1.156 +  size_t used = overall_used();
   1.157 +  size_t eden_used = eden_space_used();
   1.158 +  size_t survivor_used = survivor_space_used();
   1.159 +  used = subtract_up_to_zero(used, eden_used);
   1.160 +  used = subtract_up_to_zero(used, survivor_used);
   1.161 +  return used;
   1.162 +}
   1.163 +
   1.164 +void G1MonitoringSupport::update_counters() {
   1.165 +  if (UsePerfData) {
   1.166 +    eden_counters()->update_capacity(eden_space_committed());
   1.167 +    eden_counters()->update_used(eden_space_used());
   1.168 +    to_counters()->update_capacity(survivor_space_committed());
   1.169 +    to_counters()->update_used(survivor_space_used());
   1.170 +    old_space_counters()->update_capacity(old_space_committed());
   1.171 +    old_space_counters()->update_used(old_space_used());
   1.172 +    non_young_collection_counters()->update_all();
   1.173 +  }
   1.174 +}
   1.175 +
   1.176 +void G1MonitoringSupport::update_eden_counters() {
   1.177 +  if (UsePerfData) {
   1.178 +    eden_counters()->update_capacity(eden_space_committed());
   1.179 +    eden_counters()->update_used(eden_space_used());
   1.180 +  }
   1.181 +}

mercurial