author | ihse |
Tue, 20 Feb 2018 21:47:54 +0100 | |
changeset 48923 | b75c9e2e3b1f |
parent 48500 | 899a137688b8 |
child 50791 | b1e90a8a876c |
permissions | -rw-r--r-- |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
1 |
/* |
48500
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
4 |
* |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
8 |
* |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
13 |
* accompanied this code). |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
14 |
* |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
18 |
* |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
21 |
* questions. |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
22 |
*/ |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
23 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
24 |
import java.io.IOException; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
25 |
import java.io.OutputStream; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
26 |
import java.util.ArrayList; |
48500
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
27 |
import java.util.Arrays; |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
28 |
import java.util.List; |
48500
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
29 |
import java.util.regex.Matcher; |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
30 |
import java.util.regex.Pattern; |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
31 |
|
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
32 |
import jdk.test.lib.apps.LingeredApp; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
33 |
import jdk.test.lib.Asserts; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
34 |
import jdk.test.lib.JDKToolLauncher; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
35 |
import jdk.test.lib.Platform; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
36 |
import jdk.test.lib.process.OutputAnalyzer; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
37 |
import jdk.test.lib.process.ProcessTools; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
38 |
import jdk.test.lib.Utils; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
39 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
40 |
/* |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
41 |
* @test |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
42 |
* @library /test/lib |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
43 |
* @run main/othervm TestJhsdbJstackLock |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
44 |
*/ |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
45 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
46 |
public class TestJhsdbJstackLock { |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
47 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
48 |
public static void main (String... args) throws Exception { |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
49 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
50 |
LingeredApp app = null; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
51 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
52 |
if (!Platform.shouldSAAttach()) { |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
53 |
System.out.println("SA attach not expected to work - test skipped."); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
54 |
return; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
55 |
} |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
56 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
57 |
try { |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
58 |
List<String> vmArgs = new ArrayList<String>(Utils.getVmOptions()); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
59 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
60 |
app = new LingeredAppWithLock(); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
61 |
LingeredApp.startApp(vmArgs, app); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
62 |
System.out.println ("Started LingeredApp with pid " + app.getPid()); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
63 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
64 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
65 |
launcher.addToolArg("jstack"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
66 |
launcher.addToolArg("--pid"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
67 |
launcher.addToolArg(Long.toString(app.getPid())); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
68 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
69 |
ProcessBuilder pb = new ProcessBuilder(); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
70 |
pb.command(launcher.getCommand()); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
71 |
Process jhsdb = pb.start(); |
48178 | 72 |
OutputAnalyzer out = new OutputAnalyzer(jhsdb); |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
73 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
74 |
jhsdb.waitFor(); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
75 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
76 |
System.out.println(out.getStdout()); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
77 |
System.err.println(out.getStderr()); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
78 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
79 |
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
80 |
out.shouldMatch("^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
81 |
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
82 |
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$"); |
48500
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
83 |
|
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
84 |
// stderr should be empty except for VM warnings. |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
85 |
if (!out.getStderr().isEmpty()) { |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
86 |
List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)")); |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
87 |
Pattern p = Pattern.compile(".*VM warning.*"); |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
88 |
for (String line : lines) { |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
89 |
Matcher m = p.matcher(line); |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
90 |
if (!m.matches()) { |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
91 |
throw new RuntimeException("Stderr has output other than VM warnings"); |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
92 |
} |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
93 |
} |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
94 |
} |
899a137688b8
8194067: [Testbug] serviceability/sa/Jhsdb* tests can't tolerate unrelated warnings
sballal
parents:
48178
diff
changeset
|
95 |
|
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
96 |
|
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
97 |
System.out.println("Test Completed"); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
98 |
} finally { |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
99 |
LingeredApp.stopApp(app); |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
100 |
} |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
101 |
} |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
diff
changeset
|
102 |
} |