/* * Copyright (c) 2018, 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. * */ #include "precompiled.hpp" #include "memory/metaspace/chunkLevel.hpp" #include "memory/metaspace/metaspaceCommon.hpp" #include "memory/metaspace/metaspaceStatistics.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/ostream.hpp" namespace metaspace { // FreeChunksStatistics methods void FreeChunksStatistics::print_on(outputStream* st, size_t scale) const { st->print(UINTX_FORMAT, num); st->print(" chunks, total capacity "); print_scaled_words(st, word_size, scale); } // ChunkManagerStatistics methods void ChunkManagerStatistics::reset() { for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { chunk_stats[l].reset(); } } size_t ChunkManagerStatistics::total_capacity() const { size_t cap = 0; for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { cap += chunk_stats[l].word_size; } } void ChunkManagerStatistics::print_on(outputStream* st, size_t scale) const { FreeChunksStatistics totals; totals.reset(); for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { st->cr(); st->print(SIZE_FORMAT "k chunks: ", (chklvl::word_size_for_level(l) * BytesPerWord) / K); if (chunk_stats[l].num > 0) { st->print(UINTX_FORMAT_W(4) ", capacity ", chunk_stats[l].num); print_scaled_words(st, chunk_stats[l].word_size, scale); } else { st->print("(none)"); } totals.add(chunk_stats[l]); } st->cr(); st->print("Total: " UINTX_FORMAT_W(4) ", capacity=", totals.num()); print_scaled_words(st, totals.word_size, scale); st->cr(); } // UsedChunksStatistics methods void UsedChunksStatistics::print_on(outputStream* st, size_t scale) const { int col = st->position(); st->print(UINTX_FORMAT_W(4) " chunk%s, ", num, num != 1 ? "s" : ""); if (num > 0) { col += 14; st->fill_to(col); print_scaled_words(st, cap, scale, 5); st->print(" capacity, "); col += 18; st->fill_to(col); print_scaled_words_and_percentage(st, used, cap, scale, 5); st->print(" used, "); col += 20; st->fill_to(col); print_scaled_words_and_percentage(st, free, cap, scale, 5); st->print(" free, "); col += 20; st->fill_to(col); print_scaled_words_and_percentage(st, waste, cap, scale, 5); st->print(" waste "); } DEBUG_ONLY(check_sanity()); } #ifdef ASSERT void UsedChunksStatistics::check_sanity() const { assert(cap == used + free + waste, "Sanity: Capacity."); } #endif // SpaceManagerStatistics methods SpaceManagerStatistics::SpaceManagerStatistics() { reset(); } void SpaceManagerStatistics::reset() { for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { chunk_stats[l].reset(); } free_blocks_num = 0; free_blocks_word_size = 0; } void SpaceManagerStatistics::add(const SpaceManagerStatistics& other) { for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { chunk_stats[l].add(other.chunk_stats[l]); } free_blocks_num += other.free_blocks_num; free_blocks_word_size += other.free_blocks_word_size; } // Returns total chunk statistics over all chunk types. UsedChunksStatistics SpaceManagerStatistics::totals() const { UsedChunksStatistics stat; stat.reset(); for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { stat.add(chunk_stats[l]); } return stat; } void SpaceManagerStatistics::print_on(outputStream* st, size_t scale, bool detailed) const { streamIndentor sti(st); if (detailed) { st->cr_indent(); st->print("Usage by chunk level:"); { streamIndentor sti2(st); for (chklvl_t l = chklvl::LOWEST_CHUNK_LEVEL; l <= chklvl::HIGHEST_CHUNK_LEVEL; l ++) { st->cr_indent(); st->print(SIZE_FORMAT "k chunks: ", (chklvl::word_size_for_level(l) * BytesPerWord) / K); if (chunk_stats[l].num == 0) { st->print(" (none)"); } else { chunk_stats[l].print_on(st, scale); } } st->cr_indent(); st->print("%15s: ", "-total-"); totals().print_on(st, scale); } if (free_blocks_num > 0) { st->cr_indent(); st->print("deallocated: " UINTX_FORMAT " blocks with ", free_blocks_num); print_scaled_words(st, free_blocks_word_size, scale); } } else { totals().print_on(st, scale); st->print(", "); st->print("deallocated: " UINTX_FORMAT " blocks with ", free_blocks_num); print_scaled_words(st, free_blocks_word_size, scale); } } // ClassLoaderMetaspaceStatistics methods // Returns total space manager statistics for both class and non-class metaspace SpaceManagerStatistics ClassLoaderMetaspaceStatistics::totals() const { SpaceManagerStatistics stats; stats.reset(); stats.add(sm_stats[Metaspace::ClassType]); stats.add(sm_stats[Metaspace::NonClassType]); return stats; } void ClassLoaderMetaspaceStatistics::print_on(outputStream* st, size_t scale, bool detailed) const { streamIndentor sti(st); st->cr_indent(); if (Metaspace::using_class_space()) { st->print("Non-Class: "); } sm_stats[Metaspace::NonClassType].print_on(st, scale, detailed); if (detailed) { st->cr(); } if (Metaspace::using_class_space()) { st->cr_indent(); st->print(" Class: "); sm_stats[Metaspace::ClassType].print_on(st, scale, detailed); if (detailed) { st->cr(); } st->cr_indent(); st->print(" Both: "); totals().print_on(st, scale, detailed); if (detailed) { st->cr(); } } st->cr(); } } // end namespace metaspace