author | jiefu |
Wed, 06 Nov 2019 13:43:25 +0800 | |
changeset 58944 | bb2a436e616c |
parent 57567 | b000362a89a0 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
49739
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 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 |
import sun.hotspot.WhiteBox; |
|
26 |
||
27 |
public class JvmtiApp { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
28 |
static Class forname(String cn) { |
48138 | 29 |
try { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
30 |
return Class.forName(cn); |
48138 | 31 |
} catch (Throwable t) { |
32 |
return null; |
|
33 |
} |
|
34 |
} |
|
35 |
||
36 |
static void failed(String msg) { |
|
37 |
System.out.println("TEST FAILED: " + msg); |
|
38 |
System.exit(1); |
|
39 |
} |
|
40 |
||
41 |
// See ../JvmtiAddPath.java for how the classpaths are configured. |
|
42 |
public static void main(String args[]) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
43 |
String cn = "Hello"; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
44 |
if (args.length >= 3) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
45 |
cn = args[args.length - 1]; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
46 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
47 |
|
48138 | 48 |
if (args[0].equals("noadd")) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
49 |
if (forname(cn) != null) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
50 |
failed(cn + " class was loaded unexpectedly"); |
48138 | 51 |
} |
52 |
// We use -verbose:class to verify that Extra.class IS loaded by AppCDS if |
|
53 |
// the boot classpath HAS NOT been appended. |
|
54 |
ExtraClass.doit(); |
|
55 |
System.exit(0); |
|
56 |
} |
|
57 |
||
58 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
|
59 |
||
60 |
if (args[0].equals("bootonly")) { |
|
61 |
wb.addToBootstrapClassLoaderSearch(args[1]); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
62 |
Class cls = forname(cn); |
48138 | 63 |
if (cls == null) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
64 |
failed("Cannot find " + cn + " class"); |
48138 | 65 |
} |
66 |
if (cls.getClassLoader() != null) { |
|
67 |
failed("Hello class not loaded by boot classloader"); |
|
68 |
} |
|
69 |
} else if (args[0].equals("apponly")) { |
|
70 |
wb.addToSystemClassLoaderSearch(args[1]); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
71 |
Class cls = forname(cn); |
48138 | 72 |
if (cls == null) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
73 |
failed("Cannot find " + cn + " class"); |
48138 | 74 |
} |
75 |
if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
76 |
failed(cn + " class not loaded by app classloader"); |
48138 | 77 |
} |
78 |
} else if (args[0].equals("noadd-appcds")) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
79 |
cn = (args.length == 1) ? "Hello" : args[1]; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
80 |
Class cls = forname(cn); |
48138 | 81 |
if (cls == null) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
82 |
failed("Cannot find " + cn + " class"); |
48138 | 83 |
} |
84 |
if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
85 |
failed(cn + " class not loaded by app classloader"); |
48138 | 86 |
} |
87 |
} else if (args[0].equals("appandboot")) { |
|
88 |
wb.addToBootstrapClassLoaderSearch(args[1]); |
|
89 |
wb.addToSystemClassLoaderSearch(args[2]); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
90 |
cn = (args.length == 3) ? "Hello" : args[3]; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
91 |
Class cls = forname(cn); |
48138 | 92 |
if (cls == null) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
93 |
failed("Cannot find " + cn + " class"); |
48138 | 94 |
} |
95 |
if (cls.getClassLoader() != null) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
96 |
failed(cn + " class not loaded by boot classloader"); |
48138 | 97 |
} |
98 |
} else { |
|
99 |
failed("unknown option " + args[0]); |
|
100 |
} |
|
101 |
||
102 |
// We use -verbose:class to verify that Extra.class IS NOT loaded by AppCDS if |
|
103 |
// the boot classpath HAS been appended. |
|
104 |
ExtraClass.doit(); |
|
105 |
||
106 |
System.out.println("Test passed: " + args[0]); |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
class ExtraClass { |
|
111 |
static void doit() {} |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48138
diff
changeset
|
112 |
} |