1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018 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 #ifndef SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP 27 #define SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP 28 29 #include "memory/metaspace.hpp" // for MetadataType enum 30 #include "memory/metaspace/chunkLevel.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 class outputStream; 34 35 namespace metaspace { 36 37 // Contains statistics for a ChunkManager. 38 struct ChunkManagerStatistics { 39 40 // How many chunks per level are checked in. 41 int num_chunks[chklvl::NUM_CHUNK_LEVELS]; 42 43 // Size, in words, of the sum of all committed areas in this chunk manager, per level. 44 size_t committed_word_size[chklvl::NUM_CHUNK_LEVELS]; 45 46 ChunkManagerStatistics(); 47 48 size_t total_capacity() const; 49 50 void print_on(outputStream* st, size_t scale) const; 51 52 }; // ChunkManagerStatistics 53 54 // Contains statistics for a number of chunks in use. 55 // Each chunk has a used and free portion; however, there are current chunks (serving 56 // potential future metaspace allocations) and non-current chunks. Unused portion of the 57 // former is counted as free, unused portion of the latter counts as waste. 58 struct UsedChunksStatistics { 59 60 // Number of chunks 61 int num; 62 63 64 // Note: all sizes in number of words. 65 66 // Capacity in words. May contain committed and uncommitted space. 67 size_t cap; 68 69 // Total used area, in words. May contain committed and uncommitted space. 70 size_t used; 71 72 // Total free area (unused portions of current chunks). May contain committed and uncommitted space. 73 size_t free; 74 75 // Total waste area (unused portions of non-current chunks). May contain committed and uncommitted space. 76 size_t waste; 77 78 79 // Total committed area, in words. May be smaller or larger than used. 80 size_t committed; 81 82 UsedChunksStatistics() : num(0), cap(0), used(0), free(0), waste(0), committed(0) {} 83 84 void add(const UsedChunksStatistics& other) { 85 num = other.num; cap = other.cap; used = other.used; 86 free = other.free; waste = other.waste; 87 } 88 89 void print_on(outputStream* st, size_t scale) const; 90 91 DEBUG_ONLY(void check_sanity() const;) 92 93 }; // UsedChunksStatistics 94 95 // Class containing statistics for one or more space managers. 96 struct SpaceManagerStatistics { 97 98 UsedChunksStatistics chunk_stats[chklvl::NUM_CHUNK_LEVELS]; 99 uintx free_blocks_num; 100 size_t free_blocks_word_size; 101 102 SpaceManagerStatistics() : chunk_stats(), free_blocks_num(0), free_blocks_word_size(0) {} 103 104 void add_free_blocks_info(uintx num, size_t cap) { 105 free_blocks_num += num; free_blocks_word_size += cap; 106 } 107 108 // Returns total chunk statistics over all chunk levels. 109 UsedChunksStatistics totals() const; 110 111 void add(const SpaceManagerStatistics& other); 112 113 void print_on(outputStream* st, size_t scale, bool detailed) const; 114 115 }; // SpaceManagerStatistics 116 117 struct ClassLoaderMetaspaceStatistics { 118 119 SpaceManagerStatistics sm_stats[MetadataTypeCount]; 120 121 ClassLoaderMetaspaceStatistics() : sm_stats() {} 122 123 void add(const ClassLoaderMetaspaceStatistics& other) { 124 sm_stats[ClassType].add(other.sm_stats[ClassType]); 125 sm_stats[NonClassType].add(other.sm_stats[NonClassType]); 126 } 127 128 // Returns total space manager statistics for both class and non-class metaspace 129 SpaceManagerStatistics totals() const; 130 131 void print_on(outputStream* st, size_t scale, bool detailed) const; 132 133 }; // ClassLoaderMetaspaceStatistics 134 135 } // namespace metaspace 136 137 #endif // SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP