Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/ClassUnload/ConstantPoolDependsTest.java
32284 views
1
/*
2
* Copyright (c) 2018, 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 ConstantPoolDependsTest
26
* @bug 8210094
27
* @summary Create ClassLoader dependency from initiating loader to class loader through constant pool reference
28
* @modules java.base/jdk.internal.misc
29
* java.compiler
30
* @library /testlibrary /testlibrary/whitebox /runtime/testlibrary
31
* @build sun.hotspot.WhiteBox
32
* @compile p2/c2.java MyDiffClassLoader.java
33
* @run main ClassFileInstaller sun.hotspot.WhiteBox
34
* sun.hotspot.WhiteBox$WhiteBoxPermission
35
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ConstantPoolDependsTest
36
*/
37
38
import sun.hotspot.WhiteBox;
39
40
41
public class ConstantPoolDependsTest {
42
public static WhiteBox wb = WhiteBox.getWhiteBox();
43
public static final String MY_TEST = "ConstantPoolDependsTest$c1c";
44
45
public static class c1c {
46
private void test() throws Exception {
47
// ConstantPool.klass_at_impl loads through constant pool and creates dependency
48
p2.c2 c2_obj = new p2.c2();
49
c2_obj.method2();
50
}
51
52
public c1c () throws Exception {
53
test();
54
ClassUnloadCommon.triggerUnloading(); // should not unload anything
55
test();
56
ClassUnloadCommon.triggerUnloading(); // should not unload anything
57
}
58
}
59
60
static void test() throws Throwable {
61
62
// now use the same loader to load class MyTest
63
Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST);
64
65
try {
66
// Call MyTest to load p2.c2 twice and call p2.c2.method2
67
MyTest_class.newInstance();
68
} catch (Exception e) {
69
throw new RuntimeException("Test FAILED if NoSuchMethodException is thrown");
70
}
71
ClassUnloadCommon.triggerUnloading(); // should not unload anything
72
ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded");
73
ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded");
74
// Unless MyTest_class is referenced here, the compiler can unload it.
75
System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive.");
76
}
77
78
public static void main(String args[]) throws Throwable {
79
test();
80
ClassUnloadCommon.triggerUnloading(); // should unload
81
System.gc();
82
System.out.println("Should unload p2.c2 just now");
83
ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded");
84
ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded");
85
}
86
}
87
88