2386N/A/*
3681N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2386N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2386N/A *
2386N/A * This code is free software; you can redistribute it and/or modify it
2386N/A * under the terms of the GNU General Public License version 2 only, as
2386N/A * published by the Free Software Foundation.
2386N/A *
2386N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2386N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2386N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2386N/A * version 2 for more details (a copy is included in the LICENSE file that
2386N/A * accompanied this code).
2386N/A *
2386N/A * You should have received a copy of the GNU General Public License version
2386N/A * 2 along with this work; if not, write to the Free Software Foundation,
2386N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2386N/A *
2386N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2386N/A * or visit www.oracle.com if you need additional information or have any
2386N/A * questions.
2386N/A *
2386N/A */
2386N/A
2386N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
2386N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
2386N/A
2386N/A#include "gc_implementation/shared/hSpaceCounters.hpp"
2386N/A
2386N/Aclass G1CollectedHeap;
2386N/A
2816N/A// Class for monitoring logical spaces in G1. It provides data for
2816N/A// both G1's jstat counters as well as G1's memory pools.
2816N/A//
2816N/A// G1 splits the heap into heap regions and each heap region belongs
2816N/A// to one of the following categories:
2816N/A//
2816N/A// * eden : regions that have been allocated since the last GC
2816N/A// * survivors : regions with objects that survived the last few GCs
2816N/A// * old : long-lived non-humongous regions
2816N/A// * humongous : humongous regions
2816N/A// * free : free regions
2816N/A//
2816N/A// The combination of eden and survivor regions form the equivalent of
2816N/A// the young generation in the other GCs. The combination of old and
2816N/A// humongous regions form the equivalent of the old generation in the
2816N/A// other GCs. Free regions do not have a good equivalent in the other
2816N/A// GCs given that they can be allocated as any of the other region types.
2386N/A//
2816N/A// The monitoring tools expect the heap to contain a number of
2816N/A// generations (young, old, perm) and each generation to contain a
2816N/A// number of spaces (young: eden, survivors, old). Given that G1 does
2816N/A// not maintain those spaces physically (e.g., the set of
2816N/A// non-contiguous eden regions can be considered as a "logical"
2816N/A// space), we'll provide the illusion that those generations and
2816N/A// spaces exist. In reality, each generation and space refers to a set
2816N/A// of heap regions that are potentially non-contiguous.
2386N/A//
2816N/A// This class provides interfaces to access the min, current, and max
2816N/A// capacity and current occupancy for each of G1's logical spaces and
2816N/A// generations we expose to the monitoring tools. Also provided are
2816N/A// counters for G1 concurrent collections and stop-the-world full heap
2816N/A// collections.
2386N/A//
2816N/A// Below is a description of how the various sizes are calculated.
2386N/A//
2816N/A// * Current Capacity
2386N/A//
2816N/A// - heap_capacity = current heap capacity (e.g., current committed size)
2816N/A// - young_gen_capacity = current max young gen target capacity
2816N/A// (i.e., young gen target capacity + max allowed expansion capacity)
2816N/A// - survivor_capacity = current survivor region capacity
2816N/A// - eden_capacity = young_gen_capacity - survivor_capacity
2816N/A// - old_capacity = heap_capacity - young_gen_capacity
2816N/A//
2816N/A// What we do in the above is to distribute the free regions among
2816N/A// eden_capacity and old_capacity.
2386N/A//
2816N/A// * Occupancy
2386N/A//
2816N/A// - young_gen_used = current young region capacity
2816N/A// - survivor_used = survivor_capacity
2816N/A// - eden_used = young_gen_used - survivor_used
2816N/A// - old_used = overall_used - young_gen_used
2386N/A//
2816N/A// Unfortunately, we currently only keep track of the number of
2816N/A// currently allocated young and survivor regions + the overall used
2816N/A// bytes in the heap, so the above can be a little inaccurate.
2816N/A//
2816N/A// * Min Capacity
2386N/A//
3115N/A// We set this to 0 for all spaces.
2816N/A//
2816N/A// * Max Capacity
2386N/A//
2816N/A// For jstat, we set the max capacity of all spaces to heap_capacity,
3115N/A// given that we don't always have a reasonable upper bound on how big
3115N/A// each space can grow. For the memory pools, we make the max
3115N/A// capacity undefined with the exception of the old memory pool for
3115N/A// which we make the max capacity same as the max heap capacity.
2386N/A//
2816N/A// If we had more accurate occupancy / capacity information per
2816N/A// region set the above calculations would be greatly simplified and
2816N/A// be made more accurate.
2386N/A//
2816N/A// We update all the above synchronously and we store the results in
2816N/A// fields so that we just read said fields when needed. A subtle point
2816N/A// is that all the above sizes need to be recalculated when the old
2816N/A// gen changes capacity (after a GC or after a humongous allocation)
2816N/A// but only the eden occupancy changes when a new eden region is
2816N/A// allocated. So, in the latter case we have minimal recalcuation to
2816N/A// do which is important as we want to keep the eden region allocation
2816N/A// path as low-overhead as possible.
2386N/A
3863N/Aclass G1MonitoringSupport : public CHeapObj<mtGC> {
2820N/A friend class VMStructs;
2820N/A
2386N/A G1CollectedHeap* _g1h;
2386N/A
2386N/A // jstat performance counters
2986N/A // incremental collections both young and mixed
2386N/A CollectorCounters* _incremental_collection_counters;
2386N/A // full stop-the-world collections
2386N/A CollectorCounters* _full_collection_counters;
2386N/A // young collection set counters. The _eden_counters,
2386N/A // _from_counters, and _to_counters are associated with
2386N/A // this "generational" counter.
2386N/A GenerationCounters* _young_collection_counters;
2816N/A // old collection set counters. The _old_space_counters
2386N/A // below are associated with this "generational" counter.
2816N/A GenerationCounters* _old_collection_counters;
2386N/A // Counters for the capacity and used for
2386N/A // the whole heap
2386N/A HSpaceCounters* _old_space_counters;
2386N/A // the young collection
2386N/A HSpaceCounters* _eden_counters;
2386N/A // the survivor collection (only one, _to_counters, is actively used)
2386N/A HSpaceCounters* _from_counters;
2386N/A HSpaceCounters* _to_counters;
2386N/A
2816N/A // When it's appropriate to recalculate the various sizes (at the
2816N/A // end of a GC, when a new eden region is allocated, etc.) we store
2816N/A // them here so that we can easily report them when needed and not
2816N/A // have to recalculate them every time.
2816N/A
2816N/A size_t _overall_reserved;
2816N/A size_t _overall_committed;
2816N/A size_t _overall_used;
2816N/A
3681N/A uint _young_region_num;
2816N/A size_t _young_gen_committed;
2816N/A size_t _eden_committed;
2816N/A size_t _eden_used;
2816N/A size_t _survivor_committed;
2816N/A size_t _survivor_used;
2816N/A
2816N/A size_t _old_committed;
2816N/A size_t _old_used;
2816N/A
2816N/A G1CollectedHeap* g1h() { return _g1h; }
2816N/A
2386N/A // It returns x - y if x > y, 0 otherwise.
2386N/A // As described in the comment above, some of the inputs to the
2386N/A // calculations we have to do are obtained concurrently and hence
2386N/A // may be inconsistent with each other. So, this provides a
2386N/A // defensive way of performing the subtraction and avoids the value
2386N/A // going negative (which would mean a very large result, given that
2386N/A // the parameter are size_t).
2386N/A static size_t subtract_up_to_zero(size_t x, size_t y) {
2386N/A if (x > y) {
2386N/A return x - y;
2386N/A } else {
2386N/A return 0;
2386N/A }
2386N/A }
2386N/A
2816N/A // Recalculate all the sizes.
2816N/A void recalculate_sizes();
2816N/A // Recalculate only what's necessary when a new eden region is allocated.
2816N/A void recalculate_eden_size();
2816N/A
2386N/A public:
2816N/A G1MonitoringSupport(G1CollectedHeap* g1h);
2386N/A
2816N/A // Unfortunately, the jstat tool assumes that no space has 0
2816N/A // capacity. In our case, given that each space is logical, it's
2816N/A // possible that no regions will be allocated to it, hence to have 0
2816N/A // capacity (e.g., if there are no survivor regions, the survivor
2816N/A // space has 0 capacity). The way we deal with this is to always pad
2816N/A // each capacity value we report to jstat by a very small amount to
2816N/A // make sure that it's never zero. Given that we sometimes have to
2816N/A // report a capacity of a generation that contains several spaces
2816N/A // (e.g., young gen includes one eden, two survivor spaces), the
2816N/A // mult parameter is provided in order to adding the appropriate
2816N/A // padding multiple times so that the capacities add up correctly.
2816N/A static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
2816N/A return size_bytes + MinObjAlignmentInBytes * mult;
2816N/A }
2386N/A
2816N/A // Recalculate all the sizes from scratch and update all the jstat
2816N/A // counters accordingly.
2816N/A void update_sizes();
2816N/A // Recalculate only what's necessary when a new eden region is
2816N/A // allocated and update any jstat counters that need to be updated.
2816N/A void update_eden_size();
2386N/A
2386N/A CollectorCounters* incremental_collection_counters() {
2386N/A return _incremental_collection_counters;
2386N/A }
2386N/A CollectorCounters* full_collection_counters() {
2386N/A return _full_collection_counters;
2386N/A }
2816N/A GenerationCounters* young_collection_counters() {
2816N/A return _young_collection_counters;
2816N/A }
2816N/A GenerationCounters* old_collection_counters() {
2816N/A return _old_collection_counters;
2386N/A }
2386N/A HSpaceCounters* old_space_counters() { return _old_space_counters; }
2386N/A HSpaceCounters* eden_counters() { return _eden_counters; }
2386N/A HSpaceCounters* from_counters() { return _from_counters; }
2386N/A HSpaceCounters* to_counters() { return _to_counters; }
2386N/A
2386N/A // Monitoring support used by
2386N/A // MemoryService
2386N/A // jstat counters
4141N/A // Tracing
2816N/A
2816N/A size_t overall_reserved() { return _overall_reserved; }
2816N/A size_t overall_committed() { return _overall_committed; }
2816N/A size_t overall_used() { return _overall_used; }
2386N/A
2816N/A size_t young_gen_committed() { return _young_gen_committed; }
2816N/A size_t young_gen_max() { return overall_reserved(); }
2816N/A size_t eden_space_committed() { return _eden_committed; }
2816N/A size_t eden_space_used() { return _eden_used; }
2816N/A size_t survivor_space_committed() { return _survivor_committed; }
2816N/A size_t survivor_space_used() { return _survivor_used; }
2816N/A
2816N/A size_t old_gen_committed() { return old_space_committed(); }
2816N/A size_t old_gen_max() { return overall_reserved(); }
2816N/A size_t old_space_committed() { return _old_committed; }
2816N/A size_t old_space_used() { return _old_used; }
2816N/A};
2386N/A
2816N/Aclass G1GenerationCounters: public GenerationCounters {
2816N/Aprotected:
2816N/A G1MonitoringSupport* _g1mm;
2816N/A
2816N/Apublic:
2816N/A G1GenerationCounters(G1MonitoringSupport* g1mm,
2816N/A const char* name, int ordinal, int spaces,
2816N/A size_t min_capacity, size_t max_capacity,
2816N/A size_t curr_capacity);
2816N/A};
2386N/A
2816N/Aclass G1YoungGenerationCounters: public G1GenerationCounters {
2816N/Apublic:
2816N/A G1YoungGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
2816N/A virtual void update_all();
2816N/A};
2816N/A
2816N/Aclass G1OldGenerationCounters: public G1GenerationCounters {
2816N/Apublic:
2816N/A G1OldGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
2816N/A virtual void update_all();
2386N/A};
2386N/A
2386N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP