author | coleenp |
Mon, 29 Jul 2019 10:34:20 -0400 | |
changeset 57567 | b000362a89a0 |
parent 53249 | test/hotspot/jtreg/runtime/appcds/test-classes/JimageClassProtDomain.java@fbab5d82f3d7 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
53249
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 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 |
public class JimageClassProtDomain { |
|
26 |
public static void main(String args[]) throws Throwable { |
|
27 |
// Test ProtectionDomain for boot/app/ext module classes from the "modules" jimage. |
|
28 |
// The following classes are archived. See runtime/AppCDS/ProtectionDomain.java. |
|
29 |
// java.util.Dictionary (testcase 0), |
|
30 |
// sun.tools.javac.Main (testcase 1), |
|
31 |
// jdk.nio.zipfs.ZipInfo (testcase 2), |
|
32 |
// java.net.URL (testcase 3), |
|
33 |
// sun.rmi.rmic.Main (testcase 4), |
|
34 |
// com.sun.jndi.dns.DnsName (testcase 5) |
|
35 |
String testcases[][] = |
|
36 |
{{"Loading shared boot module class first", |
|
37 |
"java.util.Dictionary", "java.util.ServiceConfigurationError"}, |
|
38 |
||
39 |
{"Loading shared app module class first", |
|
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
40 |
"com.sun.tools.javac.Main", "com.sun.tools.javac.code.Symbol"}, |
48138 | 41 |
|
42 |
{"Loading shared ext module class first", |
|
43 |
"jdk.nio.zipfs.ZipInfo", "jdk.nio.zipfs.ZipPath"}, |
|
44 |
||
45 |
{"Loading non-shared boot module class first", |
|
46 |
"java.net.HttpCookie", "java.net.URL"}, |
|
47 |
||
48 |
{"Loading non-shared app module class first", |
|
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
49 |
"com.sun.tools.sjavac.Util", "com.sun.tools.sjavac.Main"}, |
48138 | 50 |
|
51 |
{"Loading non-shared ext module class first", |
|
52 |
"com.sun.jndi.dns.Resolver", "com.sun.jndi.dns.DnsName"}}; |
|
53 |
for (int i = 0; i < testcases.length; i++) { |
|
54 |
System.out.println("Testcase " + i + ": " + testcases[i][0]); |
|
55 |
JimageClassProtDomain.testProtectionDomain(testcases[i][1], testcases[i][2]); |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
private static void testProtectionDomain(String shared, String nonShared) |
|
60 |
throws Throwable { |
|
61 |
Class c1 = Class.forName(shared); |
|
62 |
Class c2 = Class.forName(nonShared); |
|
63 |
if (c1.getProtectionDomain() != c2.getProtectionDomain()) { |
|
64 |
System.out.println(c1.getProtectionDomain()); |
|
65 |
System.out.println(c1.getProtectionDomain().getCodeSource()); |
|
66 |
System.out.println(c2.getProtectionDomain()); |
|
67 |
System.out.println(c2.getProtectionDomain().getCodeSource()); |
|
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
68 |
throw new RuntimeException("Failed: Protection Domains do not match!"); |
48138 | 69 |
} else { |
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
70 |
System.out.println(c1.getProtectionDomain()); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
71 |
System.out.println(c1.getProtectionDomain().getCodeSource()); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
72 |
System.out.println(c2.getProtectionDomain()); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
48138
diff
changeset
|
73 |
System.out.println(c2.getProtectionDomain().getCodeSource()); |
48138 | 74 |
System.out.println("Passed: Protection Domains match."); |
75 |
} |
|
76 |
} |
|
77 |
} |