Skip to content

Commit ae5b765

Browse files
author
Vladimir Kozlov
committed
8382430: Extend output format of -XX:+PrintCompilation2 diagnostic flag
Reviewed-by: vlivanov, aseoane
1 parent b854ba1 commit ae5b765

9 files changed

Lines changed: 299 additions & 53 deletions

File tree

src/hotspot/share/compiler/compileBroker.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ void CompileQueue::add(CompileTask* task) {
345345
// Mark the method as being in the compile queue.
346346
task->method()->set_queued_for_compilation();
347347

348+
task->mark_queued(os::elapsed_counter());
349+
348350
if (CIPrintCompileQueue) {
349351
print_tty();
350352
}
@@ -2402,23 +2404,19 @@ void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
24022404
}
24032405
}
24042406

2405-
DirectivesStack::release(directive);
2407+
task->mark_finished(os::elapsed_counter());
24062408

24072409
methodHandle method(thread, task->method());
24082410

24092411
DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
24102412

24112413
collect_statistics(thread, time, task);
24122414

2413-
if (PrintCompilation && PrintCompilation2) {
2414-
tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
2415-
tty->print("%4d ", compile_id); // print compilation number
2416-
tty->print("%s ", (is_osr ? "%" : " "));
2417-
if (task->is_success()) {
2418-
tty->print("size: %d(%d) ", task->nm_total_size(), task->nm_insts_size());
2419-
}
2420-
tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2415+
if (PrintCompilation2 || directive->PrintCompilation2Option) {
2416+
ResourceMark rm;
2417+
task->print_post(tty);
24212418
}
2419+
DirectivesStack::release(directive);
24222420

24232421
Log(compilation, codecache) log;
24242422
if (log.is_debug()) {
@@ -2614,7 +2612,7 @@ void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time
26142612
}
26152613

26162614
// Collect statistic per compiler
2617-
AbstractCompiler* comp = compiler(comp_level);
2615+
AbstractCompiler* comp = task->compiler();
26182616
if (comp) {
26192617
CompilerStatistics* stats = comp->stats();
26202618
if (is_osr) {

src/hotspot/share/compiler/compileTask.cpp

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,31 @@ CompileTask::CompileTask(int compile_id,
5151
_method_holder = JNIHandles::make_weak_global(Handle(thread, method->method_holder()->klass_holder()));
5252
_osr_bci = osr_bci;
5353
_is_blocking = is_blocking;
54-
JVMCI_ONLY(_has_waiter = CompileBroker::compiler(comp_level)->is_jvmci();)
55-
JVMCI_ONLY(_blocking_jvmci_compile_state = nullptr;)
5654
_comp_level = comp_level;
5755
_num_inlined_bytecodes = 0;
5856

5957
_is_complete = false;
6058
_is_success = false;
6159

6260
_hot_count = hot_count;
63-
_time_queued = os::elapsed_counter();
61+
_time_created = os::elapsed_counter();
62+
_time_queued = 0;
6463
_time_started = 0;
64+
_time_finished = 0;
6565
_compile_reason = compile_reason;
6666
_nm_content_size = 0;
67-
AbstractCompiler* comp = compiler();
68-
_directive = DirectivesStack::getMatchingDirective(method, comp);
6967
_nm_insts_size = 0;
7068
_nm_total_size = 0;
7169
_failure_reason = nullptr;
7270
_failure_reason_on_C_heap = false;
7371
_training_data = nullptr;
72+
73+
AbstractCompiler* comp = CompileBroker::compiler(comp_level);
74+
_compiler = comp;
75+
_directive = DirectivesStack::getMatchingDirective(method, comp);
76+
77+
JVMCI_ONLY(_has_waiter = comp->is_jvmci();)
78+
JVMCI_ONLY(_blocking_jvmci_compile_state = nullptr;)
7479
_arena_bytes = 0;
7580

7681
_next = nullptr;
@@ -108,7 +113,8 @@ void CompileTask::wait_for_no_active_tasks() {
108113
* Returns the compiler for this task.
109114
*/
110115
AbstractCompiler* CompileTask::compiler() const {
111-
return CompileBroker::compiler(_comp_level);
116+
assert(_compiler != nullptr, "should be set");
117+
return _compiler;
112118
}
113119

114120
// Replace weak handles by strong handles to avoid unloading during compilation.
@@ -157,7 +163,7 @@ void CompileTask::metadata_do(MetadataClosure* f) {
157163
//
158164
void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) {
159165
// print compiler name
160-
st->print("%s:", CompileBroker::compiler_name(comp_level()));
166+
st->print("%s:", compiler()->name());
161167
print(st);
162168
}
163169

@@ -168,29 +174,71 @@ void CompileTask::print_tty() {
168174
print(tty);
169175
}
170176

177+
void CompileTask::print_post(outputStream* st) {
178+
bool is_osr_method = osr_bci() != InvocationEntryBci;
179+
print_impl(st, is_unloaded() ? nullptr : method(), compile_id(), comp_level(),
180+
is_osr_method, osr_bci(), is_blocking(),
181+
compiler()->name(), nullptr, false /* short_form */, true /* cr */,
182+
true /* after_compile_details */,
183+
_num_inlined_bytecodes, _nm_total_size, _nm_insts_size,
184+
_time_created, _time_queued, _time_started, _time_finished);
185+
}
186+
171187
// ------------------------------------------------------------------
172188
// CompileTask::print_impl
173189
void CompileTask::print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
174190
bool is_osr_method, int osr_bci, bool is_blocking,
175-
const char* msg, bool short_form, bool cr,
176-
jlong time_queued, jlong time_started) {
177-
if (!short_form) {
191+
const char* compiler_name,
192+
const char* msg, bool short_form, bool cr, bool after_compile_details,
193+
int inlined_bytecodes, int nm_total_size, int nm_insts_size,
194+
jlong time_created, jlong time_queued, jlong time_started, jlong time_finished) {
195+
// Use stringStream to avoid breaking the line
196+
stringStream sst;
197+
if (after_compile_details) {
198+
{ // Print current time
199+
stringStream ss;
200+
ss.print(UINT64_FORMAT, (uint64_t) tty->time_stamp().milliseconds());
201+
sst.print("%7s ", ss.freeze());
202+
}
203+
{ // Time waiting to be put on queue
204+
stringStream ss;
205+
if (time_created != 0 && time_queued != 0) {
206+
ss.print("W%.1f", TimeHelper::counter_to_millis(time_queued - time_created));
207+
}
208+
sst.print("%7s ", ss.freeze());
209+
}
210+
{ // Time in queue
211+
stringStream ss;
212+
if (time_queued != 0 && time_started != 0) {
213+
ss.print("Q%.1f", TimeHelper::counter_to_millis(time_started - time_queued));
214+
}
215+
sst.print("%7s ", ss.freeze());
216+
}
217+
{ // Time in compilation
218+
stringStream ss;
219+
if (time_started != 0 && time_finished != 0) {
220+
ss.print("C%.1f", TimeHelper::counter_to_millis(time_finished - time_started));
221+
}
222+
sst.print("%7s ", ss.freeze());
223+
}
224+
} else if (!short_form) {
178225
// Print current time
179-
st->print(UINT64_FORMAT " ", (uint64_t) tty->time_stamp().milliseconds());
226+
sst.print(UINT64_FORMAT " ", (uint64_t) tty->time_stamp().milliseconds());
180227
if (Verbose && time_queued != 0) {
181228
// Print time in queue and time being processed by compiler thread
182229
jlong now = os::elapsed_counter();
183-
st->print("%.0f ", TimeHelper::counter_to_millis(now-time_queued));
230+
sst.print("%.0f ", TimeHelper::counter_to_millis(now-time_queued));
184231
if (time_started != 0) {
185-
st->print("%.0f ", TimeHelper::counter_to_millis(now-time_started));
232+
sst.print("%.0f ", TimeHelper::counter_to_millis(now-time_started));
186233
}
187234
}
188235
}
236+
189237
// print compiler name if requested
190238
if (CIPrintCompilerName) {
191-
st->print("%s:", CompileBroker::compiler_name(comp_level));
239+
sst.print("%s:", compiler_name);
192240
}
193-
st->print("%4d ", compile_id); // print compilation number
241+
sst.print("%4d ", compile_id); // print compilation number
194242

195243
bool is_synchronized = false;
196244
bool has_exception_handler = false;
@@ -208,40 +256,52 @@ void CompileTask::print_impl(outputStream* st, Method* method, int compile_id, i
208256
const char native_char = is_native ? 'n' : ' ';
209257

210258
// print method attributes
211-
st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char);
259+
sst.print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char);
212260

213261
if (TieredCompilation) {
214-
if (comp_level != -1) st->print("%d ", comp_level);
215-
else st->print("- ");
262+
if (comp_level != -1) sst.print("%d ", comp_level);
263+
else sst.print("- ");
216264
}
217-
st->print(" "); // more indent
265+
sst.print(" "); // more indent
218266

219267
if (method == nullptr) {
220-
st->print("(method)");
268+
sst.print("(method)");
221269
} else {
222-
method->print_short_name(st);
270+
if (after_compile_details) {
271+
sst.print("%s", method->name_and_sig_as_C_string(true /* use_double_colon */));
272+
} else {
273+
method->print_short_name(&sst);
274+
}
223275
if (is_osr_method) {
224-
st->print(" @ %d", osr_bci);
276+
sst.print(" @ %d", osr_bci);
225277
}
226-
if (method->is_native())
227-
st->print(" (native)");
228-
else
229-
st->print(" (%d bytes)", method->code_size());
278+
if (method->is_native()) {
279+
sst.print(" (native)");
280+
} else {
281+
sst.print(" (%d bytes)", method->code_size());
282+
}
283+
}
284+
if (after_compile_details) {
285+
sst.print(" (inlined %d)", inlined_bytecodes);
286+
sst.print(" (size %d/%d)", nm_total_size, nm_insts_size);
230287
}
231288

232289
if (msg != nullptr) {
233-
st->print(" %s", msg);
290+
sst.print(" %s", msg);
234291
}
235292
if (cr) {
236-
st->cr();
293+
sst.cr();
237294
}
295+
st->print("%s",sst.freeze());
238296
}
239297

240298
// ------------------------------------------------------------------
241299
// CompileTask::print_compilation
242300
void CompileTask::print(outputStream* st, const char* msg, bool short_form, bool cr) {
243301
bool is_osr_method = osr_bci() != InvocationEntryBci;
244-
print_impl(st, is_unloaded() ? nullptr : method(), compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), msg, short_form, cr, _time_queued, _time_started);
302+
print_impl(st, is_unloaded() ? nullptr : method(), compile_id(), comp_level(),
303+
is_osr_method, osr_bci(), is_blocking(),
304+
compiler()->name(), msg, short_form, cr);
245305
}
246306

247307
// ------------------------------------------------------------------
@@ -435,6 +495,7 @@ void CompileTask::print_ul(const nmethod* nm, const char* msg) {
435495
nm->comp_level(), nm->is_osr_method(),
436496
nm->is_osr_method() ? nm->osr_entry_bci() : -1,
437497
/*is_blocking*/ false,
498+
nm->compiler_name(),
438499
msg, /* short form */ true, /* cr */ true);
439500
}
440501
}

src/hotspot/share/compiler/compileTask.hpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class CompileTask : public CHeapObj<mtCompiler> {
9393
CodeSection::csize_t _nm_content_size;
9494
CodeSection::csize_t _nm_total_size;
9595
CodeSection::csize_t _nm_insts_size;
96-
DirectiveSet* _directive;
96+
DirectiveSet* _directive;
97+
AbstractCompiler* _compiler;
9798
#if INCLUDE_JVMCI
9899
bool _has_waiter;
99100
// Compilation state for a blocking JVMCI compilation
@@ -104,8 +105,10 @@ class CompileTask : public CHeapObj<mtCompiler> {
104105
CompileTask* _next;
105106
CompileTask* _prev;
106107
// Fields used for logging why the compilation was initiated:
108+
jlong _time_created; // time when task was created
107109
jlong _time_queued; // time when task was enqueued
108110
jlong _time_started; // time when compilation started
111+
jlong _time_finished; // time when compilation finished
109112
int _hot_count; // information about its invocation counter
110113
CompileReason _compile_reason; // more info about the task
111114
const char* _failure_reason;
@@ -118,6 +121,7 @@ class CompileTask : public CHeapObj<mtCompiler> {
118121
CompileTask(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
119122
int hot_count, CompileReason compile_reason, bool is_blocking);
120123
~CompileTask();
124+
121125
static void wait_for_no_active_tasks();
122126

123127
int compile_id() const { return _compile_id; }
@@ -127,6 +131,7 @@ class CompileTask : public CHeapObj<mtCompiler> {
127131
bool is_blocking() const { return _is_blocking; }
128132
bool is_success() const { return _is_success; }
129133
DirectiveSet* directive() const { return _directive; }
134+
CompileReason compile_reason() const { return _compile_reason; }
130135
CodeSection::csize_t nm_content_size() { return _nm_content_size; }
131136
void set_nm_content_size(CodeSection::csize_t size) { _nm_content_size = size; }
132137
CodeSection::csize_t nm_insts_size() { return _nm_insts_size; }
@@ -166,8 +171,9 @@ class CompileTask : public CHeapObj<mtCompiler> {
166171

167172
void mark_complete() { _is_complete = true; }
168173
void mark_success() { _is_success = true; }
174+
void mark_queued(jlong time) { _time_queued = time; }
169175
void mark_started(jlong time) { _time_started = time; }
170-
176+
void mark_finished(jlong time) { _time_finished = time; }
171177
int comp_level() { return _comp_level;}
172178
void set_comp_level(int comp_level) { _comp_level = comp_level;}
173179

@@ -198,16 +204,20 @@ class CompileTask : public CHeapObj<mtCompiler> {
198204
private:
199205
static void print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
200206
bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,
207+
const char* compiler_name = nullptr,
201208
const char* msg = nullptr, bool short_form = false, bool cr = true,
202-
jlong time_queued = 0, jlong time_started = 0);
209+
bool after_compile_details = false,
210+
int inlined_bytecodes = 0, int nm_total_size = 0, int nm_insts_size = 0,
211+
jlong time_created = 0, jlong time_queued = 0,
212+
jlong time_started = 0, jlong time_finished = 0);
203213

204214
public:
205215
void print(outputStream* st = tty, const char* msg = nullptr, bool short_form = false, bool cr = true);
206216
void print_ul(const char* msg = nullptr);
207217
static void print(outputStream* st, const nmethod* nm, const char* msg = nullptr, bool short_form = false, bool cr = true) {
208218
print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
209-
nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
210-
msg, short_form, cr);
219+
nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
220+
nm->compiler_name(), msg, short_form, cr);
211221
}
212222
static void print_ul(const nmethod* nm, const char* msg = nullptr);
213223

@@ -217,6 +227,7 @@ class CompileTask : public CHeapObj<mtCompiler> {
217227
static void print_inline_indent(int inline_level, outputStream* st = tty);
218228

219229
void print_tty();
230+
void print_post(outputStream* st);
220231
void print_line_on_error(outputStream* st, char* buf, int buflen);
221232

222233
void log_task(xmlStream* log);

src/hotspot/share/compiler/compilerDirectives.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
cflags(MemStat, uintx, 0, MemStat) \
4545
cflags(PrintAssembly, bool, PrintAssembly, PrintAssembly) \
4646
cflags(PrintCompilation, bool, PrintCompilation, PrintCompilation) \
47+
cflags(PrintCompilation2, bool, PrintCompilation2, PrintCompilation2) \
4748
cflags(PrintInlining, bool, PrintInlining, PrintInlining) \
4849
cflags(PrintNMethods, bool, PrintNMethods, PrintNMethods) \
4950
cflags(BackgroundCompilation, bool, BackgroundCompilation, BackgroundCompilation) \

src/hotspot/share/compiler/compilerOracle.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class methodHandle;
6363
option(MemStat, "MemStat", Uintx) \
6464
option(PrintAssembly, "PrintAssembly", Bool) \
6565
option(PrintCompilation, "PrintCompilation", Bool) \
66+
option(PrintCompilation2, "PrintCompilation2", Bool) \
6667
option(PrintInlining, "PrintInlining", Bool) \
6768
option(PrintIntrinsics, "PrintIntrinsics", Bool) \
6869
option(PrintNMethods, "PrintNMethods", Bool) \

src/hotspot/share/oops/method.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,30 @@ address Method::get_c2i_no_clinit_check_entry() {
184184
return adapter()->get_c2i_no_clinit_check_entry();
185185
}
186186

187-
char* Method::name_and_sig_as_C_string() const {
188-
return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
187+
char* Method::name_and_sig_as_C_string(bool use_double_colon) const {
188+
return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), use_double_colon);
189189
}
190190

191191
char* Method::name_and_sig_as_C_string(char* buf, int size) const {
192192
return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size);
193193
}
194194

195-
char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
195+
char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, bool use_double_colon) {
196196
const char* klass_name = klass->external_name();
197197
int klass_name_len = (int)strlen(klass_name);
198198
int method_name_len = method_name->utf8_length();
199-
int len = klass_name_len + 1 + method_name_len + signature->utf8_length();
199+
int separator_len = use_double_colon ? 2 : 1;
200+
int len = klass_name_len + separator_len + method_name_len + signature->utf8_length();
200201
char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
201202
strcpy(dest, klass_name);
202-
dest[klass_name_len] = '.';
203-
strcpy(&dest[klass_name_len + 1], method_name->as_C_string());
204-
strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string());
203+
if (use_double_colon) {
204+
dest[klass_name_len + 0] = ':';
205+
dest[klass_name_len + 1] = ':';
206+
} else {
207+
dest[klass_name_len] = '.';
208+
}
209+
strcpy(&dest[klass_name_len + separator_len], method_name->as_C_string());
210+
strcpy(&dest[klass_name_len + separator_len + method_name_len], signature->as_C_string());
205211
dest[len] = 0;
206212
return dest;
207213
}

0 commit comments

Comments
 (0)