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 /* |
|
26 * @test |
|
27 * @summary AppCDS handling of prohibited package. |
|
28 * @requires vm.cds |
|
29 * @library /test/lib |
|
30 * @modules jdk.jartool/sun.tools.jar |
|
31 * @compile test-classes/ProhibitedHelper.java test-classes/Prohibited.jasm |
|
32 * @run driver ProhibitedPackage |
|
33 */ |
|
34 |
|
35 import jdk.test.lib.cds.CDSOptions; |
|
36 import jdk.test.lib.Platform; |
|
37 import jdk.test.lib.process.OutputAnalyzer; |
|
38 |
|
39 public class ProhibitedPackage { |
|
40 |
|
41 public static void main(String[] args) throws Exception { |
|
42 JarBuilder.build("prohibited_pkg", "java/lang/Prohibited", "ProhibitedHelper"); |
|
43 |
|
44 String appJar = TestCommon.getTestJar("prohibited_pkg.jar"); |
|
45 |
|
46 // Test support for customer loaders |
|
47 if (Platform.areCustomLoadersSupportedForCDS() && |
|
48 !TestCommon.isDynamicArchive()) { |
|
49 String classlist[] = new String[] { |
|
50 "java/lang/Object id: 1", |
|
51 "java/lang/Prohibited id: 2 super: 1 source: " + appJar |
|
52 }; |
|
53 |
|
54 // Make sure a class in a prohibited package for a custom loader |
|
55 // will be ignored during dumping. |
|
56 TestCommon.dump(appJar, classlist, "-Xlog:cds") |
|
57 .shouldContain("Dumping") |
|
58 .shouldContain("[cds] Prohibited package for non-bootstrap classes: java/lang/Prohibited.class") |
|
59 .shouldHaveExitValue(0); |
|
60 } |
|
61 |
|
62 |
|
63 // Make sure a class in a prohibited package for a non-custom loader |
|
64 // will be ignored during dumping. |
|
65 TestCommon.dump(appJar, |
|
66 TestCommon.list("java/lang/Prohibited", "ProhibitedHelper"), |
|
67 "-Xlog:class+load") |
|
68 .shouldContain("Dumping") |
|
69 .shouldNotContain("[info][class,load] java.lang.Prohibited source: ") |
|
70 .shouldHaveExitValue(0); |
|
71 |
|
72 // Try loading the class in a prohibited package with various -Xshare |
|
73 // modes. The class shouldn't be loaded and appropriate exceptions |
|
74 // are expected. |
|
75 |
|
76 OutputAnalyzer output; |
|
77 |
|
78 // -Xshare:on |
|
79 TestCommon.run( |
|
80 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
81 "-cp", appJar, "ProhibitedHelper") |
|
82 .assertNormalExit("Prohibited package name: java.lang"); |
|
83 |
|
84 // -Xshare:auto |
|
85 output = TestCommon.execAuto( |
|
86 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
87 "-cp", appJar, "ProhibitedHelper"); |
|
88 CDSOptions opts = (new CDSOptions()).setXShareMode("auto"); |
|
89 TestCommon.checkExec(output, opts, "Prohibited package name: java.lang"); |
|
90 |
|
91 // -Xshare:off |
|
92 output = TestCommon.execOff( |
|
93 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
94 "-cp", appJar, "ProhibitedHelper"); |
|
95 output.shouldContain("Prohibited package name: java.lang"); |
|
96 } |
|
97 } |
|