hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java
author mchung
Fri, 12 May 2017 13:29:38 -0700
changeset 45139 7be55dfa1742
parent 40631 ed82623d7831
permissions -rw-r--r--
8180208: Provide a new docs bundle page Reviewed-by: ihse, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     4
 *
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     7
 * published by the Free Software Foundation.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     8
 *
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    13
 * accompanied this code).
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    14
 *
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    18
 *
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    21
 * questions.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    22
 */
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    23
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    24
/*
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    25
 * @test
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    26
 * @bug     8036823
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    27
 * @bug     8046287
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    28
 * @summary Creates two threads contending for the same lock and checks
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    29
 *      whether jstack reports "locked" by more than one thread.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    30
 *
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    31
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 30604
diff changeset
    32
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 25061
diff changeset
    33
 *          java.management
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    34
 * @run main/othervm TestThreadDumpMonitorContention
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    35
 */
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    36
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    37
import java.io.BufferedReader;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    38
import java.io.InputStreamReader;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    39
import java.lang.management.ManagementFactory;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    40
import java.lang.management.RuntimeMXBean;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    41
import java.util.ArrayList;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    42
import java.util.List;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    43
import java.util.regex.Matcher;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    44
import java.util.regex.Pattern;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    45
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    46
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    47
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    48
import jdk.test.lib.JDKToolFinder;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    49
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    50
public class TestThreadDumpMonitorContention {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    51
    // jstack tends to be closely bound to the VM that we are running
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    52
    // so use getTestJDKTool() instead of getCompileJDKTool() or even
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    53
    // getJDKTool() which can fall back to "compile.jdk".
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    54
    final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    55
    final static String PID = getPid();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    56
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    57
    // looking for header lines with these patterns:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    58
    // "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000]
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    59
    // "ContendingThread-2" #21 prio=5 os_prio=64 tid=0x0000000000780000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000]
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    60
    // "ContendingThread-2" #24 prio=5 os_prio=64 tid=0x0000000000ec8800 nid=0x31 waiting on condition [0xfffffd7bbfffe000]
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    61
    final static Pattern HEADER_PREFIX_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    62
        "^\"ContendingThread-.*");
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    63
    final static Pattern HEADER_WAITING_PATTERN1 = Pattern.compile(
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    64
        "^\"ContendingThread-.* waiting for monitor entry .*");
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    65
    final static Pattern HEADER_WAITING_PATTERN2 = Pattern.compile(
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    66
        "^\"ContendingThread-.* waiting on condition .*");
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    67
    final static Pattern HEADER_RUNNABLE_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    68
        "^\"ContendingThread-.* runnable .*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    69
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    70
    // looking for thread state lines with these patterns:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    71
    // java.lang.Thread.State: RUNNABLE
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    72
    // java.lang.Thread.State: BLOCKED (on object monitor)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    73
    final static Pattern THREAD_STATE_PREFIX_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    74
        " *java\\.lang\\.Thread\\.State: .*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    75
    final static Pattern THREAD_STATE_BLOCKED_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    76
        " *java\\.lang\\.Thread\\.State: BLOCKED \\(on object monitor\\)");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    77
    final static Pattern THREAD_STATE_RUNNABLE_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    78
        " *java\\.lang\\.Thread\\.State: RUNNABLE");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    79
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    80
    // looking for duplicates of this pattern:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    81
    // - locked <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    82
    final static Pattern LOCK_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    83
        ".* locked \\<.*\\(a TestThreadDumpMonitorContention.*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    84
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    85
    // sanity checking header and thread state lines associated
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    86
    // with this pattern:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    87
    // - waiting to lock <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    88
    final static Pattern WAITING_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    89
        ".* waiting to lock \\<.*\\(a TestThreadDumpMonitorContention.*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    90
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    91
    final static Object barrier = new Object();
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    92
    volatile static boolean done = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    93
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    94
    static int barrier_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    95
    static int blank_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    96
    static int error_cnt = 0;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    97
    static boolean have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    98
    static boolean have_thread_state_line = false;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    99
    static String header_line = null;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   100
    static int header_prefix_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   101
    static int locked_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   102
    static String[] locked_match_list = new String[2];
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   103
    static int n_samples = 15;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   104
    static int sum_both_running_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   105
    static int sum_both_waiting_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   106
    static int sum_contended_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   107
    static int sum_locked_hdr_runnable_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   108
    static int sum_locked_hdr_waiting1_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   109
    static int sum_locked_hdr_waiting2_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   110
    static int sum_locked_thr_state_blocked_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   111
    static int sum_locked_thr_state_runnable_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   112
    static int sum_one_waiting_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   113
    static int sum_uncontended_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   114
    static int sum_waiting_hdr_waiting1_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   115
    static int sum_waiting_thr_state_blocked_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   116
    static String thread_state_line = null;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   117
    static boolean verbose = false;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   118
    static int waiting_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   119
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   120
    public static void main(String[] args) throws Exception {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   121
        if (args.length != 0) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   122
            int arg_i = 0;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   123
            if (args[arg_i].equals("-v")) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   124
                verbose = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   125
                arg_i++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   126
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   127
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   128
            try {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   129
                n_samples = Integer.parseInt(args[arg_i]);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   130
            } catch (NumberFormatException nfe) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   131
                System.err.println(nfe);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   132
                usage();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   133
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   134
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   135
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   136
        Runnable runnable = new Runnable() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   137
            public void run() {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   138
                synchronized (barrier) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   139
                    // let the main thread know we're running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   140
                    barrier_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   141
                    barrier.notify();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   142
                }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   143
                while (!done) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   144
                    synchronized (this) { }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   145
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   146
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   147
        };
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   148
        Thread[] thread_list = new Thread[2];
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   149
        thread_list[0] = new Thread(runnable, "ContendingThread-1");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   150
        thread_list[1] = new Thread(runnable, "ContendingThread-2");
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   151
        synchronized (barrier) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   152
            thread_list[0].start();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   153
            thread_list[1].start();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   154
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   155
            // Wait until the contending threads are running so that
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   156
            // we don't sample any thread init states.
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   157
            while (barrier_cnt < 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   158
                barrier.wait();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   159
            }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   160
        }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   161
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   162
        doSamples();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   163
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   164
        done = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   165
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   166
        thread_list[0].join();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   167
        thread_list[1].join();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   168
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   169
        if (error_cnt == 0) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   170
            System.out.println("Test PASSED.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   171
        } else {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   172
            System.out.println("Test FAILED.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   173
            throw new AssertionError("error_cnt=" + error_cnt);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   174
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   175
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   176
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   177
    // Reached a blank line which is the end of the
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   178
    // stack trace without matching either LOCK_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   179
    // or WAITING_PATTERN. Rare, but it's not an error.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   180
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   181
    // Example:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   182
    // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000]
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   183
    //    java.lang.Thread.State: RUNNABLE
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   184
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   185
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   186
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   187
    static boolean checkBlankLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   188
        if (line.length() == 0) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   189
            blank_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   190
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   191
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   192
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   193
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   194
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   195
        return false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   196
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   197
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   198
    // Process the locked line here if we found one.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   199
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   200
    // Example 1:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   201
    // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000]
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   202
    //    java.lang.Thread.State: RUNNABLE
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   203
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   204
    //         - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   205
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   206
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   207
    // Example 2:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   208
    // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000]
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   209
    //    java.lang.Thread.State: BLOCKED (on object monitor)
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   210
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   211
    //         - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   212
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   213
    //
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   214
    // Example 3:
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   215
    // "ContendingThread-2" #24 prio=5 os_prio=64 tid=0x0000000000ec8800 nid=0x31 waiting on condition [0xfffffd7bbfffe000]
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   216
    //    java.lang.Thread.State: RUNNABLE
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   217
    //    JavaThread state: _thread_blocked
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   218
    // Thread: 0x0000000000ec8800  [0x31] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   219
    //    JavaThread state: _thread_blocked
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   220
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   221
    //         - locked <0xfffffd7e6d03eb28> (a TestThreadDumpMonitorContention$1)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   222
    //         at java.lang.Thread.run(Thread.java:745)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   223
    //
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   224
    static boolean checkLockedLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   225
        Matcher matcher = LOCK_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   226
        if (matcher.matches()) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   227
            if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   228
                System.out.println("locked_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   229
            }
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   230
            locked_match_list[locked_line_match_cnt] = new String(line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   231
            locked_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   232
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   233
            matcher = HEADER_RUNNABLE_PATTERN.matcher(header_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   234
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   235
                sum_locked_hdr_runnable_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   236
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   237
                // It's strange, but a locked line can also
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   238
                // match the HEADER_WAITING_PATTERN{1,2}.
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   239
                matcher = HEADER_WAITING_PATTERN1.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   240
                if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   241
                    sum_locked_hdr_waiting1_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   242
                } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   243
                    matcher = HEADER_WAITING_PATTERN2.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   244
                    if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   245
                        sum_locked_hdr_waiting2_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   246
                    } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   247
                        System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   248
                        System.err.println("ERROR: header line does " +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   249
                            "not match runnable or waiting patterns.");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   250
                        System.err.println("ERROR: header_line='" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   251
                            header_line + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   252
                        System.err.println("ERROR: locked_line='" + line +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   253
                            "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   254
                        error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   255
                    }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   256
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   257
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   258
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   259
            matcher = THREAD_STATE_RUNNABLE_PATTERN.matcher(thread_state_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   260
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   261
                sum_locked_thr_state_runnable_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   262
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   263
                // It's strange, but a locked line can also
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   264
                // match the THREAD_STATE_BLOCKED_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   265
                matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   266
                              thread_state_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   267
                if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   268
                    sum_locked_thr_state_blocked_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   269
                } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   270
                    System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   271
                    System.err.println("ERROR: thread state line does not " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   272
                        "match runnable or waiting patterns.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   273
                    System.err.println("ERROR: " + "thread_state_line='" +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   274
                        thread_state_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   275
                    System.err.println("ERROR: locked_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   276
                    error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   277
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   278
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   279
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   280
            // Have everything we need from this thread stack
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   281
            // that matches the LOCK_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   282
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   283
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   284
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   285
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   286
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   287
        return false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   288
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   289
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   290
    // Process the waiting line here if we found one.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   291
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   292
    // Example:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   293
    // "ContendingThread-2" #22 prio=5 os_prio=64 tid=0x00000000007b9800 nid=0x30 waiting for monitor entry [0xfffffd7fc1010000]
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   294
    //    java.lang.Thread.State: BLOCKED (on object monitor)
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   295
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   296
    //         - waiting to lock <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   297
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   298
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   299
    static boolean checkWaitingLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   300
        Matcher matcher = WAITING_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   301
        if (matcher.matches()) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   302
            waiting_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   303
            if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   304
                System.out.println("waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   305
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   306
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   307
            matcher = HEADER_WAITING_PATTERN1.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   308
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   309
                sum_waiting_hdr_waiting1_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   310
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   311
                System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   312
                System.err.println("ERROR: header line does " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   313
                    "not match a waiting pattern.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   314
                System.err.println("ERROR: header_line='" + header_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   315
                System.err.println("ERROR: waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   316
                error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   317
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   318
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   319
            matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(thread_state_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   320
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   321
                sum_waiting_thr_state_blocked_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   322
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   323
                System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   324
                System.err.println("ERROR: thread state line " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   325
                    "does not match a waiting pattern.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   326
                System.err.println("ERROR: thread_state_line='" +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   327
                    thread_state_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   328
                System.err.println("ERROR: waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   329
                error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   330
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   331
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   332
            // Have everything we need from this thread stack
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   333
            // that matches the WAITING_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   334
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   335
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   336
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   337
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   338
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   339
        return false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   340
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   341
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   342
    static void doSamples() throws Exception {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   343
        for (int count = 0; count < n_samples; count++) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   344
            blank_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   345
            header_prefix_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   346
            locked_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   347
            waiting_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   348
            // verbose mode or an error has a lot of output so add more space
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   349
            if (verbose || error_cnt > 0) System.out.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   350
            System.out.println("Sample #" + count);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   351
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   352
            // We don't use the ProcessTools, OutputBuffer or
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   353
            // OutputAnalyzer classes from the testlibrary because
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   354
            // we have a complicated multi-line parse to perform
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   355
            // on a narrow subset of the JSTACK output.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   356
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   357
            // - we only care about stack traces that match
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   358
            //   HEADER_PREFIX_PATTERN; only two should match
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   359
            // - we care about at most three lines from each stack trace
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   360
            // - if both stack traces match LOCKED_PATTERN, then that's
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   361
            //   a failure and we report it
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   362
            // - for a stack trace that matches LOCKED_PATTERN, we verify:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   363
            //   - the header line matches HEADER_RUNNABLE_PATTERN
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   364
            //     or HEADER_WAITING_PATTERN{1,2}
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   365
            //   - the thread state line matches THREAD_STATE_BLOCKED_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   366
            //     or THREAD_STATE_RUNNABLE_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   367
            //   - we report any mismatches as failures
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   368
            // - for a stack trace that matches WAITING_PATTERN, we verify:
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   369
            //   - the header line matches HEADER_WAITING_PATTERN1
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   370
            //   - the thread state line matches THREAD_STATE_BLOCKED_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   371
            //   - we report any mismatches as failures
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   372
            // - the stack traces that match HEADER_PREFIX_PATTERN may
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   373
            //   not match either LOCKED_PATTERN or WAITING_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   374
            //   because we might observe the thread outside of
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   375
            //   monitor operations; this is not considered a failure
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   376
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   377
            // When we do observe LOCKED_PATTERN or WAITING_PATTERN,
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   378
            // then we are checking the header and thread state patterns
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   379
            // that occurred earlier in the current stack trace that
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   380
            // matched HEADER_PREFIX_PATTERN. We don't use data from
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   381
            // stack traces that don't match HEADER_PREFIX_PATTERN and
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   382
            // we don't mix data between the two stack traces that do
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   383
            // match HEADER_PREFIX_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   384
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   385
            Process process = new ProcessBuilder(JSTACK, PID)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   386
                .redirectErrorStream(true).start();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   387
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   388
            BufferedReader reader = new BufferedReader(new InputStreamReader(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   389
                                        process.getInputStream()));
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   390
            String line;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   391
            while ((line = reader.readLine()) != null) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   392
                Matcher matcher = null;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   393
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   394
                // process the header line here
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   395
                if (!have_header_line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   396
                    matcher = HEADER_PREFIX_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   397
                    if (matcher.matches()) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   398
                        header_prefix_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   399
                        if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   400
                            System.out.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   401
                            System.out.println("header='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   402
                        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   403
                        header_line = new String(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   404
                        have_header_line = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   405
                        continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   406
                    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   407
                    continue;  // skip until have a header line
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   408
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   409
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   410
                // process the thread state line here
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   411
                if (!have_thread_state_line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   412
                    matcher = THREAD_STATE_PREFIX_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   413
                    if (matcher.matches()) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   414
                        if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   415
                            System.out.println("thread_state='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   416
                        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   417
                        thread_state_line = new String(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   418
                        have_thread_state_line = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   419
                        continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   420
                    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   421
                    continue;  // skip until we have a thread state line
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   422
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   423
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   424
                // process the locked line here if we find one
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   425
                if (checkLockedLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   426
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   427
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   428
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   429
                // process the waiting line here if we find one
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   430
                if (checkWaitingLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   431
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   432
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   433
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   434
                // process the blank line here if we find one
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   435
                if (checkBlankLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   436
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   437
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   438
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   439
            process.waitFor();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   440
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   441
            if (header_prefix_match_cnt != 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   442
                System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   443
                System.err.println("ERROR: should match exactly two headers.");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   444
                System.err.println("ERROR: header_prefix_match_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   445
                    header_prefix_match_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   446
                error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   447
            }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   448
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   449
            if (locked_line_match_cnt == 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   450
                if (locked_match_list[0].equals(locked_match_list[1])) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   451
                    System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   452
                    System.err.println("ERROR: matching lock lines:");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   453
                    System.err.println("ERROR: line[0]'" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   454
                        locked_match_list[0] + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   455
                    System.err.println("ERROR: line[1]'" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   456
                        locked_match_list[1] + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   457
                    error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   458
                }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   459
            }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   460
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   461
            if (locked_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   462
                // one thread has the lock
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   463
                if (waiting_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   464
                    // and the other contended for it
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   465
                    sum_contended_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   466
                } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   467
                    // and the other is just running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   468
                    sum_uncontended_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   469
                }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   470
            } else if (waiting_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   471
                // one thread is waiting
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   472
                sum_one_waiting_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   473
            } else if (waiting_line_match_cnt == 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   474
                // both threads are waiting
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   475
                sum_both_waiting_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   476
            } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   477
                // both threads are running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   478
                sum_both_running_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   479
            }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   480
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   481
            // slight delay between jstack launches
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   482
            Thread.sleep(500);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   483
        }
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   484
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   485
        if (error_cnt != 0) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   486
            // skip summary info since there were errors
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   487
            return;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   488
        }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   489
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   490
        System.out.println("INFO: Summary for all samples:");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   491
        System.out.println("INFO: both_running_cnt=" + sum_both_running_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   492
        System.out.println("INFO: both_waiting_cnt=" + sum_both_waiting_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   493
        System.out.println("INFO: contended_cnt=" + sum_contended_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   494
        System.out.println("INFO: one_waiting_cnt=" + sum_one_waiting_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   495
        System.out.println("INFO: uncontended_cnt=" + sum_uncontended_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   496
        System.out.println("INFO: locked_hdr_runnable_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   497
            sum_locked_hdr_runnable_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   498
        System.out.println("INFO: locked_hdr_waiting1_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   499
            sum_locked_hdr_waiting1_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   500
        System.out.println("INFO: locked_hdr_waiting2_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   501
            sum_locked_hdr_waiting2_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   502
        System.out.println("INFO: locked_thr_state_blocked_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   503
            sum_locked_thr_state_blocked_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   504
        System.out.println("INFO: locked_thr_state_runnable_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   505
            sum_locked_thr_state_runnable_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   506
        System.out.println("INFO: waiting_hdr_waiting1_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   507
            sum_waiting_hdr_waiting1_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   508
        System.out.println("INFO: waiting_thr_state_blocked_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   509
            sum_waiting_thr_state_blocked_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   510
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   511
        if (sum_contended_cnt == 0) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   512
            System.err.println("WARNING: the primary scenario for 8036823" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   513
                " has not been exercised by this test run.");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   514
        }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   515
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   516
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   517
    // This helper relies on RuntimeMXBean.getName() returning a string
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   518
    // that looks like this: 5436@mt-haku
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   519
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   520
    // The testlibrary has tryFindJvmPid(), but that uses a separate
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   521
    // process which is much more expensive for finding out your own PID.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   522
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   523
    static String getPid() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   524
        RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   525
        String vmname = runtimebean.getName();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   526
        int i = vmname.indexOf('@');
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   527
        if (i != -1) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   528
            vmname = vmname.substring(0, i);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   529
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   530
        return vmname;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   531
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   532
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   533
    static void usage() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   534
        System.err.println("Usage: " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   535
            "java TestThreadDumpMonitorContention [-v] [n_samples]");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   536
        System.exit(1);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   537
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   538
}