Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceCommon.hpp
40957 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, 2020 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP26#define SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP2728#include "runtime/globals.hpp"29#include "utilities/align.hpp"30#include "utilities/debug.hpp"31#include "utilities/globalDefinitions.hpp"3233class outputStream;3435namespace metaspace {3637// Metaspace allocation alignment:3839// 1) Metaspace allocations have to be aligned such that 64bit values are aligned40// correctly.41//42// 2) Klass* structures allocated from Metaspace have to be aligned to KlassAlignmentInBytes.43//44// At the moment LogKlassAlignmentInBytes is 3, so KlassAlignmentInBytes == 8,45// so (1) and (2) can both be fulfilled with an alignment of 8. Should we increase46// KlassAlignmentInBytes at any time this will increase the necessary alignment as well. In47// that case we may think about introducing a separate alignment just for the class space48// since that alignment would only be needed for Klass structures.4950static const size_t AllocationAlignmentByteSize = 8;51STATIC_ASSERT(AllocationAlignmentByteSize == (size_t)KlassAlignmentInBytes);5253static const size_t AllocationAlignmentWordSize = AllocationAlignmentByteSize / BytesPerWord;5455// Returns the raw word size allocated for a given net allocation56size_t get_raw_word_size_for_requested_word_size(size_t word_size);5758// Utility functions5960// Print a size, in words, scaled.61void print_scaled_words(outputStream* st, size_t word_size, size_t scale = 0, int width = -1);6263// Convenience helper: prints a size value and a percentage.64void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale = 0, int width = -1);6566// Print a human readable size.67// byte_size: size, in bytes, to be printed.68// scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,69// or 0, which means the best scale is choosen dynamically.70// width: printing width.71void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale = 0, int width = -1);7273// Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values74// larger than 99% but not 100% are displayed as ">100%".75void print_percentage(outputStream* st, size_t total, size_t part);7677#ifdef ASSERT78#define assert_is_aligned(value, alignment) \79assert(is_aligned((value), (alignment)), \80SIZE_FORMAT_HEX " is not aligned to " \81SIZE_FORMAT_HEX, (size_t)(uintptr_t)value, (size_t)(alignment))82#else83#define assert_is_aligned(value, alignment)84#endif8586// Pretty printing helpers87const char* classes_plural(uintx num);88const char* loaders_plural(uintx num);89void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared);9091// Since Metaspace verifications are expensive, we want to do them at a reduced rate,92// but not completely avoiding them.93// For that we introduce the macros SOMETIMES() and ASSERT_SOMETIMES() which will94// execute code or assert at intervals controlled via VerifyMetaspaceInterval.95#ifdef ASSERT9697#define EVERY_NTH(n) \98{ static int counter_ = 0; \99if (n > 0) { \100counter_++; \101if (counter_ >= n) { \102counter_ = 0; \103104#define END_EVERY_NTH } } }105106#define SOMETIMES(code) \107EVERY_NTH(VerifyMetaspaceInterval) \108{ code } \109END_EVERY_NTH110111#define ASSERT_SOMETIMES(condition, ...) \112EVERY_NTH(VerifyMetaspaceInterval) \113assert( (condition), __VA_ARGS__); \114END_EVERY_NTH115116#else117118#define SOMETIMES(code)119#define ASSERT_SOMETIMES(condition, ...)120121#endif // ASSERT122123///////// Logging //////////////124125// What we log at which levels:126127// "info" : metaspace failed allocation, commit failure, reserve failure, metaspace oom, metaspace gc threshold changed, Arena created, destroyed, metaspace purged128129// "debug" : "info" + vslist extended, memory committed/uncommitted, chunk created/split/merged/enlarged, chunk returned130131// "trace" : "debug" + every single allocation and deallocation, internals132133#define HAVE_UL134135#ifdef HAVE_UL136#define UL(level, message) log_##level(metaspace)(LOGFMT ": " message, LOGFMT_ARGS);137#define UL2(level, message, ...) log_##level(metaspace)(LOGFMT ": " message, LOGFMT_ARGS, __VA_ARGS__);138#else139#define UL(level, ...)140#define UL2(level, ...)141#endif142143} // namespace metaspace144145#endif // SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP146147148