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