Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/Dictionary/ProtectionDomainCacheTest.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
26
* @bug 8151486 8218266
27
* @summary Call Class.forName() on the system classloader from a class loaded
28
* from a custom classloader, using the current class's protection domain.
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* @build jdk.test.lib.Utils
32
* jdk.test.lib.util.JarUtils
33
* @build ClassForName ProtectionDomainCacheTest
34
* @run driver ProtectionDomainCacheTest
35
*/
36
37
import java.net.URL;
38
import java.net.URLClassLoader;
39
import java.nio.file.FileSystems;
40
import java.nio.file.Files;
41
import java.nio.file.Path;
42
import java.nio.file.Paths;
43
import java.util.List;
44
import jdk.test.lib.Utils;
45
import jdk.test.lib.util.JarUtils;
46
import java.io.File;
47
48
import jdk.test.lib.process.OutputAnalyzer;
49
import jdk.test.lib.process.ProcessTools;
50
51
/*
52
* Create .jar, load ClassForName from .jar using a URLClassLoader
53
*/
54
public class ProtectionDomainCacheTest {
55
static class Test {
56
private static final long TIMEOUT = (long)(5000.0 * Utils.TIMEOUT_FACTOR);
57
private static final String TESTCLASSES = System.getProperty("test.classes", ".");
58
private static final String CLASSFILENAME = "ClassForName.class";
59
60
// Use a new classloader to load the ClassForName class.
61
public static void loadAndRun(Path jarFilePath)
62
throws Exception {
63
ClassLoader classLoader = new URLClassLoader(
64
new URL[]{jarFilePath.toUri().toURL()}) {
65
@Override public String toString() { return "LeakedClassLoader"; }
66
};
67
68
Class<?> loadClass = Class.forName("ClassForName", true, classLoader);
69
loadClass.newInstance();
70
71
System.out.println("returning : " + classLoader);
72
}
73
74
public static void main(final String[] args) throws Exception {
75
// Create a temporary .jar file containing ClassForName.class
76
Path testClassesDir = Paths.get(TESTCLASSES);
77
Path jarFilePath = Files.createTempFile("cfn", ".jar");
78
JarUtils.createJarFile(jarFilePath, testClassesDir, CLASSFILENAME);
79
jarFilePath.toFile().deleteOnExit();
80
81
// Remove the ClassForName.class file that jtreg built, to make sure
82
// we're loading from the tmp .jar
83
Path classFile = FileSystems.getDefault().getPath(TESTCLASSES,
84
CLASSFILENAME);
85
Files.delete(classFile);
86
87
for (int i = 0; i < 20; i++) {
88
loadAndRun(jarFilePath);
89
}
90
91
// Give the GC a chance to unload protection domains
92
for (int i = 0; i < 100; i++) {
93
System.gc();
94
}
95
System.out.println("All Classloaders and protection domain cache entries successfully unloaded");
96
}
97
}
98
99
public static void main(String args[]) throws Exception {
100
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
101
"-Djava.security.policy==" + System.getProperty("test.src") + File.separator + "test.policy",
102
"-Dtest.classes=" + System.getProperty("test.classes", "."),
103
"-XX:+UnlockDiagnosticVMOptions",
104
"-XX:VerifySubSet=dictionary",
105
"-XX:+VerifyAfterGC",
106
"-Xlog:gc+verify,protectiondomain=trace",
107
"-Djava.security.manager",
108
Test.class.getName());
109
OutputAnalyzer output = new OutputAnalyzer(pb.start());
110
output.shouldContain("PD in set is not alive");
111
output.shouldContain("HandshakeForPD::do_thread");
112
output.shouldHaveExitValue(0);
113
}
114
}
115
116