diff --git a/src/hotspot/share/ci/ciMethod.cpp b/src/hotspot/share/ci/ciMethod.cpp index 627f28ad5b9..adb7e7e2ea5 100644 --- a/src/hotspot/share/ci/ciMethod.cpp +++ b/src/hotspot/share/ci/ciMethod.cpp @@ -40,6 +40,8 @@ #include "interpreter/interpreter.hpp" #include "interpreter/linkResolver.hpp" #include "interpreter/oopMapCache.hpp" +#include "logging/log.hpp" +#include "logging/logStream.hpp" #include "memory/allocation.inline.hpp" #include "memory/resourceArea.hpp" #include "oops/generateOopMap.hpp" @@ -728,12 +730,14 @@ ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller, } #ifndef PRODUCT - if (TraceDependencies && target() != nullptr && target() != root_m->get_Method()) { - tty->print("found a non-root unique target method"); - tty->print_cr(" context = %s", actual_recv->get_Klass()->external_name()); - tty->print(" method = "); - target->print_short_name(tty); - tty->cr(); + LogTarget(Debug, dependencies) lt; + if (lt.is_enabled() && target() != nullptr && target() != root_m->get_Method()) { + LogStream ls(<); + ls.print("found a non-root unique target method"); + ls.print_cr(" context = %s", actual_recv->get_Klass()->external_name()); + ls.print(" method = "); + target->print_short_name(&ls); + ls.cr(); } #endif //PRODUCT diff --git a/src/hotspot/share/code/dependencies.cpp b/src/hotspot/share/code/dependencies.cpp index d0f05b39a48..52ba939d6da 100644 --- a/src/hotspot/share/code/dependencies.cpp +++ b/src/hotspot/share/code/dependencies.cpp @@ -59,6 +59,8 @@ static bool must_be_in_vm() { } #endif //ASSERT +bool Dependencies::_verify_in_progress = false; // don't -Xlog:dependencies + void Dependencies::initialize(ciEnv* env) { Arena* arena = env->arena(); _oop_recorder = env->oop_recorder(); @@ -638,7 +640,7 @@ Dependencies::DepType Dependencies::validate_dependencies(CompileTask* task, cha // resizing in the context of an inner resource mark. char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN); stringStream st(buffer, O_BUFLEN); - deps.print_dependency(witness, true, &st); + deps.print_dependency(&st, witness, true); *failure_detail = st.as_string(); } } @@ -866,7 +868,7 @@ void Dependencies::DepStream::log_dependency(Klass* witness) { guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope"); } -void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose, outputStream* st) { +void Dependencies::DepStream::print_dependency(outputStream* st, Klass* witness, bool verbose) { ResourceMark rm; int nargs = argument_count(); GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs); @@ -1763,7 +1765,7 @@ Klass* Dependencies::find_unique_concrete_subtype(InstanceKlass* ctxk) { // Make sure the dependency mechanism will pass this discovery: if (VerifyDependencies) { // Turn off dependency tracing while actually testing deps. - FlagSetting fs(TraceDependencies, false); + FlagSetting fs(_verify_in_progress, true); if (!Dependencies::is_concrete_klass(ctxk)) { guarantee(nullptr == (void *) check_abstract_with_unique_concrete_subtype(ctxk, conck), @@ -2058,9 +2060,12 @@ Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_hand } void Dependencies::DepStream::trace_and_log_witness(Klass* witness) { + if (_verify_in_progress) return; // don't log if (witness != nullptr) { - if (TraceDependencies) { - print_dependency(witness, /*verbose=*/ true); + LogTarget(Debug, dependencies) lt; + if (lt.is_enabled()) { + LogStream ls(<); + print_dependency(&ls, witness, /*verbose=*/ true); } // The following is a no-op unless logging is enabled: log_dependency(witness); @@ -2170,26 +2175,28 @@ Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) { } -void DepChange::print() { +void DepChange::print() { print_on(tty); } + +void DepChange::print_on(outputStream* st) { int nsup = 0, nint = 0; for (ContextStream str(*this); str.next(); ) { InstanceKlass* k = str.klass(); switch (str.change_type()) { case Change_new_type: - tty->print_cr(" dependee = %s", k->external_name()); + st->print_cr(" dependee = %s", k->external_name()); break; case Change_new_sub: if (!WizardMode) { ++nsup; } else { - tty->print_cr(" context super = %s", k->external_name()); + st->print_cr(" context super = %s", k->external_name()); } break; case Change_new_impl: if (!WizardMode) { ++nint; } else { - tty->print_cr(" context interface = %s", k->external_name()); + st->print_cr(" context interface = %s", k->external_name()); } break; default: @@ -2197,7 +2204,7 @@ void DepChange::print() { } } if (nsup + nint != 0) { - tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint); + st->print_cr(" context supers = %d, interfaces = %d", nsup, nint); } } diff --git a/src/hotspot/share/code/dependencies.hpp b/src/hotspot/share/code/dependencies.hpp index fac96a2a975..bdb7998fd8c 100644 --- a/src/hotspot/share/code/dependencies.hpp +++ b/src/hotspot/share/code/dependencies.hpp @@ -465,6 +465,8 @@ class Dependencies: public ResourceObj { void copy_to(nmethod* nm); + static bool _verify_in_progress; // turn off logging dependencies + DepType validate_dependencies(CompileTask* task, char** failure_detail = nullptr); void log_all_dependencies(); @@ -640,7 +642,7 @@ class Dependencies: public ResourceObj { void log_dependency(Klass* witness = nullptr); // Print the current dependency to tty. - void print_dependency(Klass* witness = nullptr, bool verbose = false, outputStream* st = tty); + void print_dependency(outputStream* st, Klass* witness = nullptr, bool verbose = false); }; friend class Dependencies::DepStream; @@ -701,6 +703,7 @@ class DepChange : public StackObj { } void print(); + void print_on(outputStream* st); public: enum ChangeType { diff --git a/src/hotspot/share/code/dependencyContext.cpp b/src/hotspot/share/code/dependencyContext.cpp index d3ef2d3db2a..904b0927014 100644 --- a/src/hotspot/share/code/dependencyContext.cpp +++ b/src/hotspot/share/code/dependencyContext.cpp @@ -26,6 +26,8 @@ #include "code/nmethod.hpp" #include "code/dependencies.hpp" #include "code/dependencyContext.hpp" +#include "logging/log.hpp" +#include "logging/logStream.hpp" #include "memory/resourceArea.hpp" #include "runtime/atomic.hpp" #include "runtime/deoptimization.hpp" @@ -72,12 +74,14 @@ void DependencyContext::mark_dependent_nmethods(DeoptimizationScope* deopt_scope if (nm->is_marked_for_deoptimization()) { deopt_scope->dependent(nm); } else if (nm->check_dependency_on(changes)) { - if (TraceDependencies) { + LogTarget(Info, dependencies) lt; + if (lt.is_enabled()) { ResourceMark rm; - tty->print_cr("Marked for deoptimization"); - changes.print(); - nm->print(); - nm->print_dependencies(); + LogStream ls(<); + ls.print_cr("Marked for deoptimization"); + changes.print_on(&ls); + nm->print_on(&ls); + nm->print_dependencies_on(&ls); } deopt_scope->mark(nm, !changes.is_call_site_change()); } @@ -210,7 +214,7 @@ void DependencyContext::print_dependent_nmethods(bool verbose) { tty->print_cr(" } "); } else { nm->print(); - nm->print_dependencies(); + nm->print_dependencies_on(tty); tty->print_cr("--- } "); } } diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index f06e172725a..be5a592c247 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -1044,7 +1044,7 @@ void nmethod::print_nmethod(bool printmethod) { tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); } if (printmethod || PrintDependencies || CompilerOracle::has_option(mh, CompileCommand::PrintDependencies)) { - print_dependencies(); + print_dependencies_on(tty); tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); } if (printmethod || PrintExceptionHandlers) { @@ -2150,7 +2150,7 @@ void nmethod::check_all_dependencies(DepChange& changes) { ResourceMark rm; // Turn off dependency tracing while actually testing dependencies. - NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) ); + NOT_PRODUCT( FlagSetting fs(Dependencies::_verify_in_progress, true)); typedef ResourceHashtable<DependencySignature, int, 11027, AnyObj::RESOURCE_AREA, mtInternal, @@ -2180,7 +2180,7 @@ void nmethod::check_all_dependencies(DepChange& changes) { tty->print_cr("Failed dependency:"); changes.print(); nm->print(); - nm->print_dependencies(); + nm->print_dependencies_on(tty); assert(false, "Should have been marked for deoptimization"); } } @@ -2481,20 +2481,21 @@ void nmethod::print_code() { #ifndef PRODUCT // called InstanceKlass methods are available only then. Declared as PRODUCT_RETURN -void nmethod::print_dependencies() { +void nmethod::print_dependencies_on(outputStream* out) { ResourceMark rm; - ttyLocker ttyl; // keep the following output all in one block - tty->print_cr("Dependencies:"); + stringStream st; + st.print_cr("Dependencies:"); for (Dependencies::DepStream deps(this); deps.next(); ) { - deps.print_dependency(); + deps.print_dependency(&st); InstanceKlass* ctxk = deps.context_type(); if (ctxk != nullptr) { if (ctxk->is_dependent_nmethod(this)) { - tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name()); + st.print_cr(" [nmethod<=klass]%s", ctxk->external_name()); } } deps.log_dependency(); // put it into the xml log also } + out->print_raw(st.as_string()); } #endif diff --git a/src/hotspot/share/code/nmethod.hpp b/src/hotspot/share/code/nmethod.hpp index b73e4e1a26d..669baff1b51 100644 --- a/src/hotspot/share/code/nmethod.hpp +++ b/src/hotspot/share/code/nmethod.hpp @@ -467,7 +467,7 @@ class nmethod : public CompiledMethod { } bool has_dependencies() { return dependencies_size() != 0; } - void print_dependencies() PRODUCT_RETURN; + void print_dependencies_on(outputStream* out) PRODUCT_RETURN; void flush_dependencies(); bool has_flushed_dependencies() { return _has_flushed_dependencies; } void set_has_flushed_dependencies() { diff --git a/src/hotspot/share/logging/logTag.hpp b/src/hotspot/share/logging/logTag.hpp index 4705a5d376d..151046664b6 100644 --- a/src/hotspot/share/logging/logTag.hpp +++ b/src/hotspot/share/logging/logTag.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -68,6 +68,7 @@ class outputStream; LOG_TAG(decoder) \ LOG_TAG(defaultmethods) \ LOG_TAG(deoptimization) \ + LOG_TAG(dependencies) \ LOG_TAG(director) \ NOT_PRODUCT(LOG_TAG(downcall)) \ LOG_TAG(dump) \ diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index cceee1472c6..c843bb4efa8 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -3591,7 +3591,7 @@ static bool use_vm_log() { if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || - PrintAssembly || TraceDeoptimization || TraceDependencies || + PrintAssembly || TraceDeoptimization || (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { return true; } @@ -4004,10 +4004,9 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { FLAG_SET_DEFAULT(PrintNMTStatistics, false); } - if (TraceDependencies && VerifyDependencies) { - if (!FLAG_IS_DEFAULT(TraceDependencies)) { - warning("TraceDependencies results may be inflated by VerifyDependencies"); - } + bool trace_dependencies = log_is_enabled(Debug, dependencies); + if (trace_dependencies && VerifyDependencies) { + warning("dependency logging results may be inflated by VerifyDependencies"); } apply_debugger_ergo(); diff --git a/src/hotspot/share/runtime/frame.cpp b/src/hotspot/share/runtime/frame.cpp index 37bacf9864d..bb4a6cc2e54 100644 --- a/src/hotspot/share/runtime/frame.cpp +++ b/src/hotspot/share/runtime/frame.cpp @@ -306,10 +306,12 @@ bool frame::should_be_deoptimized() const { !is_compiled_frame() ) return false; assert(_cb != nullptr && _cb->is_compiled(), "must be an nmethod"); CompiledMethod* nm = (CompiledMethod *)_cb; - if (TraceDependencies) { - tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); - nm->print_value_on(tty); - tty->cr(); + LogTarget(Debug, dependencies) lt; + if (lt.is_enabled()) { + LogStream ls(<); + ls.print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); + nm->print_value_on(&ls); + ls.cr(); } if( !nm->is_marked_for_deoptimization() ) diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 3111425f120..6006063421e 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -853,9 +853,6 @@ const int ObjectAlignmentInBytes = 8; develop(bool, TraceInlineCacheClearing, false, \ "Trace clearing of inline caches in nmethods") \ \ - develop(bool, TraceDependencies, false, \ - "Trace dependencies") \ - \ develop(bool, VerifyDependencies, trueInDebug, \ "Exercise and verify the compilation dependency mechanism") \ \ diff --git a/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java b/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java index 5ddfb7459f1..57f41dece80 100644 --- a/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java +++ b/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -33,7 +33,7 @@ * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -Xbatch -Xmixed -XX:+WhiteBoxAPI @@ -42,7 +42,7 @@ * compiler.cha.AbstractRootMethod * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -Xbatch -Xmixed -XX:+WhiteBoxAPI diff --git a/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.java b/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.java index d3bdb1ede0d..ee2dda744e6 100644 --- a/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.java +++ b/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -33,7 +33,7 @@ * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -Xbatch -Xmixed -XX:+WhiteBoxAPI @@ -42,7 +42,7 @@ * compiler.cha.DefaultRootMethod * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -Xbatch -Xmixed -XX:+WhiteBoxAPI diff --git a/test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java b/test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java index a57b19cff55..736fa242bdc 100644 --- a/test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java +++ b/test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -33,7 +33,7 @@ * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -XX:CompileCommand=compileonly,*::testHelper -XX:CompileCommand=inline,*::testHelper @@ -42,7 +42,7 @@ * compiler.cha.StrengthReduceInterfaceCall * * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions - * -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet + * -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet * -XX:CompileCommand=compileonly,*::m * -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test * -XX:CompileCommand=compileonly,*::testHelper -XX:CompileCommand=inline,*::testHelper diff --git a/test/hotspot/jtreg/compiler/jsr292/CallSiteDepContextTest.java b/test/hotspot/jtreg/compiler/jsr292/CallSiteDepContextTest.java index 5453028816f..f49affbb935 100644 --- a/test/hotspot/jtreg/compiler/jsr292/CallSiteDepContextTest.java +++ b/test/hotspot/jtreg/compiler/jsr292/CallSiteDepContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -31,7 +31,7 @@ * * @build java.base/java.lang.invoke.MethodHandleHelper * @run main/bootclasspath/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -Xlog:class+unload - * -XX:+PrintCompilation -XX:+TraceDependencies -XX:+TraceReferenceGC + * -XX:+PrintCompilation -Xlog:dependencies=debug -XX:+TraceReferenceGC * -verbose:gc * compiler.jsr292.CallSiteDepContextTest */