/* * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP #define SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP #include "memory/metaspace.hpp" // for MetadataType enum #include "memory/metaspace/chunkLevel.hpp" #include "utilities/globalDefinitions.hpp" class outputStream; namespace metaspace { // Contains statistics for a ChunkManager. struct ChunkManagerStatistics { // How many chunks per level are checked in. int num_chunks[chklvl::NUM_CHUNK_LEVELS]; // Size, in words, of the sum of all committed areas in this chunk manager, per level. size_t committed_word_size[chklvl::NUM_CHUNK_LEVELS]; ChunkManagerStatistics(); size_t total_capacity() const; void print_on(outputStream* st, size_t scale) const; }; // ChunkManagerStatistics // Contains statistics for a number of chunks in use. // Each chunk has a used and free portion; however, there are current chunks (serving // potential future metaspace allocations) and non-current chunks. Unused portion of the // former is counted as free, unused portion of the latter counts as waste. struct UsedChunksStatistics { // Number of chunks int num; // Note: all sizes in number of words. // Capacity in words. May contain committed and uncommitted space. size_t cap; // Total used area, in words. May contain committed and uncommitted space. size_t used; // Total free area (unused portions of current chunks). May contain committed and uncommitted space. size_t free; // Total waste area (unused portions of non-current chunks). May contain committed and uncommitted space. size_t waste; // Total committed area, in words. May be smaller or larger than used. size_t committed; UsedChunksStatistics() : num(0), cap(0), used(0), free(0), waste(0), committed(0) {} void add(const UsedChunksStatistics& other) { num = other.num; cap = other.cap; used = other.used; free = other.free; waste = other.waste; } void print_on(outputStream* st, size_t scale) const; DEBUG_ONLY(void check_sanity() const;) }; // UsedChunksStatistics // Class containing statistics for one or more space managers. struct SpaceManagerStatistics { UsedChunksStatistics chunk_stats[chklvl::NUM_CHUNK_LEVELS]; uintx free_blocks_num; size_t free_blocks_word_size; SpaceManagerStatistics() : chunk_stats(), free_blocks_num(0), free_blocks_word_size(0) {} void add_free_blocks_info(uintx num, size_t cap) { free_blocks_num += num; free_blocks_word_size += cap; } // Returns total chunk statistics over all chunk levels. UsedChunksStatistics totals() const; void add(const SpaceManagerStatistics& other); void print_on(outputStream* st, size_t scale, bool detailed) const; }; // SpaceManagerStatistics struct ClassLoaderMetaspaceStatistics { SpaceManagerStatistics sm_stats[MetadataTypeCount]; ClassLoaderMetaspaceStatistics() : sm_stats() {} void add(const ClassLoaderMetaspaceStatistics& other) { sm_stats[ClassType].add(other.sm_stats[ClassType]); sm_stats[NonClassType].add(other.sm_stats[NonClassType]); } // Returns total space manager statistics for both class and non-class metaspace SpaceManagerStatistics totals() const; void print_on(outputStream* st, size_t scale, bool detailed) const; }; // ClassLoaderMetaspaceStatistics } // namespace metaspace #endif // SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP