Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestRedefineWithUnresolvedClass.java
41153 views
1
/*
2
* Copyright (c) 2014, 2019, 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
* @summary Redefine a class with an UnresolvedClass reference in the constant pool.
27
* @bug 8035150
28
* @requires vm.jvmti
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* java.compiler
32
* java.instrument
33
* java.management
34
* jdk.jartool/sun.tools.jar
35
* jdk.internal.jvmstat/sun.jvmstat.monitor
36
* @build UnresolvedClassAgent
37
* @run main TestRedefineWithUnresolvedClass
38
*/
39
40
import java.io.File;
41
import java.util.Arrays;
42
43
import jdk.test.lib.process.OutputAnalyzer;
44
import jdk.test.lib.process.ProcessTools;
45
46
public class TestRedefineWithUnresolvedClass {
47
48
final static String slash = File.separator;
49
final static String testClasses = System.getProperty("test.classes") + slash;
50
51
public static void main(String... args) throws Throwable {
52
// delete this class to cause a NoClassDefFoundError
53
File unresolved = new File(testClasses, "MyUnresolvedClass.class");
54
if (unresolved.exists() && !unresolved.delete()) {
55
throw new Exception("Could not delete: " + unresolved);
56
}
57
58
// build the javaagent
59
buildJar("UnresolvedClassAgent");
60
61
// launch a VM with the javaagent
62
launchTest();
63
}
64
65
private static void buildJar(String jarName) throws Throwable {
66
String testSrc = System.getProperty("test.src", "?") + slash;
67
68
String jarPath = String.format("%s%s.jar", testClasses, jarName);
69
String manifestPath = String.format("%s%s.mf", testSrc, jarName);
70
String className = String.format("%s.class", jarName);
71
72
String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className};
73
74
System.out.println("Running jar " + Arrays.toString(args));
75
sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
76
if (!jarTool.run(args)) {
77
throw new Exception("jar failed: args=" + Arrays.toString(args));
78
}
79
}
80
81
private static void launchTest() throws Throwable {
82
OutputAnalyzer output = ProcessTools.executeTestJvm(
83
"-javaagent:" + testClasses + "UnresolvedClassAgent.jar",
84
"-Dtest.classes=" + testClasses,
85
"UnresolvedClassAgent");
86
output.shouldHaveExitValue(0);
87
}
88
}
89
90