author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58384 | 9a3a700ca571 |
permissions | -rw-r--r-- |
50571 | 1 |
/* |
58384 | 2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50571 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
50791
b1e90a8a876c
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents:
50571
diff
changeset
|
24 |
/** |
50571 | 25 |
* @test TestJmapCore |
26 |
* @summary Test verifies that jhsdb jmap could generate heap dump from core when heap is full |
|
50791
b1e90a8a876c
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents:
50571
diff
changeset
|
27 |
* @requires vm.hasSA |
50571 | 28 |
* @library /test/lib |
29 |
* @run driver/timeout=240 TestJmapCore run heap |
|
30 |
*/ |
|
31 |
||
58384 | 32 |
import java.io.File; |
33 |
||
50571 | 34 |
import jdk.test.lib.Asserts; |
35 |
import jdk.test.lib.JDKToolFinder; |
|
36 |
import jdk.test.lib.JDKToolLauncher; |
|
37 |
import jdk.test.lib.Platform; |
|
58384 | 38 |
import jdk.test.lib.Utils; |
50571 | 39 |
import jdk.test.lib.classloader.GeneratingClassLoader; |
40 |
import jdk.test.lib.hprof.HprofParser; |
|
41 |
import jdk.test.lib.process.ProcessTools; |
|
42 |
import jdk.test.lib.process.OutputAnalyzer; |
|
58384 | 43 |
import jdk.test.lib.SA.SATestUtils; |
51287
7b1ddbafa134
8208655: use JTreg skipped status in hotspot tests
iignatyev
parents:
50791
diff
changeset
|
44 |
import jtreg.SkippedException; |
50571 | 45 |
|
46 |
public class TestJmapCore { |
|
47 |
static final String pidSeparator = ":KILLED_PID"; |
|
48 |
||
49 |
public static final String HEAP_OOME = "heap"; |
|
50 |
public static final String METASPACE_OOME = "metaspace"; |
|
51 |
||
52 |
||
53 |
public static void main(String[] args) throws Throwable { |
|
54 |
if (args.length == 1) { |
|
55 |
// If 1 argument is set prints pid so main process could find corefile |
|
56 |
System.out.println(ProcessHandle.current().pid() + pidSeparator); |
|
57 |
try { |
|
58 |
if (args[0].equals(HEAP_OOME)) { |
|
59 |
Object[] oa = new Object[Integer.MAX_VALUE / 2]; |
|
60 |
for(int i = 0; i < oa.length; i++) { |
|
61 |
oa[i] = new Object[Integer.MAX_VALUE / 2]; |
|
62 |
} |
|
63 |
} else { |
|
64 |
GeneratingClassLoader loader = new GeneratingClassLoader(); |
|
65 |
for (int i = 0; ; i++) { |
|
66 |
loader.loadClass(loader.getClassName(i)); |
|
67 |
} |
|
68 |
} |
|
69 |
throw new Error("OOME not triggered"); |
|
70 |
} catch (OutOfMemoryError err) { |
|
71 |
return; |
|
72 |
} |
|
73 |
} |
|
74 |
test(args[1]); |
|
75 |
} |
|
76 |
||
77 |
// Test tries to run java with ulimit unlimited if it is possible |
|
78 |
static boolean useDefaultUlimit() { |
|
79 |
if (Platform.isWindows()) { |
|
80 |
return true; |
|
81 |
} |
|
82 |
try { |
|
83 |
OutputAnalyzer output = ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && ulimit -c"); |
|
84 |
return !(output.getExitValue() == 0 && output.getStdout().contains("unlimited")); |
|
85 |
} catch (Throwable t) { |
|
86 |
return true; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
static void test(String type) throws Throwable { |
|
91 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash", |
|
51946
7bd8d6b011c9
8207745: serviceability/sa/TestJmapCore.java times out parsing a 4GB hprof file
sballal
parents:
51579
diff
changeset
|
92 |
"-Xmx512m", "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", |
50571 | 93 |
TestJmapCore.class.getName(), type); |
94 |
||
95 |
boolean useDefaultUlimit = useDefaultUlimit(); |
|
96 |
System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited")); |
|
97 |
OutputAnalyzer output = useDefaultUlimit |
|
98 |
? ProcessTools.executeProcess(pb) |
|
99 |
: ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && " |
|
100 |
+ ProcessTools.getCommandLine(pb)); |
|
58384 | 101 |
File pwd = new File("."); |
102 |
SATestUtils.unzipCores(pwd); |
|
50571 | 103 |
File core; |
58127
41082cd965cc
8230881: serviceability/sa/TestJmapCore tests fail with java.lang.RuntimeException: Could not find dump file
lmesnik
parents:
53817
diff
changeset
|
104 |
String pattern = Platform.isWindows() ? ".*\\.mdmp" : "core(\\.\\d+)?"; |
58384 | 105 |
File[] cores = pwd.listFiles((dir, name) -> name.matches(pattern)); |
50571 | 106 |
if (cores.length == 0) { |
107 |
// /cores/core.$pid might be generated on macosx by default |
|
108 |
String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1); |
|
109 |
core = new File("cores/core." + pid); |
|
110 |
if (!core.exists()) { |
|
51287
7b1ddbafa134
8208655: use JTreg skipped status in hotspot tests
iignatyev
parents:
50791
diff
changeset
|
111 |
throw new SkippedException("Has not been able to find coredump"); |
50571 | 112 |
} |
113 |
} else { |
|
114 |
Asserts.assertTrue(cores.length == 1, |
|
115 |
"There are unexpected files containing core " |
|
58384 | 116 |
+ ": " + String.join(",", pwd.list()) + "."); |
50571 | 117 |
core = cores[0]; |
118 |
} |
|
119 |
System.out.println("Found corefile: " + core.getAbsolutePath()); |
|
120 |
||
121 |
File dumpFile = new File("heap.hprof"); |
|
122 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
|
123 |
launcher.addToolArg("jmap"); |
|
124 |
launcher.addToolArg("--binaryheap"); |
|
125 |
launcher.addToolArg("--dumpfile=" + dumpFile); |
|
126 |
launcher.addToolArg("--exe"); |
|
127 |
launcher.addToolArg(JDKToolFinder.getTestJDKTool("java")); |
|
128 |
launcher.addToolArg("--core"); |
|
129 |
launcher.addToolArg(core.getPath()); |
|
130 |
||
131 |
ProcessBuilder jhsdpb = new ProcessBuilder(); |
|
132 |
jhsdpb.command(launcher.getCommand()); |
|
133 |
Process jhsdb = jhsdpb.start(); |
|
134 |
OutputAnalyzer out = new OutputAnalyzer(jhsdb); |
|
135 |
||
136 |
jhsdb.waitFor(); |
|
137 |
||
138 |
System.out.println(out.getStdout()); |
|
139 |
System.err.println(out.getStderr()); |
|
140 |
||
52810
a2500cf11ee5
8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC
jgeorge
parents:
51946
diff
changeset
|
141 |
if (dumpFile.exists() && dumpFile.isFile()) { |
a2500cf11ee5
8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC
jgeorge
parents:
51946
diff
changeset
|
142 |
HprofParser.parse(dumpFile); |
a2500cf11ee5
8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC
jgeorge
parents:
51946
diff
changeset
|
143 |
} else { |
53817 | 144 |
throw new RuntimeException( |
145 |
"Could not find dump file " + dumpFile.getAbsolutePath()); |
|
52810
a2500cf11ee5
8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC
jgeorge
parents:
51946
diff
changeset
|
146 |
} |
a2500cf11ee5
8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC
jgeorge
parents:
51946
diff
changeset
|
147 |
|
50571 | 148 |
System.out.println("PASSED"); |
149 |
} |
|
150 |
} |