jmasa@2821: /* sla@5237: * Copyright (c) 2011, 2013, 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: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP jmasa@2821: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP jmasa@2821: jmasa@2821: #include "gc_implementation/shared/hSpaceCounters.hpp" jmasa@2821: jmasa@2821: class G1CollectedHeap; jmasa@2821: tonyp@3176: // Class for monitoring logical spaces in G1. It provides data for tonyp@3176: // both G1's jstat counters as well as G1's memory pools. jmasa@2821: // tonyp@3176: // G1 splits the heap into heap regions and each heap region belongs tonyp@3176: // to one of the following categories: jmasa@2821: // tonyp@3176: // * eden : regions that have been allocated since the last GC tonyp@3176: // * survivors : regions with objects that survived the last few GCs tonyp@3176: // * old : long-lived non-humongous regions tonyp@3176: // * humongous : humongous regions tonyp@3176: // * free : free regions jmasa@2821: // tonyp@3176: // The combination of eden and survivor regions form the equivalent of tonyp@3176: // the young generation in the other GCs. The combination of old and tonyp@3176: // humongous regions form the equivalent of the old generation in the tonyp@3176: // other GCs. Free regions do not have a good equivalent in the other tonyp@3176: // GCs given that they can be allocated as any of the other region types. jmasa@2821: // tonyp@3176: // The monitoring tools expect the heap to contain a number of tonyp@3176: // generations (young, old, perm) and each generation to contain a tonyp@3176: // number of spaces (young: eden, survivors, old). Given that G1 does tonyp@3176: // not maintain those spaces physically (e.g., the set of tonyp@3176: // non-contiguous eden regions can be considered as a "logical" tonyp@3176: // space), we'll provide the illusion that those generations and tonyp@3176: // spaces exist. In reality, each generation and space refers to a set tonyp@3176: // of heap regions that are potentially non-contiguous. jmasa@2821: // tonyp@3176: // This class provides interfaces to access the min, current, and max tonyp@3176: // capacity and current occupancy for each of G1's logical spaces and tonyp@3176: // generations we expose to the monitoring tools. Also provided are tonyp@3176: // counters for G1 concurrent collections and stop-the-world full heap tonyp@3176: // collections. jmasa@2821: // tonyp@3176: // Below is a description of how the various sizes are calculated. jmasa@2821: // tonyp@3176: // * Current Capacity jmasa@2821: // tonyp@3176: // - heap_capacity = current heap capacity (e.g., current committed size) tonyp@3176: // - young_gen_capacity = current max young gen target capacity tonyp@3176: // (i.e., young gen target capacity + max allowed expansion capacity) tonyp@3176: // - survivor_capacity = current survivor region capacity tonyp@3176: // - eden_capacity = young_gen_capacity - survivor_capacity tonyp@3176: // - old_capacity = heap_capacity - young_gen_capacity jmasa@2821: // tonyp@3176: // What we do in the above is to distribute the free regions among tonyp@3176: // eden_capacity and old_capacity. jmasa@2821: // tonyp@3176: // * Occupancy jmasa@2821: // tonyp@3176: // - young_gen_used = current young region capacity tonyp@3176: // - survivor_used = survivor_capacity tonyp@3176: // - eden_used = young_gen_used - survivor_used tonyp@3176: // - old_used = overall_used - young_gen_used jmasa@2821: // tonyp@3176: // Unfortunately, we currently only keep track of the number of tonyp@3176: // currently allocated young and survivor regions + the overall used tonyp@3176: // bytes in the heap, so the above can be a little inaccurate. jmasa@2821: // tonyp@3176: // * Min Capacity tonyp@3176: // tonyp@3459: // We set this to 0 for all spaces. tonyp@3176: // tonyp@3176: // * Max Capacity tonyp@3176: // tonyp@3176: // For jstat, we set the max capacity of all spaces to heap_capacity, tonyp@3459: // given that we don't always have a reasonable upper bound on how big tonyp@3459: // each space can grow. For the memory pools, we make the max tonyp@3459: // capacity undefined with the exception of the old memory pool for tonyp@3459: // which we make the max capacity same as the max heap capacity. tonyp@3176: // tonyp@3176: // If we had more accurate occupancy / capacity information per tonyp@3176: // region set the above calculations would be greatly simplified and tonyp@3176: // be made more accurate. tonyp@3176: // tonyp@3176: // We update all the above synchronously and we store the results in tonyp@3176: // fields so that we just read said fields when needed. A subtle point tonyp@3176: // is that all the above sizes need to be recalculated when the old tonyp@3176: // gen changes capacity (after a GC or after a humongous allocation) tonyp@3176: // but only the eden occupancy changes when a new eden region is tonyp@3176: // allocated. So, in the latter case we have minimal recalcuation to tonyp@3176: // do which is important as we want to keep the eden region allocation tonyp@3176: // path as low-overhead as possible. jmasa@2821: zgu@3900: class G1MonitoringSupport : public CHeapObj { tonyp@3180: friend class VMStructs; tonyp@3180: jmasa@2821: G1CollectedHeap* _g1h; jmasa@2821: jmasa@2821: // jstat performance counters tonyp@3337: // incremental collections both young and mixed jmasa@2821: CollectorCounters* _incremental_collection_counters; jmasa@2821: // full stop-the-world collections jmasa@2821: CollectorCounters* _full_collection_counters; jmasa@2821: // young collection set counters. The _eden_counters, jmasa@2821: // _from_counters, and _to_counters are associated with jmasa@2821: // this "generational" counter. jmasa@2821: GenerationCounters* _young_collection_counters; tonyp@3176: // old collection set counters. The _old_space_counters jmasa@2821: // below are associated with this "generational" counter. tonyp@3176: GenerationCounters* _old_collection_counters; jmasa@2821: // Counters for the capacity and used for jmasa@2821: // the whole heap jmasa@2821: HSpaceCounters* _old_space_counters; jmasa@2821: // the young collection jmasa@2821: HSpaceCounters* _eden_counters; jmasa@2821: // the survivor collection (only one, _to_counters, is actively used) jmasa@2821: HSpaceCounters* _from_counters; jmasa@2821: HSpaceCounters* _to_counters; jmasa@2821: tonyp@3176: // When it's appropriate to recalculate the various sizes (at the tonyp@3176: // end of a GC, when a new eden region is allocated, etc.) we store tonyp@3176: // them here so that we can easily report them when needed and not tonyp@3176: // have to recalculate them every time. tonyp@3176: tonyp@3176: size_t _overall_reserved; tonyp@3176: size_t _overall_committed; tonyp@3176: size_t _overall_used; tonyp@3176: tonyp@3713: uint _young_region_num; tonyp@3176: size_t _young_gen_committed; tonyp@3176: size_t _eden_committed; tonyp@3176: size_t _eden_used; tonyp@3176: size_t _survivor_committed; tonyp@3176: size_t _survivor_used; tonyp@3176: tonyp@3176: size_t _old_committed; tonyp@3176: size_t _old_used; tonyp@3176: tonyp@3176: G1CollectedHeap* g1h() { return _g1h; } tonyp@3176: jmasa@2821: // It returns x - y if x > y, 0 otherwise. jmasa@2821: // As described in the comment above, some of the inputs to the jmasa@2821: // calculations we have to do are obtained concurrently and hence jmasa@2821: // may be inconsistent with each other. So, this provides a jmasa@2821: // defensive way of performing the subtraction and avoids the value jmasa@2821: // going negative (which would mean a very large result, given that jmasa@2821: // the parameter are size_t). jmasa@2821: static size_t subtract_up_to_zero(size_t x, size_t y) { jmasa@2821: if (x > y) { jmasa@2821: return x - y; jmasa@2821: } else { jmasa@2821: return 0; jmasa@2821: } jmasa@2821: } jmasa@2821: tonyp@3176: // Recalculate all the sizes. tonyp@3176: void recalculate_sizes(); tonyp@3176: // Recalculate only what's necessary when a new eden region is allocated. tonyp@3176: void recalculate_eden_size(); tonyp@3176: jmasa@2821: public: tonyp@3176: G1MonitoringSupport(G1CollectedHeap* g1h); jmasa@2821: tonyp@3176: // Unfortunately, the jstat tool assumes that no space has 0 tonyp@3176: // capacity. In our case, given that each space is logical, it's tonyp@3176: // possible that no regions will be allocated to it, hence to have 0 tonyp@3176: // capacity (e.g., if there are no survivor regions, the survivor tonyp@3176: // space has 0 capacity). The way we deal with this is to always pad tonyp@3176: // each capacity value we report to jstat by a very small amount to tonyp@3176: // make sure that it's never zero. Given that we sometimes have to tonyp@3176: // report a capacity of a generation that contains several spaces tonyp@3176: // (e.g., young gen includes one eden, two survivor spaces), the tonyp@3176: // mult parameter is provided in order to adding the appropriate tonyp@3176: // padding multiple times so that the capacities add up correctly. tonyp@3176: static size_t pad_capacity(size_t size_bytes, size_t mult = 1) { tonyp@3176: return size_bytes + MinObjAlignmentInBytes * mult; tonyp@3176: } jmasa@2821: tonyp@3176: // Recalculate all the sizes from scratch and update all the jstat tonyp@3176: // counters accordingly. tonyp@3176: void update_sizes(); tonyp@3176: // Recalculate only what's necessary when a new eden region is tonyp@3176: // allocated and update any jstat counters that need to be updated. tonyp@3176: void update_eden_size(); jmasa@2821: jmasa@2821: CollectorCounters* incremental_collection_counters() { jmasa@2821: return _incremental_collection_counters; jmasa@2821: } jmasa@2821: CollectorCounters* full_collection_counters() { jmasa@2821: return _full_collection_counters; jmasa@2821: } tonyp@3176: GenerationCounters* young_collection_counters() { tonyp@3176: return _young_collection_counters; tonyp@3176: } tonyp@3176: GenerationCounters* old_collection_counters() { tonyp@3176: return _old_collection_counters; jmasa@2821: } jmasa@2821: HSpaceCounters* old_space_counters() { return _old_space_counters; } jmasa@2821: HSpaceCounters* eden_counters() { return _eden_counters; } jmasa@2821: HSpaceCounters* from_counters() { return _from_counters; } jmasa@2821: HSpaceCounters* to_counters() { return _to_counters; } jmasa@2821: jmasa@2821: // Monitoring support used by jmasa@2821: // MemoryService jmasa@2821: // jstat counters sla@5237: // Tracing jmasa@2821: tonyp@3176: size_t overall_reserved() { return _overall_reserved; } tonyp@3176: size_t overall_committed() { return _overall_committed; } tonyp@3176: size_t overall_used() { return _overall_used; } jmasa@2821: tonyp@3176: size_t young_gen_committed() { return _young_gen_committed; } tonyp@3176: size_t young_gen_max() { return overall_reserved(); } tonyp@3176: size_t eden_space_committed() { return _eden_committed; } tonyp@3176: size_t eden_space_used() { return _eden_used; } tonyp@3176: size_t survivor_space_committed() { return _survivor_committed; } tonyp@3176: size_t survivor_space_used() { return _survivor_used; } jmasa@2821: tonyp@3176: size_t old_gen_committed() { return old_space_committed(); } tonyp@3176: size_t old_gen_max() { return overall_reserved(); } tonyp@3176: size_t old_space_committed() { return _old_committed; } tonyp@3176: size_t old_space_used() { return _old_used; } tonyp@3176: }; tonyp@3176: tonyp@3176: class G1GenerationCounters: public GenerationCounters { tonyp@3176: protected: tonyp@3176: G1MonitoringSupport* _g1mm; tonyp@3176: tonyp@3176: public: tonyp@3176: G1GenerationCounters(G1MonitoringSupport* g1mm, tonyp@3176: const char* name, int ordinal, int spaces, tonyp@3176: size_t min_capacity, size_t max_capacity, tonyp@3176: size_t curr_capacity); tonyp@3176: }; tonyp@3176: tonyp@3176: class G1YoungGenerationCounters: public G1GenerationCounters { tonyp@3176: public: tonyp@3176: G1YoungGenerationCounters(G1MonitoringSupport* g1mm, const char* name); tonyp@3176: virtual void update_all(); tonyp@3176: }; tonyp@3176: tonyp@3176: class G1OldGenerationCounters: public G1GenerationCounters { tonyp@3176: public: tonyp@3176: G1OldGenerationCounters(G1MonitoringSupport* g1mm, const char* name); tonyp@3176: virtual void update_all(); jmasa@2821: }; jmasa@2821: jmasa@2821: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP