1 /*
2 * Copyright (c) 2013, 2018, 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
25 package org.graalvm.compiler.hotspot.test;
26
27 import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
28 import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
29
30 import java.io.File;
31 import java.io.IOException;
32 import java.nio.file.Path;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.Enumeration;
37 import java.util.List;
38 import java.util.zip.ZipEntry;
39 import java.util.zip.ZipFile;
40
41 import org.graalvm.compiler.core.GraalCompilerOptions;
42 import org.graalvm.compiler.core.test.GraalCompilerTest;
43 import org.graalvm.compiler.test.SubprocessUtil;
44 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
45 import org.junit.Assert;
46 import org.junit.Test;
47
48 /**
49 * Tests support for dumping graphs and other info useful for debugging a compiler crash.
50 */
51 public class CompilationWrapperTest extends GraalCompilerTest {
52
53 /**
54 * Tests compilation requested by the VM.
55 */
56 @Test
57 public void testVMCompilation1() throws IOException, InterruptedException {
58 assumeManagementLibraryIsLoadable();
59 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
60 "-XX:+UseJVMCICompiler",
61 "-Dgraal.CompilationFailureAction=ExitVM",
62 "-Dgraal.CrashAt=TestProgram.*",
63 "-Xcomp",
64 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
65 TestProgram.class.getName()));
66 }
67
68 /**
69 * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
70 * {@code -Dgraal.CompilationFailureAction=ExitVM}.
71 */
72 @Test
135 retryingProbe,
136 adjustmentProbe
137 };
138 testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
139 "-XX:+UseJVMCICompiler",
140 "-Dgraal.CompilationFailureAction=Diagnose",
141 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
142 "-Dgraal.CrashAt=TestProgram.*",
143 "-Xcomp",
144 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
145 TestProgram.class.getName()));
146 }
147
148 /**
149 * Tests compilation requested by Truffle.
150 */
151 @Test
152 public void testTruffleCompilation1() throws IOException, InterruptedException {
153 assumeManagementLibraryIsLoadable();
154 testHelper(Collections.emptyList(),
155 Arrays.asList(
156 "-Dgraal.CompilationFailureAction=ExitVM",
157 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
158 "-Dgraal.CrashAt=root test1"),
159 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
160 }
161
162 /**
163 * Tests that TruffleCompilationExceptionsAreFatal works as expected.
164 */
165 @Test
166 public void testTruffleCompilation2() throws IOException, InterruptedException {
167 Probe[] probes = {
168 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
169 };
170 testHelper(Arrays.asList(probes),
171 Arrays.asList(
172 "-Dgraal.CompilationFailureAction=Silent",
173 "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
174 "-Dgraal.CrashAt=root test1"),
175 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
176 }
177
178 /**
179 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
180 */
181 @Test
182 public void testTruffleCompilation3() throws IOException, InterruptedException {
183 assumeManagementLibraryIsLoadable();
184 Probe[] probes = {
185 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
186 };
187 testHelper(Arrays.asList(probes),
188 Arrays.asList(
189 "-Dgraal.CompilationFailureAction=Silent",
190 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
191 "-Dgraal.CrashAt=root test1:PermanentBailout"),
192 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
193 }
194
195 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
196
197 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
198 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
199 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
200 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
201 vmArgs.remove("-esa");
202 vmArgs.remove("-ea");
203 vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
204 // Force output to a file even if there's a running IGV instance available.
205 vmArgs.add("-Dgraal.PrintGraphFile=true");
206 vmArgs.addAll(extraVmArgs);
207
208 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
209 if (VERBOSE) {
210 System.out.println(proc);
211 }
|
1 /*
2 * Copyright (c) 2013, 2019, 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
25 package org.graalvm.compiler.hotspot.test;
26
27 import static org.graalvm.compiler.test.SubprocessUtil.getPackageOpeningOptions;
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;
33 import java.nio.file.Path;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.Enumeration;
38 import java.util.List;
39 import java.util.zip.ZipEntry;
40 import java.util.zip.ZipFile;
41
42 import org.graalvm.compiler.core.GraalCompilerOptions;
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
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
61 /**
62 * Tests compilation requested by the VM.
63 */
64 @Test
65 public void testVMCompilation1() throws IOException, InterruptedException {
66 assumeManagementLibraryIsLoadable();
67 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
68 "-XX:+UseJVMCICompiler",
69 "-Dgraal.CompilationFailureAction=ExitVM",
70 "-Dgraal.CrashAt=TestProgram.*",
71 "-Xcomp",
72 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
73 TestProgram.class.getName()));
74 }
75
76 /**
77 * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
78 * {@code -Dgraal.CompilationFailureAction=ExitVM}.
79 */
80 @Test
143 retryingProbe,
144 adjustmentProbe
145 };
146 testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
147 "-XX:+UseJVMCICompiler",
148 "-Dgraal.CompilationFailureAction=Diagnose",
149 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
150 "-Dgraal.CrashAt=TestProgram.*",
151 "-Xcomp",
152 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
153 TestProgram.class.getName()));
154 }
155
156 /**
157 * Tests compilation requested by Truffle.
158 */
159 @Test
160 public void testTruffleCompilation1() throws IOException, InterruptedException {
161 assumeManagementLibraryIsLoadable();
162 testHelper(Collections.emptyList(),
163 join(getPackageOpeningOptions(),
164 Arrays.asList(
165 "-Dgraal.CompilationFailureAction=ExitVM",
166 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
167 "-Dgraal.CrashAt=root test1")),
168 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
169 }
170
171 /**
172 * Tests that TruffleCompilationExceptionsAreFatal works as expected.
173 */
174 @Test
175 public void testTruffleCompilation2() throws IOException, InterruptedException {
176 Probe[] probes = {
177 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
178 };
179 testHelper(Arrays.asList(probes),
180 join(getPackageOpeningOptions(),
181 Arrays.asList(
182 "-Dgraal.CompilationFailureAction=Silent",
183 "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
184 "-Dgraal.CrashAt=root test1")),
185 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
186 }
187
188 /**
189 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
190 */
191 @Test
192 public void testTruffleCompilation3() throws IOException, InterruptedException {
193 assumeManagementLibraryIsLoadable();
194 Probe[] probes = {
195 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
196 };
197 testHelper(Arrays.asList(probes),
198 join(getPackageOpeningOptions(),
199 Arrays.asList(
200 "-Dgraal.CompilationFailureAction=Silent",
201 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
202 "-Dgraal.CrashAt=root test1:PermanentBailout")),
203 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
204 }
205
206 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
207
208 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
209 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
210 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
211 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
212 vmArgs.remove("-esa");
213 vmArgs.remove("-ea");
214 vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
215 // Force output to a file even if there's a running IGV instance available.
216 vmArgs.add("-Dgraal.PrintGraphFile=true");
217 vmArgs.addAll(extraVmArgs);
218
219 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
220 if (VERBOSE) {
221 System.out.println(proc);
222 }
|