1 /* 2 * Copyright (c) 2015, 2019, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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. 8 * 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). 14 * 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. 18 * 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 21 * questions. 22 * 23 */ 24 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" 34 35 class ShenandoahYoungGenerationCounters : public GenerationCounters { 36 public: 37 ShenandoahYoungGenerationCounters() : 38 GenerationCounters("Young", 0, 0, 0, (size_t)0, (size_t)0) {}; 39 40 virtual void update_all() { 41 // no update 42 } 43 }; 44 45 class ShenandoahGenerationCounters : public GenerationCounters { 46 private: 47 ShenandoahHeap* _heap; 48 public: 49 ShenandoahGenerationCounters(ShenandoahHeap* heap) : 50 GenerationCounters("Heap", 1, 1, heap->initial_capacity(), heap->max_capacity(), heap->capacity()), 51 _heap(heap) 52 {}; 53 54 virtual void update_all() { 55 _current_size->set_value(_heap->capacity()); 56 } 57 }; 58 59 ShenandoahMonitoringSupport::ShenandoahMonitoringSupport(ShenandoahHeap* heap) : 60 _partial_counters(nullptr), 61 _full_counters(nullptr) 62 { 63 // Collection counters do not fit Shenandoah very well. 64 // We record partial cycles as "young", and full cycles (including full STW GC) as "old". 65 _partial_counters = new CollectorCounters("Shenandoah partial", 0); 66 _full_counters = new CollectorCounters("Shenandoah full", 1); 67 68 // We report young gen as unused. 69 _young_counters = new ShenandoahYoungGenerationCounters(); 70 _heap_counters = new ShenandoahGenerationCounters(heap); 71 _space_counters = new HSpaceCounters(_heap_counters->name_space(), "Heap", 0, heap->max_capacity(), heap->initial_capacity()); 72 73 _heap_region_counters = new ShenandoahHeapRegionCounters(); 74 } 75 76 CollectorCounters* ShenandoahMonitoringSupport::stw_collection_counters() { 77 return _full_counters; 78 } 79 80 CollectorCounters* ShenandoahMonitoringSupport::full_stw_collection_counters() { 81 return _full_counters; 82 } 83 84 CollectorCounters* ShenandoahMonitoringSupport::concurrent_collection_counters() { 85 return _full_counters; 86 } 87 88 CollectorCounters* ShenandoahMonitoringSupport::partial_collection_counters() { 89 return _partial_counters; 90 } 91 92 void ShenandoahMonitoringSupport::update_counters() { 93 MemoryService::track_memory_usage(); 94 95 if (UsePerfData) { 96 ShenandoahHeap* heap = ShenandoahHeap::heap(); 97 size_t used = heap->used(); 98 size_t capacity = heap->max_capacity(); 99 _heap_counters->update_all(); 100 _space_counters->update_all(capacity, used); 101 _heap_region_counters->update(); 102 103 MetaspaceCounters::update_performance_counters(); 104 } 105 }