Path: blob/master/src/hotspot/share/gc/epsilon/epsilonMonitoringSupport.cpp
41152 views
/*1* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc/epsilon/epsilonMonitoringSupport.hpp"26#include "gc/epsilon/epsilonHeap.hpp"27#include "gc/shared/generationCounters.hpp"28#include "memory/allocation.hpp"29#include "memory/metaspaceCounters.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/perfData.hpp"32#include "services/memoryService.hpp"3334class EpsilonSpaceCounters: public CHeapObj<mtGC> {35friend class VMStructs;3637private:38PerfVariable* _capacity;39PerfVariable* _used;40char* _name_space;4142public:43EpsilonSpaceCounters(const char* name,44int ordinal,45size_t max_size,46size_t initial_capacity,47GenerationCounters* gc) {48if (UsePerfData) {49EXCEPTION_MARK;50ResourceMark rm;5152const char* cns = PerfDataManager::name_space(gc->name_space(), "space", ordinal);5354_name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC);55strcpy(_name_space, cns);5657const char* cname = PerfDataManager::counter_name(_name_space, "name");58PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK);5960cname = PerfDataManager::counter_name(_name_space, "maxCapacity");61PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, (jlong)max_size, CHECK);6263cname = PerfDataManager::counter_name(_name_space, "capacity");64_capacity = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, initial_capacity, CHECK);6566cname = PerfDataManager::counter_name(_name_space, "used");67_used = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, (jlong) 0, CHECK);6869cname = PerfDataManager::counter_name(_name_space, "initCapacity");70PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, initial_capacity, CHECK);71}72}7374~EpsilonSpaceCounters() {75FREE_C_HEAP_ARRAY(char, _name_space);76}7778inline void update_all(size_t capacity, size_t used) {79_capacity->set_value(capacity);80_used->set_value(used);81}82};8384class EpsilonGenerationCounters : public GenerationCounters {85private:86EpsilonHeap* _heap;87public:88EpsilonGenerationCounters(EpsilonHeap* heap) :89GenerationCounters("Heap", 1, 1, 0, heap->max_capacity(), heap->capacity()),90_heap(heap)91{};9293virtual void update_all() {94_current_size->set_value(_heap->capacity());95}96};9798EpsilonMonitoringSupport::EpsilonMonitoringSupport(EpsilonHeap* heap) {99_heap_counters = new EpsilonGenerationCounters(heap);100_space_counters = new EpsilonSpaceCounters("Heap", 0, heap->max_capacity(), 0, _heap_counters);101}102103void EpsilonMonitoringSupport::update_counters() {104MemoryService::track_memory_usage();105106if (UsePerfData) {107EpsilonHeap* heap = EpsilonHeap::heap();108size_t used = heap->used();109size_t capacity = heap->capacity();110_heap_counters->update_all();111_space_counters->update_all(capacity, used);112MetaspaceCounters::update_performance_counters();113}114}115116117118