1 /* 2 * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "memory/metaspace/chunkManager.hpp" 28 #include "memory/metaspace/metaspaceContext.hpp" 29 #include "memory/metaspace/runningCounters.hpp" 30 #include "memory/metaspace/virtualSpaceList.hpp" 31 32 namespace metaspace { 33 34 // Return reserved size, in words, for Metaspace 35 size_t RunningCounters::reserved_words() { 36 return reserved_words_class() + reserved_words_nonclass(); 37 } 38 39 size_t RunningCounters::reserved_words_class() { 40 VirtualSpaceList* vs = VirtualSpaceList::vslist_class(); 41 return vs != nullptr ? vs->reserved_words() : 0; 42 } 43 44 size_t RunningCounters::reserved_words_nonclass() { 45 return VirtualSpaceList::vslist_nonclass()->reserved_words(); 46 } 47 48 // Return total committed size, in words, for Metaspace 49 size_t RunningCounters::committed_words() { 50 return committed_words_class() + committed_words_nonclass(); 51 } 52 53 size_t RunningCounters::committed_words_class() { 54 VirtualSpaceList* vs = VirtualSpaceList::vslist_class(); 55 return vs != nullptr ? vs->committed_words() : 0; 56 } 57 58 size_t RunningCounters::committed_words_nonclass() { 59 return VirtualSpaceList::vslist_nonclass()->committed_words(); 60 } 61 62 // ---- used chunks ----- 63 64 // Returns size, in words, used for metadata. 65 size_t RunningCounters::used_words() { 66 return used_words_class() + used_words_nonclass(); 67 } 68 69 size_t RunningCounters::used_words_class() { 70 const MetaspaceContext* context = MetaspaceContext::context_class(); 71 return context != nullptr ? context->used_words() : 0; 72 } 73 74 size_t RunningCounters::used_words_nonclass() { 75 return MetaspaceContext::context_nonclass()->used_words(); 76 } 77 78 // ---- free chunks ----- 79 80 // Returns size, in words, of all chunks in all freelists. 81 size_t RunningCounters::free_chunks_words() { 82 return free_chunks_words_class() + free_chunks_words_nonclass(); 83 } 84 85 size_t RunningCounters::free_chunks_words_class() { 86 ChunkManager* cm = ChunkManager::chunkmanager_class(); 87 return cm != nullptr ? cm->total_word_size() : 0; 88 } 89 90 size_t RunningCounters::free_chunks_words_nonclass() { 91 return ChunkManager::chunkmanager_nonclass()->total_word_size(); 92 } 93 94 } // namespace metaspace 95