Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java
40942 views
1
/*
2
* Copyright (c) 2018, 2021, 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 DictionaryDependsTest
26
* @bug 8210094
27
* @summary Create ClassLoader dependency from initiating loader to class loader through reflection
28
* @requires vm.opt.final.ClassUnloading
29
* @modules java.base/jdk.internal.misc
30
* java.compiler
31
* @library /test/lib
32
* @build sun.hotspot.WhiteBox
33
* @compile p2/c2.java MyDiffClassLoader.java
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI DictionaryDependsTest
36
*/
37
import sun.hotspot.WhiteBox;
38
import java.lang.reflect.Method;
39
import jdk.test.lib.classloader.ClassUnloadCommon;
40
41
public class DictionaryDependsTest {
42
public static WhiteBox wb = WhiteBox.getWhiteBox();
43
public static final String MY_TEST = "DictionaryDependsTest$c1r";
44
45
static public class c1r {
46
47
private void test() throws Exception {
48
// forName loads through reflection and doesn't create dependency
49
Class<?> x = Class.forName("p2.c2", true, c1r.class.getClassLoader());
50
Method m = x.getMethod("method2");
51
java.lang.Object t = x.newInstance();
52
m.invoke(t);
53
}
54
55
public c1r () throws Exception {
56
test();
57
ClassUnloadCommon.triggerUnloading(); // should unload p2.c2
58
test();
59
ClassUnloadCommon.triggerUnloading(); // should unload p2.c2
60
}
61
}
62
63
public void test() throws Throwable {
64
65
// now use the same loader to load class MyTest
66
Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST);
67
68
try {
69
// Call MyTest to load p2.c2 twice and call p2.c2.method2
70
MyTest_class.newInstance();
71
} catch (Exception e) {
72
System.out.println("Not expected NSME");
73
throw new RuntimeException("Not expecting NSME");
74
}
75
ClassUnloadCommon.triggerUnloading(); // should not unload anything
76
ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded");
77
ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded");
78
// Unless MyTest_class is referenced here, the compiler can unload it.
79
System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive.");
80
}
81
82
public static void main(String args[]) throws Throwable {
83
DictionaryDependsTest d = new DictionaryDependsTest();
84
d.test();
85
ClassUnloadCommon.triggerUnloading(); // should not unload anything
86
System.out.println("Should unload MyTest and p2.c2 just now");
87
ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded");
88
ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded");
89
}
90
}
91
92