Skip to content

Commit 151ef5d

Browse files
committed
8330677: Add Per-Compilation memory usage to JFR
Reviewed-by: kvn, mbaesken
1 parent 7272939 commit 151ef5d

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed

src/hotspot/share/compiler/compilationMemoryStatistic.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2023, Red Hat, Inc. and/or its affiliates.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -394,16 +394,20 @@ void CompilationMemoryStatistic::on_end_compilation() {
394394
ResourceMark rm;
395395
CompilerThread* const th = Thread::current()->as_Compiler_thread();
396396
ArenaStatCounter* const arena_stat = th->arena_stat();
397-
const CompilerType ct = th->task()->compiler()->type();
397+
CompileTask* const task = th->task();
398+
const CompilerType ct = task->compiler()->type();
398399

399400
const Method* const m = th->task()->method();
400401
FullMethodName fmn(m);
401402
fmn.make_permanent();
402403

403404
const DirectiveSet* directive = th->task()->directive();
404-
assert(directive->should_collect_memstat(), "Only call if memstat is enabled");
405+
assert(directive->should_collect_memstat(), "Should only be called if memstat is enabled for this method");
405406
const bool print = directive->should_print_memstat();
406407

408+
// Store memory used in task, for later processing by JFR
409+
task->set_arena_bytes(arena_stat->peak_since_start());
410+
407411
// Store result
408412
// For this to work, we must call on_end_compilation() at a point where
409413
// Compile|Compilation already handed over the failure string to ciEnv,
@@ -492,7 +496,7 @@ void CompilationMemoryStatistic::on_arena_change(ssize_t diff, const Arena* aren
492496
CompilerType ct = compiler_none;
493497

494498
// get some more info
495-
const CompileTask* task = th->task();
499+
const CompileTask* const task = th->task();
496500
if (task != nullptr) {
497501
ct = task->compiler()->type();
498502
const DirectiveSet* directive = task->directive();

src/hotspot/share/compiler/compileBroker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,8 @@ static void post_compilation_event(EventCompilation& event, CompileTask* task) {
21262126
task->is_success(),
21272127
task->osr_bci() != CompileBroker::standard_entry_bci,
21282128
task->nm_total_size(),
2129-
task->num_inlined_bytecodes());
2129+
task->num_inlined_bytecodes(),
2130+
task->arena_bytes());
21302131
}
21312132

21322133
int DirectivesStack::_depth = 0;

src/hotspot/share/compiler/compileTask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -123,6 +123,7 @@ void CompileTask::initialize(int compile_id,
123123
_nm_total_size = 0;
124124
_failure_reason = nullptr;
125125
_failure_reason_on_C_heap = false;
126+
_arena_bytes = 0;
126127

127128
if (LogCompilation) {
128129
if (hot_method.not_null()) {

src/hotspot/share/compiler/compileTask.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -114,6 +114,7 @@ class CompileTask : public CHeapObj<mtCompiler> {
114114
const char* _failure_reason;
115115
// Specifies if _failure_reason is on the C heap.
116116
bool _failure_reason_on_C_heap;
117+
size_t _arena_bytes; // peak size of temporary memory during compilation (e.g. node arenas)
117118

118119
public:
119120
CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
@@ -200,6 +201,9 @@ class CompileTask : public CHeapObj<mtCompiler> {
200201
void metadata_do(MetadataClosure* f);
201202
void mark_on_stack();
202203

204+
void set_arena_bytes(size_t s) { _arena_bytes = s; }
205+
size_t arena_bytes() const { return _arena_bytes; }
206+
203207
private:
204208
static void print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
205209
bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,

src/hotspot/share/compiler/compilerEvent.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -134,7 +134,9 @@ static inline void commit(EventType& event) {
134134
}
135135
}
136136

137-
void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) {
137+
void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method,
138+
int compile_level, bool success, bool is_osr, int code_size,
139+
int inlined_bytecodes, size_t arenaBytes) {
138140
event.set_compileId(compile_id);
139141
event.set_compiler(compiler_type);
140142
event.set_method(method);
@@ -143,6 +145,7 @@ void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_
143145
event.set_isOsr(is_osr);
144146
event.set_codeSize(code_size);
145147
event.set_inlinedBytes(inlined_bytecodes);
148+
event.set_arenaBytes(arenaBytes);
146149
commit(event);
147150
}
148151

src/hotspot/share/compiler/compilerEvent.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -52,7 +52,9 @@ class CompilerEvent : AllStatic {
5252

5353
class CompilationEvent : AllStatic {
5454
public:
55-
static void post(EventCompilation& event, int compile_id, CompilerType type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) NOT_JFR_RETURN();
55+
static void post(EventCompilation& event, int compile_id, CompilerType type, Method* method,
56+
int compile_level, bool success, bool is_osr, int code_size,
57+
int inlined_bytecodes, size_t arenaBytes) NOT_JFR_RETURN();
5658
};
5759

5860
class CompilationFailureEvent : AllStatic {

src/hotspot/share/jfr/metadata/metadata.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@
608608
<Field type="boolean" name="isOsr" label="On Stack Replacement" />
609609
<Field type="ulong" contentType="bytes" name="codeSize" label="Compiled Code Size" />
610610
<Field type="ulong" contentType="bytes" name="inlinedBytes" label="Inlined Code Size" />
611+
<Field type="ulong" contentType="bytes" name="arenaBytes" label="Arena Usage" />
611612
</Event>
612613

613614
<Event name="CompilerPhase" category="Java Virtual Machine, Compiler" label="Compiler Phase"

test/jdk/jdk/jfr/event/compiler/TestCompilerCompile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* @run main/othervm -Xbootclasspath/a:.
4949
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
5050
* -XX:CompileOnly=jdk.jfr.event.compiler.TestCompilerCompile::dummyMethod,jdk.jfr.event.compiler.TestCompilerCompile::doTest
51+
* -XX:CompileCommand=MemStat,*.*
5152
* jdk.jfr.event.compiler.TestCompilerCompile
5253
*/
5354
public class TestCompilerCompile {
@@ -138,5 +139,6 @@ private void verifyEvent(RecordedEvent event) throws Throwable {
138139
Events.assertField(event, "inlinedBytes").atLeast(0L);
139140
Events.assertField(event, "codeSize").atLeast(0L);
140141
Events.assertField(event, "isOsr");
142+
Events.assertField(event, "arenaBytes").atLeast(1024L);
141143
}
142144
}

0 commit comments

Comments
 (0)