test/hotspot/jtreg/runtime/ErrorHandling/SafeFetchInErrorHandlingTest.java
author jiefu
Wed, 28 Aug 2019 08:47:40 +0800
changeset 57918 edc00278955d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230228: [TESTBUG] Several runtime/ErrorHandling tests may fail on some platforms Reviewed-by: coleenp, stuefe, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30110
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
30110
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     4
 *
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     7
 * published by the Free Software Foundation.
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     8
 *
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    13
 * accompanied this code).
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    14
 *
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    18
 *
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    21
 * questions.
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    22
 */
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    23
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    24
import java.io.BufferedReader;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    25
import java.io.File;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    26
import java.io.FileInputStream;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    27
import java.io.InputStreamReader;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    28
import java.util.regex.Pattern;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    29
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    30
import jdk.test.lib.process.OutputAnalyzer;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    31
import jdk.test.lib.Platform;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    32
import jdk.test.lib.process.ProcessTools;
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    33
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    34
/*
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    35
 * @test
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    36
 * @bug 8074552
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    37
 * @summary SafeFetch32 and SafeFetchN do not work in error handling
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 30604
diff changeset
    38
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    39
 * @library /test/lib
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    40
 * @author Thomas Stuefe (SAP)
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    41
 */
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    42
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    43
public class SafeFetchInErrorHandlingTest {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    44
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    45
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    46
  public static void main(String[] args) throws Exception {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    47
30110
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    48
    if (!Platform.isDebugBuild() || Platform.isZero()) {
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    49
      return;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    50
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    51
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    52
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    53
        "-XX:+UnlockDiagnosticVMOptions",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    54
        "-Xmx100M",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    55
        "-XX:ErrorHandlerTest=14",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    56
        "-XX:+TestSafeFetchInErrorHandler",
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 30110
diff changeset
    57
        "-XX:-CreateCoredumpOnCrash",
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    58
        "-version");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    59
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    60
    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    61
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    62
    // we should have crashed with a SIGSEGV
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    63
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
57918
edc00278955d 8230228: [TESTBUG] Several runtime/ErrorHandling tests may fail on some platforms
jiefu
parents: 47216
diff changeset
    64
    output_detail.shouldMatch("# +(?:SIGSEGV|SIGBUS|EXCEPTION_ACCESS_VIOLATION).*");
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    65
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    66
    // extract hs-err file
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    67
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    68
    if (hs_err_file == null) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    69
      throw new RuntimeException("Did not find hs-err file in output.\n");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    70
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    71
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    72
    File f = new File(hs_err_file);
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    73
    if (!f.exists()) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    74
      throw new RuntimeException("hs-err file missing at "
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    75
          + f.getAbsolutePath() + ".\n");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    76
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    77
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    78
    System.out.println("Found hs_err file. Scanning...");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    79
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    80
    FileInputStream fis = new FileInputStream(f);
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    81
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    82
    String line = null;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    83
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    84
    Pattern [] pattern = new Pattern[] {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    85
        Pattern.compile("Will test SafeFetch..."),
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    86
        Pattern.compile("SafeFetch OK."),
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    87
    };
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    88
    int currentPattern = 0;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    89
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    90
    String lastLine = null;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    91
    while ((line = br.readLine()) != null) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    92
      if (currentPattern < pattern.length) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    93
        if (pattern[currentPattern].matcher(line).matches()) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    94
          System.out.println("Found: " + line + ".");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    95
          currentPattern ++;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    96
        }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    97
      }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    98
      lastLine = line;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    99
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   100
    br.close();
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   101
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   102
    if (currentPattern < pattern.length) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   103
      throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   104
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   105
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   106
    if (!lastLine.equals("END.")) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   107
      throw new RuntimeException("hs-err file incomplete (missing END marker.)");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   108
    } else {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   109
      System.out.println("End marker found.");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   110
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   111
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   112
    System.out.println("OK.");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   113
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   114
  }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   115
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   116
}
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   117