hotspot/test/runtime/ErrorHandling/SafeFetchInErrorHandlingTest.java
author stefank
Wed, 20 Apr 2016 09:58:15 +0200
changeset 38000 7519aefb5b86
parent 30604 b8d532cb6420
child 38152 80e5da81fb2c
permissions -rw-r--r--
8079843: do_young_space_rescan - comment out of sync with code Reviewed-by: mgerdin, sjohanss, ehelin, tschatzl
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
/*
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    30
import jdk.test.lib.OutputAnalyzer;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    31
import jdk.test.lib.Platform;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    32
import jdk.test.lib.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
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    38
 * @library /testlibrary
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    39
 * @author Thomas Stuefe (SAP)
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    40
 */
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
public class SafeFetchInErrorHandlingTest {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    43
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
  public static void main(String[] args) throws Exception {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    46
30110
20d4dc1409a6 8075533: Zero JVM segfaults for -version after JDK-8074552
sgehwolf
parents: 29573
diff changeset
    47
    if (!Platform.isDebugBuild() || Platform.isZero()) {
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    48
      return;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    49
    }
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
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    52
        "-XX:+UnlockDiagnosticVMOptions",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    53
        "-Xmx100M",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    54
        "-XX:ErrorHandlerTest=14",
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    55
        "-XX:+TestSafeFetchInErrorHandler",
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 30110
diff changeset
    56
        "-XX:-CreateCoredumpOnCrash",
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    57
        "-version");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    58
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    59
    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    60
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    61
    // we should have crashed with a SIGSEGV
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    62
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    63
    output_detail.shouldMatch("# +(?:SIGSEGV|EXCEPTION_ACCESS_VIOLATION).*");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    64
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    65
    // extract hs-err file
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    66
    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
    67
    if (hs_err_file == null) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    68
      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
    69
    }
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
    File f = new File(hs_err_file);
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    72
    if (!f.exists()) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    73
      throw new RuntimeException("hs-err file missing at "
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    74
          + f.getAbsolutePath() + ".\n");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    75
    }
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
    System.out.println("Found hs_err file. Scanning...");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    78
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    79
    FileInputStream fis = new FileInputStream(f);
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    80
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    81
    String line = null;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    82
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    83
    Pattern [] pattern = new Pattern[] {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    84
        Pattern.compile("Will test SafeFetch..."),
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    85
        Pattern.compile("SafeFetch OK."),
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    86
    };
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    87
    int currentPattern = 0;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    88
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    89
    String lastLine = null;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    90
    while ((line = br.readLine()) != null) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    91
      if (currentPattern < pattern.length) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    92
        if (pattern[currentPattern].matcher(line).matches()) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    93
          System.out.println("Found: " + line + ".");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    94
          currentPattern ++;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    95
        }
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
      lastLine = line;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    98
    }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
    99
    br.close();
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   100
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   101
    if (currentPattern < pattern.length) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   102
      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
   103
    }
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
    if (!lastLine.equals("END.")) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   106
      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
   107
    } else {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   108
      System.out.println("End marker found.");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   109
    }
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
    System.out.println("OK.");
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
diff changeset
   112
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