jmasa@2821: /* jmasa@2821: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. jmasa@2821: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jmasa@2821: * jmasa@2821: * This code is free software; you can redistribute it and/or modify it jmasa@2821: * under the terms of the GNU General Public License version 2 only, as jmasa@2821: * published by the Free Software Foundation. jmasa@2821: * jmasa@2821: * This code is distributed in the hope that it will be useful, but WITHOUT jmasa@2821: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jmasa@2821: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jmasa@2821: * version 2 for more details (a copy is included in the LICENSE file that jmasa@2821: * accompanied this code). jmasa@2821: * jmasa@2821: * You should have received a copy of the GNU General Public License version jmasa@2821: * 2 along with this work; if not, write to the Free Software Foundation, jmasa@2821: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jmasa@2821: * jmasa@2821: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jmasa@2821: * or visit www.oracle.com if you need additional information or have any jmasa@2821: * questions. jmasa@2821: * jmasa@2821: */ jmasa@2821: jmasa@2821: #include "precompiled.hpp" jmasa@2821: #include "gc_implementation/g1/g1MonitoringSupport.hpp" jmasa@2821: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" jmasa@2821: #include "gc_implementation/g1/g1CollectorPolicy.hpp" jmasa@2821: jmasa@2821: G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h, jmasa@2821: VirtualSpace* g1_storage_addr) : jmasa@2821: _g1h(g1h), jmasa@2821: _incremental_collection_counters(NULL), jmasa@2821: _full_collection_counters(NULL), jmasa@2821: _non_young_collection_counters(NULL), jmasa@2821: _old_space_counters(NULL), jmasa@2821: _young_collection_counters(NULL), jmasa@2821: _eden_counters(NULL), jmasa@2821: _from_counters(NULL), jmasa@2821: _to_counters(NULL), jmasa@2821: _g1_storage_addr(g1_storage_addr) jmasa@2821: { jmasa@2821: // Counters for GC collections jmasa@2821: // jmasa@2821: // name "collector.0". In a generational collector this would be the jmasa@2821: // young generation collection. jmasa@2821: _incremental_collection_counters = jmasa@2821: new CollectorCounters("G1 incremental collections", 0); jmasa@2821: // name "collector.1". In a generational collector this would be the jmasa@2821: // old generation collection. jmasa@2821: _full_collection_counters = jmasa@2821: new CollectorCounters("G1 stop-the-world full collections", 1); jmasa@2821: jmasa@2821: // timer sampling for all counters supporting sampling only update the jmasa@2821: // used value. See the take_sample() method. G1 requires both used and jmasa@2821: // capacity updated so sampling is not currently used. It might jmasa@2821: // be sufficient to update all counters in take_sample() even though jmasa@2821: // take_sample() only returns "used". When sampling was used, there jmasa@2821: // were some anomolous values emitted which may have been the consequence jmasa@2821: // of not updating all values simultaneously (i.e., see the calculation done jmasa@2821: // in eden_space_used(), is it possbile that the values used to jmasa@2821: // calculate either eden_used or survivor_used are being updated by jmasa@2821: // the collector when the sample is being done?). jmasa@2821: const bool sampled = false; jmasa@2821: jmasa@2821: // "Generation" and "Space" counters. jmasa@2821: // jmasa@2821: // name "generation.1" This is logically the old generation in jmasa@2821: // generational GC terms. The "1, 1" parameters are for jmasa@2821: // the n-th generation (=1) with 1 space. jmasa@2821: // Counters are created from minCapacity, maxCapacity, and capacity jmasa@2821: _non_young_collection_counters = jmasa@2821: new GenerationCounters("whole heap", 1, 1, _g1_storage_addr); jmasa@2821: jmasa@2821: // name "generation.1.space.0" jmasa@2821: // Counters are created from maxCapacity, capacity, initCapacity, jmasa@2821: // and used. jmasa@2821: _old_space_counters = new HSpaceCounters("space", 0, jmasa@2821: _g1h->max_capacity(), _g1h->capacity(), _non_young_collection_counters); jmasa@2821: jmasa@2821: // Young collection set jmasa@2821: // name "generation.0". This is logically the young generation. jmasa@2821: // The "0, 3" are paremeters for the n-th genertaion (=0) with 3 spaces. jmasa@2821: // See _non_young_collection_counters for additional counters jmasa@2821: _young_collection_counters = new GenerationCounters("young", 0, 3, NULL); jmasa@2821: jmasa@2821: // Replace "max_heap_byte_size() with maximum young gen size for jmasa@2821: // g1Collectedheap jmasa@2821: // name "generation.0.space.0" jmasa@2821: // See _old_space_counters for additional counters jmasa@2821: _eden_counters = new HSpaceCounters("eden", 0, jmasa@2821: _g1h->max_capacity(), eden_space_committed(), jmasa@2821: _young_collection_counters); jmasa@2821: jmasa@2821: // name "generation.0.space.1" jmasa@2821: // See _old_space_counters for additional counters jmasa@2821: // Set the arguments to indicate that this survivor space is not used. jmasa@2821: _from_counters = new HSpaceCounters("s0", 1, (long) 0, (long) 0, jmasa@2821: _young_collection_counters); jmasa@2821: jmasa@2821: // name "generation.0.space.2" jmasa@2821: // See _old_space_counters for additional counters jmasa@2821: _to_counters = new HSpaceCounters("s1", 2, jmasa@2821: _g1h->max_capacity(), jmasa@2821: survivor_space_committed(), jmasa@2821: _young_collection_counters); jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::overall_committed() { jmasa@2821: return g1h()->capacity(); jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::overall_used() { jmasa@2821: return g1h()->used_unlocked(); jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::eden_space_committed() { jmasa@2821: return MAX2(eden_space_used(), (size_t) HeapRegion::GrainBytes); jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::eden_space_used() { jmasa@2821: size_t young_list_length = g1h()->young_list()->length(); jmasa@2821: size_t eden_used = young_list_length * HeapRegion::GrainBytes; jmasa@2821: size_t survivor_used = survivor_space_used(); jmasa@2821: eden_used = subtract_up_to_zero(eden_used, survivor_used); jmasa@2821: return eden_used; jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::survivor_space_committed() { jmasa@2821: return MAX2(survivor_space_used(), jmasa@2821: (size_t) HeapRegion::GrainBytes); jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::survivor_space_used() { jmasa@2821: size_t survivor_num = g1h()->g1_policy()->recorded_survivor_regions(); jmasa@2821: size_t survivor_used = survivor_num * HeapRegion::GrainBytes; jmasa@2821: return survivor_used; jmasa@2821: } jmasa@2821: jmasa@2821: size_t G1MonitoringSupport::old_space_committed() { jmasa@2821: size_t committed = overall_committed(); jmasa@2821: size_t eden_committed = eden_space_committed(); jmasa@2821: size_t survivor_committed = survivor_space_committed(); jmasa@2821: committed = subtract_up_to_zero(committed, eden_committed); jmasa@2821: committed = subtract_up_to_zero(committed, survivor_committed); jmasa@2821: committed = MAX2(committed, (size_t) HeapRegion::GrainBytes); jmasa@2821: return committed; jmasa@2821: } jmasa@2821: jmasa@2821: // See the comment near the top of g1MonitoringSupport.hpp for jmasa@2821: // an explanation of these calculations for "used" and "capacity". jmasa@2821: size_t G1MonitoringSupport::old_space_used() { jmasa@2821: size_t used = overall_used(); jmasa@2821: size_t eden_used = eden_space_used(); jmasa@2821: size_t survivor_used = survivor_space_used(); jmasa@2821: used = subtract_up_to_zero(used, eden_used); jmasa@2821: used = subtract_up_to_zero(used, survivor_used); jmasa@2821: return used; jmasa@2821: } jmasa@2821: jmasa@2821: void G1MonitoringSupport::update_counters() { jmasa@2821: if (UsePerfData) { jmasa@2821: eden_counters()->update_capacity(eden_space_committed()); jmasa@2821: eden_counters()->update_used(eden_space_used()); jmasa@2821: to_counters()->update_capacity(survivor_space_committed()); jmasa@2821: to_counters()->update_used(survivor_space_used()); jmasa@2821: old_space_counters()->update_capacity(old_space_committed()); jmasa@2821: old_space_counters()->update_used(old_space_used()); jmasa@2821: non_young_collection_counters()->update_all(); jmasa@2821: } jmasa@2821: } jmasa@2821: jmasa@2821: void G1MonitoringSupport::update_eden_counters() { jmasa@2821: if (UsePerfData) { jmasa@2821: eden_counters()->update_capacity(eden_space_committed()); jmasa@2821: eden_counters()->update_used(eden_space_used()); jmasa@2821: } jmasa@2821: }