2
* Copyright (c) 2015, 2019, Red Hat, Inc. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
25
#include "precompiled.hpp"
26
#include "gc/shared/collectorCounters.hpp"
27
#include "gc/shared/generationCounters.hpp"
28
#include "gc/shared/hSpaceCounters.hpp"
29
#include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
30
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
31
#include "gc/shenandoah/shenandoahHeapRegionCounters.hpp"
32
#include "memory/metaspaceCounters.hpp"
33
#include "services/memoryService.hpp"
35
class ShenandoahYoungGenerationCounters : public GenerationCounters {
37
ShenandoahYoungGenerationCounters() :
38
GenerationCounters("Young", 0, 0, 0, (size_t)0, (size_t)0) {};
40
void update_all() override {
45
class ShenandoahGenerationCounters : public GenerationCounters {
47
ShenandoahHeap* _heap;
49
explicit ShenandoahGenerationCounters(ShenandoahHeap* heap) :
50
GenerationCounters("Heap", 1, 1, heap->initial_capacity(), heap->max_capacity(), heap->capacity()),
54
void update_all() override {
55
_current_size->set_value(_heap->capacity());
59
ShenandoahMonitoringSupport::ShenandoahMonitoringSupport(ShenandoahHeap* heap) :
60
_partial_counters(nullptr),
61
_full_counters(nullptr),
62
_counters_update_task(this)
64
// Collection counters do not fit Shenandoah very well.
65
// We record partial cycles as "young", and full cycles (including full STW GC) as "old".
66
_partial_counters = new CollectorCounters("Shenandoah partial", 0);
67
_full_counters = new CollectorCounters("Shenandoah full", 1);
69
// We report young gen as unused.
70
_young_counters = new ShenandoahYoungGenerationCounters();
71
_heap_counters = new ShenandoahGenerationCounters(heap);
72
_space_counters = new HSpaceCounters(_heap_counters->name_space(), "Heap", 0, heap->max_capacity(), heap->initial_capacity());
74
_heap_region_counters = new ShenandoahHeapRegionCounters();
76
_counters_update_task.enroll();
79
CollectorCounters* ShenandoahMonitoringSupport::stw_collection_counters() {
80
return _full_counters;
83
CollectorCounters* ShenandoahMonitoringSupport::full_stw_collection_counters() {
84
return _full_counters;
87
CollectorCounters* ShenandoahMonitoringSupport::concurrent_collection_counters() {
88
return _full_counters;
91
CollectorCounters* ShenandoahMonitoringSupport::partial_collection_counters() {
92
return _partial_counters;
95
void ShenandoahMonitoringSupport::update_counters() {
96
MemoryService::track_memory_usage();
99
ShenandoahHeap* heap = ShenandoahHeap::heap();
100
size_t used = heap->used();
101
size_t capacity = heap->max_capacity();
102
_heap_counters->update_all();
103
_space_counters->update_all(capacity, used);
104
_heap_region_counters->update();
106
MetaspaceCounters::update_performance_counters();
110
void ShenandoahMonitoringSupport::notify_heap_changed() {
111
_counters_update_task.notify_heap_changed();
114
void ShenandoahMonitoringSupport::set_forced_counters_update(bool value) {
115
_counters_update_task.set_forced_counters_update(value);
118
void ShenandoahMonitoringSupport::handle_force_counters_update() {
119
_counters_update_task.handle_force_counters_update();
122
void ShenandoahPeriodicCountersUpdateTask::task() {
123
handle_force_counters_update();
124
handle_counters_update();
127
void ShenandoahPeriodicCountersUpdateTask::handle_counters_update() {
128
if (_do_counters_update.is_set()) {
129
_do_counters_update.unset();
130
_monitoring_support->update_counters();
134
void ShenandoahPeriodicCountersUpdateTask::handle_force_counters_update() {
135
if (_force_counters_update.is_set()) {
136
_do_counters_update.unset(); // reset these too, we do update now!
137
_monitoring_support->update_counters();
141
void ShenandoahPeriodicCountersUpdateTask::notify_heap_changed() {
142
if (_do_counters_update.is_unset()) {
143
_do_counters_update.set();
147
void ShenandoahPeriodicCountersUpdateTask::set_forced_counters_update(bool value) {
148
_force_counters_update.set_cond(value);