From 769b3e48ea97a13756cf096ae235d7434c0cae34 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Sun, 2 Jun 2024 20:29:03 +0000 Subject: [PATCH] 8333182: Add truncated tracing mode for TraceBytecodes Reviewed-by: dholmes, fparain, coleenp --- .../share/interpreter/bytecodeTracer.cpp | 33 ++++++++++++------- src/hotspot/share/runtime/globals.hpp | 3 ++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/hotspot/share/interpreter/bytecodeTracer.cpp b/src/hotspot/share/interpreter/bytecodeTracer.cpp index b7617c38602..e5a3e9c16f4 100644 --- a/src/hotspot/share/interpreter/bytecodeTracer.cpp +++ b/src/hotspot/share/interpreter/bytecodeTracer.cpp @@ -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; } diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 43771d550a2..481115ddbe9 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -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") \ \