Mercurial > hg > truffle
annotate test/runtime/Thread/TestThreadDumpMonitorContention.java @ 17965:4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
Summary: Add a !owner check for 'waiting to lock' to catch current_pending_monitor corner cases.
Reviewed-by: dholmes, sspitsyn, kmo, zgu
Contributed-by: rednaxelafx@gmail.com, zhengyu.gu@oracle.com, daniel.daugherty@oracle.com
author | dcubed |
---|---|
date | Wed, 04 Jun 2014 06:25:53 -0700 |
parents | |
children | 22146594cd5a |
rev | line source |
---|---|
17965
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
1 /* |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4a1062dc52d1
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. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
4 * |
4a1062dc52d1
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 |
4a1062dc52d1
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 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
8 * |
4a1062dc52d1
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 |
4a1062dc52d1
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 |
4a1062dc52d1
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 |
4a1062dc52d1
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 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
13 * accompanied this code). |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
14 * |
4a1062dc52d1
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 |
4a1062dc52d1
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, |
4a1062dc52d1
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. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
18 * |
4a1062dc52d1
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 |
4a1062dc52d1
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 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
21 * questions. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
22 */ |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
23 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
24 /* |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
25 * @test |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
26 * @bug 8036823 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
27 * @summary Creates two threads contending for the same lock and checks |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
28 * whether jstack reports "locked" by more than one thread. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
29 * |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
30 * @library /testlibrary |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
31 * @run main/othervm TestThreadDumpMonitorContention |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
32 */ |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
33 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
34 import java.io.BufferedReader; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
35 import java.io.InputStreamReader; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
36 import java.lang.management.ManagementFactory; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
37 import java.lang.management.RuntimeMXBean; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
38 import java.util.ArrayList; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
39 import java.util.List; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
40 import java.util.regex.Matcher; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
41 import java.util.regex.Pattern; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
42 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
43 import com.oracle.java.testlibrary.*; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
44 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
45 public class TestThreadDumpMonitorContention { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
46 // jstack tends to be closely bound to the VM that we are running |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
47 // so use getTestJDKTool() instead of getCompileJDKTool() or even |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
48 // getJDKTool() which can fall back to "compile.jdk". |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
49 final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
50 final static String PID = getPid(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
51 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
52 // looking for header lines with these patterns: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
53 // "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
54 // "ContendingThread-2" #21 prio=5 os_prio=64 tid=0x0000000000780000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
55 final static Pattern HEADER_PREFIX_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
56 "^\"ContendingThread-.*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
57 final static Pattern HEADER_WAITING_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
58 "^\"ContendingThread-.* waiting for monitor entry .*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
59 final static Pattern HEADER_RUNNABLE_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
60 "^\"ContendingThread-.* runnable .*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
61 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
62 // looking for thread state lines with these patterns: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
63 // java.lang.Thread.State: RUNNABLE |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
64 // java.lang.Thread.State: BLOCKED (on object monitor) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
65 final static Pattern THREAD_STATE_PREFIX_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
66 " *java\\.lang\\.Thread\\.State: .*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
67 final static Pattern THREAD_STATE_BLOCKED_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
68 " *java\\.lang\\.Thread\\.State: BLOCKED \\(on object monitor\\)"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
69 final static Pattern THREAD_STATE_RUNNABLE_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
70 " *java\\.lang\\.Thread\\.State: RUNNABLE"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
71 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
72 // looking for duplicates of this pattern: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
73 // - locked <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
74 final static Pattern LOCK_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
75 ".* locked \\<.*\\(a TestThreadDumpMonitorContention.*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
76 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
77 // sanity checking header and thread state lines associated |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
78 // with this pattern: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
79 // - waiting to lock <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
80 final static Pattern WAITING_PATTERN = Pattern.compile( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
81 ".* waiting to lock \\<.*\\(a TestThreadDumpMonitorContention.*"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
82 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
83 volatile static boolean done = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
84 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
85 static int error_cnt = 0; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
86 static String header_line = null; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
87 static boolean have_header_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
88 static boolean have_thread_state_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
89 static int match_cnt = 0; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
90 static String[] match_list = new String[2]; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
91 static int n_samples = 15; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
92 static String thread_state_line = null; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
93 static boolean verbose = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
94 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
95 public static void main(String[] args) throws Exception { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
96 if (args.length != 0) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
97 int arg_i = 0; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
98 if (args[arg_i].equals("-v")) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
99 verbose = true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
100 arg_i++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
101 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
102 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
103 try { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
104 n_samples = Integer.parseInt(args[arg_i]); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
105 } catch (NumberFormatException nfe) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
106 System.err.println(nfe); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
107 usage(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
108 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
109 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
110 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
111 Runnable runnable = new Runnable() { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
112 public void run() { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
113 while (!done) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
114 synchronized (this) { } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
115 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
116 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
117 }; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
118 Thread[] thread_list = new Thread[2]; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
119 thread_list[0] = new Thread(runnable, "ContendingThread-1"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
120 thread_list[1] = new Thread(runnable, "ContendingThread-2"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
121 thread_list[0].start(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
122 thread_list[1].start(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
123 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
124 doSamples(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
125 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
126 done = true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
127 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
128 thread_list[0].join(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
129 thread_list[1].join(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
130 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
131 if (error_cnt == 0) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
132 System.out.println("Test PASSED."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
133 } else { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
134 System.out.println("Test FAILED."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
135 throw new AssertionError("error_cnt=" + error_cnt); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
136 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
137 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
138 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
139 // Reached a blank line which is the end of the |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
140 // stack trace without matching either LOCK_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
141 // or WAITING_PATTERN. Rare, but it's not an error. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
142 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
143 // Example: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
144 // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
145 // java.lang.Thread.State: RUNNABLE |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
146 // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
147 // at java.lang.Thread.run(Thread.java:745) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
148 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
149 static boolean checkBlankLine(String line) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
150 if (line.length() == 0) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
151 have_header_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
152 have_thread_state_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
153 return true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
154 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
155 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
156 return false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
157 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
158 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
159 // Process the locked line here if we found one. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
160 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
161 // Example 1: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
162 // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
163 // java.lang.Thread.State: RUNNABLE |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
164 // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
165 // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
166 // at java.lang.Thread.run(Thread.java:745) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
167 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
168 // Example 2: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
169 // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
170 // java.lang.Thread.State: BLOCKED (on object monitor) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
171 // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
172 // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
173 // at java.lang.Thread.run(Thread.java:745) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
174 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
175 static boolean checkLockedLine(String line) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
176 Matcher matcher = LOCK_PATTERN.matcher(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
177 if (matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
178 if (verbose) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
179 System.out.println("locked_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
180 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
181 match_list[match_cnt] = new String(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
182 match_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
183 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
184 matcher = HEADER_RUNNABLE_PATTERN.matcher(header_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
185 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
186 // It's strange, but a locked line can also |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
187 // match the HEADER_WAITING_PATTERN. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
188 matcher = HEADER_WAITING_PATTERN.matcher(header_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
189 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
190 System.err.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
191 System.err.println("ERROR: header line does " + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
192 "not match runnable or waiting patterns."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
193 System.err.println("ERROR: header_line='" + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
194 header_line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
195 System.err.println("ERROR: locked_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
196 error_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
197 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
198 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
199 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
200 matcher = THREAD_STATE_RUNNABLE_PATTERN.matcher(thread_state_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
201 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
202 // It's strange, but a locked line can also |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
203 // match the THREAD_STATE_BLOCKED_PATTERN. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
204 matcher = THREAD_STATE_BLOCKED_PATTERN.matcher( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
205 thread_state_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
206 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
207 System.err.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
208 System.err.println("ERROR: thread state line does not " + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
209 "match runnable or waiting patterns."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
210 System.err.println("ERROR: " + "thread_state_line='" + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
211 thread_state_line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
212 System.err.println("ERROR: locked_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
213 error_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
214 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
215 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
216 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
217 // Have everything we need from this thread stack |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
218 // that matches the LOCK_PATTERN. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
219 have_header_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
220 have_thread_state_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
221 return true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
222 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
223 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
224 return false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
225 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
226 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
227 // Process the waiting line here if we found one. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
228 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
229 // Example: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
230 // "ContendingThread-2" #22 prio=5 os_prio=64 tid=0x00000000007b9800 nid=0x30 waiting for monitor entry [0xfffffd7fc1010000] |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
231 // java.lang.Thread.State: BLOCKED (on object monitor) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
232 // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
233 // - waiting to lock <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
234 // at java.lang.Thread.run(Thread.java:745) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
235 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
236 static boolean checkWaitingLine(String line) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
237 Matcher matcher = WAITING_PATTERN.matcher(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
238 if (matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
239 if (verbose) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
240 System.out.println("waiting_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
241 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
242 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
243 matcher = HEADER_WAITING_PATTERN.matcher(header_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
244 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
245 System.err.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
246 System.err.println("ERROR: header line does " + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
247 "not match a waiting pattern."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
248 System.err.println("ERROR: header_line='" + header_line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
249 System.err.println("ERROR: waiting_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
250 error_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
251 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
252 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
253 matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(thread_state_line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
254 if (!matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
255 System.err.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
256 System.err.println("ERROR: thread state line " + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
257 "does not match a waiting pattern."); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
258 System.err.println("ERROR: thread_state_line='" + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
259 thread_state_line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
260 System.err.println("ERROR: waiting_line='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
261 error_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
262 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
263 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
264 // Have everything we need from this thread stack |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
265 // that matches the WAITING_PATTERN. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
266 have_header_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
267 have_thread_state_line = false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
268 return true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
269 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
270 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
271 return false; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
272 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
273 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
274 static void doSamples() throws Exception { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
275 for (int count = 0; count < n_samples; count++) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
276 match_cnt = 0; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
277 // verbose mode or an error has a lot of output so add more space |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
278 if (verbose || error_cnt > 0) System.out.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
279 System.out.println("Sample #" + count); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
280 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
281 // We don't use the ProcessTools, OutputBuffer or |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
282 // OutputAnalyzer classes from the testlibrary because |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
283 // we have a complicated multi-line parse to perform |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
284 // on a narrow subset of the JSTACK output. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
285 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
286 // - we only care about stack traces that match |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
287 // HEADER_PREFIX_PATTERN; only two should match |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
288 // - we care about at most three lines from each stack trace |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
289 // - if both stack traces match LOCKED_PATTERN, then that's |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
290 // a failure and we report it |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
291 // - for a stack trace that matches LOCKED_PATTERN, we verify: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
292 // - the header line matches HEADER_RUNNABLE_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
293 // or HEADER_WAITING_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
294 // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
295 // or THREAD_STATE_RUNNABLE_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
296 // - we report any mismatches as failures |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
297 // - for a stack trace that matches WAITING_PATTERN, we verify: |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
298 // - the header line matches HEADER_WAITING_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
299 // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
300 // - we report any mismatches as failures |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
301 // - the stack traces that match HEADER_PREFIX_PATTERN may |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
302 // not match either LOCKED_PATTERN or WAITING_PATTERN |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
303 // because we might observe the thread outside of |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
304 // monitor operations; this is not considered a failure |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
305 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
306 // When we do observe LOCKED_PATTERN or WAITING_PATTERN, |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
307 // then we are checking the header and thread state patterns |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
308 // that occurred earlier in the current stack trace that |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
309 // matched HEADER_PREFIX_PATTERN. We don't use data from |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
310 // stack traces that don't match HEADER_PREFIX_PATTERN and |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
311 // we don't mix data between the two stack traces that do |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
312 // match HEADER_PREFIX_PATTERN. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
313 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
314 Process process = new ProcessBuilder(JSTACK, PID) |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
315 .redirectErrorStream(true).start(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
316 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
317 BufferedReader reader = new BufferedReader(new InputStreamReader( |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
318 process.getInputStream())); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
319 String line; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
320 while ((line = reader.readLine()) != null) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
321 Matcher matcher = null; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
322 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
323 // process the header line here |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
324 if (!have_header_line) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
325 matcher = HEADER_PREFIX_PATTERN.matcher(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
326 if (matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
327 if (verbose) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
328 System.out.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
329 System.out.println("header='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
330 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
331 header_line = new String(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
332 have_header_line = true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
333 continue; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
334 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
335 continue; // skip until have a header line |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
336 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
337 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
338 // process the thread state line here |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
339 if (!have_thread_state_line) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
340 matcher = THREAD_STATE_PREFIX_PATTERN.matcher(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
341 if (matcher.matches()) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
342 if (verbose) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
343 System.out.println("thread_state='" + line + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
344 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
345 thread_state_line = new String(line); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
346 have_thread_state_line = true; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
347 continue; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
348 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
349 continue; // skip until we have a thread state line |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
350 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
351 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
352 // process the locked line here if we find one |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
353 if (checkLockedLine(line)) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
354 continue; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
355 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
356 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
357 // process the waiting line here if we find one |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
358 if (checkWaitingLine(line)) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
359 continue; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
360 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
361 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
362 // process the blank line here if we find one |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
363 if (checkBlankLine(line)) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
364 continue; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
365 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
366 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
367 process.waitFor(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
368 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
369 if (match_cnt == 2) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
370 if (match_list[0].equals(match_list[1])) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
371 System.err.println(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
372 System.err.println("ERROR: matching lock lines:"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
373 System.err.println("ERROR: line[0]'" + match_list[0] + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
374 System.err.println("ERROR: line[1]'" + match_list[1] + "'"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
375 error_cnt++; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
376 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
377 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
378 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
379 // slight delay between jstack launches |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
380 Thread.sleep(500); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
381 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
382 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
383 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
384 // This helper relies on RuntimeMXBean.getName() returning a string |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
385 // that looks like this: 5436@mt-haku |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
386 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
387 // The testlibrary has tryFindJvmPid(), but that uses a separate |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
388 // process which is much more expensive for finding out your own PID. |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
389 // |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
390 static String getPid() { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
391 RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
392 String vmname = runtimebean.getName(); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
393 int i = vmname.indexOf('@'); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
394 if (i != -1) { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
395 vmname = vmname.substring(0, i); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
396 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
397 return vmname; |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
398 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
399 |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
400 static void usage() { |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
401 System.err.println("Usage: " + |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
402 "java TestThreadDumpMonitorContention [-v] [n_samples]"); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
403 System.exit(1); |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
404 } |
4a1062dc52d1
8036823: Stack trace sometimes shows 'locked' instead of 'waiting to lock'
dcubed
parents:
diff
changeset
|
405 } |