1 /* 2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. 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 #include "precompiled.hpp" 25 #include "gc/shared/generationCounters.hpp" 26 #include "gc/shared/hSpaceCounters.hpp" 27 #include "gc/z/zCollectedHeap.hpp" 28 #include "gc/z/zHeap.inline.hpp" 29 #include "gc/z/zServiceability.hpp" 30 #include "memory/metaspaceCounters.hpp" 31 #include "runtime/perfData.hpp" 32 33 class ZOldGenerationCounters : public GenerationCounters { 34 public: 35 ZOldGenerationCounters(const char* name, size_t min_capacity, size_t max_capacity) : 36 // The "1, 1" parameters are for the n-th generation (=1) with 1 space. 37 GenerationCounters(name, 38 1 /* ordinal */, 39 1 /* spaces */, 40 min_capacity /* min_capacity */, 41 max_capacity /* max_capacity */, 42 min_capacity /* curr_capacity */) {} 43 44 virtual void update_all() { 45 size_t committed = ZHeap::heap()->capacity(); 46 _current_size->set_value(committed); 47 } 48 }; 49 50 // Class to expose perf counters used by jstat. 51 class ZServiceabilityCounters : public CHeapObj<mtGC> { 52 private: 53 ZOldGenerationCounters _old_collection_counters; 54 HSpaceCounters _old_space_counters; 55 CollectorCounters* _cgc_counters; 56 57 public: 58 ZServiceabilityCounters(size_t min_capacity, size_t max_capacity); 59 60 void update_sizes(); 61 62 CollectorCounters* cgc_counters() { 63 return _cgc_counters; 64 } 65 }; 66 67 ZServiceabilityCounters::ZServiceabilityCounters(size_t min_capacity, size_t max_capacity) : 68 // generation.1 69 _old_collection_counters("old", 70 min_capacity, 71 max_capacity), 72 // generation.1.space.0 73 _old_space_counters(_old_collection_counters.name_space(), 74 "space", 75 0 /* ordinal */, 76 max_capacity /* max_capacity */, 77 min_capacity /* init_capacity */), 78 // gc.collector.2 79 _cgc_counters(new CollectorCounters("Z stop-the-world phases", 2)) {} 80 81 void ZServiceabilityCounters::update_sizes() { 82 if (UsePerfData) { 83 size_t capacity = ZHeap::heap()->capacity(); 84 size_t used = MIN2(ZHeap::heap()->used(), capacity); 85 86 _old_space_counters.update_capacity(capacity); 87 _old_space_counters.update_used(used); 88 89 _old_collection_counters.update_all(); 90 91 MetaspaceCounters::update_performance_counters(); 92 CompressedClassSpaceCounters::update_performance_counters(); 93 } 94 } 95 96 ZServiceabilityMemoryPool::ZServiceabilityMemoryPool(size_t min_capacity, size_t max_capacity) : 97 CollectedMemoryPool("ZHeap", 98 min_capacity, 99 max_capacity, 100 true /* support_usage_threshold */) {} 101 102 size_t ZServiceabilityMemoryPool::used_in_bytes() { 103 return ZHeap::heap()->used(); 104 } 105 106 MemoryUsage ZServiceabilityMemoryPool::get_memory_usage() { 107 const size_t committed = ZHeap::heap()->capacity(); 108 const size_t used = MIN2(ZHeap::heap()->used(), committed); 109 110 return MemoryUsage(initial_size(), used, committed, max_size()); 111 } 112 113 ZServiceabilityMemoryManager::ZServiceabilityMemoryManager(ZServiceabilityMemoryPool* pool) 114 : GCMemoryManager("ZGC", "end of major GC") { 115 add_pool(pool); 116 } 117 118 ZServiceability::ZServiceability(size_t min_capacity, size_t max_capacity) : 119 _min_capacity(min_capacity), 120 _max_capacity(max_capacity), 121 _memory_pool(_min_capacity, _max_capacity), 122 _memory_manager(&_memory_pool), 123 _counters(NULL) {} 124 125 void ZServiceability::initialize() { 126 _counters = new ZServiceabilityCounters(_min_capacity, _max_capacity); 127 } 128 129 MemoryPool* ZServiceability::memory_pool() { 130 return &_memory_pool; 131 } 132 133 GCMemoryManager* ZServiceability::memory_manager() { 134 return &_memory_manager; 135 } 136 137 ZServiceabilityCounters* ZServiceability::counters() { 138 return _counters; 139 } 140 141 ZServiceabilityMemoryUsageTracker::~ZServiceabilityMemoryUsageTracker() { 142 MemoryService::track_memory_usage(); 143 } 144 145 ZServiceabilityManagerStatsTracer::ZServiceabilityManagerStatsTracer(bool is_gc_begin, bool is_gc_end) : 146 _stats(ZHeap::heap()->serviceability_memory_manager(), 147 ZCollectedHeap::heap()->gc_cause() /* cause */, 148 true /* allMemoryPoolsAffected */, 149 is_gc_begin /* recordGCBeginTime */, 150 is_gc_begin /* recordPreGCUsage */, 151 true /* recordPeakUsage */, 152 is_gc_end /* recordPostGCusage */, 153 true /* recordAccumulatedGCTime */, 154 is_gc_end /* recordGCEndTime */, 155 is_gc_end /* countCollection */) {} 156 157 ZServiceabilityCountersTracer::ZServiceabilityCountersTracer() : 158 _stats(ZHeap::heap()->serviceability_counters()->cgc_counters()) { 159 } 160 161 ZServiceabilityCountersTracer::~ZServiceabilityCountersTracer() { 162 ZHeap::heap()->serviceability_counters()->update_sizes(); 163 }