|
28 | 28 | * @summary Testing that ciReplay inlining does not fail with unresolved signature classes.
|
29 | 29 | * @requires vm.flightRecorder != true & vm.compMode != "Xint" & vm.compMode != "Xcomp" & vm.debug == true & vm.compiler2.enabled
|
30 | 30 | * @modules java.base/jdk.internal.misc
|
31 |
| - * @build sun.hotspot.WhiteBox |
32 |
| - * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox |
33 |
| - * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
34 |
| - * compiler.ciReplay.TestInliningProtectionDomain |
| 31 | + * @run driver compiler.ciReplay.TestInliningProtectionDomain |
35 | 32 | */
|
36 | 33 |
|
37 | 34 | package compiler.ciReplay;
|
38 | 35 |
|
39 | 36 | import jdk.test.lib.Asserts;
|
40 | 37 |
|
41 |
| -import java.io.IOException; |
42 |
| -import java.nio.file.Files; |
43 |
| -import java.nio.file.Paths; |
44 |
| -import java.util.ArrayList; |
45 | 38 | import java.util.List;
|
46 |
| -import java.util.regex.Matcher; |
47 |
| -import java.util.regex.Pattern; |
48 | 39 |
|
49 |
| -public class TestInliningProtectionDomain extends DumpReplayBase { |
50 |
| - public static final String LOG_FILE_NORMAL = "hotspot_normal.log"; |
51 |
| - public static final String LOG_FILE_REPLAY = "hotspot_replay.log"; |
52 |
| - private final String[] commandLineReplay; |
53 |
| - |
54 |
| - private final String className; |
| 40 | +public class TestInliningProtectionDomain extends InliningBase { |
55 | 41 |
|
56 | 42 | public static void main(String[] args) {
|
57 |
| - new TestInliningProtectionDomain("ProtectionDomainTestCompiledBefore", true); |
58 |
| - new TestInliningProtectionDomain("ProtectionDomainTestNoOtherCompilationPublic", false); |
59 |
| - new TestInliningProtectionDomain("ProtectionDomainTestNoOtherCompilationPrivate", false); |
60 |
| - new TestInliningProtectionDomain("ProtectionDomainTestNoOtherCompilationPrivateString", false); |
| 43 | + new TestInliningProtectionDomain(ProtectionDomainTestCompiledBefore.class, true); |
| 44 | + new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPublic.class, false); |
| 45 | + new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPrivate.class, false); |
| 46 | + new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPrivateString.class, false); |
61 | 47 | }
|
62 | 48 |
|
63 |
| - public TestInliningProtectionDomain(String className, boolean compileBar) { |
64 |
| - this.className = className; |
65 |
| - List<String> commandLineNormal = new ArrayList<>(List.of("-XX:LogFile=" + LOG_FILE_NORMAL + "", "-XX:+LogCompilation", "-XX:-TieredCompilation", |
66 |
| - "-XX:CompileCommand=exclude," + getTestClass() + "::main", |
67 |
| - "-XX:CompileCommand=option," + getTestClass() + "::test,bool,PrintInlining,true")); |
| 49 | + public TestInliningProtectionDomain(Class<?> testClass, boolean compileBar) { |
| 50 | + super(testClass); |
68 | 51 | if (compileBar) {
|
69 |
| - commandLineNormal.add("-XX:CompileCommand=compileonly," + getTestClass() + "::bar"); |
| 52 | + commandLineNormal.add("-XX:CompileCommand=compileonly," + testClass.getName() + "::bar"); |
70 | 53 | }
|
71 |
| - commandLineReplay = new String[] |
72 |
| - {"-XX:LogFile=" + LOG_FILE_REPLAY + "", "-XX:+LogCompilation", |
73 |
| - "-XX:CompileCommand=option," + getTestClass() + "::test,bool,PrintInlining,true"}; |
74 |
| - runTest(commandLineNormal.toArray(new String[0])); |
| 54 | + runTest(); |
75 | 55 | }
|
76 | 56 |
|
77 | 57 | @Override
|
78 | 58 | public void testAction() {
|
79 | 59 | positiveTest(commandLineReplay);
|
80 |
| - String klass = "compiler.ciReplay." + className; |
81 |
| - String entryString = klass + " " + "test"; |
82 |
| - boolean inlineFails = className.equals("ProtectionDomainTestNoOtherCompilationPrivate"); |
| 60 | + String entryString = getTestClass() + " " + "test"; |
| 61 | + boolean inlineFails = testClass == ProtectionDomainTestNoOtherCompilationPrivate.class; |
83 | 62 | int inlineeCount = inlineFails ? 1 : 5;
|
84 | 63 |
|
85 |
| - List<Entry> inlineesNormal = parseLogFile(LOG_FILE_NORMAL, entryString, "compile_id='" + getCompileIdFromFile(getReplayFileName()), inlineeCount); |
86 |
| - List<Entry> inlineesReplay = parseLogFile(LOG_FILE_REPLAY, entryString, "test ()V", inlineeCount); |
| 64 | + List<InlineEntry> inlineesNormal = parseLogFile(LOG_FILE_NORMAL, entryString, "compile_id='" + getCompileIdFromFile(getReplayFileName()), inlineeCount); |
| 65 | + List<InlineEntry> inlineesReplay = parseLogFile(LOG_FILE_REPLAY, entryString, "test ()V", inlineeCount); |
87 | 66 | verifyLists(inlineesNormal, inlineesReplay, inlineeCount);
|
88 | 67 |
|
89 | 68 | if (inlineFails) {
|
90 |
| - Asserts.assertTrue(compare(inlineesNormal.get(0), "compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", |
91 |
| - "bar", inlineesNormal.get(0).isUnloadedSignatureClasses())); |
92 |
| - Asserts.assertTrue(compare(inlineesReplay.get(0), "compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", |
93 |
| - "bar", inlineesReplay.get(0).isDisallowedByReplay())); |
| 69 | + Asserts.assertTrue(inlineesNormal.get(0).compare("compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", "bar", inlineesNormal.get(0).isUnloadedSignatureClasses())); |
| 70 | + Asserts.assertTrue(inlineesReplay.get(0).compare("compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", "bar", inlineesReplay.get(0).isDisallowedByReplay())); |
94 | 71 | } else {
|
95 |
| - Asserts.assertTrue(compare(inlineesNormal.get(4), "compiler.ciReplay.InliningBar", "bar2", inlineesNormal.get(4).isNormalInline())); |
96 |
| - Asserts.assertTrue(compare(inlineesReplay.get(4), "compiler.ciReplay.InliningBar", "bar2", inlineesReplay.get(4).isForcedByReplay())); |
97 |
| - } |
98 |
| - remove(LOG_FILE_NORMAL); |
99 |
| - remove(LOG_FILE_REPLAY); |
100 |
| - } |
101 |
| - |
102 |
| - private void verifyLists(List<Entry> inlineesNormal, List<Entry> inlineesReplay, int expectedSize) { |
103 |
| - if (!inlineesNormal.equals(inlineesReplay)) { |
104 |
| - System.err.println("Normal entries:"); |
105 |
| - inlineesNormal.forEach(System.err::println); |
106 |
| - System.err.println("Replay entries:"); |
107 |
| - inlineesReplay.forEach(System.err::println); |
108 |
| - Asserts.fail("different inlining decision in normal run vs. replay run"); |
109 |
| - } |
110 |
| - Asserts.assertEQ(expectedSize, inlineesNormal.size(), "unexpected number of inlinees found"); |
111 |
| - } |
112 |
| - |
113 |
| - public static boolean compare(Entry e, String klass, String method, boolean kind) { |
114 |
| - return e.klass.equals(klass) && e.method.equals(method) && kind; |
115 |
| - } |
116 |
| - |
117 |
| - public static List<Entry> parseLogFile(String logFile, String rootMethod, String nmethodMatch, int inlineeCount) { |
118 |
| - String nmethodStart = "<nmethod"; |
119 |
| - List<Entry> inlinees = new ArrayList<>(); |
120 |
| - int foundLines = 0; |
121 |
| - try (var br = Files.newBufferedReader(Paths.get(logFile))) { |
122 |
| - String line; |
123 |
| - boolean nmethodLine = false; |
124 |
| - boolean inlinineLine = false; |
125 |
| - while ((line = br.readLine()) != null) { |
126 |
| - if (nmethodLine) { |
127 |
| - // Ignore other entries which could be in between nmethod entry and inlining statements |
128 |
| - if (line.startsWith(" ")) { |
129 |
| - inlinineLine = true; |
130 |
| - Pattern p = Pattern.compile("(\\S+)::(\\S+).*bytes\\)\s+(.*)"); |
131 |
| - Matcher matcher = p.matcher(line); |
132 |
| - Asserts.assertTrue(matcher.find(), "must find inlinee method"); |
133 |
| - inlinees.add(new Entry(matcher.group(1), matcher.group(2), matcher.group(3).trim())); |
134 |
| - foundLines++; |
135 |
| - } else if (inlinineLine) { |
136 |
| - Asserts.assertEQ(foundLines, inlineeCount, "did not find all inlinees"); |
137 |
| - return inlinees; |
138 |
| - } |
139 |
| - } else { |
140 |
| - nmethodLine = line.startsWith(nmethodStart) && line.contains(nmethodMatch); |
141 |
| - if (nmethodLine) { |
142 |
| - Asserts.assertTrue(line.contains(rootMethod), "should only dump inline information for " + rootMethod); |
143 |
| - } |
144 |
| - } |
145 |
| - } |
146 |
| - } catch (IOException e) { |
147 |
| - throw new Error("Failed to read " + logFile + " data: " + e, e); |
148 |
| - } |
149 |
| - Asserts.fail("Should have found inlinees"); |
150 |
| - return inlinees; |
151 |
| - } |
152 |
| - |
153 |
| - |
154 |
| - @Override |
155 |
| - public String getTestClass() { |
156 |
| - return "compiler.ciReplay." + className; |
157 |
| - } |
158 |
| - |
159 |
| - static class Entry { |
160 |
| - String klass; |
161 |
| - String method; |
162 |
| - String reason; |
163 |
| - |
164 |
| - public Entry(String klass, String method, String reason) { |
165 |
| - this.klass = klass; |
166 |
| - this.method = method; |
167 |
| - this.reason = reason; |
168 |
| - } |
169 |
| - |
170 |
| - public boolean isNormalInline() { |
171 |
| - return reason.equals("inline (hot)"); |
172 |
| - } |
173 |
| - |
174 |
| - public boolean isForcedByReplay() { |
175 |
| - return reason.equals("force inline by ciReplay"); |
176 |
| - } |
177 |
| - |
178 |
| - public boolean isDisallowedByReplay() { |
179 |
| - return reason.equals("disallowed by ciReplay"); |
180 |
| - } |
181 |
| - |
182 |
| - public boolean isUnloadedSignatureClasses() { |
183 |
| - return reason.equals("unloaded signature classes"); |
184 |
| - } |
185 |
| - |
186 |
| - @Override |
187 |
| - public boolean equals(Object other) { |
188 |
| - if (other == this) { |
189 |
| - return true; |
190 |
| - } |
191 |
| - |
192 |
| - if (!(other instanceof Entry)) { |
193 |
| - return false; |
194 |
| - } |
195 |
| - |
196 |
| - Entry e = (Entry)other; |
197 |
| - return klass.equals(e.klass) && method.equals(e.method); |
| 72 | + Asserts.assertTrue(inlineesNormal.get(4).compare("compiler.ciReplay.InliningBar", "bar2", inlineesNormal.get(4).isNormalInline())); |
| 73 | + Asserts.assertTrue(inlineesReplay.get(4).compare("compiler.ciReplay.InliningBar", "bar2", inlineesReplay.get(4).isForcedByReplay())); |
198 | 74 | }
|
199 | 75 | }
|
200 | 76 | }
|
|
0 commit comments