Skip to content

Commit ddf1e34

Browse files
committedMar 22, 2023
8304089: Convert TraceDependencies to UL
Reviewed-by: vlivanov, dholmes
1 parent 358c61b commit ddf1e34

14 files changed

+74
-56
lines changed
 

‎src/hotspot/share/ci/ciMethod.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "interpreter/interpreter.hpp"
4141
#include "interpreter/linkResolver.hpp"
4242
#include "interpreter/oopMapCache.hpp"
43+
#include "logging/log.hpp"
44+
#include "logging/logStream.hpp"
4345
#include "memory/allocation.inline.hpp"
4446
#include "memory/resourceArea.hpp"
4547
#include "oops/generateOopMap.hpp"
@@ -728,12 +730,14 @@ ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
728730
}
729731

730732
#ifndef PRODUCT
731-
if (TraceDependencies && target() != nullptr && target() != root_m->get_Method()) {
732-
tty->print("found a non-root unique target method");
733-
tty->print_cr(" context = %s", actual_recv->get_Klass()->external_name());
734-
tty->print(" method = ");
735-
target->print_short_name(tty);
736-
tty->cr();
733+
LogTarget(Debug, dependencies) lt;
734+
if (lt.is_enabled() && target() != nullptr && target() != root_m->get_Method()) {
735+
LogStream ls(&lt);
736+
ls.print("found a non-root unique target method");
737+
ls.print_cr(" context = %s", actual_recv->get_Klass()->external_name());
738+
ls.print(" method = ");
739+
target->print_short_name(&ls);
740+
ls.cr();
737741
}
738742
#endif //PRODUCT
739743

‎src/hotspot/share/code/dependencies.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static bool must_be_in_vm() {
5959
}
6060
#endif //ASSERT
6161

62+
bool Dependencies::_verify_in_progress = false; // don't -Xlog:dependencies
63+
6264
void Dependencies::initialize(ciEnv* env) {
6365
Arena* arena = env->arena();
6466
_oop_recorder = env->oop_recorder();
@@ -638,7 +640,7 @@ Dependencies::DepType Dependencies::validate_dependencies(CompileTask* task, cha
638640
// resizing in the context of an inner resource mark.
639641
char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN);
640642
stringStream st(buffer, O_BUFLEN);
641-
deps.print_dependency(witness, true, &st);
643+
deps.print_dependency(&st, witness, true);
642644
*failure_detail = st.as_string();
643645
}
644646
}
@@ -866,7 +868,7 @@ void Dependencies::DepStream::log_dependency(Klass* witness) {
866868
guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope");
867869
}
868870

869-
void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose, outputStream* st) {
871+
void Dependencies::DepStream::print_dependency(outputStream* st, Klass* witness, bool verbose) {
870872
ResourceMark rm;
871873
int nargs = argument_count();
872874
GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs);
@@ -1763,7 +1765,7 @@ Klass* Dependencies::find_unique_concrete_subtype(InstanceKlass* ctxk) {
17631765
// Make sure the dependency mechanism will pass this discovery:
17641766
if (VerifyDependencies) {
17651767
// Turn off dependency tracing while actually testing deps.
1766-
FlagSetting fs(TraceDependencies, false);
1768+
FlagSetting fs(_verify_in_progress, true);
17671769
if (!Dependencies::is_concrete_klass(ctxk)) {
17681770
guarantee(nullptr == (void *)
17691771
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
20582060
}
20592061

20602062
void Dependencies::DepStream::trace_and_log_witness(Klass* witness) {
2063+
if (_verify_in_progress) return; // don't log
20612064
if (witness != nullptr) {
2062-
if (TraceDependencies) {
2063-
print_dependency(witness, /*verbose=*/ true);
2065+
LogTarget(Debug, dependencies) lt;
2066+
if (lt.is_enabled()) {
2067+
LogStream ls(&lt);
2068+
print_dependency(&ls, witness, /*verbose=*/ true);
20642069
}
20652070
// The following is a no-op unless logging is enabled:
20662071
log_dependency(witness);
@@ -2170,34 +2175,36 @@ Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) {
21702175
}
21712176

21722177

2173-
void DepChange::print() {
2178+
void DepChange::print() { print_on(tty); }
2179+
2180+
void DepChange::print_on(outputStream* st) {
21742181
int nsup = 0, nint = 0;
21752182
for (ContextStream str(*this); str.next(); ) {
21762183
InstanceKlass* k = str.klass();
21772184
switch (str.change_type()) {
21782185
case Change_new_type:
2179-
tty->print_cr(" dependee = %s", k->external_name());
2186+
st->print_cr(" dependee = %s", k->external_name());
21802187
break;
21812188
case Change_new_sub:
21822189
if (!WizardMode) {
21832190
++nsup;
21842191
} else {
2185-
tty->print_cr(" context super = %s", k->external_name());
2192+
st->print_cr(" context super = %s", k->external_name());
21862193
}
21872194
break;
21882195
case Change_new_impl:
21892196
if (!WizardMode) {
21902197
++nint;
21912198
} else {
2192-
tty->print_cr(" context interface = %s", k->external_name());
2199+
st->print_cr(" context interface = %s", k->external_name());
21932200
}
21942201
break;
21952202
default:
21962203
break;
21972204
}
21982205
}
21992206
if (nsup + nint != 0) {
2200-
tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint);
2207+
st->print_cr(" context supers = %d, interfaces = %d", nsup, nint);
22012208
}
22022209
}
22032210

‎src/hotspot/share/code/dependencies.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ class Dependencies: public ResourceObj {
465465

466466
void copy_to(nmethod* nm);
467467

468+
static bool _verify_in_progress; // turn off logging dependencies
469+
468470
DepType validate_dependencies(CompileTask* task, char** failure_detail = nullptr);
469471

470472
void log_all_dependencies();
@@ -640,7 +642,7 @@ class Dependencies: public ResourceObj {
640642
void log_dependency(Klass* witness = nullptr);
641643

642644
// Print the current dependency to tty.
643-
void print_dependency(Klass* witness = nullptr, bool verbose = false, outputStream* st = tty);
645+
void print_dependency(outputStream* st, Klass* witness = nullptr, bool verbose = false);
644646
};
645647
friend class Dependencies::DepStream;
646648

@@ -701,6 +703,7 @@ class DepChange : public StackObj {
701703
}
702704

703705
void print();
706+
void print_on(outputStream* st);
704707

705708
public:
706709
enum ChangeType {

‎src/hotspot/share/code/dependencyContext.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "code/nmethod.hpp"
2727
#include "code/dependencies.hpp"
2828
#include "code/dependencyContext.hpp"
29+
#include "logging/log.hpp"
30+
#include "logging/logStream.hpp"
2931
#include "memory/resourceArea.hpp"
3032
#include "runtime/atomic.hpp"
3133
#include "runtime/deoptimization.hpp"
@@ -72,12 +74,14 @@ void DependencyContext::mark_dependent_nmethods(DeoptimizationScope* deopt_scope
7274
if (nm->is_marked_for_deoptimization()) {
7375
deopt_scope->dependent(nm);
7476
} else if (nm->check_dependency_on(changes)) {
75-
if (TraceDependencies) {
77+
LogTarget(Info, dependencies) lt;
78+
if (lt.is_enabled()) {
7679
ResourceMark rm;
77-
tty->print_cr("Marked for deoptimization");
78-
changes.print();
79-
nm->print();
80-
nm->print_dependencies();
80+
LogStream ls(&lt);
81+
ls.print_cr("Marked for deoptimization");
82+
changes.print_on(&ls);
83+
nm->print_on(&ls);
84+
nm->print_dependencies_on(&ls);
8185
}
8286
deopt_scope->mark(nm, !changes.is_call_site_change());
8387
}
@@ -210,7 +214,7 @@ void DependencyContext::print_dependent_nmethods(bool verbose) {
210214
tty->print_cr(" } ");
211215
} else {
212216
nm->print();
213-
nm->print_dependencies();
217+
nm->print_dependencies_on(tty);
214218
tty->print_cr("--- } ");
215219
}
216220
}

‎src/hotspot/share/code/nmethod.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ void nmethod::print_nmethod(bool printmethod) {
10441044
tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
10451045
}
10461046
if (printmethod || PrintDependencies || CompilerOracle::has_option(mh, CompileCommand::PrintDependencies)) {
1047-
print_dependencies();
1047+
print_dependencies_on(tty);
10481048
tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
10491049
}
10501050
if (printmethod || PrintExceptionHandlers) {
@@ -2150,7 +2150,7 @@ void nmethod::check_all_dependencies(DepChange& changes) {
21502150
ResourceMark rm;
21512151

21522152
// Turn off dependency tracing while actually testing dependencies.
2153-
NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) );
2153+
NOT_PRODUCT( FlagSetting fs(Dependencies::_verify_in_progress, true));
21542154

21552155
typedef ResourceHashtable<DependencySignature, int, 11027,
21562156
AnyObj::RESOURCE_AREA, mtInternal,
@@ -2180,7 +2180,7 @@ void nmethod::check_all_dependencies(DepChange& changes) {
21802180
tty->print_cr("Failed dependency:");
21812181
changes.print();
21822182
nm->print();
2183-
nm->print_dependencies();
2183+
nm->print_dependencies_on(tty);
21842184
assert(false, "Should have been marked for deoptimization");
21852185
}
21862186
}
@@ -2481,20 +2481,21 @@ void nmethod::print_code() {
24812481

24822482
#ifndef PRODUCT // called InstanceKlass methods are available only then. Declared as PRODUCT_RETURN
24832483

2484-
void nmethod::print_dependencies() {
2484+
void nmethod::print_dependencies_on(outputStream* out) {
24852485
ResourceMark rm;
2486-
ttyLocker ttyl; // keep the following output all in one block
2487-
tty->print_cr("Dependencies:");
2486+
stringStream st;
2487+
st.print_cr("Dependencies:");
24882488
for (Dependencies::DepStream deps(this); deps.next(); ) {
2489-
deps.print_dependency();
2489+
deps.print_dependency(&st);
24902490
InstanceKlass* ctxk = deps.context_type();
24912491
if (ctxk != nullptr) {
24922492
if (ctxk->is_dependent_nmethod(this)) {
2493-
tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name());
2493+
st.print_cr(" [nmethod<=klass]%s", ctxk->external_name());
24942494
}
24952495
}
24962496
deps.log_dependency(); // put it into the xml log also
24972497
}
2498+
out->print_raw(st.as_string());
24982499
}
24992500
#endif
25002501

‎src/hotspot/share/code/nmethod.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class nmethod : public CompiledMethod {
467467
}
468468

469469
bool has_dependencies() { return dependencies_size() != 0; }
470-
void print_dependencies() PRODUCT_RETURN;
470+
void print_dependencies_on(outputStream* out) PRODUCT_RETURN;
471471
void flush_dependencies();
472472
bool has_flushed_dependencies() { return _has_flushed_dependencies; }
473473
void set_has_flushed_dependencies() {

‎src/hotspot/share/logging/logTag.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -68,6 +68,7 @@ class outputStream;
6868
LOG_TAG(decoder) \
6969
LOG_TAG(defaultmethods) \
7070
LOG_TAG(deoptimization) \
71+
LOG_TAG(dependencies) \
7172
LOG_TAG(director) \
7273
NOT_PRODUCT(LOG_TAG(downcall)) \
7374
LOG_TAG(dump) \

‎src/hotspot/share/runtime/arguments.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ static bool use_vm_log() {
35913591
if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) ||
35923592
PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods ||
35933593
PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers ||
3594-
PrintAssembly || TraceDeoptimization || TraceDependencies ||
3594+
PrintAssembly || TraceDeoptimization ||
35953595
(VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) {
35963596
return true;
35973597
}
@@ -4004,10 +4004,9 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
40044004
FLAG_SET_DEFAULT(PrintNMTStatistics, false);
40054005
}
40064006

4007-
if (TraceDependencies && VerifyDependencies) {
4008-
if (!FLAG_IS_DEFAULT(TraceDependencies)) {
4009-
warning("TraceDependencies results may be inflated by VerifyDependencies");
4010-
}
4007+
bool trace_dependencies = log_is_enabled(Debug, dependencies);
4008+
if (trace_dependencies && VerifyDependencies) {
4009+
warning("dependency logging results may be inflated by VerifyDependencies");
40114010
}
40124011

40134012
apply_debugger_ergo();

‎src/hotspot/share/runtime/frame.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,12 @@ bool frame::should_be_deoptimized() const {
306306
!is_compiled_frame() ) return false;
307307
assert(_cb != nullptr && _cb->is_compiled(), "must be an nmethod");
308308
CompiledMethod* nm = (CompiledMethod *)_cb;
309-
if (TraceDependencies) {
310-
tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
311-
nm->print_value_on(tty);
312-
tty->cr();
309+
LogTarget(Debug, dependencies) lt;
310+
if (lt.is_enabled()) {
311+
LogStream ls(&lt);
312+
ls.print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
313+
nm->print_value_on(&ls);
314+
ls.cr();
313315
}
314316

315317
if( !nm->is_marked_for_deoptimization() )

‎src/hotspot/share/runtime/globals.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,6 @@ const int ObjectAlignmentInBytes = 8;
853853
develop(bool, TraceInlineCacheClearing, false, \
854854
"Trace clearing of inline caches in nmethods") \
855855
\
856-
develop(bool, TraceDependencies, false, \
857-
"Trace dependencies") \
858-
\
859856
develop(bool, VerifyDependencies, trueInDebug, \
860857
"Exercise and verify the compilation dependency mechanism") \
861858
\

‎test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
3333
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
3434
*
3535
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
36-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
36+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
3737
* -XX:CompileCommand=compileonly,*::m
3838
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
3939
* -Xbatch -Xmixed -XX:+WhiteBoxAPI
@@ -42,7 +42,7 @@
4242
* compiler.cha.AbstractRootMethod
4343
*
4444
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
45-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
45+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
4646
* -XX:CompileCommand=compileonly,*::m
4747
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
4848
* -Xbatch -Xmixed -XX:+WhiteBoxAPI

‎test/hotspot/jtreg/compiler/cha/DefaultRootMethod.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
3333
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
3434
*
3535
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
36-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
36+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
3737
* -XX:CompileCommand=compileonly,*::m
3838
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
3939
* -Xbatch -Xmixed -XX:+WhiteBoxAPI
@@ -42,7 +42,7 @@
4242
* compiler.cha.DefaultRootMethod
4343
*
4444
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
45-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
45+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
4646
* -XX:CompileCommand=compileonly,*::m
4747
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
4848
* -Xbatch -Xmixed -XX:+WhiteBoxAPI

‎test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
3333
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
3434
*
3535
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
36-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
36+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
3737
* -XX:CompileCommand=compileonly,*::m
3838
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
3939
* -XX:CompileCommand=compileonly,*::testHelper -XX:CompileCommand=inline,*::testHelper
@@ -42,7 +42,7 @@
4242
* compiler.cha.StrengthReduceInterfaceCall
4343
*
4444
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
45-
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
45+
* -XX:+PrintCompilation -XX:+PrintInlining -Xlog:dependencies=debug -verbose:class -XX:CompileCommand=quiet
4646
* -XX:CompileCommand=compileonly,*::m
4747
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
4848
* -XX:CompileCommand=compileonly,*::testHelper -XX:CompileCommand=inline,*::testHelper

0 commit comments

Comments
 (0)
Please sign in to comment.