src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompilationWrapperTest.java
author dlong
Thu, 14 Nov 2019 12:21:00 -0800
changeset 59095 03fbcd06b4c0
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
8233841: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     4
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     8
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    13
 * accompanied this code).
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    14
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    18
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    21
 * questions.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 50330
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 50330
diff changeset
    24
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    25
package org.graalvm.compiler.hotspot.test;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    26
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    27
import static org.graalvm.compiler.test.SubprocessUtil.getPackageOpeningOptions;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    28
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    29
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    30
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    31
import java.io.File;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    32
import java.io.IOException;
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
    33
import java.nio.file.Path;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    34
import java.util.ArrayList;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    35
import java.util.Arrays;
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    36
import java.util.Collections;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    37
import java.util.Enumeration;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    38
import java.util.List;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    39
import java.util.zip.ZipEntry;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    40
import java.util.zip.ZipFile;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    41
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    42
import org.graalvm.compiler.core.GraalCompilerOptions;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    43
import org.graalvm.compiler.core.test.GraalCompilerTest;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    44
import org.graalvm.compiler.test.SubprocessUtil;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    45
import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    46
import org.junit.Assert;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    47
import org.junit.Test;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    48
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    49
/**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    50
 * Tests support for dumping graphs and other info useful for debugging a compiler crash.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    51
 */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    52
public class CompilationWrapperTest extends GraalCompilerTest {
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    53
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    54
    private static List<String> join(List<String> l1, List<String> l2) {
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    55
        ArrayList<String> result = new ArrayList<>(l1.size() + l2.size());
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    56
        result.addAll(l1);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    57
        result.addAll(l2);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    58
        return result;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    59
    }
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    60
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    61
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    62
     * Tests compilation requested by the VM.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    63
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    64
    @Test
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    65
    public void testVMCompilation1() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51736
diff changeset
    66
        assumeManagementLibraryIsLoadable();
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    67
        testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    68
                        "-XX:+UseJVMCICompiler",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    69
                        "-Dgraal.CompilationFailureAction=ExitVM",
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    70
                        "-Dgraal.CrashAt=TestProgram.*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    71
                        "-Xcomp",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    72
                        "-XX:CompileCommand=compileonly,*/TestProgram.print*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    73
                        TestProgram.class.getName()));
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    74
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    75
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    76
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    77
     * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    78
     * {@code -Dgraal.CompilationFailureAction=ExitVM}.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    79
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    80
    @Test
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    81
    public void testVMCompilation2() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51736
diff changeset
    82
        assumeManagementLibraryIsLoadable();
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    83
        testHelper(Collections.emptyList(), Arrays.asList("-XX:-TieredCompilation",
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    84
                        "-XX:+UseJVMCICompiler",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    85
                        "-Dgraal.ExitVMOnException=true",
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    86
                        "-Dgraal.CrashAt=TestProgram.*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    87
                        "-Xcomp",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    88
                        "-XX:CompileCommand=compileonly,*/TestProgram.print*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
    89
                        TestProgram.class.getName()));
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    90
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    91
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    92
    static class Probe {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    93
        final String substring;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    94
        final int expectedOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    95
        int actualOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    96
        String lastMatchingLine;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    97
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    98
        Probe(String substring, int expectedOccurrences) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    99
            this.substring = substring;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   100
            this.expectedOccurrences = expectedOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   101
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   102
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   103
        boolean matches(String line) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   104
            if (line.contains(substring)) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   105
                actualOccurrences++;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   106
                lastMatchingLine = line;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   107
                return true;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   108
            }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   109
            return false;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   110
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   111
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   112
        String test() {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   113
            return expectedOccurrences == actualOccurrences ? null : String.format("expected %d, got %d occurrences", expectedOccurrences, actualOccurrences);
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   114
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   115
    }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   116
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   117
    /**
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   118
     * Tests {@link GraalCompilerOptions#MaxCompilationProblemsPerAction} in context of a
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   119
     * compilation requested by the VM.
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   120
     */
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   121
    @Test
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   122
    public void testVMCompilation3() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51736
diff changeset
   123
        assumeManagementLibraryIsLoadable();
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   124
        final int maxProblems = 2;
59095
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   125
        Probe failurePatternProbe = new Probe("[[[Graal compilation failure]]]", maxProblems) {
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   126
            @Override
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   127
            String test() {
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   128
                return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   129
            }
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   130
        };
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   131
        Probe retryingProbe = new Probe("Retrying compilation of", maxProblems) {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   132
            @Override
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   133
            String test() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   134
                return actualOccurrences > 0 && actualOccurrences <= maxProblems ? null : String.format("expected occurrences to be in [1 .. %d]", maxProblems);
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   135
            }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   136
        };
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   137
        Probe adjustmentProbe = new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1) {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   138
            @Override
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   139
            String test() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   140
                if (retryingProbe.actualOccurrences >= maxProblems) {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   141
                    if (actualOccurrences == 0) {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   142
                        return "expected at least one occurrence";
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   143
                    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   144
                }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   145
                return null;
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   146
            }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   147
        };
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   148
        Probe[] probes = {
59095
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 58299
diff changeset
   149
                        failurePatternProbe,
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   150
                        retryingProbe,
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   151
                        adjustmentProbe
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   152
        };
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   153
        testHelper(Arrays.asList(probes), Arrays.asList("-XX:-TieredCompilation",
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   154
                        "-XX:+UseJVMCICompiler",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   155
                        "-Dgraal.CompilationFailureAction=Diagnose",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   156
                        "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   157
                        "-Dgraal.CrashAt=TestProgram.*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   158
                        "-Xcomp",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   159
                        "-XX:CompileCommand=compileonly,*/TestProgram.print*",
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   160
                        TestProgram.class.getName()));
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   161
    }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   162
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   163
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   164
     * Tests compilation requested by Truffle.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   165
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   166
    @Test
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   167
    public void testTruffleCompilation1() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51736
diff changeset
   168
        assumeManagementLibraryIsLoadable();
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   169
        testHelper(Collections.emptyList(),
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   170
                        join(getPackageOpeningOptions(),
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   171
                                        Arrays.asList(
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   172
                                                        "-Dgraal.CompilationFailureAction=ExitVM",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   173
                                                        "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   174
                                                        "-Dgraal.CrashAt=root test1")),
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   175
                        "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   176
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   177
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   178
    /**
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   179
     * Tests that TruffleCompilationExceptionsAreFatal works as expected.
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   180
     */
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   181
    @Test
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   182
    public void testTruffleCompilation2() throws IOException, InterruptedException {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   183
        Probe[] probes = {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   184
                        new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   185
        };
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   186
        testHelper(Arrays.asList(probes),
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   187
                        join(getPackageOpeningOptions(),
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   188
                                        Arrays.asList(
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   189
                                                        "-Dgraal.CompilationFailureAction=Silent",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   190
                                                        "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   191
                                                        "-Dgraal.CrashAt=root test1")),
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   192
                        "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   193
    }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   194
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   195
    /**
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   196
     * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output.
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   197
     */
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   198
    @Test
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   199
    public void testTruffleCompilation3() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51736
diff changeset
   200
        assumeManagementLibraryIsLoadable();
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   201
        Probe[] probes = {
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   202
                        new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   203
        };
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   204
        testHelper(Arrays.asList(probes),
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   205
                        join(getPackageOpeningOptions(),
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   206
                                        Arrays.asList(
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   207
                                                        "-Dgraal.CompilationFailureAction=Silent",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   208
                                                        "-Dgraal.TrufflePerformanceWarningsAreFatal=true",
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   209
                                                        "-Dgraal.CrashAt=root test1:PermanentBailout")),
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   210
                        "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   211
    }
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48190
diff changeset
   212
46762
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   213
    private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   214
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   215
    private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   216
        final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   217
        List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   218
        vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   219
        vmArgs.remove("-esa");
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   220
        vmArgs.remove("-ea");
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   221
        vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   222
        // Force output to a file even if there's a running IGV instance available.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   223
        vmArgs.add("-Dgraal.PrintGraphFile=true");
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   224
        vmArgs.addAll(extraVmArgs);
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   225
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   226
        Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
46762
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   227
        if (VERBOSE) {
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   228
            System.out.println(proc);
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   229
        }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   230
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   231
        try {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   232
            List<Probe> probes = new ArrayList<>(initialProbes);
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   233
            Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1);
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   234
            probes.add(diagnosticProbe);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   235
            probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   236
                @Override
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   237
                String test() {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   238
                    return actualOccurrences > 0 ? null : "expected at least 1 occurrence";
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   239
                }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   240
            });
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   241
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   242
            for (String line : proc.output) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   243
                for (Probe probe : probes) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   244
                    if (probe.matches(line)) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   245
                        break;
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   246
                    }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   247
                }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   248
            }
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   249
            for (Probe probe : probes) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   250
                String error = probe.test();
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   251
                if (error != null) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   252
                    Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc));
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   253
                }
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   254
            }
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   255
            String line = diagnosticProbe.lastMatchingLine;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   256
            int substringStart = line.indexOf(diagnosticProbe.substring);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   257
            int substringLength = diagnosticProbe.substring.length();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   258
            String diagnosticOutputZip = line.substring(substringStart + substringLength).trim();
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   259
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   260
            List<String> dumpPathEntries = Arrays.asList(dumpPath.list());
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   261
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   262
            File zip = new File(diagnosticOutputZip).getAbsoluteFile();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   263
            Assert.assertTrue(zip.toString(), zip.exists());
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   264
            Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName()));
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   265
            try {
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents: 49873
diff changeset
   266
                int bgvOrCfgFiles = 0;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   267
                ZipFile dd = new ZipFile(diagnosticOutputZip);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   268
                List<String> entries = new ArrayList<>();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   269
                for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   270
                    ZipEntry ze = e.nextElement();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   271
                    String name = ze.getName();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   272
                    entries.add(name);
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents: 49873
diff changeset
   273
                    if (name.endsWith(".bgv") || name.endsWith(".cfg")) {
2cbc42a5764b 8202670: Update Graal
dlong
parents: 49873
diff changeset
   274
                        bgvOrCfgFiles++;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   275
                    }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   276
                }
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents: 49873
diff changeset
   277
                if (bgvOrCfgFiles == 0) {
2cbc42a5764b 8202670: Update Graal
dlong
parents: 49873
diff changeset
   278
                    Assert.fail(String.format("Expected at least one .bgv or .cfg file in %s: %s%n%s", diagnosticOutputZip, entries, proc));
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   279
                }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   280
            } finally {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   281
                zip.delete();
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   282
            }
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   283
        } finally {
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   284
            Path directory = dumpPath.toPath();
ecc6e394475f 8226771: Update Graal
dlong
parents: 52910
diff changeset
   285
            removeDirectory(directory);
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   286
        }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   287
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   288
}
51736
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   289
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   290
class TestProgram {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   291
    public static void main(String[] args) {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   292
        printHello1();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   293
        printWorld1();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   294
        printHello2();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   295
        printWorld2();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   296
        printHello3();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   297
        printWorld3();
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   298
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   299
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   300
    private static void printHello1() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   301
        System.out.println("Hello1");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   302
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   303
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   304
    private static void printWorld1() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   305
        System.out.println("World1");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   306
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   307
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   308
    private static void printHello2() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   309
        System.out.println("Hello2");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   310
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   311
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   312
    private static void printWorld2() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   313
        System.out.println("World2");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   314
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   315
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   316
    private static void printHello3() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   317
        System.out.println("Hello3");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   318
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   319
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   320
    private static void printWorld3() {
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   321
        System.out.println("World3");
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   322
    }
42d99cb7f50f 8210478: Update Graal
iveresov
parents: 50858
diff changeset
   323
}