1 /*
  2  * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2018, 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 #ifndef SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP
 27 #define SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP
 28 
 29 #include "runtime/globals.hpp"
 30 #include "utilities/align.hpp"
 31 #include "utilities/debug.hpp"
 32 #include "utilities/globalDefinitions.hpp"
 33 
 34 class outputStream;
 35 
 36 namespace metaspace {
 37 





















 38 // Utility functions
 39 
 40 // Print a size, in words, scaled.
 41 void print_scaled_words(outputStream* st, size_t word_size, size_t scale = 0, int width = -1);
 42 
 43 // Convenience helper: prints a size value and a percentage.
 44 void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale = 0, int width = -1);
 45 
 46 // Print a human readable size.
 47 // byte_size: size, in bytes, to be printed.
 48 // scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
 49 //         or 0, which means the best scale is chosen dynamically.
 50 // width: printing width.
 51 void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale = 0, int width = -1);
 52 
 53 // Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values
 54 // larger than 99% but not 100% are displayed as ">100%".
 55 void print_percentage(outputStream* st, size_t total, size_t part);
 56 
 57 #ifdef ASSERT
 58 #define assert_is_aligned(value, alignment)                  \
 59   assert(is_aligned((value), (alignment)),                   \
 60          SIZE_FORMAT_HEX " is not aligned to "               \
 61          SIZE_FORMAT_HEX, (size_t)(uintptr_t)value, (size_t)(alignment))
 62 #else
 63 #define assert_is_aligned(value, alignment)
 64 #endif
 65 
 66 // Pretty printing helpers
 67 const char* classes_plural(uintx num);
 68 const char* loaders_plural(uintx num);
 69 void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared);
 70 
 71 // Since Metaspace verifications are expensive, we want to do them at a reduced rate,
 72 // but not completely avoiding them.
 73 // For that we introduce the macros SOMETIMES() and ASSERT_SOMETIMES() which will
 74 // execute code or assert at intervals controlled via VerifyMetaspaceInterval.
 75 #ifdef ASSERT
 76 
 77 #define EVERY_NTH(n)          \
 78 { static int counter_ = 0;    \
 79   if (n > 0) {                \
 80     counter_++;              \
 81     if (counter_ >= n) {      \
 82       counter_ = 0;           \
 83 
 84 #define END_EVERY_NTH         } } }
 85 
 86 #define SOMETIMES(code) \
 87     EVERY_NTH(VerifyMetaspaceInterval) \
 88     { code } \
 89     END_EVERY_NTH
 90 
 91 #define ASSERT_SOMETIMES(condition, ...) \
 92     EVERY_NTH(VerifyMetaspaceInterval) \
 93     assert( (condition), __VA_ARGS__); \
 94     END_EVERY_NTH
 95 
 96 #else
 97 
 98 #define SOMETIMES(code)
 99 #define ASSERT_SOMETIMES(condition, ...)
100 
101 #endif // ASSERT
102 
103 ///////// Logging //////////////
104 
105 // What we log at which levels:
106 
107 // "info" : metaspace failed allocation, commit failure, reserve failure, metaspace oom, metaspace gc threshold changed, Arena created, destroyed, metaspace purged
108 
109 // "debug" : "info" + vslist extended, memory committed/uncommitted, chunk created/split/merged/enlarged, chunk returned
110 
111 // "trace" : "debug" + every single allocation and deallocation, internals
112 
113 #define HAVE_UL
114 
115 #ifdef HAVE_UL
116 #define UL(level, message)        log_##level(metaspace)(LOGFMT ": " message, LOGFMT_ARGS);
117 #define UL2(level, message, ...)  log_##level(metaspace)(LOGFMT ": " message, LOGFMT_ARGS, __VA_ARGS__);
118 #else
119 #define UL(level, ...)
120 #define UL2(level, ...)
121 #endif
122 
123 } // namespace metaspace
124 
125 #endif // SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP
--- EOF ---