author | jgeorge |
Fri, 01 Dec 2017 18:19:39 +0530 | |
changeset 48181 | 61a14b5cb1c6 |
parent 47216 | 71c04702a3d5 |
child 50791 | b1e90a8a876c |
permissions | -rw-r--r-- |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, 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 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
38 |
/* |
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 |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
41 |
* @library /test/lib |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
37443
diff
changeset
|
42 |
* @modules java.base/jdk.internal.misc |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
43 |
* @modules java.management |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
44 |
* @run main DeadlockDetectionTest |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
45 |
*/ |
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 |
public class DeadlockDetectionTest { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
48 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
49 |
private static LingeredAppWithDeadlock theApp = null; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
50 |
private static ProcessBuilder processBuilder = new ProcessBuilder(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
51 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
52 |
private static OutputAnalyzer jstack(String... toolArgs) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
53 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
54 |
launcher.addToolArg("jstack"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
55 |
if (toolArgs != null) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
56 |
for (String toolArg : toolArgs) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
57 |
launcher.addToolArg(toolArg); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
58 |
} |
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 |
processBuilder.command(launcher.getCommand()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
62 |
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" "))); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
63 |
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
64 |
System.out.println(output.getOutput()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
65 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
66 |
return output; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
67 |
} |
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 |
public static void main(String[] args) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
70 |
System.out.println("Starting DeadlockDetectionTest"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
71 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
72 |
if (!Platform.shouldSAAttach()) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
73 |
// Silently skip the test if we don't have enough permissions to attach |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
74 |
// Not all conditions checked by function is relevant to SA but it's worth |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
75 |
// to check |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
76 |
System.err.println("Error! Insufficient permissions to attach."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
77 |
return; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
78 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
79 |
|
37443
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
80 |
if (Platform.isOSX()) { |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
81 |
// Coredump stackwalking is not implemented for Darwin |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
82 |
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
|
83 |
return; |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
84 |
} |
1ac0e91a0f53
8152679: DeadlockDetectionTest.java fails due to expected output missing
dsamersoff
parents:
33730
diff
changeset
|
85 |
|
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
86 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
87 |
if (!LingeredApp.isLastModifiedWorking()) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
88 |
// 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
|
89 |
// so just print the warning and continue |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
90 |
System.err.println("Warning! Last modified time doesn't work."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
91 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
92 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
93 |
try { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
94 |
List<String> vmArgs = new ArrayList<String>(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
95 |
vmArgs.add("-XX:+UsePerfData"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
96 |
vmArgs.addAll(Utils.getVmOptions()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
97 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
98 |
theApp = new LingeredAppWithDeadlock(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
99 |
LingeredApp.startApp(vmArgs, theApp); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
100 |
OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid())); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
101 |
System.out.println(output.getOutput()); |
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 |
if (output.getExitValue() == 3) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
104 |
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
|
105 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
106 |
else { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
107 |
output.shouldHaveExitValue(0); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
108 |
output.shouldContain("Found a total of 1 deadlock."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
109 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
110 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
111 |
} finally { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
112 |
LingeredApp.stopApp(theApp); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
113 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
114 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
115 |
} |