hotspot/test/runtime/Thread/TestThreadDumpMonitorContention.java
author ykantser
Mon, 04 May 2015 16:30:07 +0200
changeset 30604 b8d532cb6420
parent 29678 dd2f3932c21e
child 36851 03e2f4d0a421
permissions -rw-r--r--
8067013: Rename the com.oracle.java.testlibary package Reviewed-by: dholmes, gtriantafill, sla Contributed-by: alexander.kulyakhtin@oracle.com
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
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 25061
diff changeset
     2
 * Copyright (c) 2014, 2015, 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
 *
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    31
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 25061
diff changeset
    32
 * @modules java.base/sun.misc
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
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    46
import jdk.test.lib.*;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    47
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    48
public class TestThreadDumpMonitorContention {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    49
    // 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
    50
    // so use getTestJDKTool() instead of getCompileJDKTool() or even
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    51
    // getJDKTool() which can fall back to "compile.jdk".
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    52
    final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    53
    final static String PID = getPid();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    54
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    55
    // looking for header lines with these patterns:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    56
    // "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
    57
    // "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
    58
    // "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
    59
    final static Pattern HEADER_PREFIX_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    60
        "^\"ContendingThread-.*");
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    61
    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
    62
        "^\"ContendingThread-.* waiting for monitor entry .*");
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    63
    final static Pattern HEADER_WAITING_PATTERN2 = Pattern.compile(
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    64
        "^\"ContendingThread-.* waiting on condition .*");
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    65
    final static Pattern HEADER_RUNNABLE_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    66
        "^\"ContendingThread-.* runnable .*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    67
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    68
    // looking for thread state lines with these patterns:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    69
    // java.lang.Thread.State: RUNNABLE
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    70
    // java.lang.Thread.State: BLOCKED (on object monitor)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    71
    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
    72
        " *java\\.lang\\.Thread\\.State: .*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    73
    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
    74
        " *java\\.lang\\.Thread\\.State: BLOCKED \\(on object monitor\\)");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    75
    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
    76
        " *java\\.lang\\.Thread\\.State: RUNNABLE");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    77
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    78
    // looking for duplicates of this pattern:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    79
    // - locked <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    80
    final static Pattern LOCK_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    81
        ".* locked \\<.*\\(a TestThreadDumpMonitorContention.*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    82
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    83
    // sanity checking header and thread state lines associated
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    84
    // with this pattern:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    85
    // - waiting to lock <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    86
    final static Pattern WAITING_PATTERN = Pattern.compile(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    87
        ".* waiting to lock \\<.*\\(a TestThreadDumpMonitorContention.*");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    88
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    89
    final static Object barrier = new Object();
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    90
    volatile static boolean done = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    91
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    92
    static int barrier_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    93
    static int blank_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    94
    static int error_cnt = 0;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    95
    static boolean have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
    96
    static boolean have_thread_state_line = false;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    97
    static String header_line = null;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    98
    static int header_prefix_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
    99
    static int locked_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   100
    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
   101
    static int n_samples = 15;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   102
    static int sum_both_running_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   103
    static int sum_both_waiting_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   104
    static int sum_contended_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   105
    static int sum_locked_hdr_runnable_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   106
    static int sum_locked_hdr_waiting1_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   107
    static int sum_locked_hdr_waiting2_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   108
    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
   109
    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
   110
    static int sum_one_waiting_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   111
    static int sum_uncontended_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   112
    static int sum_waiting_hdr_waiting1_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   113
    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
   114
    static String thread_state_line = null;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   115
    static boolean verbose = false;
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   116
    static int waiting_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   117
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   118
    public static void main(String[] args) throws Exception {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   119
        if (args.length != 0) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   120
            int arg_i = 0;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   121
            if (args[arg_i].equals("-v")) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   122
                verbose = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   123
                arg_i++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   124
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   125
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   126
            try {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   127
                n_samples = Integer.parseInt(args[arg_i]);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   128
            } catch (NumberFormatException nfe) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   129
                System.err.println(nfe);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   130
                usage();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   131
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   132
        }
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
        Runnable runnable = new Runnable() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   135
            public void run() {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   136
                synchronized (barrier) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   137
                    // let the main thread know we're running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   138
                    barrier_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   139
                    barrier.notify();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   140
                }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   141
                while (!done) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   142
                    synchronized (this) { }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   143
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   144
            }
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
        Thread[] thread_list = new Thread[2];
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   147
        thread_list[0] = new Thread(runnable, "ContendingThread-1");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   148
        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
   149
        synchronized (barrier) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   150
            thread_list[0].start();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   151
            thread_list[1].start();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   152
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   153
            // 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
   154
            // we don't sample any thread init states.
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   155
            while (barrier_cnt < 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   156
                barrier.wait();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   157
            }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   158
        }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   159
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   160
        doSamples();
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
        done = true;
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
        thread_list[0].join();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   165
        thread_list[1].join();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   166
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   167
        if (error_cnt == 0) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   168
            System.out.println("Test PASSED.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   169
        } else {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   170
            System.out.println("Test FAILED.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   171
            throw new AssertionError("error_cnt=" + error_cnt);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   172
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   173
    }
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
    // 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
   176
    // stack trace without matching either LOCK_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   177
    // 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
   178
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   179
    // Example:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   180
    // "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
   181
    //    java.lang.Thread.State: RUNNABLE
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   182
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   183
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   184
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   185
    static boolean checkBlankLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   186
        if (line.length() == 0) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   187
            blank_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   188
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   189
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   190
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   191
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   192
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   193
        return false;
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
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   196
    // 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
   197
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   198
    // Example 1:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   199
    // "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
   200
    //    java.lang.Thread.State: RUNNABLE
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   201
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   202
    //         - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   203
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   204
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   205
    // Example 2:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   206
    // "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
   207
    //    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
   208
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   209
    //         - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   210
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   211
    //
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   212
    // Example 3:
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   213
    // "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
   214
    //    java.lang.Thread.State: RUNNABLE
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   215
    //    JavaThread state: _thread_blocked
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   216
    // 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
   217
    //    JavaThread state: _thread_blocked
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   218
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   219
    //         - locked <0xfffffd7e6d03eb28> (a TestThreadDumpMonitorContention$1)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   220
    //         at java.lang.Thread.run(Thread.java:745)
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   221
    //
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   222
    static boolean checkLockedLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   223
        Matcher matcher = LOCK_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   224
        if (matcher.matches()) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   225
            if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   226
                System.out.println("locked_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   227
            }
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   228
            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
   229
            locked_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   230
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   231
            matcher = HEADER_RUNNABLE_PATTERN.matcher(header_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   232
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   233
                sum_locked_hdr_runnable_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   234
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   235
                // 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
   236
                // match the HEADER_WAITING_PATTERN{1,2}.
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   237
                matcher = HEADER_WAITING_PATTERN1.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   238
                if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   239
                    sum_locked_hdr_waiting1_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   240
                } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   241
                    matcher = HEADER_WAITING_PATTERN2.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   242
                    if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   243
                        sum_locked_hdr_waiting2_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   244
                    } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   245
                        System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   246
                        System.err.println("ERROR: header line does " +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   247
                            "not match runnable or waiting patterns.");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   248
                        System.err.println("ERROR: header_line='" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   249
                            header_line + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   250
                        System.err.println("ERROR: locked_line='" + line +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   251
                            "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   252
                        error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   253
                    }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   254
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   255
            }
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
            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
   258
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   259
                sum_locked_thr_state_runnable_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   260
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   261
                // 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
   262
                // match the THREAD_STATE_BLOCKED_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   263
                matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   264
                              thread_state_line);
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   265
                if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   266
                    sum_locked_thr_state_blocked_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   267
                } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   268
                    System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   269
                    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
   270
                        "match runnable or waiting patterns.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   271
                    System.err.println("ERROR: " + "thread_state_line='" +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   272
                        thread_state_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   273
                    System.err.println("ERROR: locked_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   274
                    error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   275
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   276
            }
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
            // Have everything we need from this thread stack
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   279
            // that matches the LOCK_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   280
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   281
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   282
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   283
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   284
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   285
        return false;
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
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   288
    // 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
   289
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   290
    // Example:
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   291
    // "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
   292
    //    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
   293
    //         at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:140)
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   294
    //         - waiting to lock <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   295
    //         at java.lang.Thread.run(Thread.java:745)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   296
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   297
    static boolean checkWaitingLine(String line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   298
        Matcher matcher = WAITING_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   299
        if (matcher.matches()) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   300
            waiting_line_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   301
            if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   302
                System.out.println("waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   303
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   304
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   305
            matcher = HEADER_WAITING_PATTERN1.matcher(header_line);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   306
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   307
                sum_waiting_hdr_waiting1_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   308
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   309
                System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   310
                System.err.println("ERROR: header line does " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   311
                    "not match a waiting pattern.");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   312
                System.err.println("ERROR: header_line='" + header_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   313
                System.err.println("ERROR: waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   314
                error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   315
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   316
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   317
            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
   318
            if (matcher.matches()) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   319
                sum_waiting_thr_state_blocked_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   320
            } else {
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   321
                System.err.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   322
                System.err.println("ERROR: thread state line " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   323
                    "does not match a waiting pattern.");
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
                    thread_state_line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   326
                System.err.println("ERROR: waiting_line='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   327
                error_cnt++;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   328
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   329
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   330
            // Have everything we need from this thread stack
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   331
            // that matches the WAITING_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   332
            have_header_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   333
            have_thread_state_line = false;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   334
            return true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   335
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   336
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   337
        return false;
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
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   340
    static void doSamples() throws Exception {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   341
        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
   342
            blank_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   343
            header_prefix_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   344
            locked_line_match_cnt = 0;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   345
            waiting_line_match_cnt = 0;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   346
            // 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
   347
            if (verbose || error_cnt > 0) System.out.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   348
            System.out.println("Sample #" + count);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   349
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   350
            // We don't use the ProcessTools, OutputBuffer or
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   351
            // OutputAnalyzer classes from the testlibrary because
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   352
            // 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
   353
            // on a narrow subset of the JSTACK output.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   354
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   355
            // - we only care about stack traces that match
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   356
            //   HEADER_PREFIX_PATTERN; only two should match
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   357
            // - 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
   358
            // - 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
   359
            //   a failure and we report it
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   360
            // - 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
   361
            //   - the header line matches HEADER_RUNNABLE_PATTERN
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   362
            //     or HEADER_WAITING_PATTERN{1,2}
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   363
            //   - 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
   364
            //     or THREAD_STATE_RUNNABLE_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   365
            //   - we report any mismatches as failures
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   366
            // - 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
   367
            //   - the header line matches HEADER_WAITING_PATTERN1
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   368
            //   - 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
   369
            //   - we report any mismatches as failures
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   370
            // - 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
   371
            //   not match either LOCKED_PATTERN or WAITING_PATTERN
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   372
            //   because we might observe the thread outside of
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   373
            //   monitor operations; this is not considered a failure
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   374
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   375
            // 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
   376
            // 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
   377
            // 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
   378
            // 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
   379
            // 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
   380
            // 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
   381
            // match HEADER_PREFIX_PATTERN.
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   382
            //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   383
            Process process = new ProcessBuilder(JSTACK, PID)
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   384
                .redirectErrorStream(true).start();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   385
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   386
            BufferedReader reader = new BufferedReader(new InputStreamReader(
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   387
                                        process.getInputStream()));
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   388
            String line;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   389
            while ((line = reader.readLine()) != null) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   390
                Matcher matcher = null;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   391
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   392
                // process the header line here
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   393
                if (!have_header_line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   394
                    matcher = HEADER_PREFIX_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   395
                    if (matcher.matches()) {
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   396
                        header_prefix_match_cnt++;
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   397
                        if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   398
                            System.out.println();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   399
                            System.out.println("header='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   400
                        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   401
                        header_line = new String(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   402
                        have_header_line = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   403
                        continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   404
                    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   405
                    continue;  // skip until have a header line
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
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   408
                // process the thread state line here
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   409
                if (!have_thread_state_line) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   410
                    matcher = THREAD_STATE_PREFIX_PATTERN.matcher(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   411
                    if (matcher.matches()) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   412
                        if (verbose) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   413
                            System.out.println("thread_state='" + line + "'");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   414
                        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   415
                        thread_state_line = new String(line);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   416
                        have_thread_state_line = true;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   417
                        continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   418
                    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   419
                    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
   420
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   421
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   422
                // 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
   423
                if (checkLockedLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   424
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   425
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   426
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   427
                // 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
   428
                if (checkWaitingLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   429
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   430
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   431
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   432
                // 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
   433
                if (checkBlankLine(line)) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   434
                    continue;
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   435
                }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   436
            }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   437
            process.waitFor();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   438
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   439
            if (header_prefix_match_cnt != 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   440
                System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   441
                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
   442
                System.err.println("ERROR: header_prefix_match_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   443
                    header_prefix_match_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   444
                error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   445
            }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   446
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   447
            if (locked_line_match_cnt == 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   448
                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
   449
                    System.err.println();
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   450
                    System.err.println("ERROR: matching lock lines:");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   451
                    System.err.println("ERROR: line[0]'" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   452
                        locked_match_list[0] + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   453
                    System.err.println("ERROR: line[1]'" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   454
                        locked_match_list[1] + "'");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   455
                    error_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   456
                }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   457
            }
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
            if (locked_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   460
                // one thread has the lock
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   461
                if (waiting_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   462
                    // and the other contended for it
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   463
                    sum_contended_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   464
                } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   465
                    // and the other is just running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   466
                    sum_uncontended_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   467
                }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   468
            } else if (waiting_line_match_cnt == 1) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   469
                // one thread is waiting
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   470
                sum_one_waiting_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   471
            } else if (waiting_line_match_cnt == 2) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   472
                // both threads are waiting
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   473
                sum_both_waiting_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   474
            } else {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   475
                // both threads are running
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   476
                sum_both_running_cnt++;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   477
            }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   478
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   479
            // slight delay between jstack launches
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   480
            Thread.sleep(500);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   481
        }
25061
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   482
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   483
        if (error_cnt != 0) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   484
            // skip summary info since there were errors
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   485
            return;
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   486
        }
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   487
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   488
        System.out.println("INFO: Summary for all samples:");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   489
        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
   490
        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
   491
        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
   492
        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
   493
        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
   494
        System.out.println("INFO: locked_hdr_runnable_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   495
            sum_locked_hdr_runnable_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   496
        System.out.println("INFO: locked_hdr_waiting1_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   497
            sum_locked_hdr_waiting1_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   498
        System.out.println("INFO: locked_hdr_waiting2_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   499
            sum_locked_hdr_waiting2_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   500
        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
   501
            sum_locked_thr_state_blocked_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_runnable_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   503
            sum_locked_thr_state_runnable_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   504
        System.out.println("INFO: waiting_hdr_waiting1_cnt=" +
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   505
            sum_waiting_hdr_waiting1_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   506
        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
   507
            sum_waiting_thr_state_blocked_cnt);
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   508
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   509
        if (sum_contended_cnt == 0) {
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   510
            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
   511
                " has not been exercised by this test run.");
b13d25e6a193 8046287: [TESTBUG] runtime/Thread/TestThreadDumpMonitorContention.java failed error_cnt=12
dcubed
parents: 24832
diff changeset
   512
        }
24832
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   513
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   514
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   515
    // 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
   516
    // that looks like this: 5436@mt-haku
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   517
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   518
    // 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
   519
    // 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
   520
    //
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   521
    static String getPid() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   522
        RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   523
        String vmname = runtimebean.getName();
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   524
        int i = vmname.indexOf('@');
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   525
        if (i != -1) {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   526
            vmname = vmname.substring(0, i);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   527
        }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   528
        return vmname;
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
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   531
    static void usage() {
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   532
        System.err.println("Usage: " +
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   533
            "java TestThreadDumpMonitorContention [-v] [n_samples]");
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   534
        System.exit(1);
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   535
    }
26a834fb508d 8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff changeset
   536
}