author | goetz |
Mon, 25 Jun 2018 23:04:21 +0200 | |
changeset 50791 | b1e90a8a876c |
parent 47216 | 71c04702a3d5 |
child 51287 | 7b1ddbafa134 |
permissions | -rw-r--r-- |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
1 |
/* |
50791
b1e90a8a876c
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
4 |
* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
8 |
* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
13 |
* accompanied this code). |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
14 |
* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
18 |
* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
21 |
* questions. |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
22 |
*/ |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
23 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
24 |
import java.util.ArrayList; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
25 |
import java.util.List; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
26 |
import java.util.stream.Collectors; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
27 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
28 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
29 |
import jdk.test.lib.apps.LingeredApp; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
30 |
import jdk.test.lib.apps.LingeredAppWithDeadlock; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
31 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
32 |
import jdk.test.lib.Utils; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
33 |
import jdk.test.lib.Platform; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
34 |
import jdk.test.lib.JDKToolLauncher; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
35 |
import jdk.test.lib.process.OutputAnalyzer; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
36 |
import jdk.test.lib.process.ProcessTools; |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
37 |
|
50791
b1e90a8a876c
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents:
47216
diff
changeset
|
38 |
/** |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
39 |
* @test |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
40 |
* @summary Test deadlock detection |
50791
b1e90a8a876c
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents:
47216
diff
changeset
|
41 |
* @requires vm.hasSAandCanAttach |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
42 |
* @library /test/lib |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
37443
diff
changeset
|
43 |
* @modules java.base/jdk.internal.misc |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
44 |
* @modules java.management |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
45 |
* @run main DeadlockDetectionTest |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
46 |
*/ |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
47 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
48 |
public class DeadlockDetectionTest { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
49 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
50 |
private static LingeredAppWithDeadlock theApp = null; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
51 |
private static ProcessBuilder processBuilder = new ProcessBuilder(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
52 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
53 |
private static OutputAnalyzer jstack(String... toolArgs) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
54 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
55 |
launcher.addToolArg("jstack"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
56 |
if (toolArgs != null) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
57 |
for (String toolArg : toolArgs) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
58 |
launcher.addToolArg(toolArg); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
59 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
60 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
61 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
62 |
processBuilder.command(launcher.getCommand()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
63 |
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" "))); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
64 |
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
65 |
System.out.println(output.getOutput()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
66 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
67 |
return output; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
68 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
69 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
70 |
public static void main(String[] args) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
71 |
System.out.println("Starting DeadlockDetectionTest"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
72 |
|
37443
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
73 |
if (Platform.isOSX()) { |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
74 |
// Coredump stackwalking is not implemented for Darwin |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
75 |
System.out.println("This test is not expected to work on OS X. Skipping"); |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
76 |
return; |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
77 |
} |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
78 |
|
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
79 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
80 |
if (!LingeredApp.isLastModifiedWorking()) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
81 |
// Exact behaviour of the test depends on operating system and the test nature, |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
82 |
// so just print the warning and continue |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
83 |
System.err.println("Warning! Last modified time doesn't work."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
84 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
85 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
86 |
try { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
87 |
List<String> vmArgs = new ArrayList<String>(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
88 |
vmArgs.add("-XX:+UsePerfData"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
89 |
vmArgs.addAll(Utils.getVmOptions()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
90 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
91 |
theApp = new LingeredAppWithDeadlock(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
92 |
LingeredApp.startApp(vmArgs, theApp); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
93 |
OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid())); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
94 |
System.out.println(output.getOutput()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
95 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
96 |
if (output.getExitValue() == 3) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
97 |
System.out.println("Test can't run for some reason. Skipping"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
98 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
99 |
else { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
100 |
output.shouldHaveExitValue(0); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
101 |
output.shouldContain("Found a total of 1 deadlock."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
102 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
103 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
104 |
} finally { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
105 |
LingeredApp.stopApp(theApp); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
106 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
107 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
108 |
} |