author | stuefe |
Tue, 10 Sep 2019 09:24:05 +0200 | |
branch | stuefe-new-metaspace-branch |
changeset 58063 | bdf136b8ae0e |
parent 54820 | fcf83b204c27 |
permissions | -rw-r--r-- |
49980 | 1 |
/* |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, SAP SE. All rights reserved. |
49980 | 3 |
* Copyright (c) 2018, Oracle and/or its affiliates. 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 |
#include "precompiled.hpp" |
|
27 |
||
28 |
#include "memory/metaspace/metaspaceCommon.hpp" |
|
50193 | 29 |
#include "memory/metaspace/virtualSpaceNode.hpp" |
30 |
#include "utilities/debug.hpp" |
|
49980 | 31 |
#include "utilities/globalDefinitions.hpp" |
32 |
#include "utilities/ostream.hpp" |
|
33 |
||
34 |
namespace metaspace { |
|
50193 | 35 |
|
49980 | 36 |
// Print a size, in words, scaled. |
37 |
void print_scaled_words(outputStream* st, size_t word_size, size_t scale, int width) { |
|
38 |
print_human_readable_size(st, word_size * sizeof(MetaWord), scale, width); |
|
39 |
} |
|
40 |
||
41 |
// Convenience helper: prints a size value and a percentage. |
|
42 |
void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale, int width) { |
|
43 |
print_scaled_words(st, word_size, scale, width); |
|
44 |
st->print(" ("); |
|
45 |
print_percentage(st, compare_word_size, word_size); |
|
46 |
st->print(")"); |
|
47 |
} |
|
48 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
49 |
static const char* display_unit_for_scale(size_t scale) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
50 |
const char* s = NULL; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
51 |
switch(scale) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
52 |
case 1: s = "bytes"; break; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
53 |
case BytesPerWord: s = "words"; break; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
54 |
case K: s = "KB"; break; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
55 |
case M: s = "MB"; break; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
56 |
case G: s = "GB"; break; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
57 |
default: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
58 |
ShouldNotReachHere(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
59 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
60 |
return s; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
61 |
} |
49980 | 62 |
|
63 |
// Print a human readable size. |
|
64 |
// byte_size: size, in bytes, to be printed. |
|
65 |
// scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively, |
|
66 |
// or 0, which means the best scale is choosen dynamically. |
|
67 |
// width: printing width. |
|
68 |
void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale, int width) { |
|
69 |
if (scale == 0) { |
|
70 |
// Dynamic mode. Choose scale for this value. |
|
71 |
if (byte_size == 0) { |
|
72 |
// Zero values are printed as bytes. |
|
73 |
scale = 1; |
|
74 |
} else { |
|
75 |
if (byte_size >= G) { |
|
76 |
scale = G; |
|
77 |
} else if (byte_size >= M) { |
|
78 |
scale = M; |
|
79 |
} else if (byte_size >= K) { |
|
80 |
scale = K; |
|
81 |
} else { |
|
82 |
scale = 1; |
|
83 |
} |
|
84 |
} |
|
85 |
return print_human_readable_size(st, byte_size, scale, width); |
|
86 |
} |
|
87 |
||
88 |
#ifdef ASSERT |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
89 |
assert(scale == 1 || scale == BytesPerWord || |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
90 |
scale == K || scale == M || scale == G, "Invalid scale"); |
49980 | 91 |
// Special case: printing wordsize should only be done with word-sized values |
92 |
if (scale == BytesPerWord) { |
|
93 |
assert(byte_size % BytesPerWord == 0, "not word sized"); |
|
94 |
} |
|
95 |
#endif |
|
96 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
97 |
if (width == -1) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
98 |
if (scale == 1) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
99 |
st->print(SIZE_FORMAT " bytes", byte_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
100 |
} else if (scale == BytesPerWord) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
101 |
st->print(SIZE_FORMAT " words", byte_size / BytesPerWord); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
102 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
103 |
const char* display_unit = display_unit_for_scale(scale); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
104 |
float display_value = (float) byte_size / scale; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
105 |
// Prevent very small but non-null values showing up as 0.00. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
106 |
if (byte_size > 0 && display_value < 0.01f) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
107 |
st->print("<0.01 %s", display_unit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
108 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
109 |
st->print("%.2f %s", display_value, display_unit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
110 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
111 |
} |
49980 | 112 |
} else { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
113 |
if (scale == 1) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
114 |
st->print("%*" PRIuPTR " bytes", width, byte_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
115 |
} else if (scale == BytesPerWord) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
116 |
st->print("%*" PRIuPTR " words", width, byte_size / BytesPerWord); |
49980 | 117 |
} else { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
118 |
const char* display_unit = display_unit_for_scale(scale); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
119 |
float display_value = (float) byte_size / scale; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
120 |
// Since we use width to display a number with two trailing digits, increase it a bit. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
121 |
width += 3; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
122 |
// Prevent very small but non-null values showing up as 0.00. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
123 |
if (byte_size > 0 && display_value < 0.01f) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
124 |
st->print("%*s %s", width, "<0.01", display_unit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
125 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
126 |
st->print("%*.2f %s", width, display_value, display_unit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54820
diff
changeset
|
127 |
} |
49980 | 128 |
} |
129 |
} |
|
130 |
} |
|
131 |
||
132 |
// Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values |
|
133 |
// larger than 99% but not 100% are displayed as ">100%". |
|
134 |
void print_percentage(outputStream* st, size_t total, size_t part) { |
|
135 |
if (total == 0) { |
|
136 |
st->print(" ?%%"); |
|
137 |
} else if (part == 0) { |
|
138 |
st->print(" 0%%"); |
|
139 |
} else if (part == total) { |
|
140 |
st->print("100%%"); |
|
141 |
} else { |
|
142 |
// Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages. |
|
143 |
float p = ((float)part / total) * 100.0f; |
|
144 |
if (p < 1.0f) { |
|
145 |
st->print(" <1%%"); |
|
146 |
} else if (p > 99.0f){ |
|
147 |
st->print(">99%%"); |
|
148 |
} else { |
|
149 |
st->print("%3.0f%%", p); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
||
54820 | 154 |
const char* loaders_plural(uintx num) { |
155 |
return num == 1 ? "loader" : "loaders"; |
|
156 |
} |
|
157 |
||
158 |
const char* classes_plural(uintx num) { |
|
159 |
return num == 1 ? "class" : "classes"; |
|
160 |
} |
|
161 |
||
162 |
void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared) { |
|
163 |
out->print(UINTX_FORMAT " %s", classes, classes_plural(classes)); |
|
164 |
if (classes_shared > 0) { |
|
165 |
out->print(" (" UINTX_FORMAT " shared)", classes_shared); |
|
166 |
} |
|
167 |
} |
|
50193 | 168 |
|
49980 | 169 |
} // namespace metaspace |
50193 | 170 |