|
1 /* |
|
2 * Copyright (c) 2015, 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 Test a few scenarios if an empty class, which has the same name as the one in the jimage, is specified in the -Xbootclasspath/a |
|
28 * 1) boot loader will always load the class from the bootclasspath |
|
29 * 2) app loader will load the class from the jimage by default; |
|
30 * app loader will load the class from the bootclasspath if the |
|
31 * "--limit-modules java.base" option is specified |
|
32 * @requires vm.cds & !vm.graal.enabled |
|
33 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds |
|
34 * @modules java.base/jdk.internal.access |
|
35 * jdk.jartool/sun.tools.jar |
|
36 * @compile ../../test-classes/EmptyClassHelper.java |
|
37 * @compile ../../test-classes/com/sun/tools/javac/Main.jasm |
|
38 * @run driver EmptyClassInBootClassPath |
|
39 */ |
|
40 |
|
41 import java.io.File; |
|
42 import java.lang.*; |
|
43 import java.lang.reflect.*; |
|
44 import java.util.List; |
|
45 import java.util.ArrayList; |
|
46 import jdk.test.lib.process.OutputAnalyzer; |
|
47 |
|
48 public class EmptyClassInBootClassPath { |
|
49 static final String EXPECTED_EXCEPTION = |
|
50 "java.lang.NoSuchMethodException: com.sun.tools.javac.Main.main([Ljava.lang.String;)"; |
|
51 public static void main(String[] args) throws Exception { |
|
52 String[] className = {"com/sun/tools/javac/Main"}; |
|
53 JarBuilder.build("emptyClass", className); |
|
54 String appJar = TestCommon.getTestJar("emptyClass.jar"); |
|
55 JarBuilder.build("EmptyClassHelper", "EmptyClassHelper"); |
|
56 String helperJar = TestCommon.getTestJar("EmptyClassHelper.jar"); |
|
57 OutputAnalyzer dumpOutput = TestCommon.dump( |
|
58 appJar, className, "-Xbootclasspath/a:" + appJar); |
|
59 TestCommon.checkDump(dumpOutput); |
|
60 dumpOutput.shouldNotContain("Preload Warning: skipping class from -Xbootclasspath/a " + className[0]); |
|
61 |
|
62 String bootclasspath = "-Xbootclasspath/a:" + appJar; |
|
63 String classPath = "-Djava.class.path=" + appJar + File.pathSeparator + helperJar; |
|
64 List<String> argsList = new ArrayList<String>(); |
|
65 argsList.add(classPath); |
|
66 argsList.add(bootclasspath); |
|
67 argsList.add("--add-exports=java.base/jdk.internal.access=ALL-UNNAMED"); |
|
68 argsList.add("EmptyClassHelper"); |
|
69 |
|
70 // case 1: load class in bootclasspath using app loader |
|
71 argsList.add("useAppLoader"); |
|
72 String[] opts = new String[argsList.size()]; |
|
73 opts = argsList.toArray(opts); |
|
74 TestCommon.run(opts).assertNormalExit("appLoader found method main"); |
|
75 |
|
76 // case 2: load class in bootclasspath using boot loader |
|
77 argsList.remove(argsList.size() - 1); |
|
78 argsList.add("useBootLoader"); |
|
79 opts = new String[argsList.size()]; |
|
80 opts = argsList.toArray(opts); |
|
81 TestCommon.run(opts).assertNormalExit(EXPECTED_EXCEPTION); |
|
82 |
|
83 // case 3: load class in bootclasspath using app loader with '--limit-modules java.base' |
|
84 argsList.add(0, "--limit-modules"); |
|
85 argsList.add(1, "java.base"); |
|
86 argsList.remove(argsList.size() - 1); |
|
87 argsList.add("useAppLoader"); |
|
88 opts = new String[argsList.size()]; |
|
89 opts = argsList.toArray(opts); |
|
90 TestCommon.run(opts) |
|
91 .assertSilentlyDisabledCDS(0, EXPECTED_EXCEPTION); |
|
92 |
|
93 // case 4: load class in bootclasspath using boot loader with '--limit-modules java.base' |
|
94 argsList.remove(argsList.size() - 1); |
|
95 argsList.add("useBootLoader"); |
|
96 opts = new String[argsList.size()]; |
|
97 opts = argsList.toArray(opts); |
|
98 TestCommon.run(opts) |
|
99 .assertSilentlyDisabledCDS(0, EXPECTED_EXCEPTION); |
|
100 } |
|
101 } |