Skip to content

Commit

Permalink
8333182: Add truncated tracing mode for TraceBytecodes
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, fparain, coleenp
  • Loading branch information
cl4es committed Jun 2, 2024
1 parent 8338946 commit 769b3e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/hotspot/share/interpreter/bytecodeTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class BytecodePrinter {
// the adjustments that BytecodeStream performs applies.
void trace(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
ResourceMark rm;
if (_current_method != method()) {
bool method_changed = _current_method != method();
if (method_changed) {
// Note 1: This code will not work as expected with true MT/MP.
// Need an explicit lock or a different solution.
// It is possible for this block to be skipped, if a garbage
Expand All @@ -119,17 +120,24 @@ class BytecodePrinter {
code = Bytecodes::code_at(method(), bcp);
}
_code = code;
int bci = (int)(bcp - method->code_base());
st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
if (Verbose) {
st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
} else {
st->print("%8d %4d %s",
BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
}
_next_pc = is_wide() ? bcp+2 : bcp+1;
print_attributes(bci, st);
// Trace each bytecode unless we're truncating the tracing output, then only print the first
// bytecode in every method as well as returns/throws that pop control flow
if (!TraceBytecodesTruncated || method_changed ||
code == Bytecodes::_athrow ||
code == Bytecodes::_return_register_finalizer ||
(code >= Bytecodes::_ireturn && code <= Bytecodes::_return)) {
int bci = (int)(bcp - method->code_base());
st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
if (Verbose) {
st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
} else {
st->print("%8d %4d %s",
BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
}
print_attributes(bci, st);
}
// Set is_wide for the next one, since the caller of this doesn't skip
// the next bytecode.
_is_wide = (code == Bytecodes::_wide);
Expand Down Expand Up @@ -336,7 +344,8 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
// If the code doesn't have any fields there's nothing to print.
// note this is ==1 because the tableswitch and lookupswitch are
// zero size (for some reason) and we want to print stuff out for them.
if (Bytecodes::length_for(code) == 1) {
// Also skip this if we're truncating bytecode output
if (TraceBytecodesTruncated || Bytecodes::length_for(code) == 1) {
st->cr();
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ const int ObjectAlignmentInBytes = 8;
develop(bool, TraceBytecodes, false, \
"Trace bytecode execution") \
\
develop(bool, TraceBytecodesTruncated, false, \
"Truncate non control-flow bytecode when tracing bytecode") \
\
develop(bool, VerifyDependencies, trueInDebug, \
"Exercise and verify the compilation dependency mechanism") \
\
Expand Down

1 comment on commit 769b3e4

@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.