author | kvn |
Wed, 13 Dec 2017 11:59:55 -0800 | |
changeset 48397 | ead47ddf5844 |
parent 48138 | 78b2ecdd3c4b |
child 48469 | 7312ae4465d6 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
2 |
* Copyright (c) 2015, 2017, 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 |
|
48397
ead47ddf5844
8191788: add jdk.internal.vm.compiler to --limit-modules if -Djvmci.Compiler=graal is in the command line
kvn
parents:
48138
diff
changeset
|
32 |
* @requires ((vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)) & !vm.graal.enabled |
48138 | 33 |
* @library /test/lib /test/hotspot/jtreg/runtime/appcds |
34 |
* @modules java.base/jdk.internal.misc |
|
35 |
* java.management |
|
36 |
* jdk.jartool/sun.tools.jar |
|
37 |
* jdk.internal.jvmstat/sun.jvmstat.monitor |
|
38 |
* @compile ../../test-classes/EmptyClassHelper.java |
|
39 |
* @compile ../../test-classes/com/sun/tools/javac/Main.jasm |
|
40 |
* @run main EmptyClassInBootClassPath |
|
41 |
*/ |
|
42 |
||
43 |
import java.io.File; |
|
44 |
import java.lang.*; |
|
45 |
import java.lang.reflect.*; |
|
46 |
import java.util.List; |
|
47 |
import java.util.ArrayList; |
|
48 |
import jdk.test.lib.process.OutputAnalyzer; |
|
49 |
||
50 |
public class EmptyClassInBootClassPath { |
|
51 |
static final String EXPECTED_EXCEPTION = |
|
52 |
"java.lang.NoSuchMethodException: com.sun.tools.javac.Main.main([Ljava.lang.String;)"; |
|
53 |
public static void main(String[] args) throws Exception { |
|
54 |
String[] className = {"com/sun/tools/javac/Main"}; |
|
55 |
JarBuilder.build("emptyClass", className); |
|
56 |
String appJar = TestCommon.getTestJar("emptyClass.jar"); |
|
57 |
JarBuilder.build("EmptyClassHelper", "EmptyClassHelper"); |
|
58 |
String helperJar = TestCommon.getTestJar("EmptyClassHelper.jar"); |
|
59 |
OutputAnalyzer dumpOutput = TestCommon.dump( |
|
60 |
appJar, className, "-Xbootclasspath/a:" + appJar); |
|
61 |
TestCommon.checkDump(dumpOutput); |
|
62 |
dumpOutput.shouldNotContain("Preload Warning: skipping class from -Xbootclasspath/a " + className[0]); |
|
63 |
||
64 |
String bootclasspath = "-Xbootclasspath/a:" + appJar; |
|
65 |
String classPath = "-Djava.class.path=" + appJar + File.pathSeparator + helperJar; |
|
66 |
List<String> argsList = new ArrayList<String>(); |
|
67 |
argsList.add(classPath); |
|
68 |
argsList.add(bootclasspath); |
|
69 |
argsList.add("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED"); |
|
70 |
argsList.add("EmptyClassHelper"); |
|
71 |
||
72 |
// case 1: load class in bootclasspath using app loader |
|
73 |
argsList.add("useAppLoader"); |
|
74 |
String[] opts = new String[argsList.size()]; |
|
75 |
opts = argsList.toArray(opts); |
|
76 |
OutputAnalyzer runOutput = TestCommon.execCommon(opts); |
|
77 |
TestCommon.checkExec(runOutput, "appLoader found method main"); |
|
78 |
||
79 |
// case 2: load class in bootclasspath using boot loader |
|
80 |
argsList.remove(argsList.size() - 1); |
|
81 |
argsList.add("useBootLoader"); |
|
82 |
opts = new String[argsList.size()]; |
|
83 |
opts = argsList.toArray(opts); |
|
84 |
runOutput = TestCommon.execCommon(opts); |
|
85 |
TestCommon.checkExec(runOutput, EXPECTED_EXCEPTION); |
|
86 |
||
87 |
// case 3: load class in bootclasspath using app loader with '--limit-modules java.base' |
|
88 |
argsList.add(0, "--limit-modules"); |
|
89 |
argsList.add(1, "java.base"); |
|
90 |
argsList.remove(argsList.size() - 1); |
|
91 |
argsList.add("useAppLoader"); |
|
92 |
opts = new String[argsList.size()]; |
|
93 |
opts = argsList.toArray(opts); |
|
94 |
runOutput = TestCommon.execCommon(opts); |
|
95 |
TestCommon.checkExec(runOutput, EXPECTED_EXCEPTION); |
|
96 |
||
97 |
// case 4: load class in bootclasspath using boot loader with '--limit-modules java.base' |
|
98 |
argsList.remove(argsList.size() - 1); |
|
99 |
argsList.add("useBootLoader"); |
|
100 |
opts = new String[argsList.size()]; |
|
101 |
opts = argsList.toArray(opts); |
|
102 |
runOutput = TestCommon.execCommon(opts); |
|
103 |
TestCommon.checkExec(runOutput, EXPECTED_EXCEPTION); |
|
104 |
||
105 |
} |
|
106 |
} |