Skip to content

Commit f3af804

Browse files
committed
[GR-68944] Compilation alarm: skip reporting for 0ms subtrees.
PullRequest: graal/21927
2 parents 3e8ffa7 + a044de9 commit f3af804

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ public static class Options {
7171
private final CompilationAlarm previous;
7272

7373
@SuppressWarnings("this-escape")
74-
private CompilationAlarm(double period) {
74+
private CompilationAlarm(double period, boolean skipZeros) {
7575
this.previous = currentAlarm.get();
7676
reset(period);
7777
JMXService.GCTimeStatistics timing = null;
7878
if (period != 0) {
7979
timing = GraalServices.getGCTimeStatistics();
8080
}
8181
this.gcTiming = timing;
82+
this.skipZeros = skipZeros;
8283
}
8384

8485
/**
@@ -113,7 +114,7 @@ public static double scaleExpirationPeriod(double period, OptionValues options)
113114
*/
114115
private static final ThreadLocal<CompilationAlarm> currentAlarm = new ThreadLocal<>();
115116

116-
private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm(0);
117+
private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm(0, false);
117118

118119
/**
119120
* Gets the current compilation alarm. If there is no current alarm, a non-null value is
@@ -183,7 +184,8 @@ public boolean isEnabled() {
183184
public void checkExpiration() {
184185
if (hasExpired()) {
185186

186-
setCurrentNodeDuration(currentNode.name);
187+
// also set all parent node times
188+
setCurrentNodeDuration(currentNode.name, true);
187189

188190
/*
189191
* We clone the phase tree here for the sake of the error message. We want to fix up the
@@ -194,7 +196,7 @@ public void checkExpiration() {
194196
StringBuilder sb = new StringBuilder();
195197
// also update the root time to be consistent for the error message
196198
cloneTree.durationNS = elapsed();
197-
printTree("", sb, cloneTree, true);
199+
printTree("", sb, cloneTree, true, skipZeros);
198200

199201
// Include information about time spent in the GC if it's available.
200202
String gcMessage = "";
@@ -227,6 +229,11 @@ public void close() {
227229
*/
228230
private final JMXService.GCTimeStatistics gcTiming;
229231

232+
/**
233+
* On timeout skip zero entries.
234+
*/
235+
private final boolean skipZeros;
236+
230237
/**
231238
* Signal the execution of the phase identified by {@code name} starts.
232239
*/
@@ -296,7 +303,7 @@ public void exitPhase(CharSequence name, StructuredGraph graph) {
296303
currentNode = currentNode.parent;
297304
}
298305
assert currentNode.name.equals(name) : Assertions.errorMessage("Must see the same phase that was opened in the close operation", name, elapsedPhaseTreeAsString());
299-
setCurrentNodeDuration(name);
306+
setCurrentNodeDuration(name, false);
300307
currentNode.closed = true;
301308
if (graph != null) {
302309
currentNode.graphSizeAfter = graph.getNodeCount();
@@ -316,9 +323,17 @@ private boolean graphMarksIntermediateRootEnd(StructuredGraph graph) {
316323
return currentNode instanceof PhaseTreeIntermediateRoot && currentNode.graph != null && graph != null && !currentNode.graph.equals(graph);
317324
}
318325

319-
private void setCurrentNodeDuration(CharSequence name) {
326+
private void setCurrentNodeDuration(CharSequence name, boolean setParentTime) {
320327
assert currentNode.startTimeNS >= 0 : Assertions.errorMessage("Must have a positive start time", name, elapsedPhaseTreeAsString());
321-
currentNode.durationNS = System.nanoTime() - currentNode.startTimeNS;
328+
long currentTimeNano = System.nanoTime();
329+
currentNode.durationNS = currentTimeNano - currentNode.startTimeNS;
330+
if (setParentTime) {
331+
PhaseTreeNode node = currentNode.parent;
332+
while (node != null) {
333+
node.durationNS = currentTimeNano - node.startTimeNS;
334+
node = node.parent;
335+
}
336+
}
322337
}
323338

324339
/**
@@ -413,6 +428,10 @@ public String toString() {
413428
"->" + graphSizeAfter + "]";
414429
}
415430

431+
private boolean durationZeroInMS() {
432+
return TimeUnit.NANOSECONDS.toMillis(durationNS) == 0;
433+
}
434+
416435
}
417436

418437
private static class PhaseTreeIntermediateRoot extends PhaseTreeNode {
@@ -449,27 +468,34 @@ private PhaseTreeNode cloneTree(PhaseTreeNode clonee, PhaseTreeNode parent) {
449468
/**
450469
* Recursively print the phase tree represented by {@code node}.
451470
*/
452-
private void printTree(String indent, StringBuilder sb, PhaseTreeNode node, boolean printRoot) {
471+
private void printTree(String indent, StringBuilder sb, PhaseTreeNode node, boolean printRoot, boolean skipPrintingZeroSubTree) {
453472
if (root == null) {
454473
return;
455474
}
456-
sb.append(indent);
475+
boolean skip = skipPrintingZeroSubTree && node.durationZeroInMS();
476+
if (!skip) {
477+
sb.append(indent);
478+
}
457479
if (!printRoot && node == root) {
458480
sb.append(node.name);
459481
} else {
460-
sb.append(node);
482+
if (!skip) {
483+
sb.append(node);
484+
}
485+
}
486+
if (!skip) {
487+
sb.append(System.lineSeparator());
461488
}
462-
sb.append(System.lineSeparator());
463-
if (node.children != null) {
489+
if (node.children != null && !skip) {
464490
for (int i = 0; i < node.childIndex; i++) {
465-
printTree(indent + "\t", sb, node.children[i], printRoot);
491+
printTree(indent + "\t", sb, node.children[i], printRoot, skipPrintingZeroSubTree);
466492
}
467493
}
468494
}
469495

470496
public StringBuilder elapsedPhaseTreeAsString() {
471497
StringBuilder sb = new StringBuilder();
472-
printTree("", sb, root, false);
498+
printTree("", sb, root, false, false);
473499
return sb;
474500
}
475501

@@ -493,7 +519,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
493519
}
494520
CompilationAlarm current = currentAlarm.get();
495521
if (current == null) {
496-
current = new CompilationAlarm(period);
522+
current = new CompilationAlarm(period, true/* skip 0 entries */);
497523
currentAlarm.set(current);
498524
return current;
499525
}
@@ -506,7 +532,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
506532
* statement to restore the previous alarm state.
507533
*/
508534
public static CompilationAlarm disable() {
509-
CompilationAlarm current = new CompilationAlarm(0);
535+
CompilationAlarm current = new CompilationAlarm(0, false);
510536
currentAlarm.set(current);
511537
return current;
512538
}

0 commit comments

Comments
 (0)