Skip to content

Commit d3701f8

Browse files
committed
8323795: jcmd Compiler.codecache should print total size of code cache
Backport-of: 3742bc626e80f597373913f02e79c5231e1b7dbc
1 parent 2b6eccc commit d3701f8

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

src/hotspot/share/code/codeCache.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,10 @@ void CodeCache::print() {
17051705

17061706
void CodeCache::print_summary(outputStream* st, bool detailed) {
17071707
int full_count = 0;
1708+
julong total_used = 0;
1709+
julong total_max_used = 0;
1710+
julong total_free = 0;
1711+
julong total_size = 0;
17081712
FOR_ALL_HEAPS(heap_iterator) {
17091713
CodeHeap* heap = (*heap_iterator);
17101714
size_t total = (heap->high_boundary() - heap->low_boundary());
@@ -1713,10 +1717,17 @@ void CodeCache::print_summary(outputStream* st, bool detailed) {
17131717
} else {
17141718
st->print("CodeCache:");
17151719
}
1720+
size_t size = total/K;
1721+
size_t used = (total - heap->unallocated_capacity())/K;
1722+
size_t max_used = heap->max_allocated_capacity()/K;
1723+
size_t free = heap->unallocated_capacity()/K;
1724+
total_size += size;
1725+
total_used += used;
1726+
total_max_used += max_used;
1727+
total_free += free;
17161728
st->print_cr(" size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
17171729
"Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
1718-
total/K, (total - heap->unallocated_capacity())/K,
1719-
heap->max_allocated_capacity()/K, heap->unallocated_capacity()/K);
1730+
size, used, max_used, free);
17201731

17211732
if (detailed) {
17221733
st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
@@ -1729,17 +1740,22 @@ void CodeCache::print_summary(outputStream* st, bool detailed) {
17291740
}
17301741

17311742
if (detailed) {
1732-
st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
1733-
" adapters=" UINT32_FORMAT,
1734-
blob_count(), nmethod_count(), adapter_count());
1735-
st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
1743+
if (SegmentedCodeCache) {
1744+
st->print("CodeCache:");
1745+
st->print_cr(" size=" JULONG_FORMAT "Kb, used=" JULONG_FORMAT
1746+
"Kb, max_used=" JULONG_FORMAT "Kb, free=" JULONG_FORMAT "Kb",
1747+
total_size, total_used, total_max_used, total_free);
1748+
}
1749+
st->print_cr(" total_blobs=" UINT32_FORMAT ", nmethods=" UINT32_FORMAT
1750+
", adapters=" UINT32_FORMAT ", full_count=" UINT32_FORMAT,
1751+
blob_count(), nmethod_count(), adapter_count(), full_count);
1752+
st->print_cr("Compilation: %s, stopped_count=%d, restarted_count=%d",
1753+
CompileBroker::should_compile_new_jobs() ?
17361754
"enabled" : Arguments::mode() == Arguments::_int ?
17371755
"disabled (interpreter mode)" :
1738-
"disabled (not enough contiguous free space left)");
1739-
st->print_cr(" stopped_count=%d, restarted_count=%d",
1756+
"disabled (not enough contiguous free space left)",
17401757
CompileBroker::get_total_compiler_stopped_count(),
17411758
CompileBroker::get_total_compiler_restarted_count());
1742-
st->print_cr(" full_count=%d", full_count);
17431759
}
17441760
}
17451761

test/hotspot/jtreg/serviceability/dcmd/compiler/CodeCacheTest.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,28 @@ public class CodeCacheTest {
5555
*
5656
* Expected output without code cache segmentation:
5757
*
58-
* CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb
59-
* bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000]
60-
* total_blobs=575 nmethods=69 adapters=423
61-
* compilation: enabled
58+
* CodeCache: size=245760Kb used=1366Kb max_used=1935Kb free=244393Kb
59+
* bounds [0x00007ff4d89f2000, 0x00007ff4d8c62000, 0x00007ff4e79f2000]
60+
* total_blobs=474, nmethods=87, adapters=293, full_count=0
61+
* Compilation: enabled, stopped_count=0, restarted_count=0
6262
*
6363
* Expected output with code cache segmentation (number of segments may change):
6464
*
65-
* CodeHeap 'non-nmethods': size=5696Kb used=2236Kb max_used=2238Kb free=3459Kb
66-
* bounds [0x00007fa0f0ffe000, 0x00007fa0f126e000, 0x00007fa0f158e000]
67-
* CodeHeap 'profiled nmethods': size=120036Kb used=8Kb max_used=8Kb free=120027Kb
68-
* bounds [0x00007fa0f158e000, 0x00007fa0f17fe000, 0x00007fa0f8ac7000]
69-
* CodeHeap 'non-profiled nmethods': size=120036Kb used=2Kb max_used=2Kb free=120034Kb
70-
* bounds [0x00007fa0f8ac7000, 0x00007fa0f8d37000, 0x00007fa100000000]
71-
* total_blobs=486 nmethods=8 adapters=399
72-
* compilation: enabled
65+
* CodeHeap 'non-profiled nmethods': size=118592Kb used=29Kb max_used=29Kb free=118562Kb
66+
* bounds [0x00007f09f8622000, 0x00007f09f8892000, 0x00007f09ff9f2000]
67+
* CodeHeap 'profiled nmethods': size=118588Kb used=80Kb max_used=80Kb free=118507Kb
68+
* bounds [0x00007f09f09f2000, 0x00007f09f0c62000, 0x00007f09f7dc1000]
69+
* CodeHeap 'non-nmethods': size=8580Kb used=1257Kb max_used=1833Kb free=7323Kb
70+
* bounds [0x00007f09f7dc1000, 0x00007f09f8031000, 0x00007f09f8622000]
71+
* CodeCache: size=245760Kb, used=1366Kb, max_used=1942Kb, free=244392Kb
72+
* total_blobs=474, nmethods=87, adapters=293, full_count=0
73+
* Compilation: enabled, stopped_count=0, restarted_count=0
7374
*/
7475

7576
static Pattern line1 = Pattern.compile("(CodeCache|CodeHeap.*): size=(\\p{Digit}*)Kb used=(\\p{Digit}*)Kb max_used=(\\p{Digit}*)Kb free=(\\p{Digit}*)Kb");
7677
static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]");
77-
static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)");
78-
static Pattern line4 = Pattern.compile(" compilation: (.*)");
78+
static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*), nmethods=(\\p{Digit}*), adapters=(\\p{Digit}*), full_count=(\\p{Digit}*)");
79+
static Pattern line4 = Pattern.compile("Compilation: (.*?), stopped_count=(\\p{Digit}*), restarted_count=(\\p{Digit}*)");
7980

8081
private static boolean getFlagBool(String flag, String where) {
8182
Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
@@ -157,6 +158,10 @@ public void run(CommandExecutor executor) {
157158
Assert.fail("Fewer segments matched (" + matchedCount + ") than expected (" + segmentsCount + ")");
158159
}
159160

161+
if (segmentsCount != 1) {
162+
// Skip this line CodeCache: size=245760Kb, used=5698Kb, max_used=5735Kb, free=240059Kb
163+
line = lines.next();
164+
}
160165
// Validate third line
161166
m = line3.matcher(line);
162167
if (m.matches()) {
@@ -182,7 +187,19 @@ public void run(CommandExecutor executor) {
182187
// Validate fourth line
183188
line = lines.next();
184189
m = line4.matcher(line);
185-
if (!m.matches()) {
190+
if (m.matches()) {
191+
if (!m.group(1).contains("enabled") && !m.group(1).contains("disabled")) {
192+
Assert.fail("Failed parsing dcmd codecache output");
193+
}
194+
int stopped = Integer.parseInt(m.group(2));
195+
if (stopped < 0) {
196+
Assert.fail("Failed parsing dcmd codecache output");
197+
}
198+
int restarted = Integer.parseInt(m.group(3));
199+
if (restarted < 0) {
200+
Assert.fail("Failed parsing dcmd codecache output");
201+
}
202+
} else {
186203
Assert.fail("Regexp 4 failed to match line: " + line);
187204
}
188205
}

test/hotspot/jtreg/vmTestbase/vm/compiler/CodeCacheInfo/Test.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ public class Test {
5656
static {
5757
String p1 = " size=\\d+Kb used=\\d+Kb max_used=\\d+Kb free=\\d+Kb\\n";
5858
String p2 = " bounds \\[0x[0-9a-f]+, 0x[0-9a-f]+, 0x[0-9a-f]+\\]\\n";
59-
String p3 = " total_blobs=\\d+ nmethods=\\d+ adapters=\\d+\\n";
60-
String p4 = " compilation: enabled\\n";
59+
String p3 = "CodeCache:.*\\n";
60+
String p4 = " total_blobs=\\d+, nmethods=\\d+, adapters=\\d+, full_count=\\d+\\n";
61+
String p5 = "Compilation: enabled.*\\n";
6162

6263
String segPrefix = "^(CodeHeap '[^']+':" + p1 + p2 + ")+";
6364
String nosegPrefix = "^CodeCache:" + p1 + p2;
6465

65-
SEG_REGEXP = segPrefix + p3 + p4;
66-
NOSEG_REGEXP = nosegPrefix + p3 + p4;
66+
SEG_REGEXP = segPrefix + p3 + p4 + p5;
67+
NOSEG_REGEXP = nosegPrefix + p4 + p5;
6768
}
6869

6970
public static void main(String[] args) throws Exception {

0 commit comments

Comments
 (0)