46680
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 2016, 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 |
package org.graalvm.compiler.hotspot.test;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
|
|
26 |
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
|
|
27 |
|
|
28 |
import java.io.File;
|
|
29 |
import java.io.IOException;
|
|
30 |
import java.util.ArrayList;
|
|
31 |
import java.util.Arrays;
|
46807
|
32 |
import java.util.Collections;
|
46680
|
33 |
import java.util.Enumeration;
|
|
34 |
import java.util.List;
|
|
35 |
import java.util.zip.ZipEntry;
|
|
36 |
import java.util.zip.ZipFile;
|
|
37 |
|
46807
|
38 |
import org.graalvm.compiler.core.GraalCompilerOptions;
|
46680
|
39 |
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
|
40 |
import org.graalvm.compiler.test.SubprocessUtil;
|
|
41 |
import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
|
|
42 |
import org.junit.Assert;
|
46807
|
43 |
import org.junit.Assume;
|
46680
|
44 |
import org.junit.Test;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Tests support for dumping graphs and other info useful for debugging a compiler crash.
|
|
48 |
*/
|
|
49 |
public class CompilationWrapperTest extends GraalCompilerTest {
|
46807
|
50 |
public CompilationWrapperTest() {
|
|
51 |
try {
|
|
52 |
Class.forName("java.lang.management.ManagementFactory");
|
|
53 |
} catch (ClassNotFoundException ex) {
|
|
54 |
Assume.assumeNoException("skip this test if there is no java.management JDK9 module around", ex);
|
|
55 |
}
|
|
56 |
}
|
46680
|
57 |
|
|
58 |
/**
|
|
59 |
* Tests compilation requested by the VM.
|
|
60 |
*/
|
|
61 |
@Test
|
|
62 |
public void testVMCompilation1() throws IOException, InterruptedException {
|
46807
|
63 |
testHelper(Collections.emptyList(), Arrays.asList("-XX:+BootstrapJVMCI",
|
46680
|
64 |
"-XX:+UseJVMCICompiler",
|
|
65 |
"-Dgraal.CompilationFailureAction=ExitVM",
|
|
66 |
"-Dgraal.CrashAt=Object.*,String.*",
|
|
67 |
"-version"));
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
|
|
72 |
* {@code -Dgraal.CompilationFailureAction=ExitVM}.
|
|
73 |
*/
|
|
74 |
@Test
|
|
75 |
public void testVMCompilation2() throws IOException, InterruptedException {
|
46807
|
76 |
testHelper(Collections.emptyList(), Arrays.asList("-XX:+BootstrapJVMCI",
|
46680
|
77 |
"-XX:+UseJVMCICompiler",
|
|
78 |
"-Dgraal.ExitVMOnException=true",
|
|
79 |
"-Dgraal.CrashAt=Object.*,String.*",
|
|
80 |
"-version"));
|
|
81 |
}
|
|
82 |
|
46807
|
83 |
static class Probe {
|
|
84 |
final String substring;
|
|
85 |
final int expectedOccurrences;
|
|
86 |
int actualOccurrences;
|
|
87 |
String lastMatchingLine;
|
|
88 |
|
|
89 |
Probe(String substring, int expectedOccurrences) {
|
|
90 |
this.substring = substring;
|
|
91 |
this.expectedOccurrences = expectedOccurrences;
|
|
92 |
}
|
|
93 |
|
|
94 |
boolean matches(String line) {
|
|
95 |
if (line.contains(substring)) {
|
|
96 |
actualOccurrences++;
|
|
97 |
lastMatchingLine = line;
|
|
98 |
return true;
|
|
99 |
}
|
|
100 |
return false;
|
|
101 |
}
|
|
102 |
|
|
103 |
String test() {
|
|
104 |
return expectedOccurrences == actualOccurrences ? null : String.format("expected %d, got %d occurrences", expectedOccurrences, actualOccurrences);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Tests {@link GraalCompilerOptions#MaxCompilationProblemsPerAction} in context of a
|
|
110 |
* compilation requested by the VM.
|
|
111 |
*/
|
|
112 |
@Test
|
|
113 |
public void testVMCompilation3() throws IOException, InterruptedException {
|
|
114 |
final int maxProblems = 4;
|
|
115 |
Probe[] probes = {
|
|
116 |
new Probe("To capture more information for diagnosing or reporting a compilation", maxProblems),
|
|
117 |
new Probe("Retrying compilation of", maxProblems),
|
|
118 |
new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1),
|
|
119 |
new Probe("adjusting CompilationFailureAction from Print to Silent", 1),
|
|
120 |
};
|
|
121 |
testHelper(Arrays.asList(probes), Arrays.asList("-XX:+BootstrapJVMCI",
|
|
122 |
"-XX:+UseJVMCICompiler",
|
|
123 |
"-Dgraal.CompilationFailureAction=Diagnose",
|
|
124 |
"-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
|
|
125 |
"-Dgraal.CrashAt=Object.*,String.*",
|
|
126 |
"-version"));
|
|
127 |
}
|
|
128 |
|
46680
|
129 |
/**
|
|
130 |
* Tests compilation requested by Truffle.
|
|
131 |
*/
|
|
132 |
@Test
|
|
133 |
public void testTruffleCompilation() throws IOException, InterruptedException {
|
46807
|
134 |
testHelper(Collections.emptyList(),
|
|
135 |
Arrays.asList(
|
|
136 |
"-Dgraal.CompilationFailureAction=ExitVM",
|
|
137 |
"-Dgraal.CrashAt=root test1"),
|
|
138 |
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
|
46680
|
139 |
}
|
|
140 |
|
46762
|
141 |
private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
|
|
142 |
|
46807
|
143 |
private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
|
46680
|
144 |
final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
|
|
145 |
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
|
|
146 |
vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
|
46807
|
147 |
vmArgs.remove("-esa");
|
|
148 |
vmArgs.remove("-ea");
|
46680
|
149 |
vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
|
|
150 |
// Force output to a file even if there's a running IGV instance available.
|
|
151 |
vmArgs.add("-Dgraal.PrintGraphFile=true");
|
|
152 |
vmArgs.addAll(extraVmArgs);
|
|
153 |
|
|
154 |
Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
|
46762
|
155 |
if (VERBOSE) {
|
|
156 |
System.out.println(proc);
|
|
157 |
}
|
46680
|
158 |
|
46807
|
159 |
List<Probe> probes = new ArrayList<>(initialProbes);
|
|
160 |
Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1);
|
|
161 |
probes.add(diagnosticProbe);
|
|
162 |
probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) {
|
|
163 |
@Override
|
|
164 |
String test() {
|
|
165 |
return actualOccurrences > 0 ? null : "expected at least 1 occurrence";
|
|
166 |
}
|
|
167 |
});
|
46680
|
168 |
|
|
169 |
for (String line : proc.output) {
|
46807
|
170 |
for (Probe probe : probes) {
|
|
171 |
if (probe.matches(line)) {
|
|
172 |
break;
|
46680
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
46807
|
176 |
for (Probe probe : probes) {
|
|
177 |
String error = probe.test();
|
|
178 |
if (error != null) {
|
|
179 |
Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc));
|
|
180 |
}
|
46680
|
181 |
}
|
|
182 |
|
46807
|
183 |
String diagnosticOutputZip = diagnosticProbe.lastMatchingLine.substring(diagnosticProbe.substring.length()).trim();
|
|
184 |
|
|
185 |
List<String> dumpPathEntries = Arrays.asList(dumpPath.list());
|
46680
|
186 |
|
|
187 |
File zip = new File(diagnosticOutputZip).getAbsoluteFile();
|
|
188 |
Assert.assertTrue(zip.toString(), zip.exists());
|
46807
|
189 |
Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName()));
|
46680
|
190 |
try {
|
|
191 |
int bgv = 0;
|
|
192 |
int cfg = 0;
|
|
193 |
ZipFile dd = new ZipFile(diagnosticOutputZip);
|
|
194 |
List<String> entries = new ArrayList<>();
|
|
195 |
for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) {
|
|
196 |
ZipEntry ze = e.nextElement();
|
|
197 |
String name = ze.getName();
|
|
198 |
entries.add(name);
|
|
199 |
if (name.endsWith(".bgv")) {
|
|
200 |
bgv++;
|
|
201 |
} else if (name.endsWith(".cfg")) {
|
|
202 |
cfg++;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
if (bgv == 0) {
|
|
206 |
Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc));
|
|
207 |
}
|
|
208 |
if (cfg == 0) {
|
|
209 |
Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries));
|
|
210 |
}
|
|
211 |
} finally {
|
|
212 |
zip.delete();
|
|
213 |
dumpPath.delete();
|
|
214 |
}
|
|
215 |
}
|
|
216 |
}
|