Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/IR.java
64507 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package compiler.lib.ir_framework;
25
26
import compiler.lib.ir_framework.driver.IRViolationException;
27
28
import java.lang.annotation.Repeatable;
29
import java.lang.annotation.Retention;
30
import java.lang.annotation.RetentionPolicy;
31
32
/**
33
* This annotation is used to define a constraint/rule/check on the resulting IR of a test method (method with
34
* {@link Test @Test} annotation). A test method can define multiple {@code @IR} rules.
35
* <p>
36
* There are two kinds of checks that can be specified:
37
* <ul>
38
* <li><p>{@link #failOn()}: Specify a list of (node) regexes that should not be matched on the {@code PrintIdeal} or
39
* {@code PrintOptoAssembly} output.</li>
40
* <li><p>{@link #counts()}: Specify a list of ({@code regex,count}) pairs: The (node) {@code regex} should be matched
41
* for the specified amount in {@code count} on the {@code PrintIdeal} or {@code PrintOptoAssembly} output.</li>
42
* </ul>
43
* An IR rule must specify either or both of these two checks. If one or both of the checks fails, an
44
* {@link IRViolationException} is thrown. A user can provide a custom regex string or specify any of the default node
45
* regexes defined in {@link IRNode}.
46
* <p>
47
* Sometimes, the shape of the resulting IR is changed by commonly used VM flags in such a way that an IR rule no longer
48
* applies. Generally, the framework does <b>not</b> apply any IR rules when any of the following flags are used:
49
* {@code -Xint, -XX:-UseCompiler, -XX:TieredStopAtLevel={1,2,3}, -DExcludeRandom=true, -DFlipC1C2=true}.
50
* Furthermore, a JTreg test could be run with additional VM and Javaoptions flags. The IR verification is <b>not</b>
51
* performed in this case if any of these JTreg flags is used that is not part of the whitelist specified by
52
* {@link TestFramework#JTREG_WHITELIST_FLAGS}.
53
* <p>
54
* For any other flag specified either by user code (e.g. {@link Scenario#Scenario(int, String...)},
55
* {@link TestFramework#runWithFlags(String...) etc.} or as part of the JTreg whitelist, IR verification is applied.
56
* To restrict the application of IR rules when certain flags are present that could change the IR, each {@code @IR}
57
* annotation can specify additional preconditions on the allowed test VM flags that must hold when an IR rule is applied.
58
* If the specified preconditions fail, then the framework does not apply the IR rule. These preconditions can be
59
* set with {@link #applyIf()}, {@link #applyIfNot()}, {@link #applyIfAnd()}, or {@link #applyIfOr()}.
60
* <p>
61
* Examples on how to write tests with IR rules can be found in {@link jdk.test.lib.hotspot.ir_framework.examples.IRExample}
62
* and also as part of the internal testing in {@link jdk.test.lib.hotspot.ir_framework.tests.TestIRMatching}.
63
*
64
* @see Test
65
* @see IRNode
66
*/
67
@Retention(RetentionPolicy.RUNTIME)
68
@Repeatable(IRs.class)
69
public @interface IR {
70
/**
71
* Define a list of (node) regexes. If any of these regexes are matched on the PrintIdeal or PrintOptoAssembly, the
72
* IR rule fails and an {@link IRViolationException} is thrown.
73
*/
74
String[] failOn() default {};
75
76
/**
77
* Define a list of ((node) regexes,count) string pairs: A regex to be matched on the PrintIdeal or PrintOptoAssembly
78
* is immediately followed by a number specifying how often the regex should be matched. The number can be proceeded
79
* by comparators ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is
80
* specified).
81
* <p>
82
* If any constraint on the number of regexes cannot be met, the IR rule fails and an
83
* {@link IRViolationException} is thrown.
84
*/
85
String[] counts() default {};
86
87
/**
88
* Define a single VM flag precondition which <i>must hold</i> when applying the IR rule. If the VM flag precondition
89
* fails, then the IR rule is not applied. This is useful if a commonly used flag alters the IR in such a way that an IR rule
90
* would fail.
91
* <p>
92
* The precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform
93
* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator
94
* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).
95
* <p>
96
* This is the inverse of {@link #applyIfNot()}. For multiple preconditions, use {@link #applyIfAnd()} or
97
* {@link #applyIfOr()} depending on the use case.
98
*/
99
String[] applyIf() default {};
100
101
/**
102
* Define a single VM flag precondition which <i>must <b>not</b> hold</i> when applying the IR rule. If, however,
103
* the VM flag precondition holds, then the IR rule is not applied. This could also be defined as <i>negative</i>
104
* precondition. This is useful if a commonly used flag alters the IR in such a way that an IR rule would fail.
105
* <p>
106
* The precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform
107
* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator
108
* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).
109
* <p>
110
* This is the inverse of {@link #applyIf()}. For multiple preconditions, use {@link #applyIfAnd()} or
111
* {@link #applyIfOr()} depending on the use case.
112
*/
113
String[] applyIfNot() default {};
114
115
/**
116
* Define a list of at least two VM flag precondition which <i><b>all</b> must hold</i> when applying the IR rule.
117
* If the one of the VM flag preconditions does not hold, then the IR rule is not applied. This is useful if
118
* commonly used flags alter the IR in such a way that an IR rule would fail. This can also be defined as conjunction
119
* of preconditions.
120
* <p>
121
* A precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform
122
* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator
123
* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).
124
* <p>
125
* Use {@link #applyIfOr()} for disjunction and for single precondition constraints use {@link #applyIf()} or
126
* {@link #applyIfNot()} depending on the use case.
127
*/
128
String[] applyIfAnd() default {};
129
130
/**
131
* Define a list of at least two VM flag precondition from which <i><b>at least one</b> must hold</i> when applying
132
* the IR rule. If none of the VM flag preconditions holds, then the IR rule is not applied. This is useful if
133
* commonly used flags alter the IR in such a way that an IR rule would fail. This can also be defined as disjunction
134
* of preconditions.
135
* <p>
136
* A precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform
137
* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator
138
* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).
139
* <p>
140
* Use {@link #applyIfAnd()} for conjunction and for single precondition constraints use {@link #applyIf()} or
141
* {@link #applyIfNot()} depending on the use case.
142
*/
143
String[] applyIfOr() default {};
144
}
145
146