Skip to content

Commit 81f57f0

Browse files
committed
Cache compiler phase name.
1 parent c502eb2 commit 81f57f0

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

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

0 commit comments

Comments
 (0)