test/hotspot/jtreg/runtime/ErrorHandling/NestedThreadsListHandleInErrorHandlingTest.java
author dcubed
Wed, 02 May 2018 16:47:40 -0400
changeset 49956 a87f2e7a527c
parent 48382 0997d6959851
child 52270 487bd00f4ea8
permissions -rw-r--r--
8191798: redo nested ThreadsListHandle to drop Threads_lock Summary: Refactor Thread hazard ptrs and nested ThreadsLists into SafeThreadsListPtr. Reviewed-by: dcubed, eosterlund, rehn Contributed-by: erik.osterlund@oracle.com, daniel.daugherty@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     1
/*
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 48382
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     4
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     8
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    13
 * accompanied this code).
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    14
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    18
 *
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    21
 * questions.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    22
 */
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    23
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    24
import java.io.BufferedReader;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    25
import java.io.File;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    26
import java.io.FileInputStream;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    27
import java.io.InputStreamReader;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    28
import java.util.regex.Pattern;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    29
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    30
import jdk.test.lib.process.OutputAnalyzer;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    31
import jdk.test.lib.Platform;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    32
import jdk.test.lib.process.ProcessTools;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    33
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    34
/*
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    35
 * @test
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    36
 * @requires (vm.debug == true)
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    37
 * @bug 8167108
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    38
 * @summary Nested ThreadsListHandle info should be in error handling output.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    39
 * @modules java.base/jdk.internal.misc
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    40
 * @library /test/lib
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    41
 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+EnableThreadSMRStatistics NestedThreadsListHandleInErrorHandlingTest
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    42
 */
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    43
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    44
/*
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    45
 * This test was created using SafeFetchInErrorHandlingTest.java
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    46
 * as a guide.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    47
 */
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    48
public class NestedThreadsListHandleInErrorHandlingTest {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    49
  public static void main(String[] args) throws Exception {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    50
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    51
    // The -XX:ErrorHandlerTest=N option requires debug bits.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    52
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    53
        "-XX:+UnlockDiagnosticVMOptions",
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    54
        "-Xmx100M",
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    55
        "-XX:ErrorHandlerTest=17",
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    56
        "-XX:-CreateCoredumpOnCrash",
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    57
        "-version");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    58
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    59
    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    60
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    61
    // We should have crashed with a specific fatal error:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    62
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    63
    System.out.println("Found fatal error header.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    64
    output_detail.shouldMatch("# +fatal error: Force crash with a nested ThreadsListHandle.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    65
    System.out.println("Found specific fatal error.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    66
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    67
    // Extract hs_err_pid file.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    68
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    69
    if (hs_err_file == null) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    70
        throw new RuntimeException("Did not find hs_err_pid file in output.\n");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    71
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    72
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    73
    File f = new File(hs_err_file);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    74
    if (!f.exists()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    75
        throw new RuntimeException("hs_err_pid file missing at "
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    76
                                   + f.getAbsolutePath() + ".\n");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    77
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    78
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    79
    System.out.println("Found hs_err_pid file. Scanning...");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    80
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    81
    FileInputStream fis = new FileInputStream(f);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    82
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    83
    String line = null;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    84
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    85
    Pattern [] pattern = new Pattern[] {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    86
        // The "Current thread" line should show a hazard ptr and
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    87
        // a nested hazard ptr:
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 48382
diff changeset
    88
        Pattern.compile("Current thread .* _threads_hazard_ptr=0x[0-9A-Fa-f][0-9A-Fa-f]*, _nested_threads_hazard_ptr_cnt=1, _nested_threads_hazard_ptr=0x[0-9A-Fa-f][0-9A-Fa-f]*.*"),
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    89
        // We should have a section of Threads class SMR info:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    90
        Pattern.compile("Threads class SMR info:"),
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    91
        // We should have one nested ThreadsListHandle:
48382
0997d6959851 8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents: 48105
diff changeset
    92
        Pattern.compile(".*, _nested_thread_list_max=1"),
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    93
        // The current thread (marked with '=>') in the threads list
49956
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 48382
diff changeset
    94
        // should show a hazard ptr and a nested hazard ptr:
a87f2e7a527c 8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents: 48382
diff changeset
    95
        Pattern.compile("=>.* JavaThread \"main\" .* _threads_hazard_ptr=0x[0-9A-Fa-f][0-9A-Fa-f]*, _nested_threads_hazard_ptr_cnt=1, _nested_threads_hazard_ptr=0x[0-9A-Fa-f][0-9A-Fa-f]*.*"),
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    96
    };
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    97
    int currentPattern = 0;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    98
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
    99
    String lastLine = null;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   100
    while ((line = br.readLine()) != null) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   101
        if (currentPattern < pattern.length) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   102
            if (pattern[currentPattern].matcher(line).matches()) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   103
                System.out.println("Found: " + line + ".");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   104
                currentPattern++;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   105
            }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   106
        }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   107
        lastLine = line;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   108
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   109
    br.close();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   110
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   111
    if (currentPattern < pattern.length) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   112
        throw new RuntimeException("hs_err_pid file incomplete (first missing pattern: " +  currentPattern + ")");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   113
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   114
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   115
    if (!lastLine.equals("END.")) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   116
        throw new RuntimeException("hs-err file incomplete (missing END marker.)");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   117
    } else {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   118
        System.out.println("End marker found.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   119
    }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   120
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   121
    System.out.println("Done scanning hs_err_pid_file.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   122
    System.out.println("PASSED.");
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   123
  }
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff changeset
   124
}