--- a/src/hotspot/share/memory/metaspace/metaspaceCommon.cpp Tue Sep 10 14:52:53 2019 +0800
+++ b/src/hotspot/share/memory/metaspace/metaspaceCommon.cpp Tue Sep 10 09:24:05 2019 +0200
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2018, 2019, SAP SE. All rights reserved.
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -32,8 +33,6 @@
namespace metaspace {
-DEBUG_ONLY(internal_statistics_t g_internal_statistics;)
-
// Print a size, in words, scaled.
void print_scaled_words(outputStream* st, size_t word_size, size_t scale, int width) {
print_human_readable_size(st, word_size * sizeof(MetaWord), scale, width);
@@ -47,6 +46,19 @@
st->print(")");
}
+static const char* display_unit_for_scale(size_t scale) {
+ const char* s = NULL;
+ switch(scale) {
+ case 1: s = "bytes"; break;
+ case BytesPerWord: s = "words"; break;
+ case K: s = "KB"; break;
+ case M: s = "MB"; break;
+ case G: s = "GB"; break;
+ default:
+ ShouldNotReachHere();
+ }
+ return s;
+}
// Print a human readable size.
// byte_size: size, in bytes, to be printed.
@@ -74,36 +86,45 @@
}
#ifdef ASSERT
- assert(scale == 1 || scale == BytesPerWord || scale == K || scale == M || scale == G, "Invalid scale");
+ assert(scale == 1 || scale == BytesPerWord ||
+ scale == K || scale == M || scale == G, "Invalid scale");
// Special case: printing wordsize should only be done with word-sized values
if (scale == BytesPerWord) {
assert(byte_size % BytesPerWord == 0, "not word sized");
}
#endif
- if (scale == 1) {
- st->print("%*" PRIuPTR " bytes", width, byte_size);
- } else if (scale == BytesPerWord) {
- st->print("%*" PRIuPTR " words", width, byte_size / BytesPerWord);
+ if (width == -1) {
+ if (scale == 1) {
+ st->print(SIZE_FORMAT " bytes", byte_size);
+ } else if (scale == BytesPerWord) {
+ st->print(SIZE_FORMAT " words", byte_size / BytesPerWord);
+ } else {
+ const char* display_unit = display_unit_for_scale(scale);
+ float display_value = (float) byte_size / scale;
+ // Prevent very small but non-null values showing up as 0.00.
+ if (byte_size > 0 && display_value < 0.01f) {
+ st->print("<0.01 %s", display_unit);
+ } else {
+ st->print("%.2f %s", display_value, display_unit);
+ }
+ }
} else {
- const char* display_unit = "";
- switch(scale) {
- case 1: display_unit = "bytes"; break;
- case BytesPerWord: display_unit = "words"; break;
- case K: display_unit = "KB"; break;
- case M: display_unit = "MB"; break;
- case G: display_unit = "GB"; break;
- default:
- ShouldNotReachHere();
- }
- float display_value = (float) byte_size / scale;
- // Since we use width to display a number with two trailing digits, increase it a bit.
- width += 3;
- // Prevent very small but non-null values showing up as 0.00.
- if (byte_size > 0 && display_value < 0.01f) {
- st->print("%*s %s", width, "<0.01", display_unit);
+ if (scale == 1) {
+ st->print("%*" PRIuPTR " bytes", width, byte_size);
+ } else if (scale == BytesPerWord) {
+ st->print("%*" PRIuPTR " words", width, byte_size / BytesPerWord);
} else {
- st->print("%*.2f %s", width, display_value, display_unit);
+ const char* display_unit = display_unit_for_scale(scale);
+ float display_value = (float) byte_size / scale;
+ // Since we use width to display a number with two trailing digits, increase it a bit.
+ width += 3;
+ // Prevent very small but non-null values showing up as 0.00.
+ if (byte_size > 0 && display_value < 0.01f) {
+ st->print("%*s %s", width, "<0.01", display_unit);
+ } else {
+ st->print("%*.2f %s", width, display_value, display_unit);
+ }
}
}
}
@@ -130,70 +151,6 @@
}
}
-// Returns size of this chunk type.
-size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
- assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
- size_t size = 0;
- if (is_class) {
- switch(chunktype) {
- case SpecializedIndex: size = ClassSpecializedChunk; break;
- case SmallIndex: size = ClassSmallChunk; break;
- case MediumIndex: size = ClassMediumChunk; break;
- default:
- ShouldNotReachHere();
- }
- } else {
- switch(chunktype) {
- case SpecializedIndex: size = SpecializedChunk; break;
- case SmallIndex: size = SmallChunk; break;
- case MediumIndex: size = MediumChunk; break;
- default:
- ShouldNotReachHere();
- }
- }
- return size;
-}
-
-ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
- if (is_class) {
- if (size == ClassSpecializedChunk) {
- return SpecializedIndex;
- } else if (size == ClassSmallChunk) {
- return SmallIndex;
- } else if (size == ClassMediumChunk) {
- return MediumIndex;
- } else if (size > ClassMediumChunk) {
- // A valid humongous chunk size is a multiple of the smallest chunk size.
- assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
- return HumongousIndex;
- }
- } else {
- if (size == SpecializedChunk) {
- return SpecializedIndex;
- } else if (size == SmallChunk) {
- return SmallIndex;
- } else if (size == MediumChunk) {
- return MediumIndex;
- } else if (size > MediumChunk) {
- // A valid humongous chunk size is a multiple of the smallest chunk size.
- assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
- return HumongousIndex;
- }
- }
- ShouldNotReachHere();
- return (ChunkIndex)-1;
-}
-
-ChunkIndex next_chunk_index(ChunkIndex i) {
- assert(i < NumberOfInUseLists, "Out of bound");
- return (ChunkIndex) (i+1);
-}
-
-ChunkIndex prev_chunk_index(ChunkIndex i) {
- assert(i > ZeroIndex, "Out of bound");
- return (ChunkIndex) (i-1);
-}
-
const char* loaders_plural(uintx num) {
return num == 1 ? "loader" : "loaders";
}