8333182: Add truncated tracing mode for TraceBytecodes

Reviewed-by: dholmes, fparain, coleenp
This commit is contained in:
Claes Redestad 2024-06-02 20:29:03 +00:00
parent 8338946a6d
commit 769b3e48ea
2 changed files with 24 additions and 12 deletions

View File

@ -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
@ -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);
@ -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;
}

View File

@ -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") \
\