diff --git a/src/hotspot/share/interpreter/bytecodeTracer.cpp b/src/hotspot/share/interpreter/bytecodeTracer.cpp index f9980e389e2..69fc93b6c0f 100644 --- a/src/hotspot/share/interpreter/bytecodeTracer.cpp +++ b/src/hotspot/share/interpreter/bytecodeTracer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -192,18 +192,20 @@ void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, } #endif -void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) { +void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags, bool buffered) { BytecodePrinter method_printer(flags); BytecodeStream s(method); s.set_interval(from, to); - // Keep output to st coherent: collect all lines and print at once. ResourceMark rm; stringStream ss; + outputStream* out = buffered ? &ss : st; while (s.next() >= 0) { - method_printer.trace(method, s.bcp(), &ss); + method_printer.trace(method, s.bcp(), out); + } + if (buffered) { + st->print("%s", ss.as_string()); } - st->print("%s", ss.as_string()); } void BytecodePrinter::print_constant(int cp_index, outputStream* st) { diff --git a/src/hotspot/share/interpreter/bytecodeTracer.hpp b/src/hotspot/share/interpreter/bytecodeTracer.hpp index b32e55abbcf..e199a2b7ea2 100644 --- a/src/hotspot/share/interpreter/bytecodeTracer.hpp +++ b/src/hotspot/share/interpreter/bytecodeTracer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,7 +39,7 @@ class BytecodeClosure; class BytecodeTracer: AllStatic { public: NOT_PRODUCT(static void trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st = tty);) - static void print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags); + static void print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags, bool buffered = true); }; #endif // SHARE_INTERPRETER_BYTECODETRACER_HPP diff --git a/src/hotspot/share/oops/method.cpp b/src/hotspot/share/oops/method.cpp index 1a2e5f0bee4..949441585d8 100644 --- a/src/hotspot/share/oops/method.cpp +++ b/src/hotspot/share/oops/method.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1898,15 +1898,15 @@ void Method::print_name(outputStream* st) const { #endif // !PRODUCT || INCLUDE_JVMTI -void Method::print_codes_on(outputStream* st, int flags) const { - print_codes_on(0, code_size(), st, flags); +void Method::print_codes_on(outputStream* st, int flags, bool buffered) const { + print_codes_on(0, code_size(), st, flags, buffered); } -void Method::print_codes_on(int from, int to, outputStream* st, int flags) const { +void Method::print_codes_on(int from, int to, outputStream* st, int flags, bool buffered) const { Thread *thread = Thread::current(); ResourceMark rm(thread); methodHandle mh (thread, (Method*)this); - BytecodeTracer::print_method_codes(mh, from, to, st, flags); + BytecodeTracer::print_method_codes(mh, from, to, st, flags, buffered); } CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) { diff --git a/src/hotspot/share/oops/method.hpp b/src/hotspot/share/oops/method.hpp index 4592cb8a8c0..add8e59b2be 100644 --- a/src/hotspot/share/oops/method.hpp +++ b/src/hotspot/share/oops/method.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -466,8 +466,8 @@ public: // prints byte codes void print_codes(int flags = 0) const { print_codes_on(tty, flags); } - void print_codes_on(outputStream* st, int flags = 0) const; - void print_codes_on(int from, int to, outputStream* st, int flags = 0) const; + void print_codes_on(outputStream* st, int flags = 0, bool buffered = true) const; + void print_codes_on(int from, int to, outputStream* st, int flags = 0, bool buffered = true) const; // method parameters bool has_method_parameters() const diff --git a/src/hotspot/share/runtime/vframeArray.cpp b/src/hotspot/share/runtime/vframeArray.cpp index a68a0adf299..9f1c082ed8f 100644 --- a/src/hotspot/share/runtime/vframeArray.cpp +++ b/src/hotspot/share/runtime/vframeArray.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -491,6 +491,15 @@ void vframeArrayElement::unpack_on_stack(int caller_actual_parameters, #ifndef PRODUCT if (PrintDeoptimizationDetails) { + const bool print_codes = WizardMode && Verbose; + ResourceMark rm(thread); + stringStream codes_ss; + if (print_codes) { + // print_codes_on() may acquire MDOExtraData_lock (rank nosafepoint-1). + // To keep the lock acquisition order correct, call it before taking tty_lock. + // Avoid double buffering: set buffered=false. + method()->print_codes_on(&codes_ss, 0, false); + } ttyLocker ttyl; tty->print_cr("[%d. Interpreted Frame]", ++unpack_counter); iframe()->print_on(tty); @@ -500,7 +509,9 @@ void vframeArrayElement::unpack_on_stack(int caller_actual_parameters, RegisterMap::WalkContinuation::skip); vframe* f = vframe::new_vframe(iframe(), &map, thread); f->print(); - if (WizardMode && Verbose) method()->print_codes(); + if (print_codes) { + tty->print("%s", codes_ss.as_string()); + } tty->cr(); } #endif // !PRODUCT diff --git a/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java b/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java new file mode 100644 index 00000000000..2866a84ba46 --- /dev/null +++ b/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + /** + * @test + * @bug 8374862 + * @summary Regression test for -XX:+Verbose -XX:+WizardMode -XX:+PrintDeoptimizationDetails crash + * @requires vm.debug + * @run main/othervm -XX:+Verbose -XX:+WizardMode -XX:+PrintDeoptimizationDetails compiler.uncommontrap.TestDeoptDetailsLockRank + */ + +package compiler.uncommontrap; + +public class TestDeoptDetailsLockRank { + + public static void main(String[] args) { + System.out.println("passed"); + } +} \ No newline at end of file