Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpTest.java
64507 views
1
/*
2
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
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
24
import org.testng.annotations.Test;
25
import org.testng.Assert;
26
27
import java.io.File;
28
import java.nio.file.Files;
29
import java.io.IOException;
30
import java.util.List;
31
32
import jdk.test.lib.hprof.HprofParser;
33
import jdk.test.lib.hprof.model.Snapshot;
34
35
import jdk.test.lib.JDKToolFinder;
36
import jdk.test.lib.process.OutputAnalyzer;
37
import jdk.test.lib.dcmd.CommandExecutor;
38
import jdk.test.lib.dcmd.PidJcmdExecutor;
39
40
/*
41
* @test
42
* @summary Test of diagnostic command GC.heap_dump
43
* @library /test/lib
44
* @modules java.base/jdk.internal.misc
45
* java.compiler
46
* java.management
47
* jdk.internal.jvmstat/sun.jvmstat.monitor
48
* @run testng HeapDumpTest
49
*/
50
public class HeapDumpTest {
51
protected String heapDumpArgs = "";
52
53
public void run(CommandExecutor executor, boolean overwrite) throws IOException {
54
File dump = new File("jcmd.gc.heap_dump." + System.currentTimeMillis() + ".hprof");
55
if (!overwrite && dump.exists()) {
56
dump.delete();
57
} else if (overwrite) {
58
dump.createNewFile();
59
}
60
61
String cmd = "GC.heap_dump " + (overwrite ? "-overwrite " : "") + heapDumpArgs + " " + dump.getAbsolutePath();
62
executor.execute(cmd);
63
64
verifyHeapDump(dump);
65
dump.delete();
66
}
67
68
private void verifyHeapDump(File dump) {
69
Assert.assertTrue(dump.exists() && dump.isFile(), "Could not create dump file " + dump.getAbsolutePath());
70
try {
71
File out = HprofParser.parse(dump);
72
73
Assert.assertTrue(out != null && out.exists() && out.isFile(), "Could not find hprof parser output file");
74
List<String> lines = Files.readAllLines(out.toPath());
75
Assert.assertTrue(lines.size() > 0, "hprof parser output file is empty");
76
for (String line : lines) {
77
Assert.assertFalse(line.matches(".*WARNING(?!.*Failed to resolve object.*constantPoolOop.*).*"));
78
}
79
80
out.delete();
81
} catch (Exception e) {
82
e.printStackTrace();
83
Assert.fail("Could not parse dump file " + dump.getAbsolutePath());
84
}
85
}
86
87
/* GC.heap_dump is not available over JMX, running jcmd pid executor instead */
88
@Test
89
public void pid() throws IOException {
90
run(new PidJcmdExecutor(), false);
91
}
92
93
@Test
94
public void pidRewrite() throws IOException {
95
run(new PidJcmdExecutor(), true);
96
}
97
}
98
99
100