Skip to content

Commit a45fe3c

Browse files
committed
[GR-69439] Cache compiler phase name.
PullRequest: graal/22054
2 parents 7557afd + 4ab772b commit a45fe3c

File tree

9 files changed

+62
-38
lines changed

9 files changed

+62
-38
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/CompilationListenerProfiler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, 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
@@ -26,7 +26,6 @@
2626

2727
import jdk.graal.compiler.debug.CompilationListener;
2828
import jdk.graal.compiler.debug.DebugContext;
29-
3029
import jdk.vm.ci.meta.ResolvedJavaMethod;
3130

3231
/**
@@ -47,7 +46,7 @@ public CompilationListenerProfiler(CompilerProfiler profiler, int compileId) {
4746

4847
@Override
4948
public void notifyInlining(ResolvedJavaMethod caller, ResolvedJavaMethod callee, boolean succeeded, CharSequence message, int bci) {
50-
profiler.notifyCompilerInlingEvent(compileId, caller, callee, succeeded, message.toString(), bci);
49+
profiler.notifyCompilerInliningEvent(compileId, caller, callee, succeeded, message.toString(), bci);
5150
}
5251

5352
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/CompilerProfiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, 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
@@ -61,5 +61,5 @@ public interface CompilerProfiler {
6161
* @param message extra information about inlining decision
6262
* @param bci byte code index of call site
6363
*/
64-
void notifyCompilerInlingEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee, boolean succeeded, String message, int bci);
64+
void notifyCompilerInliningEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee, boolean succeeded, String message, int bci);
6565
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JFRCompilerProfiler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, 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
@@ -26,7 +26,6 @@
2626

2727
import jdk.graal.compiler.core.common.CompilerProfiler;
2828
import jdk.graal.compiler.serviceprovider.ServiceProvider;
29-
3029
import jdk.vm.ci.hotspot.JFR;
3130
import jdk.vm.ci.meta.ResolvedJavaMethod;
3231

@@ -47,7 +46,7 @@ public void notifyCompilerPhaseEvent(int compileId, long startTime, String name,
4746
}
4847

4948
@Override
50-
public void notifyCompilerInlingEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee,
49+
public void notifyCompilerInliningEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee,
5150
boolean succeeded, String message, int bci) {
5251
JFR.CompilerInliningEvent.write(compileId, caller, callee, succeeded, message, bci);
5352
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/CompilerInterfaceDeclarations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ public static CompilerInterfaceDeclarations build() {
672672
new RegistrationBuilder<>(CompilerProfiler.class).setSingleton(true)
673673
.setStrategy(CompilerProfilerProxy.getTicksMethod, MethodStrategy.Passthrough)
674674
.setStrategy(CompilerProfilerProxy.notifyCompilerPhaseEventMethod, MethodStrategy.Passthrough)
675-
.setDefaultValueStrategy(CompilerProfilerProxy.notifyCompilerInlingEventMethod, null)
675+
.setDefaultValueStrategy(CompilerProfilerProxy.notifyCompilerInliningEventMethod, null)
676676
.register(declarations);
677677
new RegistrationBuilder<>(HotSpotResolvedObjectType.class, HotSpotResolvedJavaType.class)
678678
.ensureRecorded(HotSpotResolvedObjectTypeProxy.getNameMethod, HotSpotResolvedObjectTypeProxy.getNameInvokable)

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/proxy/CompilerProfilerProxy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public void notifyCompilerPhaseEvent(int compileId, long startTime, String name,
5757
handle(notifyCompilerPhaseEventMethod, notifyCompilerPhaseEventInvokable, compileId, startTime, name, nestingLevel);
5858
}
5959

60-
public static final SymbolicMethod notifyCompilerInlingEventMethod = method("notifyCompilerInlingEvent", int.class, ResolvedJavaMethod.class, ResolvedJavaMethod.class, boolean.class,
60+
public static final SymbolicMethod notifyCompilerInliningEventMethod = method("notifyCompilerInliningEvent", int.class, ResolvedJavaMethod.class, ResolvedJavaMethod.class, boolean.class,
6161
String.class, int.class);
62-
private static final InvokableMethod notifyCompilerInlingEventInvokable = (receiver, args) -> {
63-
((CompilerProfiler) receiver).notifyCompilerInlingEvent((int) args[0], (ResolvedJavaMethod) args[1], (ResolvedJavaMethod) args[2], (boolean) args[3], (String) args[4], (int) args[5]);
62+
private static final InvokableMethod notifyCompilerInliningEventInvokable = (receiver, args) -> {
63+
((CompilerProfiler) receiver).notifyCompilerInliningEvent((int) args[0], (ResolvedJavaMethod) args[1], (ResolvedJavaMethod) args[2], (boolean) args[3], (String) args[4], (int) args[5]);
6464
return null;
6565
};
6666

6767
@Override
68-
public void notifyCompilerInlingEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee, boolean succeeded, String message, int bci) {
69-
handle(notifyCompilerInlingEventMethod, notifyCompilerInlingEventInvokable, compileId, caller, callee, succeeded, message, bci);
68+
public void notifyCompilerInliningEvent(int compileId, ResolvedJavaMethod caller, ResolvedJavaMethod callee, boolean succeeded, String message, int bci) {
69+
handle(notifyCompilerInliningEventMethod, notifyCompilerInliningEventInvokable, compileId, caller, callee, succeeded, message, bci);
7070
}
7171
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/phases/LIRPhase.java

Lines changed: 18 additions & 16 deletions
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, 2025, 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
@@ -52,15 +52,7 @@ public static class Options {
5252
// @formatter:on
5353
}
5454

55-
/**
56-
* Records time spent within {@link #apply}.
57-
*/
58-
private final TimerKey timer;
59-
60-
/**
61-
* Records memory usage within {@link #apply}.
62-
*/
63-
private final MemUseTrackerKey memUseTracker;
55+
private final LIRPhaseStatistics statistics;
6456

6557
public static final class LIRPhaseStatistics {
6658
/**
@@ -73,6 +65,13 @@ public static final class LIRPhaseStatistics {
7365
*/
7466
public final MemUseTrackerKey memUseTracker;
7567

68+
/**
69+
* Cached phase name.
70+
*
71+
* @see LIRPhase#getName()
72+
*/
73+
CharSequence phaseName;
74+
7675
public LIRPhaseStatistics(Class<?> clazz) {
7776
timer = DebugContext.timer("LIRPhaseTime_%s", clazz);
7877
memUseTracker = DebugContext.memUseTracker("LIRPhaseMemUse_%s", clazz);
@@ -101,9 +100,7 @@ private static boolean checkName(CharSequence name) {
101100
}
102101

103102
public LIRPhase() {
104-
LIRPhaseStatistics statistics = getLIRPhaseStatistics(getClass());
105-
timer = statistics.timer;
106-
memUseTracker = statistics.memUseTracker;
103+
this.statistics = getLIRPhaseStatistics(getClass());
107104
}
108105

109106
/**
@@ -129,8 +126,8 @@ public final void apply(TargetDescription target, LIRGenerationResult lirGenRes,
129126
CharSequence name = getName();
130127
try (DebugContext.Scope s = debug.scope(name, this)) {
131128
try (CompilerPhaseScope cps = debug.enterCompilerPhase(name, null);
132-
DebugCloseable a = timer.start(debug);
133-
DebugCloseable c = memUseTracker.start(debug);
129+
DebugCloseable a = statistics.timer.start(debug);
130+
DebugCloseable c = statistics.memUseTracker.start(debug);
134131
DebugCloseable d = gcStatistics(debug)) {
135132
run(target, lirGenRes, context);
136133
if (dumpLIR && debug.areScopesEnabled()) {
@@ -173,8 +170,13 @@ protected CharSequence createName() {
173170
}
174171

175172
public final CharSequence getName() {
176-
CharSequence name = createName();
173+
CharSequence name = statistics.phaseName;
174+
if (name != null) {
175+
return name;
176+
}
177+
name = createName();
177178
assert checkName(name);
179+
statistics.phaseName = name;
178180
return name;
179181
}
180182
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/BasePhase.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -246,6 +246,13 @@ public static class BasePhaseStatistics {
246246
*/
247247
private final MemUseTrackerKey memUseTracker;
248248

249+
/**
250+
* Cached phase name.
251+
*
252+
* @see BasePhase#getName()
253+
*/
254+
CharSequence phaseName;
255+
249256
public BasePhaseStatistics(Class<?> clazz) {
250257
timer = DebugContext.timer("PhaseTime_%s", clazz).doc("Time spent in phase.");
251258
executionCount = DebugContext.counter("PhaseCount_%s", clazz).doc("Number of phase executions.");
@@ -604,10 +611,20 @@ public void changed(NodeEvent e, Node node) {
604611
}
605612
}
606613

607-
public CharSequence getName() {
614+
private CharSequence createName() {
608615
return new ClassTypeSequence(this.getClass());
609616
}
610617

618+
public CharSequence getName() {
619+
CharSequence name = statistics.phaseName;
620+
if (name != null) {
621+
return name;
622+
}
623+
name = createName();
624+
statistics.phaseName = name;
625+
return name;
626+
}
627+
611628
protected abstract void run(StructuredGraph graph, C context);
612629

613630
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/ClassTypeSequence.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -30,12 +30,13 @@
3030
import jdk.vm.ci.meta.ResolvedJavaType;
3131

3232
/**
33-
* A printable representation of the name of class that can serialized as a fully qualified type for
34-
* dumping. This is to support deobfuscation of dump output. The {@link #toString()} is the
33+
* A printable representation of the name of class that can be serialized as a fully qualified type
34+
* for dumping. This is to support deobfuscation of dump output. The {@link #toString()} is the
3535
* unqualified name of the Class.
3636
*/
3737
public final class ClassTypeSequence implements JavaType, CharSequence {
3838
private final Class<?> clazz;
39+
private String simpleName;
3940

4041
public ClassTypeSequence(Class<?> clazz) {
4142
this.clazz = clazz;
@@ -56,8 +57,14 @@ public String toJavaName(boolean qualified) {
5657
if (qualified) {
5758
return clazz.getName();
5859
} else {
60+
String name = this.simpleName;
61+
if (name != null) {
62+
return name;
63+
}
5964
int lastDot = clazz.getName().lastIndexOf('.');
60-
return clazz.getName().substring(lastDot + 1);
65+
name = clazz.getName().substring(lastDot + 1);
66+
this.simpleName = name;
67+
return name;
6168
}
6269
}
6370

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, 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
@@ -379,6 +379,7 @@ static JNIObjectHandle FindClass(JNIEnvironment env, CCharPointer cname) {
379379
static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINativeMethod methods, int nmethods) {
380380
Class<?> clazz = JNIObjectHandles.getObject(hclazz);
381381
Pointer p = (Pointer) methods;
382+
String declaringClass = MetaUtil.toInternalName(clazz.getName());
382383
for (int i = 0; i < nmethods; i++) {
383384
JNINativeMethod entry = (JNINativeMethod) p;
384385
CharSequence name = Utf8.wrapUtf8CString(entry.name());
@@ -393,7 +394,6 @@ static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINative
393394

394395
CFunctionPointer fnPtr = entry.fnPtr();
395396

396-
String declaringClass = MetaUtil.toInternalName(clazz.getName());
397397
JNINativeLinkage linkage = JNIReflectionDictionary.getLinkage(declaringClass, name, signature);
398398
if (linkage != null) {
399399
linkage.setEntryPoint(fnPtr);

0 commit comments

Comments
 (0)