From 94cd8b6900959d668f1e696e03462e0c7d2ba82e Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Thu, 23 Jul 2026 14:10:14 +0000 Subject: [PATCH] 8388432: [IR Framework] Various clean-ups in preparation for skipping IR tests and IR rules Reviewed-by: mchevalier, thartmann --- ...ceptChildren.java => LeafMatchResult.java} | 31 ++-- .../driver/irmatching/MatchResult.java | 11 +- .../driver/irmatching/MatchableMatcher.java | 9 +- .../driver/irmatching/SubResults.java | 63 ++++++++ .../irmatching/TestClassMatchResult.java | 19 +-- .../driver/irmatching/irmethod/IRMethod.java | 9 +- .../irmethod/IRMethodMatchResult.java | 23 +-- .../irmethod/NotCompilableIRMethod.java | 8 +- .../NotCompilableIRMethodMatchResult.java | 13 +- .../irmethod/NotCompiledIRMethod.java | 10 +- .../NotCompiledIRMethodMatchResult.java | 15 +- .../irmatching/irrule/IRRuleMatchResult.java | 24 +-- .../CheckAttributeMatchResult.java | 21 +-- .../irrule/constraint/ConstraintFailure.java | 6 +- .../constraint/CountsConstraintFailure.java | 4 +- .../constraint/FailOnConstraintFailure.java | 4 +- .../irrule/constraint/SuccessResult.java | 6 +- .../phase/CompilePhaseIRRuleMatchResult.java | 24 +-- ...lePhaseNoCompilationIRRuleMatchResult.java | 6 +- .../report/CompilationOutputBuilder.java | 57 +++----- .../irmatching/report/FailCountVisitor.java | 52 ++----- .../report/FailureMessageBuilder.java | 119 ++++++++------- .../visitor/MatchResultVisitor.java | 137 ++++++++++++++++-- .../tests/TestPhaseIRMatching.java | 50 +++---- 24 files changed, 385 insertions(+), 336 deletions(-) rename test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/{visitor/AcceptChildren.java => LeafMatchResult.java} (53%) create mode 100644 test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/SubResults.java diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/AcceptChildren.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/LeafMatchResult.java similarity index 53% rename from test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/AcceptChildren.java rename to test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/LeafMatchResult.java index 7da6e10ab98..cc6e406c6e7 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/AcceptChildren.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/LeafMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, 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 @@ -21,31 +21,18 @@ * questions. */ -package compiler.lib.ir_framework.driver.irmatching.visitor; - -import compiler.lib.ir_framework.driver.irmatching.MatchResult; - -import java.util.Collection; -import java.util.List; -import java.util.function.Consumer; +package compiler.lib.ir_framework.driver.irmatching; /** - * This class invokes {@link MatchResult#accept(MatchResultVisitor)} on all failed match results (i.e. children) inside - * a {@link MatchResult} object to visit them. + * This interface represents a special leaf match result that does not have any further sub results. */ -public class AcceptChildren implements Consumer { - private final Collection matchResults; - - public AcceptChildren(List matchResults) { - this.matchResults = matchResults; - } +public interface LeafMatchResult extends MatchResult { + /** + * A leaf result does not have sub results and thus returns an empty {@link SubResults} object. + */ @Override - public void accept(MatchResultVisitor visitor) { - for (MatchResult result : matchResults) { - if (result.fail()) { - result.accept(visitor); - } - } + default SubResults subResults() { + return SubResults.createEmpty(); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchResult.java index 84a2eeb2f0e..b1bc840ce9f 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,14 +23,12 @@ package compiler.lib.ir_framework.driver.irmatching; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; /** * This interface is implemented by all classes which represent an IR match result of a {@link Matchable} class. * A match result class accepts a {@link MatchResultVisitor} to visit the result (i.e. for reporting etc.). - * The visitor is responsible to call {@link #accept(MatchResultVisitor)} of the children match results by using - * {@link AcceptChildren#accept(MatchResultVisitor)}. + * The visitor is responsible to call {@link #accept(MatchResultVisitor)} on the sub results. */ public interface MatchResult { /** @@ -43,4 +41,9 @@ public interface MatchResult { * visitor. */ void accept(MatchResultVisitor visitor); + + /** + * Returns the sub results of this {@link MatchResult}. + */ + SubResults subResults(); } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchableMatcher.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchableMatcher.java index 6992cd22184..507df546e4a 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchableMatcher.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/MatchableMatcher.java @@ -38,14 +38,11 @@ public class MatchableMatcher { this.matchables = matchables; } - public List match() { + public SubResults match() { List results = new ArrayList<>(); for (Matchable matchable : matchables) { - MatchResult matchResult = matchable.match(); - if (matchResult.fail()) { - results.add(matchResult); - } + results.add(matchable.match()); } - return results; + return new SubResults(results); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/SubResults.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/SubResults.java new file mode 100644 index 00000000000..aa144b91cb8 --- /dev/null +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/SubResults.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2026, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.lib.ir_framework.driver.irmatching; + +import java.util.Iterator; +import java.util.List; + +/** + * Class to represent sub results as part of a {@link MatchResult}. A {@link LeafMatchResult} use an empty sub results + * object. + */ +public class SubResults implements Iterable { + private final List subResults; + private final int failCount; + + public SubResults(List subResults) { + this.failCount = (int)subResults.stream().filter(MatchResult::fail).count(); + this.subResults = subResults; + } + + /** + * Used for {@link LeafMatchResult} objects with no sub results. + */ + public static SubResults createEmpty() { + return new SubResults(List.of()); + } + + /** + * Is there a sub result with a failure? + */ + public boolean hasFailure() { + return failCount > 0; + } + + public int failCount() { + return failCount; + } + + public Iterator iterator() { + return subResults.iterator(); + } +} diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/TestClassMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/TestClassMatchResult.java index db043643daf..8ee9bef557c 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/TestClassMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/TestClassMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,33 +23,22 @@ package compiler.lib.ir_framework.driver.irmatching; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; -import java.util.List; - /** * This class represents a matching result of a {@link TestClass}. It contains all IR method results, sorted by * method names. * * @see TestClass */ -public class TestClassMatchResult implements MatchResult { - private final AcceptChildren acceptChildren; - private final boolean failed; - - public TestClassMatchResult(List matchResults) { - this.acceptChildren = new AcceptChildren(matchResults); - this.failed = !matchResults.isEmpty(); - } - +public record TestClassMatchResult(SubResults subResults) implements MatchResult { @Override public boolean fail() { - return failed; + return subResults.hasFailure(); } @Override public void accept(MatchResultVisitor visitor) { - visitor.visitTestClass(acceptChildren); + visitor.visit(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java index 137766b0011..fa6ea9eef50 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java @@ -26,10 +26,7 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; import compiler.lib.ir_framework.CompilePhase; import compiler.lib.ir_framework.IR; import compiler.lib.ir_framework.Test; -import compiler.lib.ir_framework.driver.irmatching.Compilation; -import compiler.lib.ir_framework.driver.irmatching.MatchResult; -import compiler.lib.ir_framework.driver.irmatching.Matchable; -import compiler.lib.ir_framework.driver.irmatching.MatchableMatcher; +import compiler.lib.ir_framework.driver.irmatching.*; import compiler.lib.ir_framework.driver.irmatching.irrule.IRRule; import compiler.lib.ir_framework.driver.network.testvm.java.IRRuleIds; import compiler.lib.ir_framework.driver.network.testvm.java.VMInfo; @@ -95,10 +92,10 @@ public class IRMethod implements IRMethodMatchable { } long startTime = System.nanoTime(); - List match = matcher.match(); + SubResults subResults = matcher.match(); long endTime = System.nanoTime(); long duration = (endTime - startTime); System.out.println("Verifying IR rules for " + name() + ": " + duration + " ns = " + (duration / 1_000_000) + " ms"); - return new IRMethodMatchResult(method, match); + return new IRMethodMatchResult(method, subResults); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethodMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethodMatchResult.java index 1c86f9ff1e1..dad67cd9447 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethodMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethodMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -24,11 +24,10 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; import compiler.lib.ir_framework.driver.irmatching.MatchResult; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; +import compiler.lib.ir_framework.driver.irmatching.SubResults; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import java.lang.reflect.Method; -import java.util.List; /** * This class represents a matching result of an {@link IRMethod}. It contains a list of all IR rule match results @@ -36,26 +35,14 @@ import java.util.List; * * @see IRMethod */ -public class IRMethodMatchResult implements MatchResult { - private final AcceptChildren acceptChildren; - private final boolean failed; - private final Method method; - private final int failedIRRules; - - public IRMethodMatchResult(Method method, List matchResults) { - this.acceptChildren = new AcceptChildren(matchResults); - this.failed = !matchResults.isEmpty(); - this.method = method; - this.failedIRRules = matchResults.size(); - } - +public record IRMethodMatchResult(Method method, SubResults subResults) implements MatchResult { @Override public boolean fail() { - return failed; + return subResults.hasFailure(); } @Override public void accept(MatchResultVisitor visitor) { - visitor.visitIRMethod(acceptChildren, method, failedIRRules); + visitor.visit(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java index cb99ea219fe..27b0c709e43 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java @@ -38,11 +38,11 @@ import java.lang.reflect.Method; */ public class NotCompilableIRMethod implements IRMethodMatchable { private final Method method; - private final int ruleCount; + private final int irRuleCount; - public NotCompilableIRMethod(Method method, int ruleCount) { + public NotCompilableIRMethod(Method method, int irRuleCount) { this.method = method; - this.ruleCount = ruleCount; + this.irRuleCount = irRuleCount; } @Override @@ -55,6 +55,6 @@ public class NotCompilableIRMethod implements IRMethodMatchable { */ @Override public NotCompilableIRMethodMatchResult match() { - return new NotCompilableIRMethodMatchResult(method, ruleCount); + return new NotCompilableIRMethodMatchResult(method, irRuleCount); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java index bea8dc3ab27..01ac82a1dc5 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java @@ -24,7 +24,7 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; import compiler.lib.ir_framework.Test; -import compiler.lib.ir_framework.driver.irmatching.MatchResult; +import compiler.lib.ir_framework.driver.irmatching.LeafMatchResult; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import java.lang.reflect.Method; @@ -37,14 +37,7 @@ import java.lang.reflect.Method; * @see NotCompilableIRMethod * @see Test */ -public class NotCompilableIRMethodMatchResult implements MatchResult { - private final Method method; - private final int failedIRRules; - - public NotCompilableIRMethodMatchResult(Method method, int failedIRRules) { - this.method = method; - this.failedIRRules = failedIRRules; - } +public record NotCompilableIRMethodMatchResult(Method method, int irRuleCount) implements LeafMatchResult { @Override public boolean fail() { @@ -53,7 +46,7 @@ public class NotCompilableIRMethodMatchResult implements MatchResult { @Override public void accept(MatchResultVisitor visitor) { - visitor.visitMethodNotCompilable(method, failedIRRules); + visitor.visitLeaf(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethod.java index c3737bc8a47..724df531a0f 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -38,11 +38,11 @@ import java.lang.reflect.Method; */ public class NotCompiledIRMethod implements IRMethodMatchable { private final Method method; - private final int ruleCount; + private final int irRuleCount; - public NotCompiledIRMethod(Method method, int ruleCount) { + public NotCompiledIRMethod(Method method, int irRuleCount) { this.method = method; - this.ruleCount = ruleCount; + this.irRuleCount = irRuleCount; } @Override @@ -55,6 +55,6 @@ public class NotCompiledIRMethod implements IRMethodMatchable { */ @Override public NotCompiledIRMethodMatchResult match() { - return new NotCompiledIRMethodMatchResult(method, ruleCount); + return new NotCompiledIRMethodMatchResult(method, irRuleCount); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethodMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethodMatchResult.java index 0f7bd576012..8c77fee8851 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethodMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompiledIRMethodMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -25,7 +25,7 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; import compiler.lib.ir_framework.Run; import compiler.lib.ir_framework.RunMode; -import compiler.lib.ir_framework.driver.irmatching.MatchResult; +import compiler.lib.ir_framework.driver.irmatching.LeafMatchResult; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import java.lang.reflect.Method; @@ -37,14 +37,7 @@ import java.lang.reflect.Method; * @see NotCompiledIRMethod * @see Run */ -public class NotCompiledIRMethodMatchResult implements MatchResult { - private final Method method; - private final int failedIRRules; - - public NotCompiledIRMethodMatchResult(Method method, int failedIRRules) { - this.method = method; - this.failedIRRules = failedIRRules; - } +public record NotCompiledIRMethodMatchResult(Method method, int irRuleCount) implements LeafMatchResult { @Override public boolean fail() { @@ -53,7 +46,7 @@ public class NotCompiledIRMethodMatchResult implements MatchResult { @Override public void accept(MatchResultVisitor visitor) { - visitor.visitMethodNotCompiled(method, failedIRRules); + visitor.visitLeaf(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/IRRuleMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/IRRuleMatchResult.java index c031764ea84..6af09a89f69 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/IRRuleMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/IRRuleMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -26,12 +26,10 @@ package compiler.lib.ir_framework.driver.irmatching.irrule; import compiler.lib.ir_framework.CompilePhase; import compiler.lib.ir_framework.IR; import compiler.lib.ir_framework.driver.irmatching.MatchResult; +import compiler.lib.ir_framework.driver.irmatching.SubResults; import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseIRRuleMatchResult; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; -import java.util.List; - /** * This class represents a match result of an {@link IRRule} (applied to all compile phases specified in * {@link IR#phase()}). The {@link CompilePhaseIRRuleMatchResult} are kept in the definition order of the compile phases @@ -39,26 +37,14 @@ import java.util.List; * * @see IRRule */ -public class IRRuleMatchResult implements MatchResult { - private final AcceptChildren acceptChildren; - private final boolean failed; - private final int irRuleId; - private final IR irAnno; - - public IRRuleMatchResult(int irRuleId, IR irAnno, List matchResults) { - this.acceptChildren = new AcceptChildren(matchResults); - this.failed = !matchResults.isEmpty(); - this.irRuleId = irRuleId; - this.irAnno = irAnno; - } - +public record IRRuleMatchResult(int irRuleId, IR irAnno, SubResults subResults) implements MatchResult { @Override public boolean fail() { - return failed; + return subResults.hasFailure(); } @Override public void accept(MatchResultVisitor visitor) { - visitor.visitIRRule(acceptChildren, irRuleId, irAnno); + visitor.visit(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/checkattribute/CheckAttributeMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/checkattribute/CheckAttributeMatchResult.java index 77febd8dcda..b637e08117d 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/checkattribute/CheckAttributeMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/checkattribute/CheckAttributeMatchResult.java @@ -25,11 +25,9 @@ package compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute; import compiler.lib.ir_framework.IR; import compiler.lib.ir_framework.driver.irmatching.MatchResult; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; +import compiler.lib.ir_framework.driver.irmatching.SubResults; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; -import java.util.List; - /** * This class represents a match result of a {@link CheckAttribute} (i.e. either from {@link IR#failOn} or * {@link IR#counts}). The type of check attribute is defined by {@link CheckAttributeType}. @@ -37,24 +35,15 @@ import java.util.List; * @see CheckAttribute * @see CheckAttributeType */ -public class CheckAttributeMatchResult implements MatchResult { - private final AcceptChildren acceptChildren; - private final boolean failed; - private final CheckAttributeType checkAttributeType; - - CheckAttributeMatchResult(CheckAttributeType checkAttributeType, List matchResults) { - this.acceptChildren = new AcceptChildren(matchResults); - this.failed = !matchResults.isEmpty(); - this.checkAttributeType = checkAttributeType; - } - +public record CheckAttributeMatchResult(CheckAttributeType checkAttributeType, + SubResults subResults) implements MatchResult { @Override public boolean fail() { - return failed; + return subResults.hasFailure(); } @Override public void accept(MatchResultVisitor visitor) { - visitor.visitCheckAttribute(acceptChildren, checkAttributeType); + visitor.visit(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/ConstraintFailure.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/ConstraintFailure.java index b775df7c439..c5249359e51 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/ConstraintFailure.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/ConstraintFailure.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,7 +23,7 @@ package compiler.lib.ir_framework.driver.irmatching.irrule.constraint; -import compiler.lib.ir_framework.driver.irmatching.MatchResult; +import compiler.lib.ir_framework.driver.irmatching.LeafMatchResult; import java.util.List; @@ -32,7 +32,7 @@ import java.util.List; * * @see Constraint */ -public interface ConstraintFailure extends MatchResult { +public interface ConstraintFailure extends LeafMatchResult { @Override default boolean fail() { return true; diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/CountsConstraintFailure.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/CountsConstraintFailure.java index 0a955f46585..d91bae452a8 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/CountsConstraintFailure.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/CountsConstraintFailure.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -39,6 +39,6 @@ public record CountsConstraintFailure(String nodeRegex, int constraintId, List comparison) implements ConstraintFailure { @Override public void accept(MatchResultVisitor visitor) { - visitor.visitCountsConstraint(this); + visitor.visitLeaf(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/FailOnConstraintFailure.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/FailOnConstraintFailure.java index bce7c418cb4..7f8cff3da5f 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/FailOnConstraintFailure.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/constraint/FailOnConstraintFailure.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -43,6 +43,6 @@ public record FailOnConstraintFailure(String nodeRegex, int constraintId, List matchResults) { - this.acceptChildren = new AcceptChildren(matchResults); - this.failed = !matchResults.isEmpty(); - this.compilePhase = compilePhase; - this.compilationOutput = compilationOutput; - } - +public record CompilePhaseIRRuleMatchResult(CompilePhase compilePhase, String compilationOutput, + SubResults subResults) implements MatchResult { @Override public boolean fail() { - return failed; + return subResults.hasFailure(); } @Override public void accept(MatchResultVisitor visitor) { - visitor.visitCompilePhaseIRRule(acceptChildren, compilePhase, compilationOutput); + visitor.visit(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/phase/CompilePhaseNoCompilationIRRuleMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/phase/CompilePhaseNoCompilationIRRuleMatchResult.java index def04032240..21302cb1d70 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/phase/CompilePhaseNoCompilationIRRuleMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irrule/phase/CompilePhaseNoCompilationIRRuleMatchResult.java @@ -24,7 +24,7 @@ package compiler.lib.ir_framework.driver.irmatching.irrule.phase; import compiler.lib.ir_framework.CompilePhase; -import compiler.lib.ir_framework.driver.irmatching.MatchResult; +import compiler.lib.ir_framework.driver.irmatching.LeafMatchResult; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; /** @@ -33,7 +33,7 @@ import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; * * @see CompilePhaseNoCompilationIRRule */ -public record CompilePhaseNoCompilationIRRuleMatchResult(CompilePhase compilePhase) implements MatchResult { +public record CompilePhaseNoCompilationIRRuleMatchResult(CompilePhase compilePhase) implements LeafMatchResult { @Override public boolean fail() { @@ -42,6 +42,6 @@ public record CompilePhaseNoCompilationIRRuleMatchResult(CompilePhase compilePha @Override public void accept(MatchResultVisitor visitor) { - visitor.visitNoCompilePhaseCompilation(compilePhase); + visitor.visitLeaf(this); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/CompilationOutputBuilder.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/CompilationOutputBuilder.java index 037da604f4c..87275851069 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/CompilationOutputBuilder.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/CompilationOutputBuilder.java @@ -24,13 +24,14 @@ package compiler.lib.ir_framework.driver.irmatching.report; import compiler.lib.ir_framework.CompilePhase; -import compiler.lib.ir_framework.IR; +import compiler.lib.ir_framework.driver.irmatching.TestClassMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseIRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseNoCompilationIRRuleMatchResult; import compiler.lib.ir_framework.shared.TestFrameworkException; import compiler.lib.ir_framework.driver.irmatching.MatchResult; -import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType; -import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure; -import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.FailOnConstraintFailure; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import java.lang.reflect.Method; @@ -59,8 +60,7 @@ public class CompilationOutputBuilder implements MatchResultVisitor { } @Override - public void visitTestClass(AcceptChildren acceptChildren) { - acceptChildren.accept(this); + public void leave(TestClassMatchResult matchResult) { StringBuilder builder = new StringBuilder(); builder.append("Compilation"); if (compilePhaseCount > 1) { @@ -77,16 +77,15 @@ public class CompilationOutputBuilder implements MatchResultVisitor { output.insert(0, builder); } - private String getTitleSeparator(int failedIRMethods) { - int failedMethodDashes = failedIRMethods > 1 ? digitCount(failedIRMethods) + 4 : 0; + private String getTitleSeparator(int failedIrMethodCount) { + int failedMethodDashes = failedIrMethodCount > 1 ? digitCount(failedIrMethodCount) + 4 : 0; int compilePhaseDashes = compilePhaseCount > 1 ? digitCount(compilePhaseCount) + 4 : 0; return "-".repeat(28 + compilePhaseDashes + failedMethodDashes); } @Override - public void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules) { - acceptChildren.accept(this); - appendIRMethodHeader(method); + public void leave(IRMethodMatchResult result) { + appendIRMethodHeader(result.method()); appendMatchedCompilationOutputOfPhases(); failedCompilePhases.clear(); } @@ -116,33 +115,32 @@ public class CompilationOutputBuilder implements MatchResultVisitor { } @Override - public void visitMethodNotCompiled(Method method, int failedIRRules) { - appendIRMethodHeader(method); + public void visitLeaf(NotCompiledIRMethodMatchResult result) { + appendIRMethodHeader(result.method()); compilePhaseCount++; // Count this as one phase output.append("").append(System.lineSeparator()); } @Override - public void visitMethodNotCompilable(Method method, int failedIRRules) { - throw new TestFrameworkException("Sould not reach here"); + public void visitLeaf(NotCompilableIRMethodMatchResult result) { + throw new TestFrameworkException("Should not reach here"); } + /** + * We directly override this method to stop visiting check attribute sub results. + */ @Override - public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) { - acceptChildren.accept(this); - } - - @Override - public void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput) { + public void visit(CompilePhaseIRRuleMatchResult result) { + CompilePhase compilePhase = result.compilePhase(); if (!failedCompilePhases.containsKey(compilePhase)) { - failedCompilePhases.put(compilePhase, compilationOutput); + failedCompilePhases.put(compilePhase, result.compilationOutput()); compilePhaseCount++; } - // No need to visit check attributes } @Override - public void visitNoCompilePhaseCompilation(CompilePhase compilePhase) { + public void visitLeaf(CompilePhaseNoCompilationIRRuleMatchResult result) { + CompilePhase compilePhase = result.compilePhase(); if (!failedCompilePhases.containsKey(compilePhase)) { failedCompilePhases.put(compilePhase, "> Phase \"" + compilePhase.getName() + "\":" + System.lineSeparator() + "" + @@ -151,15 +149,6 @@ public class CompilationOutputBuilder implements MatchResultVisitor { } } - @Override - public void visitCheckAttribute(AcceptChildren acceptChildren, CheckAttributeType checkAttributeType) {} - - @Override - public void visitFailOnConstraint(FailOnConstraintFailure failOnConstraintFailure) {} - - @Override - public void visitCountsConstraint(CountsConstraintFailure countsConstraintFailure) {} - public String build() { testClassMatchResult.accept(this); return output.toString(); diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailCountVisitor.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailCountVisitor.java index 9d1ea6fc408..e72ae507280 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailCountVisitor.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailCountVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,16 +23,12 @@ package compiler.lib.ir_framework.driver.irmatching.report; -import compiler.lib.ir_framework.CompilePhase; -import compiler.lib.ir_framework.IR; -import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType; -import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure; -import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.FailOnConstraintFailure; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.IRRuleMatchResult; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; -import java.lang.reflect.Method; - /** * Visitor to collect the number of IR method and IR rule failures. */ @@ -40,54 +36,36 @@ class FailCountVisitor implements MatchResultVisitor { private int irMethodCount; private int irRuleCount; - @Override - public void visitTestClass(AcceptChildren acceptChildren) { - acceptChildren.accept(this); - } @Override - public void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules) { + public void enter(IRMethodMatchResult result) { irMethodCount++; - acceptChildren.accept(this); } + /** + * We directly override this method to stop visiting compile phase IR rule sub results. + */ @Override - public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) { + public void visit(IRRuleMatchResult result) { irRuleCount++; - // Do not need to visit compile phase IR rules } @Override - public void visitMethodNotCompiled(Method method, int failedIRRules) { + public void visitLeaf(NotCompiledIRMethodMatchResult result) { irMethodCount++; - irRuleCount += failedIRRules; + irRuleCount += result.irRuleCount(); } @Override - public void visitMethodNotCompilable(Method method, int failedIRRules) { + public void visitLeaf(NotCompilableIRMethodMatchResult result) { irMethodCount++; } - public int getIrRuleCount() { + public int irRuleCount() { return irRuleCount; } - public int getIrMethodCount() { + public int irMethodCount() { return irMethodCount; } - - @Override - public void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput) {} - - @Override - public void visitNoCompilePhaseCompilation(CompilePhase compilePhase) {} - - @Override - public void visitCheckAttribute(AcceptChildren acceptChildren, CheckAttributeType checkAttributeType) {} - - @Override - public void visitFailOnConstraint(FailOnConstraintFailure failOnConstraintFailure) {} - - @Override - public void visitCountsConstraint(CountsConstraintFailure countsConstraintFailure) {} } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailureMessageBuilder.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailureMessageBuilder.java index f52c5f8fb5f..e4dd98959a0 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailureMessageBuilder.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailureMessageBuilder.java @@ -24,13 +24,19 @@ package compiler.lib.ir_framework.driver.irmatching.report; import compiler.lib.ir_framework.CompilePhase; -import compiler.lib.ir_framework.IR; +import compiler.lib.ir_framework.driver.irmatching.TestClassMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.IRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseIRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseNoCompilationIRRuleMatchResult; import compiler.lib.ir_framework.shared.TestFrameworkException; import compiler.lib.ir_framework.driver.irmatching.MatchResult; import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.FailOnConstraintFailure; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import java.lang.reflect.Method; @@ -50,11 +56,11 @@ public class FailureMessageBuilder implements MatchResultVisitor { } @Override - public void visitTestClass(AcceptChildren acceptChildren) { + public void enter(TestClassMatchResult result) { FailCountVisitor failCountVisitor = new FailCountVisitor(); testClassMatchResult.accept(failCountVisitor); - int failedMethodCount = failCountVisitor.getIrMethodCount(); - int failedIRRulesCount = failCountVisitor.getIrRuleCount(); + int failedMethodCount = failCountVisitor.irMethodCount(); + int failedIRRulesCount = failCountVisitor.irRuleCount(); msg.append("One or more @IR rules failed:") .append(System.lineSeparator()) .append(System.lineSeparator()) @@ -62,7 +68,6 @@ public class FailureMessageBuilder implements MatchResultVisitor { .append(")").append(System.lineSeparator()) .append(getTitleSeparator(failedMethodCount, failedIRRulesCount)) .append(System.lineSeparator()); - acceptChildren.accept(this); } private static String getTitleSeparator(int failedMethodCount, int failedIRRulesCount) { @@ -70,27 +75,13 @@ public class FailureMessageBuilder implements MatchResultVisitor { } @Override - public void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules) { - appendIRMethodHeader(method, failedIRRules); - acceptChildren.accept(this); - } - - private void appendIRMethodHeader(Method method, int failedIRRules) { - methodIndex++; - indentation = new Indentation(digitCount(methodIndex)); - if (methodIndex > 1) { - msg.append(System.lineSeparator()); - } - msg.append(methodIndex).append(") "); - msg.append("Method \"") - .append(method.getDeclaringClass().getTypeName()).append("::").append(method.getName()) - .append("\" - [Failed IR rules: ").append(failedIRRules).append("]:") - .append(System.lineSeparator()); + public void enter(IRMethodMatchResult result) { + appendIRMethodHeader(result.method(), result.subResults().failCount()); } @Override - public void visitMethodNotCompiled(Method method, int failedIRRules) { - appendIRMethodHeader(method, failedIRRules); + public void visitLeaf(NotCompiledIRMethodMatchResult result) { + appendIRMethodHeader(result.method(), result.irRuleCount()); indentation.add(); msg.append(indentation) .append("* Method was not compiled. Did you specify a @Run method in STANDALONE mode? In this case, make " + @@ -99,24 +90,57 @@ public class FailureMessageBuilder implements MatchResultVisitor { indentation.sub(); } - public void visitMethodNotCompilable(Method method, int failedIRRules) { - throw new TestFrameworkException("Sould not reach here"); + private void appendIRMethodHeader(Method method, int failedIrRuleCount) { + methodIndex++; + indentation = new Indentation(digitCount(methodIndex)); + if (methodIndex > 1) { + msg.append(System.lineSeparator()); + } + msg.append(methodIndex).append(") "); + msg.append("Method \"") + .append(method.getDeclaringClass().getTypeName()).append("::").append(method.getName()) + .append("\" - [Failed IR rules: ").append(failedIrRuleCount).append("]:") + .append(System.lineSeparator()); } @Override - public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) { + public void visitLeaf(NotCompilableIRMethodMatchResult result) { + throw new TestFrameworkException("Should not reach here"); + } + + @Override + public void enter(IRRuleMatchResult result) { indentation.add(); - msg.append(indentation).append("* @IR rule ").append(irRuleId).append(": \"") - .append(irAnno).append("\"").append(System.lineSeparator()); - acceptChildren.accept(this); + msg.append(indentation).append("* @IR rule ").append(result.irRuleId()).append(": \"") + .append(result.irAnno()).append("\"").append(System.lineSeparator()); + } + + @Override + public void leave(IRRuleMatchResult result) { indentation.sub(); } @Override - public void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput) { + public void enter(CompilePhaseIRRuleMatchResult result) { indentation.add(); - appendCompilePhaseIRRule(compilePhase); - acceptChildren.accept(this); + appendCompilePhaseIRRule(result.compilePhase()); + } + + @Override + public void leave(CompilePhaseIRRuleMatchResult result) { + indentation.sub(); + } + + @Override + public void visitLeaf(CompilePhaseNoCompilationIRRuleMatchResult result) { + indentation.add(); + appendCompilePhaseIRRule(result.compilePhase()); + indentation.add(); + msg.append(indentation) + .append("- NO compilation output found for this phase! Make sure this phase is emitted or remove it from ") + .append("the list of compile phases in the @IR rule to match on.") + .append(System.lineSeparator()); + indentation.sub(); indentation.sub(); } @@ -127,20 +151,8 @@ public class FailureMessageBuilder implements MatchResultVisitor { } @Override - public void visitNoCompilePhaseCompilation(CompilePhase compilePhase) { - indentation.add(); - appendCompilePhaseIRRule(compilePhase); - indentation.add(); - msg.append(indentation) - .append("- NO compilation output found for this phase! Make sure this phase is emitted or remove it from ") - .append("the list of compile phases in the @IR rule to match on.") - .append(System.lineSeparator()); - indentation.sub(); - indentation.sub(); - } - - @Override - public void visitCheckAttribute(AcceptChildren acceptChildren, CheckAttributeType checkAttributeType) { + public void enter(CheckAttributeMatchResult result) { + CheckAttributeType checkAttributeType = result.checkAttributeType(); indentation.add(); String checkAttributeFailureMsg; switch (checkAttributeType) { @@ -151,15 +163,18 @@ public class FailureMessageBuilder implements MatchResultVisitor { } msg.append(indentation).append("- ").append(checkAttributeFailureMsg) .append(":").append(System.lineSeparator()); - acceptChildren.accept(this); + } + + @Override + public void leave(CheckAttributeMatchResult result) { indentation.sub(); } @Override - public void visitFailOnConstraint(FailOnConstraintFailure matchResult) { + public void visitLeaf(FailOnConstraintFailure result) { indentation.add(); ConstraintFailureMessageBuilder constrainFailureMessageBuilder = - new ConstraintFailureMessageBuilder(matchResult, indentation); + new ConstraintFailureMessageBuilder(result, indentation); String failureMessage = constrainFailureMessageBuilder.buildConstraintHeader() + constrainFailureMessageBuilder.buildMatchedNodesMessage("Matched forbidden"); msg.append(failureMessage); @@ -167,9 +182,9 @@ public class FailureMessageBuilder implements MatchResultVisitor { } @Override - public void visitCountsConstraint(CountsConstraintFailure matchResult) { + public void visitLeaf(CountsConstraintFailure result) { indentation.add(); - msg.append(new CountsConstraintFailureMessageBuilder(matchResult, indentation).build()); + msg.append(new CountsConstraintFailureMessageBuilder(result, indentation).build()); indentation.sub(); } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/MatchResultVisitor.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/MatchResultVisitor.java index 8191cfd55c0..87073a27d0e 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/MatchResultVisitor.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/MatchResultVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,28 +23,133 @@ package compiler.lib.ir_framework.driver.irmatching.visitor; -import compiler.lib.ir_framework.CompilePhase; -import compiler.lib.ir_framework.IR; +import compiler.lib.ir_framework.driver.irmatching.LeafMatchResult; import compiler.lib.ir_framework.driver.irmatching.MatchResult; -import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType; +import compiler.lib.ir_framework.driver.irmatching.TestClassMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.IRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeMatchResult; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.FailOnConstraintFailure; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseIRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseNoCompilationIRRuleMatchResult; -import java.lang.reflect.Method; +import java.util.function.Consumer; /** * This interface specifies visit methods for each {@link MatchResult} class must be implemented a by a concrete visitor. + * + *

+ * There are two kinds of visits: + * + *

    + *
  1. + * {@link #visit} on {@link MatchResult}s that can have one or more sub results. This interface provides the following + * default implementation for them (directly override this method when you do not want to visit sub results later): + *
      + *
    1. + * {@link #enter}: First called to visit the current {@link MatchResult} before visiting sub results. Override + * this method to specify behavior at this stage. Afterward, the sub results will be visited. + * By default, this method does nothing. + *
    2. + *
    3. + * {@link #visitSubResults}: Called after {@link #enter} to visit the sub results. This should not be overridden. + *
    4. + *
    5. + * {@link #leave}: After visiting the sub results, this method is called to visit the current {@link MatchResult} + * again to do some post work. Override this method to specify behavior at this stage. + * By default, this method does nothing. + *
    6. + *
    + *
  2. + *
  3. + * {@link #visitLeaf} on {@link LeafMatchResult}s that do not have any sub results. This interface provides + * an empty default implementation. Override {@link #visitLeaf} to specify a different behavior. + *
  4. + *
*/ public interface MatchResultVisitor { - void visitTestClass(AcceptChildren acceptChildren); - void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules); - void visitMethodNotCompiled(Method method, int failedIRRules); - void visitMethodNotCompilable(Method method, int failedIRRules); - void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno); - void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput); - void visitNoCompilePhaseCompilation(CompilePhase compilePhase); - void visitCheckAttribute(AcceptChildren acceptChildren, CheckAttributeType checkAttributeType); - void visitFailOnConstraint(FailOnConstraintFailure failOnConstraintFailure); - void visitCountsConstraint(CountsConstraintFailure countsConstraintFailure); -} + /** + * Should a result be visited? By default, we only visit failing results. Override this method to change this behavior. + */ + default boolean shouldVisit(MatchResult result) { + return result.fail(); + } + + default void visit(TestClassMatchResult result) { + doVisit(result, this::enter, this::leave); + } + + default void enter(TestClassMatchResult result) {} + default void leave(TestClassMatchResult result) {} + + default void visit(IRMethodMatchResult result) { + doVisit(result, this::enter, this::leave); + } + + default void enter(IRMethodMatchResult result) {} + default void leave(IRMethodMatchResult result) {} + + default void visit(IRRuleMatchResult result) { + doVisit(result, this::enter, this::leave); + } + + default void enter(IRRuleMatchResult result) {} + default void leave(IRRuleMatchResult result) {} + + default void visit(CompilePhaseIRRuleMatchResult result) { + doVisit(result, this::enter, this::leave); + } + + default void enter(CompilePhaseIRRuleMatchResult result) {} + default void leave(CompilePhaseIRRuleMatchResult result) {} + + default void visit(CheckAttributeMatchResult result) { + doVisit(result, this::enter, this::leave); + } + + default void enter(CheckAttributeMatchResult result) {} + default void leave(CheckAttributeMatchResult result) {} + + /** + * Default visit when {@link #visit} is not overridden. + * + *

+ * Note: Do not override this method. + */ + default void doVisit(R result, Consumer enter, Consumer leave) { + if (!shouldVisit(result)) { + return; + } + enter.accept(result); + visitSubResults(result); + leave.accept(result); + } + + /** + * Visit children of {@code result}. This is called when {@link #visit} is not overridden. + * + *

+ * Note: Do not override this method. + */ + default void visitSubResults(MatchResult result) { + for (MatchResult subResult : result.subResults()) { + if (shouldVisit(subResult)) { + subResult.accept(this); + } + } + } + + /* + * Visit methods for LeafMatchResults without sub results. + */ + + default void visitLeaf(CompilePhaseNoCompilationIRRuleMatchResult result) {} + default void visitLeaf(NotCompiledIRMethodMatchResult result) {} + default void visitLeaf(NotCompilableIRMethodMatchResult result) {} + default void visitLeaf(FailOnConstraintFailure result) {} + default void visitLeaf(CountsConstraintFailure result) {} +} diff --git a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPhaseIRMatching.java b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPhaseIRMatching.java index 8bec7c03bfe..c95f749afdf 100644 --- a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPhaseIRMatching.java +++ b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPhaseIRMatching.java @@ -28,11 +28,16 @@ import compiler.lib.ir_framework.driver.FlagVMProcess; import compiler.lib.ir_framework.driver.TestVMProcess; import compiler.lib.ir_framework.driver.irmatching.MatchResult; import compiler.lib.ir_framework.driver.irmatching.Matchable; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethodMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.IRRuleMatchResult; import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure; import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.FailOnConstraintFailure; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseIRRuleMatchResult; +import compiler.lib.ir_framework.driver.irmatching.irrule.phase.CompilePhaseNoCompilationIRRuleMatchResult; import compiler.lib.ir_framework.driver.irmatching.parser.TestClassParser; -import compiler.lib.ir_framework.driver.irmatching.visitor.AcceptChildren; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; import jdk.test.lib.Asserts; @@ -406,59 +411,46 @@ class FailureBuilder implements MatchResultVisitor { } @Override - public void visitTestClass(AcceptChildren acceptChildren) { - acceptChildren.accept(this); + public void enter(IRMethodMatchResult result) { + methodName = result.method().getName(); } @Override - public void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules) { - methodName = method.getName(); - acceptChildren.accept(this); - } - - @Override - public void visitMethodNotCompiled(Method method, int failedIRRules) { - methodName = method.getName(); + public void visitLeaf(NotCompiledIRMethodMatchResult result) { + methodName = result.method().getName(); failures.add(new Failure(methodName, -1, CompilePhase.DEFAULT, CheckAttributeType.FAIL_ON, -1)); } @Override - public void visitMethodNotCompilable(Method method, int failedIRRules) { + public void visitLeaf(NotCompilableIRMethodMatchResult result) { throw new RuntimeException("No test should bailout from compilation"); } @Override - public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) { - ruleId = irRuleId; - acceptChildren.accept(this); + public void enter(IRRuleMatchResult result) { + ruleId = result.irRuleId(); } @Override - public void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput) { - this.compilePhase = compilePhase; - acceptChildren.accept(this); + public void enter(CompilePhaseIRRuleMatchResult result) { + this.compilePhase = result.compilePhase(); } @Override - public void visitNoCompilePhaseCompilation(CompilePhase compilePhase) { - failures.add(new Failure(methodName, ruleId, compilePhase, CheckAttributeType.FAIL_ON, -1)); + public void visitLeaf(CompilePhaseNoCompilationIRRuleMatchResult result) { + failures.add(new Failure(methodName, ruleId, result.compilePhase(), CheckAttributeType.FAIL_ON, -1)); } @Override - public void visitCheckAttribute(AcceptChildren acceptChildren, CheckAttributeType checkAttributeType) { - acceptChildren.accept(this); - } - - @Override - public void visitFailOnConstraint(FailOnConstraintFailure matchResult) { + public void visitLeaf(FailOnConstraintFailure result) { failures.add(new Failure(methodName, ruleId, compilePhase, CheckAttributeType.FAIL_ON, - matchResult.constraintId())); + result.constraintId())); } @Override - public void visitCountsConstraint(CountsConstraintFailure matchResult) { + public void visitLeaf(CountsConstraintFailure result) { failures.add(new Failure(methodName, ruleId, compilePhase, CheckAttributeType.COUNTS, - matchResult.constraintId())); + result.constraintId())); } }