author | dholmes |
Tue, 15 Jan 2019 16:40:31 -0500 | |
changeset 53305 | d193d58ae79d |
child 53396 | d74b1c8e632a |
permissions | -rw-r--r-- |
53305
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
1 |
/* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
4 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
8 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
13 |
* accompanied this code). |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
14 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
18 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
21 |
* questions. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
22 |
*/ |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
23 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
24 |
/* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
25 |
* @test |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
26 |
* @bug 8213397 |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
27 |
* @summary Check that the thread dump shows when a thread is blocked |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
28 |
* on a class initialization monitor |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
29 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
30 |
* @library /test/lib |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
31 |
* @run main/othervm TestThreadDumpClassInitMonitor |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
32 |
*/ |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
33 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
34 |
import jdk.test.lib.process.OutputAnalyzer; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
35 |
import jdk.test.lib.JDKToolFinder; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
36 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
37 |
import java.io.IOException; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
38 |
import java.util.List; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
39 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
40 |
public class TestThreadDumpClassInitMonitor { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
41 |
// jstack tends to be closely bound to the VM that we are running |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
42 |
// so use getTestJDKTool() instead of getCompileJDKTool() or even |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
43 |
// getJDKTool() which can fall back to "compile.jdk". |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
44 |
final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
45 |
final static String PID = "" + ProcessHandle.current().pid(); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
46 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
47 |
final static Thread current = Thread.currentThread(); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
48 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
49 |
/* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
50 |
* This is the output we're looking for: |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
51 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
52 |
* "TestThread" #22 prio=5 os_prio=0 cpu=1.19ms elapsed=0.80s tid=0x00007f8f9405d800 nid=0x568b in Object.wait() [0x00007f8fd94d0000] |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
53 |
* java.lang.Thread.State: RUNNABLE |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
54 |
* Thread: 0x00007f8f9405d800 [0x568b] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
55 |
* JavaThread state: _thread_blocked |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
56 |
* at TestThreadDumpClassInitMonitor$Target$1.run(TestThreadDumpClassInitMonitor.java:69) |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
57 |
* - waiting on the Class initialization monitor for TestThreadDumpClassInitMonitor$Target |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
58 |
* |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
59 |
*/ |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
60 |
final static String TEST_THREAD = "TestThread"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
61 |
final static String TEST_THREAD_ENTRY = "\"" + TEST_THREAD; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
62 |
final static String IN_OBJECT_WAIT = "in Object.wait()"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
63 |
final static String THREAD_STATE = "java.lang.Thread.State: RUNNABLE"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
64 |
final static String THREAD_INFO = "Thread:"; // the details are not important |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
65 |
final static String JAVATHREAD_STATE = "JavaThread state: _thread_blocked"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
66 |
final static String CURRENT_METHOD = "at TestThreadDumpClassInitMonitor$Target$1.run"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
67 |
final static String WAIT_INFO = "- waiting on the Class initialization monitor for TestThreadDumpClassInitMonitor$Target"; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
68 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
69 |
volatile static boolean ready = false; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
70 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
71 |
static List<String> stackDump; // jstack output as lines |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
72 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
73 |
static class Target { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
74 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
75 |
static int field; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
76 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
77 |
// The main thread will initialize this class and so |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
78 |
// execute the actual test logic here. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
79 |
static { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
80 |
if (Thread.currentThread() != current) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
81 |
throw new Error("Initialization logic error"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
82 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
83 |
System.out.println("Initializing Target class in main thread"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
84 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
85 |
Thread t = new Thread() { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
86 |
public void run() { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
87 |
System.out.println("Test thread about to access Target"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
88 |
ready = true; // tell main thread we're close |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
89 |
// This will block until the main thread completes |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
90 |
// static initialization of target |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
91 |
Target.field = 42; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
92 |
System.out.println("Test thread done"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
93 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
94 |
}; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
95 |
t.setName(TEST_THREAD); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
96 |
t.start(); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
97 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
98 |
// We want to run jstack once the test thread is blocked but |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
99 |
// there's no programmatic way to detect that. So we check the flag |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
100 |
// that will be set just before it should block, then by the time |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
101 |
// we can exec jstack it should be ready. |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
102 |
try { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
103 |
while (!ready) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
104 |
Thread.sleep(200); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
105 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
106 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
107 |
catch (InterruptedException ie) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
108 |
throw new Error("Shouldn't happen"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
109 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
110 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
111 |
// Now run jstack |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
112 |
try { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
113 |
ProcessBuilder pb = new ProcessBuilder(JSTACK, PID); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
114 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
115 |
output.shouldHaveExitValue(0); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
116 |
stackDump = output.asLines(); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
117 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
118 |
catch (IOException ioe) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
119 |
throw new Error("Launching jstack failed", ioe); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
120 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
121 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
122 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
123 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
124 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
125 |
public static void main(String[] args) throws Throwable { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
126 |
// Implicitly run the main test logic |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
127 |
Target.field = 21; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
128 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
129 |
// Now check the output of jstack |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
130 |
try { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
131 |
int foundLines = 0; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
132 |
parseStack: for (String line : stackDump) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
133 |
switch(foundLines) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
134 |
case 0: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
135 |
if (!line.startsWith(TEST_THREAD_ENTRY)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
136 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
137 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
138 |
foundLines++; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
139 |
if (!line.contains(IN_OBJECT_WAIT)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
140 |
throw new Error("Unexpected initial stack line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
141 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
142 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
143 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
144 |
case 1: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
145 |
if (!line.trim().equals(THREAD_STATE)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
146 |
throw new Error("Unexpected thread state line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
147 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
148 |
foundLines++; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
149 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
150 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
151 |
case 2: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
152 |
if (!line.startsWith(THREAD_INFO)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
153 |
throw new Error("Unexpected thread info line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
154 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
155 |
foundLines++; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
156 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
157 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
158 |
case 3: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
159 |
if (!line.trim().equals(JAVATHREAD_STATE)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
160 |
throw new Error("Unexpected JavaThread state line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
161 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
162 |
foundLines++; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
163 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
164 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
165 |
case 4: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
166 |
if (!line.trim().startsWith(CURRENT_METHOD)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
167 |
throw new Error("Unexpected current method line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
168 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
169 |
foundLines++; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
170 |
continue; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
171 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
172 |
case 5: { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
173 |
if (!line.trim().equals(WAIT_INFO)) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
174 |
throw new Error("Unexpected monitor information line: " + line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
175 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
176 |
break parseStack; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
177 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
178 |
default: throw new Error("Logic error in case statement"); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
179 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
180 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
181 |
|
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
182 |
if (foundLines == 0) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
183 |
throw new Error("Unexpected stack content - did not find line starting with " |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
184 |
+ TEST_THREAD_ENTRY); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
185 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
186 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
187 |
catch (Error e) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
188 |
// Dump the full stack trace on error so we can check the content |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
189 |
for (String line : stackDump) { |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
190 |
System.out.println(line); |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
191 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
192 |
throw e; |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
193 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
194 |
} |
d193d58ae79d
8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents:
diff
changeset
|
195 |
} |