Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java
41149 views
1
/*
2
* Copyright (c) 2016, 2020, 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 java.io.File;
25
import java.io.IOException;
26
import java.io.BufferedInputStream;
27
import java.util.stream.Collectors;
28
import java.io.FileInputStream;
29
30
31
import jdk.test.lib.apps.LingeredApp;
32
import jdk.test.lib.Asserts;
33
import jdk.test.lib.JDKToolLauncher;
34
import jdk.test.lib.process.ProcessTools;
35
import jdk.test.lib.process.OutputAnalyzer;
36
import jdk.test.lib.SA.SATestUtils;
37
import jdk.test.lib.Utils;
38
import jdk.test.lib.hprof.parser.HprofReader;
39
import jdk.test.lib.hprof.parser.PositionDataInputStream;
40
import jdk.test.lib.hprof.model.Snapshot;
41
42
/**
43
* @test
44
* @library /test/lib
45
* @requires vm.hasSA
46
* @modules java.base/jdk.internal.misc
47
* jdk.hotspot.agent/sun.jvm.hotspot
48
* jdk.hotspot.agent/sun.jvm.hotspot.utilities
49
* jdk.hotspot.agent/sun.jvm.hotspot.oops
50
* jdk.hotspot.agent/sun.jvm.hotspot.debugger
51
* @run main/othervm TestHeapDumpForInvokeDynamic
52
*/
53
54
public class TestHeapDumpForInvokeDynamic {
55
56
private static LingeredAppWithInvokeDynamic theApp = null;
57
58
private static void verifyHeapDump(String heapFile) {
59
60
File heapDumpFile = new File(heapFile);
61
Asserts.assertTrue(heapDumpFile.exists() && heapDumpFile.isFile(),
62
"Could not create dump file " + heapDumpFile.getAbsolutePath());
63
try (PositionDataInputStream in = new PositionDataInputStream(
64
new BufferedInputStream(new FileInputStream(heapFile)))) {
65
int i = in.readInt();
66
if (HprofReader.verifyMagicNumber(i)) {
67
Snapshot sshot;
68
HprofReader r = new HprofReader(heapFile, in, 0,
69
false, 0);
70
sshot = r.read();
71
} else {
72
throw new IOException("Unrecognized magic number: " + i);
73
}
74
} catch (Exception e) {
75
e.printStackTrace();
76
Asserts.fail("Could not read dump file " + heapFile);
77
} finally {
78
heapDumpFile.delete();
79
}
80
}
81
82
private static void attachDumpAndVerify(String heapDumpFileName,
83
long lingeredAppPid) throws Exception {
84
85
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
86
launcher.addVMArgs(Utils.getTestJavaOpts());
87
launcher.addToolArg("jmap");
88
launcher.addToolArg("--binaryheap");
89
launcher.addToolArg("--dumpfile");
90
launcher.addToolArg(heapDumpFileName);
91
launcher.addToolArg("--pid");
92
launcher.addToolArg(Long.toString(lingeredAppPid));
93
94
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
95
System.out.println(
96
processBuilder.command().stream().collect(Collectors.joining(" ")));
97
98
OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
99
SAOutput.shouldHaveExitValue(0);
100
SAOutput.shouldContain("heap written to");
101
SAOutput.shouldContain(heapDumpFileName);
102
System.out.println(SAOutput.getOutput());
103
104
verifyHeapDump(heapDumpFileName);
105
}
106
107
public static void main (String... args) throws Exception {
108
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
109
String heapDumpFileName = "lambdaHeapDump.bin";
110
111
File heapDumpFile = new File(heapDumpFileName);
112
if (heapDumpFile.exists()) {
113
heapDumpFile.delete();
114
}
115
116
try {
117
theApp = new LingeredAppWithInvokeDynamic();
118
LingeredApp.startApp(theApp, "-XX:+UsePerfData", "-Xmx512m");
119
attachDumpAndVerify(heapDumpFileName, theApp.getPid());
120
} finally {
121
LingeredApp.stopApp(theApp);
122
}
123
}
124
}
125
126