author | aeriksso |
Thu, 18 Feb 2016 16:15:28 +0100 | |
changeset 36353 | 28b633a6919d |
parent 33730 | 30e064828045 |
child 37443 | 1ac0e91a0f53 |
permissions | -rw-r--r-- |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
1 |
/* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
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; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
35 |
import jdk.test.lib.OutputAnalyzer; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
36 |
import jdk.test.lib.ProcessTools; |
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 |
33730
30e064828045
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents:
33100
diff
changeset
|
41 |
* @library /test/lib/share/classes |
33100
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
42 |
* @library /testlibrary |
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 |
* @build jdk.test.lib.* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
45 |
* @build jdk.test.lib.apps.* |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
46 |
* @build DeadlockDetectionTest |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
47 |
* @run main 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 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
50 |
public class DeadlockDetectionTest { |
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 LingeredAppWithDeadlock theApp = null; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
53 |
private static ProcessBuilder processBuilder = new ProcessBuilder(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
54 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
55 |
private static OutputAnalyzer jstack(String... toolArgs) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
56 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
57 |
launcher.addToolArg("jstack"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
58 |
if (toolArgs != null) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
59 |
for (String toolArg : toolArgs) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
60 |
launcher.addToolArg(toolArg); |
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 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
63 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
64 |
processBuilder.command(launcher.getCommand()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
65 |
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" "))); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
66 |
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
67 |
System.out.println(output.getOutput()); |
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 |
return output; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
70 |
} |
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 |
public static void main(String[] args) throws Exception { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
73 |
System.out.println("Starting DeadlockDetectionTest"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
74 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
75 |
if (!Platform.shouldSAAttach()) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
76 |
// 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
|
77 |
// 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
|
78 |
// to check |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
79 |
System.err.println("Error! Insufficient permissions to attach."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
80 |
return; |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
81 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
82 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
83 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
84 |
if (!LingeredApp.isLastModifiedWorking()) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
85 |
// 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
|
86 |
// so just print the warning and continue |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
87 |
System.err.println("Warning! Last modified time doesn't work."); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
88 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
89 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
90 |
try { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
91 |
List<String> vmArgs = new ArrayList<String>(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
92 |
vmArgs.add("-XX:+UsePerfData"); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
93 |
vmArgs.addAll(Utils.getVmOptions()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
94 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
95 |
theApp = new LingeredAppWithDeadlock(); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
96 |
LingeredApp.startApp(vmArgs, theApp); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
97 |
OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid())); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
98 |
System.out.println(output.getOutput()); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
99 |
|
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
100 |
if (output.getExitValue() == 3) { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
101 |
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
|
102 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
103 |
else { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
104 |
output.shouldHaveExitValue(0); |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
105 |
output.shouldContain("Found a total of 1 deadlock."); |
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 |
} finally { |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
109 |
LingeredApp.stopApp(theApp); |
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 |
} |
a2899ce72a14
8086134: Deadlock detection fails to attach to core file
dsamersoff
parents:
diff
changeset
|
112 |
} |