46680
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
46680
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
46680
|
25 |
package org.graalvm.compiler.hotspot.test;
|
|
26 |
|
58299
|
27 |
import static org.graalvm.compiler.test.SubprocessUtil.getPackageOpeningOptions;
|
46680
|
28 |
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
|
|
29 |
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
|
|
30 |
|
|
31 |
import java.io.File;
|
|
32 |
import java.io.IOException;
|
57537
|
33 |
import java.nio.file.Path;
|
46680
|
34 |
import java.util.ArrayList;
|
|
35 |
import java.util.Arrays;
|
46807
|
36 |
import java.util.Collections;
|
46680
|
37 |
import java.util.Enumeration;
|
|
38 |
import java.util.List;
|
|
39 |
import java.util.zip.ZipEntry;
|
|
40 |
import java.util.zip.ZipFile;
|
|
41 |
|
46807
|
42 |
import org.graalvm.compiler.core.GraalCompilerOptions;
|
46680
|
43 |
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
|
44 |
import org.graalvm.compiler.test.SubprocessUtil;
|
|
45 |
import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
|
|
46 |
import org.junit.Assert;
|
|
47 |
import org.junit.Test;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Tests support for dumping graphs and other info useful for debugging a compiler crash.
|
|
51 |
*/
|
|
52 |
public class CompilationWrapperTest extends GraalCompilerTest {
|
|
53 |
|
58299
|
54 |
private static List<String> join(List<String> l1, List<String> l2) {
|
|
55 |
ArrayList<String> result = new ArrayList<>(l1.size() + l2.size());
|
|
56 |
result.addAll(l1);
|
|
57 |
result.addAll(l2);
|
|
58 |
return result;
|
|
59 |
}
|
|
60 |
|
46680
|
61 |
/**
|
|
62 |
* Tests compilation requested by the VM.
|
|
63 |
*/
|
|
64 |
@Test
|
|
65 |
public void testVMCompilation1() throws IOException, InterruptedException {
|
52578
|
66 |
assumeManagementLibraryIsLoadable();
|
51736
|
67 |
testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
|
46680
|
68 |
"-XX:+UseJVMCICompiler",
|
|
69 |
"-Dgraal.CompilationFailureAction=ExitVM",
|
51736
|
70 |
"-Dgraal.CrashAt=TestProgram.*",
|
|
71 |
"-Xcomp",
|
|
72 |
"-XX:CompileCommand=compileonly,*/TestProgram.print*",
|
|
73 |
TestProgram.class.getName()));
|
46680
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
|
|
78 |
* {@code -Dgraal.CompilationFailureAction=ExitVM}.
|
|
79 |
*/
|
|
80 |
@Test
|
|
81 |
public void testVMCompilation2() throws IOException, InterruptedException {
|
52578
|
82 |
assumeManagementLibraryIsLoadable();
|
51736
|
83 |
testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
|
46680
|
84 |
"-XX:+UseJVMCICompiler",
|
|
85 |
"-Dgraal.ExitVMOnException=true",
|
51736
|
86 |
"-Dgraal.CrashAt=TestProgram.*",
|
|
87 |
"-Xcomp",
|
|
88 |
"-XX:CompileCommand=compileonly,*/TestProgram.print*",
|
|
89 |
TestProgram.class.getName()));
|
46680
|
90 |
}
|
|
91 |
|
46807
|
92 |
static class Probe {
|
|
93 |
final String substring;
|
|
94 |
final int expectedOccurrences;
|
|
95 |
int actualOccurrences;
|
|
96 |
String lastMatchingLine;
|
|
97 |
|
|
98 |
Probe(String substring, int expectedOccurrences) {
|
|
99 |
this.substring = substring;
|
|
100 |
this.expectedOccurrences = expectedOccurrences;
|
|
101 |
}
|
|
102 |
|
|
103 |
boolean matches(String line) {
|
|
104 |
if (line.contains(substring)) {
|
|
105 |
actualOccurrences++;
|
|
106 |
lastMatchingLine = line;
|
|
107 |
return true;
|
|
108 |
}
|
|
109 |
return false;
|
|
110 |
}
|
|
111 |
|
|
112 |
String test() {
|
|
113 |
return expectedOccurrences == actualOccurrences ? null : String.format("expected %d, got %d occurrences", expectedOccurrences, actualOccurrences);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
/**
|
|
118 |
* Tests {@link GraalCompilerOptions#MaxCompilationProblemsPerAction} in context of a
|
|
119 |
* compilation requested by the VM.
|
|
120 |
*/
|
|
121 |
@Test
|
|
122 |
public void testVMCompilation3() throws IOException, InterruptedException {
|
52578
|
123 |
assumeManagementLibraryIsLoadable();
|
51736
|
124 |
final int maxProblems = 2;
|
59095
|
125 |
Probe failurePatternProbe = new Probe("[[[Graal compilation failure]]]", maxProblems) {
|
|
126 |
@Override
|
|
127 |
String test() {
|
|
128 |
return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
|
|
129 |
}
|
|
130 |
};
|
51736
|
131 |
Probe retryingProbe = new Probe("Retrying compilation of", maxProblems) {
|
|
132 |
@Override
|
|
133 |
String test() {
|
|
134 |
return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
|
|
135 |
}
|
|
136 |
};
|
|
137 |
Probe adjustmentProbe = new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1) {
|
|
138 |
@Override
|
|
139 |
String test() {
|
|
140 |
if (retryingProbe.actualOccurrences >= maxProblems) {
|
|
141 |
if (actualOccurrences == 0) {
|
|
142 |
return "expected at least one occurrence";
|
|
143 |
}
|
|
144 |
}
|
|
145 |
return null;
|
|
146 |
}
|
|
147 |
};
|
46807
|
148 |
Probe[] probes = {
|
59095
|
149 |
failurePatternProbe,
|
51736
|
150 |
retryingProbe,
|
|
151 |
adjustmentProbe
|
46807
|
152 |
};
|
51736
|
153 |
testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
|
46807
|
154 |
"-XX:+UseJVMCICompiler",
|
|
155 |
"-Dgraal.CompilationFailureAction=Diagnose",
|
|
156 |
"-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
|
51736
|
157 |
"-Dgraal.CrashAt=TestProgram.*",
|
|
158 |
"-Xcomp",
|
|
159 |
"-XX:CompileCommand=compileonly,*/TestProgram.print*",
|
|
160 |
TestProgram.class.getName()));
|
46807
|
161 |
}
|
|
162 |
|
46680
|
163 |
/**
|
|
164 |
* Tests compilation requested by Truffle.
|
|
165 |
*/
|
|
166 |
@Test
|
47798
|
167 |
public void testTruffleCompilation1() throws IOException, InterruptedException {
|
52578
|
168 |
assumeManagementLibraryIsLoadable();
|
46807
|
169 |
testHelper(Collections.emptyList(),
|
58299
|
170 |
join(getPackageOpeningOptions(),
|
|
171 |
Arrays.asList(
|
|
172 |
"-Dgraal.CompilationFailureAction=ExitVM",
|
|
173 |
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
|
|
174 |
"-Dgraal.CrashAt=root test1")),
|
46807
|
175 |
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
|
46680
|
176 |
}
|
|
177 |
|
47798
|
178 |
/**
|
|
179 |
* Tests that TruffleCompilationExceptionsAreFatal works as expected.
|
|
180 |
*/
|
|
181 |
@Test
|
|
182 |
public void testTruffleCompilation2() throws IOException, InterruptedException {
|
|
183 |
Probe[] probes = {
|
|
184 |
new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
|
|
185 |
};
|
|
186 |
testHelper(Arrays.asList(probes),
|
58299
|
187 |
join(getPackageOpeningOptions(),
|
|
188 |
Arrays.asList(
|
|
189 |
"-Dgraal.CompilationFailureAction=Silent",
|
|
190 |
"-Dgraal.TruffleCompilationExceptionsAreFatal=true",
|
|
191 |
"-Dgraal.CrashAt=root test1")),
|
47798
|
192 |
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
|
|
193 |
}
|
|
194 |
|
49873
|
195 |
/**
|
|
196 |
* Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
|
|
197 |
*/
|
|
198 |
@Test
|
|
199 |
public void testTruffleCompilation3() throws IOException, InterruptedException {
|
52578
|
200 |
assumeManagementLibraryIsLoadable();
|
49873
|
201 |
Probe[] probes = {
|
|
202 |
new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
|
|
203 |
};
|
|
204 |
testHelper(Arrays.asList(probes),
|
58299
|
205 |
join(getPackageOpeningOptions(),
|
|
206 |
Arrays.asList(
|
|
207 |
"-Dgraal.CompilationFailureAction=Silent",
|
|
208 |
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
|
|
209 |
"-Dgraal.CrashAt=root test1:PermanentBailout")),
|
49873
|
210 |
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
|
|
211 |
}
|
|
212 |
|
46762
|
213 |
private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
|
|
214 |
|
46807
|
215 |
private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
|
46680
|
216 |
final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
|
|
217 |
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
|
|
218 |
vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
|
46807
|
219 |
vmArgs.remove("-esa");
|
|
220 |
vmArgs.remove("-ea");
|
46680
|
221 |
vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
|
|
222 |
// Force output to a file even if there's a running IGV instance available.
|
|
223 |
vmArgs.add("-Dgraal.PrintGraphFile=true");
|
|
224 |
vmArgs.addAll(extraVmArgs);
|
|
225 |
|
|
226 |
Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
|
46762
|
227 |
if (VERBOSE) {
|
|
228 |
System.out.println(proc);
|
|
229 |
}
|
46680
|
230 |
|
57537
|
231 |
try {
|
|
232 |
List<Probe> probes = new ArrayList<>(initialProbes);
|
|
233 |
Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1);
|
47798
|
234 |
probes.add(diagnosticProbe);
|
|
235 |
probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) {
|
|
236 |
@Override
|
|
237 |
String test() {
|
|
238 |
return actualOccurrences > 0 ? null : "expected at least 1 occurrence";
|
|
239 |
}
|
|
240 |
});
|
46680
|
241 |
|
57537
|
242 |
for (String line : proc.output) {
|
|
243 |
for (Probe probe : probes) {
|
|
244 |
if (probe.matches(line)) {
|
|
245 |
break;
|
|
246 |
}
|
46680
|
247 |
}
|
|
248 |
}
|
57537
|
249 |
for (Probe probe : probes) {
|
|
250 |
String error = probe.test();
|
|
251 |
if (error != null) {
|
|
252 |
Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc));
|
|
253 |
}
|
46807
|
254 |
}
|
47798
|
255 |
String line = diagnosticProbe.lastMatchingLine;
|
|
256 |
int substringStart = line.indexOf(diagnosticProbe.substring);
|
|
257 |
int substringLength = diagnosticProbe.substring.length();
|
|
258 |
String diagnosticOutputZip = line.substring(substringStart + substringLength).trim();
|
46680
|
259 |
|
47798
|
260 |
List<String> dumpPathEntries = Arrays.asList(dumpPath.list());
|
46680
|
261 |
|
47798
|
262 |
File zip = new File(diagnosticOutputZip).getAbsoluteFile();
|
|
263 |
Assert.assertTrue(zip.toString(), zip.exists());
|
|
264 |
Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName()));
|
|
265 |
try {
|
50330
|
266 |
int bgvOrCfgFiles = 0;
|
47798
|
267 |
ZipFile dd = new ZipFile(diagnosticOutputZip);
|
|
268 |
List<String> entries = new ArrayList<>();
|
|
269 |
for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) {
|
|
270 |
ZipEntry ze = e.nextElement();
|
|
271 |
String name = ze.getName();
|
|
272 |
entries.add(name);
|
50330
|
273 |
if (name.endsWith(".bgv") || name.endsWith(".cfg")) {
|
|
274 |
bgvOrCfgFiles++;
|
47798
|
275 |
}
|
46680
|
276 |
}
|
50330
|
277 |
if (bgvOrCfgFiles == 0) {
|
|
278 |
Assert.fail(String.format("Expected at least one .bgv or .cfg file in %s: %s%n%s", diagnosticOutputZip, entries, proc));
|
47798
|
279 |
}
|
|
280 |
} finally {
|
|
281 |
zip.delete();
|
46680
|
282 |
}
|
57537
|
283 |
} finally {
|
|
284 |
Path directory = dumpPath.toPath();
|
|
285 |
removeDirectory(directory);
|
46680
|
286 |
}
|
|
287 |
}
|
|
288 |
}
|
51736
|
289 |
|
|
290 |
class TestProgram {
|
|
291 |
public static void main(String[] args) {
|
|
292 |
printHello1();
|
|
293 |
printWorld1();
|
|
294 |
printHello2();
|
|
295 |
printWorld2();
|
|
296 |
printHello3();
|
|
297 |
printWorld3();
|
|
298 |
}
|
|
299 |
|
|
300 |
private static void printHello1() {
|
|
301 |
System.out.println("Hello1");
|
|
302 |
}
|
|
303 |
|
|
304 |
private static void printWorld1() {
|
|
305 |
System.out.println("World1");
|
|
306 |
}
|
|
307 |
|
|
308 |
private static void printHello2() {
|
|
309 |
System.out.println("Hello2");
|
|
310 |
}
|
|
311 |
|
|
312 |
private static void printWorld2() {
|
|
313 |
System.out.println("World2");
|
|
314 |
}
|
|
315 |
|
|
316 |
private static void printHello3() {
|
|
317 |
System.out.println("Hello3");
|
|
318 |
}
|
|
319 |
|
|
320 |
private static void printWorld3() {
|
|
321 |
System.out.println("World3");
|
|
322 |
}
|
|
323 |
}
|