1 /* |
|
2 * Copyright (c) 2015, 2016, 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 * @summary Ensure that a newly introduced java.base package placed within the -Xpatch directory |
|
27 * is considered part of the boot loader's visibility boundary |
|
28 * @requires !(os.family == "windows") |
|
29 * @library /testlibrary |
|
30 * @modules java.base/jdk.internal.misc |
|
31 * java.management |
|
32 * @run main/othervm XpatchVisibility |
|
33 */ |
|
34 |
|
35 import java.io.File; |
|
36 import java.nio.file.Files; |
|
37 import java.nio.file.Paths; |
|
38 |
|
39 import jdk.test.lib.*; |
|
40 |
|
41 public class XpatchVisibility { |
|
42 |
|
43 public static void main(String[] args) throws Throwable { |
|
44 |
|
45 String Vis2_B_src = |
|
46 "package p2;" + |
|
47 "public class Vis2_B {" + |
|
48 " public void m() {" + |
|
49 " System.out.println(\"In B's m()\");" + |
|
50 " }" + |
|
51 "}"; |
|
52 |
|
53 String Vis2_A_src = |
|
54 "import p2.*;" + |
|
55 "public class Vis2_A {" + |
|
56 " public static void main(String args[]) throws Exception {" + |
|
57 // Try loading a class within a newly introduced java.base |
|
58 // package. Make sure the class can be found via -Xpatch. |
|
59 " try {" + |
|
60 " p2.Vis2_B b = new p2.Vis2_B();" + |
|
61 " if (b.getClass().getClassLoader() != null) {" + |
|
62 " throw new RuntimeException(\"XpatchVisibility FAILED - class B " + |
|
63 "should be loaded by boot class loader\\n\");" + |
|
64 " }" + |
|
65 " b.m();" + |
|
66 " } catch (Throwable e) {" + |
|
67 " throw new RuntimeException(\"XpatchVisibility FAILED - test " + |
|
68 "should not throw an error or exception\\n\");" + |
|
69 " }" + |
|
70 " System.out.println(\"XpatchVisibility PASSED\\n\");" + |
|
71 " }" + |
|
72 "}"; |
|
73 |
|
74 ClassFileInstaller.writeClassToDisk("p2/Vis2_B", |
|
75 InMemoryJavaCompiler.compile("p2.Vis2_B", Vis2_B_src), System.getProperty("test.classes")); |
|
76 ClassFileInstaller.writeClassToDisk("p2/Vis2_B", "mods2/java.base"); |
|
77 |
|
78 ClassFileInstaller.writeClassToDisk("Vis2_A", |
|
79 InMemoryJavaCompiler.compile("Vis2_A", Vis2_A_src), System.getProperty("test.classes")); |
|
80 |
|
81 // Make sure the classes are actually being loaded from mods2 |
|
82 Files.delete(Paths.get(System.getProperty("test.classes") + File.separator + |
|
83 "p2" + File.separator + "Vis2_B.class")); |
|
84 |
|
85 new OutputAnalyzer(ProcessTools.createJavaProcessBuilder( |
|
86 "-Xpatch:java.base=mods2/java.base", |
|
87 "-XaddExports:java.base/p2=ALL-UNNAMED", |
|
88 "Vis2_A") |
|
89 .start()).shouldHaveExitValue(0); |
|
90 } |
|
91 } |
|