37 import java.util.zip.ZipEntry;
38 import java.util.zip.ZipFile;
39
40 import org.graalvm.compiler.core.GraalCompilerOptions;
41 import org.graalvm.compiler.core.test.GraalCompilerTest;
42 import org.graalvm.compiler.test.SubprocessUtil;
43 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
44 import org.junit.Assert;
45 import org.junit.Test;
46
47 /**
48 * Tests support for dumping graphs and other info useful for debugging a compiler crash.
49 */
50 public class CompilationWrapperTest extends GraalCompilerTest {
51
52 /**
53 * Tests compilation requested by the VM.
54 */
55 @Test
56 public void testVMCompilation1() throws IOException, InterruptedException {
57 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
58 "-XX:+UseJVMCICompiler",
59 "-Dgraal.CompilationFailureAction=ExitVM",
60 "-Dgraal.CrashAt=TestProgram.*",
61 "-Xcomp",
62 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
63 TestProgram.class.getName()));
64 }
65
66 /**
67 * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
68 * {@code -Dgraal.CompilationFailureAction=ExitVM}.
69 */
70 @Test
71 public void testVMCompilation2() throws IOException, InterruptedException {
72 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
73 "-XX:+UseJVMCICompiler",
74 "-Dgraal.ExitVMOnException=true",
75 "-Dgraal.CrashAt=TestProgram.*",
76 "-Xcomp",
77 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
78 TestProgram.class.getName()));
79 }
80
81 static class Probe {
82 final String substring;
83 final int expectedOccurrences;
84 int actualOccurrences;
85 String lastMatchingLine;
86
87 Probe(String substring, int expectedOccurrences) {
88 this.substring = substring;
89 this.expectedOccurrences = expectedOccurrences;
90 }
91
92 boolean matches(String line) {
93 if (line.contains(substring)) {
94 actualOccurrences++;
95 lastMatchingLine = line;
96 return true;
97 }
98 return false;
99 }
100
101 String test() {
102 return expectedOccurrences == actualOccurrences ? null : String.format("expected %d, got %d occurrences", expectedOccurrences, actualOccurrences);
103 }
104 }
105
106 /**
107 * Tests {@link GraalCompilerOptions#MaxCompilationProblemsPerAction} in context of a
108 * compilation requested by the VM.
109 */
110 @Test
111 public void testVMCompilation3() throws IOException, InterruptedException {
112 final int maxProblems = 2;
113 Probe retryingProbe = new Probe("Retrying compilation of", maxProblems) {
114 @Override
115 String test() {
116 return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
117 }
118 };
119 Probe adjustmentProbe = new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1) {
120 @Override
121 String test() {
122 if (retryingProbe.actualOccurrences >= maxProblems) {
123 if (actualOccurrences == 0) {
124 return "expected at least one occurrence";
125 }
126 }
127 return null;
128 }
129 };
130 Probe[] probes = {
131 retryingProbe,
132 adjustmentProbe
133 };
134 testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
135 "-XX:+UseJVMCICompiler",
136 "-Dgraal.CompilationFailureAction=Diagnose",
137 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
138 "-Dgraal.CrashAt=TestProgram.*",
139 "-Xcomp",
140 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
141 TestProgram.class.getName()));
142 }
143
144 /**
145 * Tests compilation requested by Truffle.
146 */
147 @Test
148 public void testTruffleCompilation1() throws IOException, InterruptedException {
149 testHelper(Collections.emptyList(),
150 Arrays.asList(
151 "-Dgraal.CompilationFailureAction=ExitVM",
152 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
153 "-Dgraal.CrashAt=root test1"),
154 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
155 }
156
157 /**
158 * Tests that TruffleCompilationExceptionsAreFatal works as expected.
159 */
160 @Test
161 public void testTruffleCompilation2() throws IOException, InterruptedException {
162 Probe[] probes = {
163 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
164 };
165 testHelper(Arrays.asList(probes),
166 Arrays.asList(
167 "-Dgraal.CompilationFailureAction=Silent",
168 "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
169 "-Dgraal.CrashAt=root test1"),
170 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
171 }
172
173 /**
174 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
175 */
176 @Test
177 public void testTruffleCompilation3() throws IOException, InterruptedException {
178 Probe[] probes = {
179 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
180 };
181 testHelper(Arrays.asList(probes),
182 Arrays.asList(
183 "-Dgraal.CompilationFailureAction=Silent",
184 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
185 "-Dgraal.CrashAt=root test1:PermanentBailout"),
186 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
187 }
188
189 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
190
191 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
192 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
193 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
194 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
195 vmArgs.remove("-esa");
196 vmArgs.remove("-ea");
197 vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
|
37 import java.util.zip.ZipEntry;
38 import java.util.zip.ZipFile;
39
40 import org.graalvm.compiler.core.GraalCompilerOptions;
41 import org.graalvm.compiler.core.test.GraalCompilerTest;
42 import org.graalvm.compiler.test.SubprocessUtil;
43 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
44 import org.junit.Assert;
45 import org.junit.Test;
46
47 /**
48 * Tests support for dumping graphs and other info useful for debugging a compiler crash.
49 */
50 public class CompilationWrapperTest extends GraalCompilerTest {
51
52 /**
53 * Tests compilation requested by the VM.
54 */
55 @Test
56 public void testVMCompilation1() throws IOException, InterruptedException {
57 assumeManagementLibraryIsLoadable();
58 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
59 "-XX:+UseJVMCICompiler",
60 "-Dgraal.CompilationFailureAction=ExitVM",
61 "-Dgraal.CrashAt=TestProgram.*",
62 "-Xcomp",
63 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
64 TestProgram.class.getName()));
65 }
66
67 /**
68 * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
69 * {@code -Dgraal.CompilationFailureAction=ExitVM}.
70 */
71 @Test
72 public void testVMCompilation2() throws IOException, InterruptedException {
73 assumeManagementLibraryIsLoadable();
74 testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
75 "-XX:+UseJVMCICompiler",
76 "-Dgraal.ExitVMOnException=true",
77 "-Dgraal.CrashAt=TestProgram.*",
78 "-Xcomp",
79 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
80 TestProgram.class.getName()));
81 }
82
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 assumeManagementLibraryIsLoadable();
115 final int maxProblems = 2;
116 Probe retryingProbe = new Probe("Retrying compilation of", maxProblems) {
117 @Override
118 String test() {
119 return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
120 }
121 };
122 Probe adjustmentProbe = new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1) {
123 @Override
124 String test() {
125 if (retryingProbe.actualOccurrences >= maxProblems) {
126 if (actualOccurrences == 0) {
127 return "expected at least one occurrence";
128 }
129 }
130 return null;
131 }
132 };
133 Probe[] probes = {
134 retryingProbe,
135 adjustmentProbe
136 };
137 testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
138 "-XX:+UseJVMCICompiler",
139 "-Dgraal.CompilationFailureAction=Diagnose",
140 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
141 "-Dgraal.CrashAt=TestProgram.*",
142 "-Xcomp",
143 "-XX:CompileCommand=compileonly,*/TestProgram.print*",
144 TestProgram.class.getName()));
145 }
146
147 /**
148 * Tests compilation requested by Truffle.
149 */
150 @Test
151 public void testTruffleCompilation1() throws IOException, InterruptedException {
152 assumeManagementLibraryIsLoadable();
153 testHelper(Collections.emptyList(),
154 Arrays.asList(
155 "-Dgraal.CompilationFailureAction=ExitVM",
156 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
157 "-Dgraal.CrashAt=root test1"),
158 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
159 }
160
161 /**
162 * Tests that TruffleCompilationExceptionsAreFatal works as expected.
163 */
164 @Test
165 public void testTruffleCompilation2() throws IOException, InterruptedException {
166 Probe[] probes = {
167 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
168 };
169 testHelper(Arrays.asList(probes),
170 Arrays.asList(
171 "-Dgraal.CompilationFailureAction=Silent",
172 "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
173 "-Dgraal.CrashAt=root test1"),
174 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
175 }
176
177 /**
178 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
179 */
180 @Test
181 public void testTruffleCompilation3() throws IOException, InterruptedException {
182 assumeManagementLibraryIsLoadable();
183 Probe[] probes = {
184 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
185 };
186 testHelper(Arrays.asList(probes),
187 Arrays.asList(
188 "-Dgraal.CompilationFailureAction=Silent",
189 "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
190 "-Dgraal.CrashAt=root test1:PermanentBailout"),
191 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
192 }
193
194 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
195
196 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
197 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
198 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
199 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
200 vmArgs.remove("-esa");
201 vmArgs.remove("-ea");
202 vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
|