diff --git a/src/hotspot/share/gc/parallel/psOldGen.cpp b/src/hotspot/share/gc/parallel/psOldGen.cpp index 974cd6aca59..6a9f8bfeedc 100644 --- a/src/hotspot/share/gc/parallel/psOldGen.cpp +++ b/src/hotspot/share/gc/parallel/psOldGen.cpp @@ -30,6 +30,7 @@ #include "gc/parallel/psOldGen.hpp" #include "gc/shared/cardTableBarrierSet.hpp" #include "gc/shared/gcLocker.hpp" +#include "gc/shared/hSpaceCounters.hpp" #include "gc/shared/spaceDecorator.hpp" #include "logging/log.hpp" #include "oops/oop.inline.hpp" @@ -113,9 +114,11 @@ void PSOldGen::initialize_performance_counters() { const char* perf_data_name = "old"; _gen_counters = new GenerationCounters(perf_data_name, 1, 1, min_gen_size(), max_gen_size(), virtual_space()->committed_size()); - _space_counters = new SpaceCounters(perf_data_name, 0, - virtual_space()->reserved_size(), - _object_space, _gen_counters); + _space_counters = new HSpaceCounters(_gen_counters->name_space(), + perf_data_name, + 0, + virtual_space()->reserved_size(), + _object_space->capacity_in_bytes()); } HeapWord* PSOldGen::expand_and_allocate(size_t word_size) { @@ -266,7 +269,7 @@ bool PSOldGen::expand_by(size_t bytes) { } post_resize(); if (UsePerfData) { - _space_counters->update_capacity(); + _space_counters->update_capacity(_object_space->capacity_in_bytes()); _gen_counters->update_capacity(_virtual_space->committed_size()); } } @@ -394,7 +397,7 @@ void PSOldGen::print_on(outputStream* st) const { void PSOldGen::update_counters() { if (UsePerfData) { - _space_counters->update_all(); + _space_counters->update_all(_object_space->capacity_in_bytes(), _object_space->used_in_bytes()); _gen_counters->update_capacity(_virtual_space->committed_size()); } } diff --git a/src/hotspot/share/gc/parallel/psOldGen.hpp b/src/hotspot/share/gc/parallel/psOldGen.hpp index 05359b12836..7e3975036d4 100644 --- a/src/hotspot/share/gc/parallel/psOldGen.hpp +++ b/src/hotspot/share/gc/parallel/psOldGen.hpp @@ -28,7 +28,8 @@ #include "gc/parallel/mutableSpace.hpp" #include "gc/parallel/objectStartArray.hpp" #include "gc/parallel/psVirtualspace.hpp" -#include "gc/parallel/spaceCounters.hpp" +#include "gc/shared/generationCounters.hpp" +#include "gc/shared/hSpaceCounters.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/safepoint.hpp" @@ -43,7 +44,7 @@ class PSOldGen : public CHeapObj { // Performance Counters GenerationCounters* _gen_counters; - SpaceCounters* _space_counters; + HSpaceCounters* _space_counters; // Sizing information, in bytes, set in constructor const size_t _min_gen_size; diff --git a/src/hotspot/share/gc/parallel/psYoungGen.cpp b/src/hotspot/share/gc/parallel/psYoungGen.cpp index 593df38e985..870e912f51e 100644 --- a/src/hotspot/share/gc/parallel/psYoungGen.cpp +++ b/src/hotspot/share/gc/parallel/psYoungGen.cpp @@ -28,6 +28,7 @@ #include "gc/parallel/psYoungGen.hpp" #include "gc/shared/gcUtil.hpp" #include "gc/shared/genArguments.hpp" +#include "gc/shared/hSpaceCounters.hpp" #include "gc/shared/spaceDecorator.hpp" #include "logging/log.hpp" #include "oops/oop.inline.hpp" @@ -133,12 +134,21 @@ void PSYoungGen::initialize_work() { max_eden_size = size - 2 * max_survivor_size; } - _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space, - _gen_counters); - _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space, - _gen_counters); - _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space, - _gen_counters); + _eden_counters = new HSpaceCounters(_gen_counters->name_space(), + "eden", + 0, + max_eden_size, + _eden_space->capacity_in_bytes()); + _from_counters = new HSpaceCounters(_gen_counters->name_space(), + "s0", + 1, + max_survivor_size, + _from_space->capacity_in_bytes()); + _to_counters = new HSpaceCounters(_gen_counters->name_space(), + "s1", + 2, + max_survivor_size, + _to_space->capacity_in_bytes()); compute_initial_space_boundaries(); } @@ -161,9 +171,9 @@ void PSYoungGen::compute_initial_space_boundaries() { space_invariants(); if (UsePerfData) { - _eden_counters->update_capacity(); - _from_counters->update_capacity(); - _to_counters->update_capacity(); + _eden_counters->update_capacity(_eden_space->capacity_in_bytes()); + _from_counters->update_capacity(_from_space->capacity_in_bytes()); + _to_counters->update_capacity(_to_space->capacity_in_bytes()); } } @@ -606,9 +616,9 @@ void PSYoungGen::post_resize() { void PSYoungGen::update_counters() { if (UsePerfData) { - _eden_counters->update_all(); - _from_counters->update_all(); - _to_counters->update_all(); + _eden_counters->update_all(_eden_space->capacity_in_bytes(), _eden_space->used_in_bytes()); + _from_counters->update_all(_from_space->capacity_in_bytes(), _from_space->used_in_bytes()); + _to_counters->update_all(_to_space->capacity_in_bytes(), _to_space->used_in_bytes()); _gen_counters->update_capacity(_virtual_space->committed_size()); } } diff --git a/src/hotspot/share/gc/parallel/psYoungGen.hpp b/src/hotspot/share/gc/parallel/psYoungGen.hpp index 98337d53184..10aa037da98 100644 --- a/src/hotspot/share/gc/parallel/psYoungGen.hpp +++ b/src/hotspot/share/gc/parallel/psYoungGen.hpp @@ -28,7 +28,8 @@ #include "gc/parallel/mutableSpace.hpp" #include "gc/parallel/objectStartArray.hpp" #include "gc/parallel/psVirtualspace.hpp" -#include "gc/parallel/spaceCounters.hpp" +#include "gc/shared/generationCounters.hpp" +#include "gc/shared/hSpaceCounters.hpp" class ReservedSpace; @@ -51,9 +52,9 @@ class PSYoungGen : public CHeapObj { // Performance counters GenerationCounters* _gen_counters; - SpaceCounters* _eden_counters; - SpaceCounters* _from_counters; - SpaceCounters* _to_counters; + HSpaceCounters* _eden_counters; + HSpaceCounters* _from_counters; + HSpaceCounters* _to_counters; // Initialize the space boundaries void compute_initial_space_boundaries(); diff --git a/src/hotspot/share/gc/parallel/spaceCounters.cpp b/src/hotspot/share/gc/parallel/spaceCounters.cpp deleted file mode 100644 index e41b36c9ed2..00000000000 --- a/src/hotspot/share/gc/parallel/spaceCounters.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2002, 2026, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "gc/parallel/spaceCounters.hpp" -#include "memory/allocation.inline.hpp" -#include "memory/resourceArea.hpp" -#include "runtime/mutex.hpp" -#include "runtime/mutexLocker.hpp" -#include "utilities/debug.hpp" -#include "utilities/macros.hpp" - -SpaceCounters::SpaceCounters(const char* name, int ordinal, size_t max_size, - MutableSpace* m, GenerationCounters* gc) - : _object_space(m) { - if (UsePerfData) { - EXCEPTION_MARK; - ResourceMark rm; - - const char* cns = PerfDataManager::name_space(gc->name_space(), "space", - ordinal); - - _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC); - strcpy(_name_space, cns); - - const char* cname = PerfDataManager::counter_name(_name_space, "name"); - PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK); - - cname = PerfDataManager::counter_name(_name_space, "maxCapacity"); - PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, - (jlong)max_size, CHECK); - - cname = PerfDataManager::counter_name(_name_space, "capacity"); - _capacity = PerfDataManager::create_variable(SUN_GC, cname, - PerfData::U_Bytes, - _object_space->capacity_in_bytes(), - CHECK); - - cname = PerfDataManager::counter_name(_name_space, "used"); - _used = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, - _object_space->used_in_bytes(), - CHECK); - - cname = PerfDataManager::counter_name(_name_space, "initCapacity"); - PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, - _object_space->capacity_in_bytes(), CHECK); - } -} - -SpaceCounters::~SpaceCounters() { - FREE_C_HEAP_ARRAY(char, _name_space); -} - -void SpaceCounters::update_used() { - _used->set_value(_object_space->used_in_bytes()); -} diff --git a/src/hotspot/share/gc/parallel/spaceCounters.hpp b/src/hotspot/share/gc/parallel/spaceCounters.hpp deleted file mode 100644 index 86fc8438b23..00000000000 --- a/src/hotspot/share/gc/parallel/spaceCounters.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef SHARE_GC_PARALLEL_SPACECOUNTERS_HPP -#define SHARE_GC_PARALLEL_SPACECOUNTERS_HPP - -#include "gc/parallel/mutableSpace.hpp" -#include "gc/shared/generationCounters.hpp" -#include "runtime/perfData.hpp" -#include "utilities/macros.hpp" - -// A SpaceCounter is a holder class for performance counters -// that track a space; - -class SpaceCounters: public CHeapObj { - friend class VMStructs; - - private: - PerfVariable* _capacity; - PerfVariable* _used; - - // Constant PerfData types don't need to retain a reference. - // However, it's a good idea to document them here. - // PerfConstant* _size; - - MutableSpace* _object_space; - char* _name_space; - - public: - - SpaceCounters(const char* name, int ordinal, size_t max_size, - MutableSpace* m, GenerationCounters* gc); - - ~SpaceCounters(); - - inline void update_capacity() { - _capacity->set_value(_object_space->capacity_in_bytes()); - } - - void update_used(); - - inline void update_all() { - update_used(); - update_capacity(); - } - - const char* name_space() const { return _name_space; } -}; - -#endif // SHARE_GC_PARALLEL_SPACECOUNTERS_HPP