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 *
48
49 WhiteBox wb = WhiteBox.getWhiteBox();
50
51 Class<?> clazz = null;
52 for (int i = 0; i < 3; i++) {
53 try {
54 // Load the class with the default ClassLoader.
55 clazz = Class.forName(classNames[i]);
56 } catch (Exception e) {
57 if (i == excludeModIdx) {
58 System.out.println(classNames[i] + " not found as expected because the module isn't in the --limit-modules - PASSED");
59 } else {
60 throw(e);
61 }
62 }
63
64 if (clazz != null && i != excludeModIdx) {
65 // Make sure we got the expected defining ClassLoader
66 testLoader(clazz, expectedLoaders[i]);
67
68 // Make sure the class is in the shared space
69 if (!wb.isSharedClass(clazz)) {
70 throw new RuntimeException(clazz.getName() +
71 ".class should be in the shared space. " +
72 "loader=" + clazz.getClassLoader() + " module=" + clazz.getModule().getName());
73 }
74 }
75 clazz = null;
76 }
77 }
78
79 /**
80 * Asserts that given class has the expected defining loader.
81 */
82 static void testLoader(Class<?> clazz, ClassLoader expected) {
83 ClassLoader loader = clazz.getClassLoader();
84 if (loader != expected) {
85 throw new RuntimeException(clazz + " loaded by " + loader + ", expected " + expected);
86 }
87 }
88
89 static void assertTrue(boolean expr) {
90 if (!expr)
91 throw new RuntimeException("assertion failed");
92 }
|
1 /*
2 * Copyright (c) 2015, 2018, 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 *
48
49 WhiteBox wb = WhiteBox.getWhiteBox();
50
51 Class<?> clazz = null;
52 for (int i = 0; i < 3; i++) {
53 try {
54 // Load the class with the default ClassLoader.
55 clazz = Class.forName(classNames[i]);
56 } catch (Exception e) {
57 if (i == excludeModIdx) {
58 System.out.println(classNames[i] + " not found as expected because the module isn't in the --limit-modules - PASSED");
59 } else {
60 throw(e);
61 }
62 }
63
64 if (clazz != null && i != excludeModIdx) {
65 // Make sure we got the expected defining ClassLoader
66 testLoader(clazz, expectedLoaders[i]);
67
68 // Make sure the class is not in the shared space
69 // because CDS is disabled with --limit-modules during run time.
70 if (excludeModIdx != -1) {
71 if (wb.isSharedClass(clazz)) {
72 throw new RuntimeException(clazz.getName() +
73 ".class should not be in the shared space. " +
74 "loader=" + clazz.getClassLoader() + " module=" + clazz.getModule().getName());
75 }
76 } else {
77 // class should be in the shared space if --limit-modules
78 // isn't specified during run time
79 if (!wb.isSharedClass(clazz)) {
80 throw new RuntimeException(clazz.getName() +
81 ".class should be in the shared space. " +
82 "loader=" + clazz.getClassLoader() + " module=" + clazz.getModule().getName());
83 }
84 }
85 }
86 clazz = null;
87 }
88 }
89
90 /**
91 * Asserts that given class has the expected defining loader.
92 */
93 static void testLoader(Class<?> clazz, ClassLoader expected) {
94 ClassLoader loader = clazz.getClassLoader();
95 if (loader != expected) {
96 throw new RuntimeException(clazz + " loaded by " + loader + ", expected " + expected);
97 }
98 }
99
100 static void assertTrue(boolean expr) {
101 if (!expr)
102 throw new RuntimeException("assertion failed");
103 }
|