48138
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 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 If -Djava.system.class.loader=xxx is specified in command-line, disable UseAppCDS
|
|
28 |
* AppCDS does not support uncompressed oops
|
|
29 |
* @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
|
|
30 |
* @library /test/lib
|
|
31 |
* @modules java.base/jdk.internal.misc
|
|
32 |
* jdk.jartool/sun.tools.jar
|
|
33 |
* @compile test-classes/TestClassLoader.java
|
|
34 |
* @compile test-classes/ReportMyLoader.java
|
|
35 |
* @compile test-classes/TrySwitchMyLoader.java
|
|
36 |
* @run main SpecifySysLoaderProp
|
|
37 |
*/
|
|
38 |
|
|
39 |
import java.io.*;
|
|
40 |
import jdk.test.lib.process.OutputAnalyzer;
|
|
41 |
|
|
42 |
public class SpecifySysLoaderProp {
|
|
43 |
|
|
44 |
public static void main(String[] args) throws Exception {
|
|
45 |
JarBuilder.build("sysloader", "TestClassLoader", "ReportMyLoader", "TrySwitchMyLoader");
|
|
46 |
|
|
47 |
String jarFileName = "sysloader.jar";
|
|
48 |
String appJar = TestCommon.getTestJar(jarFileName);
|
|
49 |
TestCommon.testDump(appJar, TestCommon.list("ReportMyLoader"));
|
|
50 |
String warning = "VM warning: UseAppCDS is disabled because the java.system.class.loader property is specified";
|
|
51 |
|
|
52 |
|
|
53 |
// (0) Baseline. Do not specify -Djava.system.class.loader
|
|
54 |
// The test class should be loaded from archive
|
|
55 |
OutputAnalyzer output = TestCommon.execCommon(
|
|
56 |
"-verbose:class",
|
|
57 |
"-cp", appJar,
|
|
58 |
"ReportMyLoader");
|
|
59 |
TestCommon.checkExec(output,
|
|
60 |
"[class,load] ReportMyLoader source: shared objects file",
|
|
61 |
"ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@");
|
|
62 |
|
|
63 |
// (1) Try to execute the archive with -Djava.system.class.loader=no.such.Klass,
|
|
64 |
// it should fail
|
|
65 |
output = TestCommon.execCommon(
|
|
66 |
"-cp", appJar,
|
|
67 |
"-Djava.system.class.loader=no.such.Klass",
|
|
68 |
"ReportMyLoader");
|
|
69 |
try {
|
|
70 |
output.shouldContain(warning);
|
|
71 |
output.shouldContain("ClassNotFoundException: no.such.Klass");
|
|
72 |
} catch (Exception e) {
|
|
73 |
TestCommon.checkCommonExecExceptions(output, e);
|
|
74 |
}
|
|
75 |
|
|
76 |
// (2) Try to execute the archive with -Djava.system.class.loader=TestClassLoader,
|
|
77 |
// it should run, but AppCDS should be disabled
|
|
78 |
output = TestCommon.execCommon(
|
|
79 |
"-verbose:class",
|
|
80 |
"-cp", appJar,
|
|
81 |
"-Djava.system.class.loader=TestClassLoader",
|
|
82 |
"ReportMyLoader");
|
|
83 |
TestCommon.checkExec(output,
|
|
84 |
"ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@", //<-this is still printed because TestClassLoader simply delegates to Launcher$AppLoader, but ...
|
|
85 |
"TestClassLoader.called = true", //<-but this proves that TestClassLoader was indeed called.
|
|
86 |
"TestClassLoader: loadClass(\"ReportMyLoader\","); //<- this also proves that TestClassLoader was indeed called.
|
|
87 |
try {
|
|
88 |
output.shouldMatch(".class,load. TestClassLoader source: file:");
|
|
89 |
output.shouldMatch(".class,load. ReportMyLoader source: file:.*" + jarFileName);
|
|
90 |
} catch (Exception e) {
|
|
91 |
TestCommon.checkCommonExecExceptions(output, e);
|
|
92 |
}
|
|
93 |
|
|
94 |
// (3) Try to change the java.system.class.loader programmatically after
|
|
95 |
// the app's main method is executed. This should have no effect in terms of
|
|
96 |
// changing or switching the actual system class loader that's already in use.
|
|
97 |
output = TestCommon.execCommon(
|
|
98 |
"-verbose:class",
|
|
99 |
"-cp", appJar,
|
|
100 |
"TrySwitchMyLoader");
|
|
101 |
TestCommon.checkExec(output,
|
|
102 |
"[class,load] ReportMyLoader source: shared objects file",
|
|
103 |
"TrySwitchMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
|
|
104 |
"ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
|
|
105 |
"TestClassLoader.called = false");
|
|
106 |
}
|
|
107 |
}
|