Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/TestClassDump.java
41149 views
1
/*
2
* Copyright (c) 2017, 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.IOException;
25
import java.nio.file.Files;
26
import java.nio.file.Paths;
27
28
import jdk.test.lib.apps.LingeredApp;
29
import jdk.test.lib.Platform;
30
import jdk.test.lib.process.OutputAnalyzer;
31
import jdk.test.lib.process.ProcessTools;
32
import jdk.test.lib.SA.SATestUtils;
33
34
/**
35
* @test
36
* @bug 8184982
37
* @summary Test ClassDump tool
38
* @requires vm.hasSA
39
* @library /test/lib
40
* @run driver TestClassDump
41
*/
42
43
public class TestClassDump {
44
45
private static void dumpClass(long lingeredAppPid)
46
throws IOException {
47
48
ProcessBuilder pb;
49
OutputAnalyzer output;
50
51
pb = ProcessTools.createJavaProcessBuilder(
52
"-Dsun.jvm.hotspot.tools.jcore.outputDir=jtreg_classes",
53
"-m", "jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore.ClassDump", String.valueOf(lingeredAppPid));
54
SATestUtils.addPrivilegesIfNeeded(pb);
55
output = new OutputAnalyzer(pb.start());
56
output.shouldHaveExitValue(0);
57
if (!Files.isDirectory(Paths.get("jtreg_classes"))) {
58
throw new RuntimeException("jtreg_classes directory not found");
59
}
60
if (Files.notExists(Paths.get("jtreg_classes", "java", "lang", "Integer.class"))) {
61
throw new RuntimeException("jtreg_classes/java/lang/Integer.class not found");
62
}
63
if (Files.notExists(Paths.get("jtreg_classes", "jdk", "test", "lib", "apps", "LingeredApp.class"))) {
64
throw new RuntimeException("jtreg_classes/jdk/test/lib/apps/LingeredApp.class not found");
65
}
66
if (Files.notExists(Paths.get("jtreg_classes", "sun", "net", "util", "URLUtil.class"))) {
67
throw new RuntimeException("jtreg_classes/sun/net/util/URLUtil.class not found");
68
}
69
70
pb = ProcessTools.createJavaProcessBuilder(
71
"-Dsun.jvm.hotspot.tools.jcore.outputDir=jtreg_classes2",
72
"-Dsun.jvm.hotspot.tools.jcore.PackageNameFilter.pkgList=jdk,sun",
73
"-m", "jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore.ClassDump", String.valueOf(lingeredAppPid));
74
SATestUtils.addPrivilegesIfNeeded(pb);
75
output = new OutputAnalyzer(pb.start());
76
output.shouldHaveExitValue(0);
77
if (Files.exists(Paths.get("jtreg_classes2", "java", "math", "BigInteger.class"))) {
78
throw new RuntimeException("jtreg_classes2/java/math/BigInteger.class not expected");
79
}
80
if (Files.notExists(Paths.get("jtreg_classes2", "sun", "util", "calendar", "BaseCalendar.class"))) {
81
throw new RuntimeException("jtreg_classes2/sun/util/calendar/BaseCalendar.class not found");
82
}
83
if (Files.notExists(Paths.get("jtreg_classes2", "jdk", "internal", "loader", "BootLoader.class"))) {
84
throw new RuntimeException("jtreg_classes2/jdk/internal/loader/BootLoader.class not found");
85
}
86
}
87
88
public static void main(String[] args) throws Exception {
89
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
90
LingeredApp theApp = null;
91
try {
92
theApp = LingeredApp.startApp();
93
long pid = theApp.getPid();
94
System.out.println("Started LingeredApp with pid " + pid);
95
dumpClass(pid);
96
} catch (Exception ex) {
97
throw new RuntimeException("Test ERROR " + ex, ex);
98
} finally {
99
LingeredApp.stopApp(theApp);
100
}
101
System.out.println("Test PASSED");
102
}
103
}
104
105