Skip to content

Commit

Permalink
8323795: jcmd Compiler.codecache should print total size of code cache
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, kvn
  • Loading branch information
y1yang0 authored and TobiHartmann committed Feb 19, 2024
1 parent 099b744 commit 3742bc6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 28 deletions.
34 changes: 25 additions & 9 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,10 @@ void CodeCache::print() {

void CodeCache::print_summary(outputStream* st, bool detailed) {
int full_count = 0;
julong total_used = 0;
julong total_max_used = 0;
julong total_free = 0;
julong total_size = 0;
FOR_ALL_HEAPS(heap_iterator) {
CodeHeap* heap = (*heap_iterator);
size_t total = (heap->high_boundary() - heap->low_boundary());
Expand All @@ -1738,10 +1742,17 @@ void CodeCache::print_summary(outputStream* st, bool detailed) {
} else {
st->print("CodeCache:");
}
size_t size = total/K;
size_t used = (total - heap->unallocated_capacity())/K;
size_t max_used = heap->max_allocated_capacity()/K;
size_t free = heap->unallocated_capacity()/K;
total_size += size;
total_used += used;
total_max_used += max_used;
total_free += free;
st->print_cr(" size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
"Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
total/K, (total - heap->unallocated_capacity())/K,
heap->max_allocated_capacity()/K, heap->unallocated_capacity()/K);
size, used, max_used, free);

if (detailed) {
st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
Expand All @@ -1754,17 +1765,22 @@ void CodeCache::print_summary(outputStream* st, bool detailed) {
}

if (detailed) {
st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
" adapters=" UINT32_FORMAT,
blob_count(), nmethod_count(), adapter_count());
st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
if (SegmentedCodeCache) {
st->print("CodeCache:");
st->print_cr(" size=" JULONG_FORMAT "Kb, used=" JULONG_FORMAT
"Kb, max_used=" JULONG_FORMAT "Kb, free=" JULONG_FORMAT "Kb",
total_size, total_used, total_max_used, total_free);
}
st->print_cr(" total_blobs=" UINT32_FORMAT ", nmethods=" UINT32_FORMAT
", adapters=" UINT32_FORMAT ", full_count=" UINT32_FORMAT,
blob_count(), nmethod_count(), adapter_count(), full_count);
st->print_cr("Compilation: %s, stopped_count=%d, restarted_count=%d",
CompileBroker::should_compile_new_jobs() ?
"enabled" : Arguments::mode() == Arguments::_int ?
"disabled (interpreter mode)" :
"disabled (not enough contiguous free space left)");
st->print_cr(" stopped_count=%d, restarted_count=%d",
"disabled (not enough contiguous free space left)",
CompileBroker::get_total_compiler_stopped_count(),
CompileBroker::get_total_compiler_restarted_count());
st->print_cr(" full_count=%d", full_count);
}
}

Expand Down
47 changes: 32 additions & 15 deletions test/hotspot/jtreg/serviceability/dcmd/compiler/CodeCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ public class CodeCacheTest {
*
* Expected output without code cache segmentation:
*
* CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb
* bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000]
* total_blobs=575 nmethods=69 adapters=423
* compilation: enabled
* CodeCache: size=245760Kb used=1366Kb max_used=1935Kb free=244393Kb
* bounds [0x00007ff4d89f2000, 0x00007ff4d8c62000, 0x00007ff4e79f2000]
* total_blobs=474, nmethods=87, adapters=293, full_count=0
* Compilation: enabled, stopped_count=0, restarted_count=0
*
* Expected output with code cache segmentation (number of segments may change):
*
* CodeHeap 'non-nmethods': size=5696Kb used=2236Kb max_used=2238Kb free=3459Kb
* bounds [0x00007fa0f0ffe000, 0x00007fa0f126e000, 0x00007fa0f158e000]
* CodeHeap 'profiled nmethods': size=120036Kb used=8Kb max_used=8Kb free=120027Kb
* bounds [0x00007fa0f158e000, 0x00007fa0f17fe000, 0x00007fa0f8ac7000]
* CodeHeap 'non-profiled nmethods': size=120036Kb used=2Kb max_used=2Kb free=120034Kb
* bounds [0x00007fa0f8ac7000, 0x00007fa0f8d37000, 0x00007fa100000000]
* total_blobs=486 nmethods=8 adapters=399
* compilation: enabled
* CodeHeap 'non-profiled nmethods': size=118592Kb used=29Kb max_used=29Kb free=118562Kb
* bounds [0x00007f09f8622000, 0x00007f09f8892000, 0x00007f09ff9f2000]
* CodeHeap 'profiled nmethods': size=118588Kb used=80Kb max_used=80Kb free=118507Kb
* bounds [0x00007f09f09f2000, 0x00007f09f0c62000, 0x00007f09f7dc1000]
* CodeHeap 'non-nmethods': size=8580Kb used=1257Kb max_used=1833Kb free=7323Kb
* bounds [0x00007f09f7dc1000, 0x00007f09f8031000, 0x00007f09f8622000]
* CodeCache: size=245760Kb, used=1366Kb, max_used=1942Kb, free=244392Kb
* total_blobs=474, nmethods=87, adapters=293, full_count=0
* Compilation: enabled, stopped_count=0, restarted_count=0
*/

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

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

if (segmentsCount != 1) {
// Skip this line CodeCache: size=245760Kb, used=5698Kb, max_used=5735Kb, free=240059Kb
line = lines.next();
}
// Validate third line
m = line3.matcher(line);
if (m.matches()) {
Expand All @@ -182,7 +187,19 @@ public void run(CommandExecutor executor) {
// Validate fourth line
line = lines.next();
m = line4.matcher(line);
if (!m.matches()) {
if (m.matches()) {
if (!m.group(1).contains("enabled") && !m.group(1).contains("disabled")) {
Assert.fail("Failed parsing dcmd codecache output");
}
int stopped = Integer.parseInt(m.group(2));
if (stopped < 0) {
Assert.fail("Failed parsing dcmd codecache output");
}
int restarted = Integer.parseInt(m.group(3));
if (restarted < 0) {
Assert.fail("Failed parsing dcmd codecache output");
}
} else {
Assert.fail("Regexp 4 failed to match line: " + line);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ public class Test {
static {
String p1 = " size=\\d+Kb used=\\d+Kb max_used=\\d+Kb free=\\d+Kb\\n";
String p2 = " bounds \\[0x[0-9a-f]+, 0x[0-9a-f]+, 0x[0-9a-f]+\\]\\n";
String p3 = " total_blobs=\\d+ nmethods=\\d+ adapters=\\d+\\n";
String p4 = " compilation: enabled\\n";
String p3 = "CodeCache:.*\\n";
String p4 = " total_blobs=\\d+, nmethods=\\d+, adapters=\\d+, full_count=\\d+\\n";
String p5 = "Compilation: enabled.*\\n";

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

SEG_REGEXP = segPrefix + p3 + p4;
NOSEG_REGEXP = nosegPrefix + p3 + p4;
SEG_REGEXP = segPrefix + p3 + p4 + p5;
NOSEG_REGEXP = nosegPrefix + p4 + p5;
}

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

1 comment on commit 3742bc6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.