Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/CanGenerateAllClassHook/CanGenerateAllClassHook.java
41155 views
1
/*
2
* Copyright (c) 2018, 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
/**
25
* @test
26
* @bug 8161605
27
* @summary Tests that jvmtiEnv::GetPotentialCapabilities reports
28
* can_generate_all_class_hook_events capability with CDS (-Xshare:on)
29
* at ONLOAD and LIVE phases
30
* @requires vm.jvmti
31
* @requires vm.cds
32
* @library /test/lib
33
* @compile CanGenerateAllClassHook.java
34
* @run main/othervm/native CanGenerateAllClassHook
35
*/
36
37
import jdk.test.lib.cds.CDSTestUtils;
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
40
import java.io.File;
41
import java.io.IOException;
42
43
/*
44
* The simplest way to test is to use system classes.jsa,
45
* but we cannot rely on tested JRE/JDK has it.
46
* So the test runs 2 java processes -
47
* 1st to generate custom shared archive file:
48
* java -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=<jsa_file> -Xshare:dump
49
* and 2nd to perform the actual testing using generated shared archive:
50
* java -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=<jsa_file> -Xshare:on
51
* -agentlib:<agent> CanGenerateAllClassHook
52
*/
53
public class CanGenerateAllClassHook {
54
55
private static final String agentLib = "CanGenerateAllClassHook";
56
57
private static native int getClassHookAvail();
58
private static native int getOnLoadClassHookAvail();
59
60
public static void main(String[] args) throws Exception {
61
if (args.length == 0) {
62
// this is master run
63
64
final File jsaFile = File.createTempFile(agentLib, ".jsa");
65
jsaFile.deleteOnExit();
66
final String jsaPath = jsaFile.getAbsolutePath();
67
68
log("generating CDS archive...");
69
execJava(
70
"-XX:+UnlockDiagnosticVMOptions",
71
"-XX:SharedArchiveFile=" + jsaPath,
72
"-Xshare:dump")
73
.shouldHaveExitValue(0);
74
log("CDS generation completed.");
75
76
OutputAnalyzer output = execJava(
77
"-XX:+UnlockDiagnosticVMOptions",
78
"-XX:SharedArchiveFile=" + jsaPath,
79
"-Xshare:on",
80
"-agentlib:" + agentLib,
81
// copy java.library.path
82
"-Djava.library.path=" + System.getProperty("java.library.path"),
83
// specify "-showversion" to ensure the test runs in shared mode
84
"-showversion",
85
// class to run
86
CanGenerateAllClassHook.class.getCanonicalName(),
87
// and arg
88
"test");
89
// Xshare:on can cause intermittent failure
90
// checkExec handles this.
91
CDSTestUtils.checkExec(output);
92
93
log("Test PASSED.");
94
} else {
95
// this is test run
96
try {
97
System.loadLibrary(agentLib);
98
} catch (UnsatisfiedLinkError ex) {
99
System.err.println("Failed to load " + agentLib + " lib");
100
System.err.println("java.library.path: " + System.getProperty("java.library.path"));
101
throw ex;
102
}
103
104
final int onLoadValue = getOnLoadClassHookAvail();
105
final int liveValue = getClassHookAvail();
106
// Possible values returned:
107
// 1 - the capability is supported;
108
// 0 - the capability is not supported;
109
// -1 - error occured.
110
111
log("can_generate_all_class_hook_events value capability:");
112
log("ONLOAD phase: " + (onLoadValue < 0 ? "Failed to read" : onLoadValue));
113
log("LIVE phase: " + (liveValue < 0 ? "Failed to read" : liveValue));
114
if (onLoadValue != 1 || liveValue != 1) {
115
throw new RuntimeException("The can_generate_all_class_hook_events capability "
116
+ " is expected to be available in both ONLOAD and LIVE phases");
117
}
118
}
119
}
120
121
private static void log(String msg) {
122
System.out.println(msg);
123
System.out.flush();
124
}
125
126
private static OutputAnalyzer execJava(String... args) throws IOException {
127
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
128
129
OutputAnalyzer output = new OutputAnalyzer(pb.start());
130
131
log("[STDERR]\n" + output.getStderr());
132
log("[STDOUT]\n" + output.getStdout());
133
134
return output;
135
}
136
137
}
138
139