author | hseigel |
Fri, 20 Jan 2017 16:09:56 -0500 | |
changeset 43471 | bfb383279a16 |
parent 43466 | add500644443 |
child 44326 | 6c59cca7ff07 |
child 46289 | 1904e7ec236e |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
43471
bfb383279a16
8171971: Fix timing bug in JVM management of package export lists
hseigel
parents:
43466
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
36508 | 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 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/classFileParser.hpp" |
|
27 |
#include "classfile/classLoader.hpp" |
|
28 |
#include "classfile/classLoaderData.inline.hpp" |
|
29 |
#include "classfile/javaAssertions.hpp" |
|
30 |
#include "classfile/javaClasses.hpp" |
|
31 |
#include "classfile/javaClasses.inline.hpp" |
|
32 |
#include "classfile/moduleEntry.hpp" |
|
33 |
#include "classfile/modules.hpp" |
|
34 |
#include "classfile/packageEntry.hpp" |
|
35 |
#include "classfile/stringTable.hpp" |
|
36 |
#include "classfile/symbolTable.hpp" |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
37 |
#include "classfile/systemDictionary.hpp" |
36508 | 38 |
#include "classfile/vmSymbols.hpp" |
39 |
#include "logging/log.hpp" |
|
37248 | 40 |
#include "memory/resourceArea.hpp" |
36508 | 41 |
#include "oops/instanceKlass.hpp" |
42 |
#include "runtime/arguments.hpp" |
|
43 |
#include "runtime/handles.inline.hpp" |
|
44 |
#include "runtime/javaCalls.hpp" |
|
45 |
#include "runtime/reflection.hpp" |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
46 |
#include "utilities/stringUtils.hpp" |
36508 | 47 |
#include "utilities/utf8.hpp" |
48 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
49 |
static bool verify_module_name(const char *module_name) { |
36508 | 50 |
if (module_name == NULL) return false; |
51 |
int len = (int)strlen(module_name); |
|
42630
ae91fbc4b59f
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42307
diff
changeset
|
52 |
return (len > 0 && len <= Symbol::max_length()); |
36508 | 53 |
} |
54 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
55 |
bool Modules::verify_package_name(const char* package_name) { |
36508 | 56 |
if (package_name == NULL) return false; |
57 |
int len = (int)strlen(package_name); |
|
58 |
return (len > 0 && len <= Symbol::max_length() && |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
59 |
UTF8::is_legal_utf8((const unsigned char *)package_name, len, false) && |
36508 | 60 |
ClassFileParser::verify_unqualified_name(package_name, len, |
61 |
ClassFileParser::LegalClass)); |
|
62 |
} |
|
63 |
||
64 |
static char* get_module_name(oop module, TRAPS) { |
|
65 |
oop name_oop = java_lang_reflect_Module::name(module); |
|
66 |
if (name_oop == NULL) { |
|
67 |
THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "Null module name"); |
|
68 |
} |
|
69 |
char* module_name = java_lang_String::as_utf8_string(name_oop); |
|
70 |
if (!verify_module_name(module_name)) { |
|
71 |
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), |
|
72 |
err_msg("Invalid module name: %s", |
|
73 |
module_name != NULL ? module_name : "NULL")); |
|
74 |
} |
|
75 |
return module_name; |
|
76 |
} |
|
77 |
||
78 |
static const char* get_module_version(jstring version) { |
|
79 |
if (version == NULL) { |
|
80 |
return NULL; |
|
81 |
} |
|
82 |
return java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(version)); |
|
83 |
} |
|
84 |
||
85 |
static ModuleEntryTable* get_module_entry_table(Handle h_loader, TRAPS) { |
|
86 |
// This code can be called during start-up, before the classLoader's classLoader data got |
|
87 |
// created. So, call register_loader() to make sure the classLoader data gets created. |
|
88 |
ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL); |
|
89 |
return loader_cld->modules(); |
|
90 |
} |
|
91 |
||
92 |
static PackageEntryTable* get_package_entry_table(Handle h_loader, TRAPS) { |
|
93 |
// This code can be called during start-up, before the classLoader's classLoader data got |
|
94 |
// created. So, call register_loader() to make sure the classLoader data gets created. |
|
95 |
ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL); |
|
96 |
return loader_cld->packages(); |
|
97 |
} |
|
98 |
||
99 |
static ModuleEntry* get_module_entry(jobject module, TRAPS) { |
|
100 |
Handle module_h(THREAD, JNIHandles::resolve(module)); |
|
101 |
if (!java_lang_reflect_Module::is_instance(module_h())) { |
|
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
102 |
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), |
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
103 |
"module is not an instance of type java.lang.reflect.Module"); |
36508 | 104 |
} |
105 |
return java_lang_reflect_Module::module_entry(module_h(), CHECK_NULL); |
|
106 |
} |
|
107 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
108 |
static PackageEntry* get_package_entry(ModuleEntry* module_entry, const char* package_name, TRAPS) { |
36508 | 109 |
ResourceMark rm(THREAD); |
110 |
if (package_name == NULL) return NULL; |
|
111 |
TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name, CHECK_NULL); |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
112 |
PackageEntryTable* package_entry_table = module_entry->loader_data()->packages(); |
36508 | 113 |
assert(package_entry_table != NULL, "Unexpected null package entry table"); |
114 |
return package_entry_table->lookup_only(pkg_symbol); |
|
115 |
} |
|
116 |
||
117 |
static PackageEntry* get_package_entry_by_name(Symbol* package, |
|
118 |
Handle h_loader, |
|
119 |
TRAPS) { |
|
120 |
if (package != NULL) { |
|
121 |
ResourceMark rm(THREAD); |
|
122 |
if (Modules::verify_package_name(package->as_C_string())) { |
|
123 |
PackageEntryTable* const package_entry_table = |
|
124 |
get_package_entry_table(h_loader, CHECK_NULL); |
|
125 |
assert(package_entry_table != NULL, "Unexpected null package entry table"); |
|
126 |
return package_entry_table->lookup_only(package); |
|
127 |
} |
|
128 |
} |
|
129 |
return NULL; |
|
130 |
} |
|
131 |
||
132 |
bool Modules::is_package_defined(Symbol* package, Handle h_loader, TRAPS) { |
|
133 |
PackageEntry* res = get_package_entry_by_name(package, h_loader, CHECK_false); |
|
134 |
return res != NULL; |
|
135 |
} |
|
136 |
||
137 |
static void define_javabase_module(jobject module, jstring version, |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
138 |
jstring location, const char* const* packages, |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
139 |
jsize num_packages, TRAPS) { |
36508 | 140 |
ResourceMark rm(THREAD); |
141 |
||
142 |
Handle module_handle(THREAD, JNIHandles::resolve(module)); |
|
143 |
||
144 |
// Obtain java.base's module version |
|
145 |
const char* module_version = get_module_version(version); |
|
146 |
TempNewSymbol version_symbol; |
|
147 |
if (module_version != NULL) { |
|
148 |
version_symbol = SymbolTable::new_symbol(module_version, CHECK); |
|
149 |
} else { |
|
150 |
version_symbol = NULL; |
|
151 |
} |
|
152 |
||
153 |
// Obtain java.base's location |
|
154 |
const char* module_location = NULL; |
|
155 |
TempNewSymbol location_symbol = NULL; |
|
156 |
if (location != NULL) { |
|
157 |
module_location = |
|
158 |
java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location)); |
|
159 |
if (module_location != NULL) { |
|
160 |
location_symbol = SymbolTable::new_symbol(module_location, CHECK); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
||
165 |
// Check that the list of packages has no duplicates and that the |
|
166 |
// packages are syntactically ok. |
|
167 |
GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages); |
|
168 |
for (int x = 0; x < num_packages; x++) { |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
169 |
const char *package_name = packages[x]; |
36508 | 170 |
if (!Modules::verify_package_name(package_name)) { |
171 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
172 |
err_msg("Invalid package name: %s for module: " JAVA_BASE_NAME, package_name)); |
36508 | 173 |
} |
174 |
Symbol* pkg_symbol = SymbolTable::new_symbol(package_name, CHECK); |
|
175 |
// append_if_missing() returns FALSE if entry already exists. |
|
176 |
if (!pkg_list->append_if_missing(pkg_symbol)) { |
|
177 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
178 |
err_msg("Duplicate package name: %s for module " JAVA_BASE_NAME, |
36508 | 179 |
package_name)); |
180 |
} |
|
181 |
} |
|
182 |
||
183 |
// Validate java_base's loader is the boot loader. |
|
184 |
oop loader = java_lang_reflect_Module::loader(module_handle()); |
|
185 |
if (loader != NULL) { |
|
186 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
187 |
"Class loader must be the boot class loader"); |
|
188 |
} |
|
189 |
Handle h_loader = Handle(THREAD, loader); |
|
190 |
||
191 |
// Ensure the boot loader's PackageEntryTable has been created |
|
192 |
PackageEntryTable* package_table = get_package_entry_table(h_loader, CHECK); |
|
193 |
assert(pkg_list->length() == 0 || package_table != NULL, "Bad package_table"); |
|
194 |
||
195 |
// Ensure java.base's ModuleEntry has been created |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
196 |
assert(ModuleEntryTable::javabase_moduleEntry() != NULL, "No ModuleEntry for " JAVA_BASE_NAME); |
36508 | 197 |
|
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
198 |
bool duplicate_javabase = false; |
36508 | 199 |
{ |
200 |
MutexLocker m1(Module_lock, THREAD); |
|
201 |
||
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37248
diff
changeset
|
202 |
if (ModuleEntryTable::javabase_defined()) { |
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
203 |
duplicate_javabase = true; |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
204 |
} else { |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37248
diff
changeset
|
205 |
|
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
206 |
// Verify that all java.base packages created during bootstrapping are in |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
207 |
// pkg_list. If any are not in pkg_list, than a non-java.base class was |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
208 |
// loaded erroneously pre java.base module definition. |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
209 |
package_table->verify_javabase_packages(pkg_list); |
36508 | 210 |
|
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
211 |
// loop through and add any new packages for java.base |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
212 |
PackageEntry* pkg; |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
213 |
for (int x = 0; x < pkg_list->length(); x++) { |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
214 |
// Some of java.base's packages were added early in bootstrapping, ignore duplicates. |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
215 |
if (package_table->lookup_only(pkg_list->at(x)) == NULL) { |
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
40020
diff
changeset
|
216 |
pkg = package_table->locked_create_entry_or_null(pkg_list->at(x), ModuleEntryTable::javabase_moduleEntry()); |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
217 |
assert(pkg != NULL, "Unable to create a " JAVA_BASE_NAME " package entry"); |
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
218 |
} |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
219 |
// Unable to have a GrowableArray of TempNewSymbol. Must decrement the refcount of |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
220 |
// the Symbol* that was created above for each package. The refcount was incremented |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
221 |
// by SymbolTable::new_symbol and as well by the PackageEntry creation. |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
222 |
pkg_list->at(x)->decrement_refcount(); |
36508 | 223 |
} |
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
224 |
|
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
225 |
// Finish defining java.base's ModuleEntry |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
226 |
ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol); |
36508 | 227 |
} |
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
228 |
} |
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
229 |
if (duplicate_javabase) { |
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
230 |
THROW_MSG(vmSymbols::java_lang_InternalError(), |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
231 |
"Module " JAVA_BASE_NAME " is already defined"); |
36508 | 232 |
} |
233 |
||
41691
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
234 |
// Only the thread that actually defined the base module will get here, |
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
235 |
// so no locking is needed. |
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
236 |
|
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
237 |
// Patch any previously loaded class's module field with java.base's java.lang.reflect.Module. |
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
238 |
ModuleEntryTable::patch_javabase_entries(module_handle); |
1be281ee5de4
8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents:
41183
diff
changeset
|
239 |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
240 |
log_debug(modules)("define_javabase_module(): Definition of module: " |
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
241 |
JAVA_BASE_NAME ", version: %s, location: %s, package #: %d", |
36508 | 242 |
module_version != NULL ? module_version : "NULL", |
243 |
module_location != NULL ? module_location : "NULL", |
|
244 |
pkg_list->length()); |
|
245 |
||
246 |
// packages defined to java.base |
|
247 |
for (int x = 0; x < pkg_list->length(); x++) { |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
248 |
log_trace(modules)("define_javabase_module(): creation of package %s for module " JAVA_BASE_NAME, |
36508 | 249 |
(pkg_list->at(x))->as_C_string()); |
250 |
} |
|
251 |
} |
|
252 |
||
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
253 |
// Caller needs ResourceMark. |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
254 |
void throw_dup_pkg_exception(const char* module_name, PackageEntry* package, TRAPS) { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
255 |
const char* package_name = package->name()->as_C_string(); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
256 |
if (package->module()->is_named()) { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
257 |
THROW_MSG(vmSymbols::java_lang_IllegalStateException(), |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
258 |
err_msg("Package %s for module %s is already in another module, %s, defined to the class loader", |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
259 |
package_name, module_name, package->module()->name()->as_C_string())); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
260 |
} else { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
261 |
THROW_MSG(vmSymbols::java_lang_IllegalStateException(), |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
262 |
err_msg("Package %s for module %s is already in the unnamed module defined to the class loader", |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
263 |
package_name, module_name)); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
264 |
} |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
265 |
} |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
266 |
|
36508 | 267 |
void Modules::define_module(jobject module, jstring version, |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
268 |
jstring location, const char* const* packages, |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
269 |
jsize num_packages, TRAPS) { |
36508 | 270 |
ResourceMark rm(THREAD); |
271 |
||
272 |
if (module == NULL) { |
|
273 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object"); |
|
274 |
} |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
275 |
|
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
276 |
if (num_packages < 0) { |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
277 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
278 |
"num_packages must be >= 0"); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
279 |
} |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
280 |
|
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
281 |
if (packages == NULL && num_packages > 0) { |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
282 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
283 |
"num_packages should be zero if packages is null"); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
284 |
} |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
285 |
|
36508 | 286 |
Handle module_handle(THREAD, JNIHandles::resolve(module)); |
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
287 |
if (!java_lang_reflect_Module::is_instance(module_handle())) { |
36508 | 288 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
289 |
"module is not an instance of type java.lang.reflect.Module"); |
36508 | 290 |
} |
291 |
||
292 |
char* module_name = get_module_name(module_handle(), CHECK); |
|
293 |
if (module_name == NULL) { |
|
294 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
295 |
"Module name cannot be null"); |
|
296 |
} |
|
297 |
||
298 |
// Special handling of java.base definition |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
299 |
if (strcmp(module_name, JAVA_BASE_NAME) == 0) { |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
300 |
define_javabase_module(module, version, location, packages, num_packages, CHECK); |
36508 | 301 |
return; |
302 |
} |
|
303 |
||
304 |
const char* module_version = get_module_version(version); |
|
305 |
||
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
306 |
oop loader = java_lang_reflect_Module::loader(module_handle()); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
307 |
// Make sure loader is not the jdk.internal.reflect.DelegatingClassLoader. |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
308 |
if (loader != java_lang_ClassLoader::non_reflection_class_loader(loader)) { |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
309 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
310 |
"Class loader is an invalid delegating class loader"); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
311 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
312 |
Handle h_loader = Handle(THREAD, loader); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
313 |
|
36508 | 314 |
// Check that the list of packages has no duplicates and that the |
315 |
// packages are syntactically ok. |
|
316 |
GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages); |
|
317 |
for (int x = 0; x < num_packages; x++) { |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
318 |
const char* package_name = packages[x]; |
36508 | 319 |
if (!verify_package_name(package_name)) { |
320 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
321 |
err_msg("Invalid package name: %s for module: %s", |
|
322 |
package_name, module_name)); |
|
323 |
} |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
324 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
325 |
// Only modules defined to either the boot or platform class loader, can define a "java/" package. |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
326 |
if (!h_loader.is_null() && |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
327 |
!SystemDictionary::is_platform_class_loader(h_loader) && |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
328 |
strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) { |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
329 |
const char* class_loader_name = SystemDictionary::loader_name(h_loader()); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
330 |
size_t pkg_len = strlen(package_name); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
331 |
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
332 |
strncpy(pkg_name, package_name, pkg_len); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
333 |
StringUtils::replace_no_expand(pkg_name, "/", "."); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
334 |
const char* msg_text1 = "Class loader (instance of): "; |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
335 |
const char* msg_text2 = " tried to define prohibited package name: "; |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
336 |
size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + pkg_len + 1; |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
337 |
char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
338 |
jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, pkg_name); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
339 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), message); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
340 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
341 |
|
36508 | 342 |
Symbol* pkg_symbol = SymbolTable::new_symbol(package_name, CHECK); |
343 |
// append_if_missing() returns FALSE if entry already exists. |
|
344 |
if (!pkg_list->append_if_missing(pkg_symbol)) { |
|
345 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
346 |
err_msg("Duplicate package name: %s for module %s", |
|
347 |
package_name, module_name)); |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK); |
|
352 |
assert(module_table != NULL, "module entry table shouldn't be null"); |
|
353 |
||
354 |
// Create symbol* entry for module name. |
|
355 |
TempNewSymbol module_symbol = SymbolTable::new_symbol(module_name, CHECK); |
|
356 |
||
357 |
bool dupl_modules = false; |
|
358 |
||
359 |
// Create symbol* entry for module version. |
|
360 |
TempNewSymbol version_symbol; |
|
361 |
if (module_version != NULL) { |
|
362 |
version_symbol = SymbolTable::new_symbol(module_version, CHECK); |
|
363 |
} else { |
|
364 |
version_symbol = NULL; |
|
365 |
} |
|
366 |
||
367 |
// Create symbol* entry for module location. |
|
368 |
const char* module_location = NULL; |
|
369 |
TempNewSymbol location_symbol = NULL; |
|
370 |
if (location != NULL) { |
|
371 |
module_location = |
|
372 |
java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location)); |
|
373 |
if (module_location != NULL) { |
|
374 |
location_symbol = SymbolTable::new_symbol(module_location, CHECK); |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(h_loader()); |
|
379 |
assert(loader_data != NULL, "class loader data shouldn't be null"); |
|
380 |
||
381 |
PackageEntryTable* package_table = NULL; |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
382 |
PackageEntry* existing_pkg = NULL; |
36508 | 383 |
{ |
384 |
MutexLocker ml(Module_lock, THREAD); |
|
385 |
||
386 |
if (num_packages > 0) { |
|
387 |
package_table = get_package_entry_table(h_loader, CHECK); |
|
388 |
assert(package_table != NULL, "Missing package_table"); |
|
389 |
||
390 |
// Check that none of the packages exist in the class loader's package table. |
|
391 |
for (int x = 0; x < pkg_list->length(); x++) { |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
392 |
existing_pkg = package_table->lookup_only(pkg_list->at(x)); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
393 |
if (existing_pkg != NULL) { |
36508 | 394 |
// This could be because the module was already defined. If so, |
395 |
// report that error instead of the package error. |
|
396 |
if (module_table->lookup_only(module_symbol) != NULL) { |
|
397 |
dupl_modules = true; |
|
398 |
} |
|
399 |
break; |
|
400 |
} |
|
401 |
} |
|
402 |
} // if (num_packages > 0)... |
|
403 |
||
404 |
// Add the module and its packages. |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
405 |
if (!dupl_modules && existing_pkg == NULL) { |
36508 | 406 |
// Create the entry for this module in the class loader's module entry table. |
407 |
ModuleEntry* module_entry = module_table->locked_create_entry_or_null(module_handle, module_symbol, |
|
408 |
version_symbol, location_symbol, loader_data); |
|
409 |
||
410 |
if (module_entry == NULL) { |
|
411 |
dupl_modules = true; |
|
412 |
} else { |
|
413 |
// Add the packages. |
|
414 |
assert(pkg_list->length() == 0 || package_table != NULL, "Bad package table"); |
|
415 |
PackageEntry* pkg; |
|
416 |
for (int y = 0; y < pkg_list->length(); y++) { |
|
417 |
pkg = package_table->locked_create_entry_or_null(pkg_list->at(y), module_entry); |
|
418 |
assert(pkg != NULL, "Unable to create a module's package entry"); |
|
419 |
||
420 |
// Unable to have a GrowableArray of TempNewSymbol. Must decrement the refcount of |
|
421 |
// the Symbol* that was created above for each package. The refcount was incremented |
|
422 |
// by SymbolTable::new_symbol and as well by the PackageEntry creation. |
|
423 |
pkg_list->at(y)->decrement_refcount(); |
|
424 |
} |
|
425 |
||
426 |
// Store pointer to ModuleEntry record in java.lang.reflect.Module object. |
|
427 |
java_lang_reflect_Module::set_module_entry(module_handle(), module_entry); |
|
428 |
} |
|
429 |
} |
|
430 |
} // Release the lock |
|
431 |
||
432 |
// any errors ? |
|
433 |
if (dupl_modules) { |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
434 |
THROW_MSG(vmSymbols::java_lang_IllegalStateException(), |
36508 | 435 |
err_msg("Module %s is already defined", module_name)); |
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
436 |
} else if (existing_pkg != NULL) { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
437 |
throw_dup_pkg_exception(module_name, existing_pkg, CHECK); |
36508 | 438 |
} |
439 |
||
440 |
if (log_is_enabled(Debug, modules)) { |
|
37242 | 441 |
outputStream* logst = Log(modules)::debug_stream(); |
36508 | 442 |
logst->print("define_module(): creation of module: %s, version: %s, location: %s, ", |
443 |
module_name, module_version != NULL ? module_version : "NULL", |
|
444 |
module_location != NULL ? module_location : "NULL"); |
|
445 |
loader_data->print_value_on(logst); |
|
446 |
logst->print_cr(", package #: %d", pkg_list->length()); |
|
447 |
for (int y = 0; y < pkg_list->length(); y++) { |
|
448 |
log_trace(modules)("define_module(): creation of package %s for module %s", |
|
449 |
(pkg_list->at(y))->as_C_string(), module_name); |
|
450 |
} |
|
451 |
} |
|
452 |
||
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37248
diff
changeset
|
453 |
// If the module is defined to the boot loader and an exploded build is being |
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37248
diff
changeset
|
454 |
// used, prepend <java.home>/modules/modules_name, if it exists, to the system boot class path. |
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37248
diff
changeset
|
455 |
if (loader == NULL && |
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37248
diff
changeset
|
456 |
!Universe::is_module_initialized() && |
40013 | 457 |
!ClassLoader::has_jrt_entry()) { |
458 |
ClassLoader::add_to_exploded_build_list(module_symbol, CHECK); |
|
36508 | 459 |
} |
460 |
} |
|
461 |
||
462 |
void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) { |
|
463 |
ResourceMark rm(THREAD); |
|
464 |
||
465 |
if (module == NULL) { |
|
466 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object"); |
|
467 |
} |
|
468 |
Handle module_handle(THREAD, JNIHandles::resolve(module)); |
|
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
469 |
if (!java_lang_reflect_Module::is_instance(module_handle())) { |
36508 | 470 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
471 |
"module is not an instance of type java.lang.reflect.Module"); |
36508 | 472 |
} |
473 |
||
474 |
// Ensure that this is an unnamed module |
|
475 |
oop name = java_lang_reflect_Module::name(module_handle()); |
|
476 |
if (name != NULL) { |
|
477 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
478 |
"boot loader's unnamed module's java.lang.reflect.Module has a name"); |
|
479 |
} |
|
480 |
||
481 |
// Validate java_base's loader is the boot loader. |
|
482 |
oop loader = java_lang_reflect_Module::loader(module_handle()); |
|
483 |
if (loader != NULL) { |
|
484 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
485 |
"Class loader must be the boot class loader"); |
|
486 |
} |
|
487 |
Handle h_loader = Handle(THREAD, loader); |
|
488 |
||
489 |
log_debug(modules)("set_bootloader_unnamed_module(): recording unnamed module for boot loader"); |
|
490 |
||
491 |
// Ensure the boot loader's PackageEntryTable has been created |
|
492 |
ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK); |
|
493 |
||
494 |
// Set java.lang.reflect.Module for the boot loader's unnamed module |
|
495 |
ModuleEntry* unnamed_module = module_table->unnamed_module(); |
|
496 |
assert(unnamed_module != NULL, "boot loader's unnamed ModuleEntry not defined"); |
|
497 |
unnamed_module->set_module(ClassLoaderData::the_null_class_loader_data()->add_handle(module_handle)); |
|
498 |
// Store pointer to the ModuleEntry in the unnamed module's java.lang.reflect.Module object. |
|
499 |
java_lang_reflect_Module::set_module_entry(module_handle(), unnamed_module); |
|
500 |
} |
|
501 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
502 |
void Modules::add_module_exports(jobject from_module, const char* package_name, jobject to_module, TRAPS) { |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
503 |
if (package_name == NULL) { |
36508 | 504 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
505 |
"package is null"); |
|
506 |
} |
|
507 |
if (from_module == NULL) { |
|
508 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
509 |
"from_module is null"); |
|
510 |
} |
|
511 |
ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK); |
|
512 |
if (from_module_entry == NULL) { |
|
513 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
514 |
"from_module cannot be found"); |
|
515 |
} |
|
516 |
||
517 |
// All packages in unnamed are exported by default. |
|
518 |
if (!from_module_entry->is_named()) return; |
|
519 |
||
520 |
ModuleEntry* to_module_entry; |
|
521 |
if (to_module == NULL) { |
|
522 |
to_module_entry = NULL; // It's an unqualified export. |
|
523 |
} else { |
|
524 |
to_module_entry = get_module_entry(to_module, CHECK); |
|
525 |
if (to_module_entry == NULL) { |
|
526 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
527 |
"to_module is invalid"); |
|
528 |
} |
|
529 |
} |
|
530 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
531 |
PackageEntry *package_entry = get_package_entry(from_module_entry, package_name, CHECK); |
36508 | 532 |
ResourceMark rm(THREAD); |
533 |
if (package_entry == NULL) { |
|
534 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
535 |
err_msg("Package %s not found in from_module %s", |
|
536 |
package_name != NULL ? package_name : "", |
|
537 |
from_module_entry->name()->as_C_string())); |
|
538 |
} |
|
539 |
if (package_entry->module() != from_module_entry) { |
|
540 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
541 |
err_msg("Package: %s found in module %s, not in from_module: %s", |
|
542 |
package_entry->name()->as_C_string(), |
|
543 |
package_entry->module()->name()->as_C_string(), |
|
544 |
from_module_entry->name()->as_C_string())); |
|
545 |
} |
|
546 |
||
547 |
log_debug(modules)("add_module_exports(): package %s in module %s is exported to module %s", |
|
548 |
package_entry->name()->as_C_string(), |
|
549 |
from_module_entry->name()->as_C_string(), |
|
550 |
to_module_entry == NULL ? "NULL" : |
|
551 |
to_module_entry->is_named() ? |
|
552 |
to_module_entry->name()->as_C_string() : UNNAMED_MODULE); |
|
553 |
||
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
554 |
// Do nothing if modules are the same. |
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
555 |
if (from_module_entry != to_module_entry) { |
36508 | 556 |
package_entry->set_exported(to_module_entry); |
557 |
} |
|
558 |
} |
|
559 |
||
560 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
561 |
void Modules::add_module_exports_qualified(jobject from_module, const char* package, |
36508 | 562 |
jobject to_module, TRAPS) { |
563 |
if (to_module == NULL) { |
|
564 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
565 |
"to_module is null"); |
|
566 |
} |
|
567 |
add_module_exports(from_module, package, to_module, CHECK); |
|
568 |
} |
|
569 |
||
570 |
void Modules::add_reads_module(jobject from_module, jobject to_module, TRAPS) { |
|
571 |
if (from_module == NULL) { |
|
572 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
573 |
"from_module is null"); |
|
574 |
} |
|
575 |
||
576 |
ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK); |
|
577 |
if (from_module_entry == NULL) { |
|
578 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
579 |
"from_module is not valid"); |
|
580 |
} |
|
581 |
||
582 |
ModuleEntry* to_module_entry; |
|
583 |
if (to_module != NULL) { |
|
584 |
to_module_entry = get_module_entry(to_module, CHECK); |
|
585 |
if (to_module_entry == NULL) { |
|
586 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
587 |
"to_module is invalid"); |
|
588 |
} |
|
589 |
} else { |
|
590 |
to_module_entry = NULL; |
|
591 |
} |
|
592 |
||
593 |
ResourceMark rm(THREAD); |
|
594 |
log_debug(modules)("add_reads_module(): Adding read from module %s to module %s", |
|
595 |
from_module_entry->is_named() ? |
|
596 |
from_module_entry->name()->as_C_string() : UNNAMED_MODULE, |
|
597 |
to_module_entry == NULL ? "all unnamed" : |
|
598 |
(to_module_entry->is_named() ? |
|
599 |
to_module_entry->name()->as_C_string() : UNNAMED_MODULE)); |
|
600 |
||
601 |
// if modules are the same or if from_module is unnamed then no need to add the read. |
|
602 |
if (from_module_entry != to_module_entry && from_module_entry->is_named()) { |
|
603 |
from_module_entry->add_read(to_module_entry); |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
// This method is called by JFR and JNI. |
|
608 |
jobject Modules::get_module(jclass clazz, TRAPS) { |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
609 |
assert(ModuleEntryTable::javabase_defined(), |
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
610 |
"Attempt to call get_module before " JAVA_BASE_NAME " is defined"); |
36508 | 611 |
|
612 |
if (clazz == NULL) { |
|
613 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), |
|
614 |
"class is null", JNI_FALSE); |
|
615 |
} |
|
616 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
|
617 |
if (mirror == NULL) { |
|
618 |
log_debug(modules)("get_module(): no mirror, returning NULL"); |
|
619 |
return NULL; |
|
620 |
} |
|
621 |
if (!java_lang_Class::is_instance(mirror)) { |
|
622 |
THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
|
623 |
"Invalid class", JNI_FALSE); |
|
624 |
} |
|
625 |
||
626 |
oop module = java_lang_Class::module(mirror); |
|
627 |
||
628 |
assert(module != NULL, "java.lang.Class module field not set"); |
|
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
629 |
assert(java_lang_reflect_Module::is_instance(module), "module is not an instance of type java.lang.reflect.Module"); |
36508 | 630 |
|
631 |
if (log_is_enabled(Debug, modules)) { |
|
632 |
ResourceMark rm(THREAD); |
|
37242 | 633 |
outputStream* logst = Log(modules)::debug_stream(); |
36508 | 634 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
635 |
oop module_name = java_lang_reflect_Module::name(module); |
|
636 |
if (module_name != NULL) { |
|
637 |
logst->print("get_module(): module "); |
|
638 |
java_lang_String::print(module_name, tty); |
|
639 |
} else { |
|
640 |
logst->print("get_module(): Unamed Module"); |
|
641 |
} |
|
642 |
if (klass != NULL) { |
|
643 |
logst->print_cr(" for class %s", klass->external_name()); |
|
644 |
} else { |
|
645 |
logst->print_cr(" for primitive class"); |
|
646 |
} |
|
647 |
} |
|
648 |
||
649 |
return JNIHandles::make_local(THREAD, module); |
|
650 |
} |
|
651 |
||
652 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
653 |
jobject Modules::get_module_by_package_name(jobject loader, const char* package_name, TRAPS) { |
36508 | 654 |
ResourceMark rm(THREAD); |
655 |
assert(ModuleEntryTable::javabase_defined(), |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
656 |
"Attempt to call get_module_from_pkg before " JAVA_BASE_NAME " is defined"); |
36508 | 657 |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
658 |
if (package_name == NULL) { |
36508 | 659 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), |
660 |
"package is null", JNI_FALSE); |
|
661 |
} |
|
662 |
||
663 |
Handle h_loader (THREAD, JNIHandles::resolve(loader)); |
|
664 |
// Check that loader is a subclass of java.lang.ClassLoader. |
|
665 |
if (loader != NULL && !java_lang_ClassLoader::is_subclass(h_loader->klass())) { |
|
666 |
THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
|
667 |
"Class loader is not a subclass of java.lang.ClassLoader", JNI_FALSE); |
|
668 |
} |
|
669 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
670 |
if (strlen(package_name) == 0) { |
36508 | 671 |
// Return the unnamed module |
672 |
ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK_NULL); |
|
673 |
if (NULL == module_table) return NULL; |
|
674 |
const ModuleEntry* const unnamed_module = module_table->unnamed_module(); |
|
675 |
return JNIHandles::make_local(THREAD, JNIHandles::resolve(unnamed_module->module())); |
|
676 |
||
677 |
} else { |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
678 |
TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL); |
36508 | 679 |
return get_module(package_sym, h_loader, CHECK_NULL); |
680 |
} |
|
681 |
return NULL; |
|
682 |
} |
|
683 |
||
684 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
685 |
jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) { |
39706 | 686 |
assert(ModuleEntryTable::javabase_defined(), |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
687 |
"Attempt to call get_named_module before " JAVA_BASE_NAME " is defined"); |
39706 | 688 |
assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()), |
689 |
"Class loader is not a subclass of java.lang.ClassLoader"); |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
690 |
assert(package_name != NULL, "the package_name should not be NULL"); |
39706 | 691 |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
692 |
if (strlen(package_name) == 0) { |
39706 | 693 |
return NULL; |
694 |
} |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
695 |
TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL); |
39706 | 696 |
const PackageEntry* const pkg_entry = |
697 |
get_package_entry_by_name(package_sym, h_loader, THREAD); |
|
698 |
const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL); |
|
699 |
||
700 |
if (module_entry != NULL && module_entry->module() != NULL && module_entry->is_named()) { |
|
701 |
return JNIHandles::make_local(THREAD, JNIHandles::resolve(module_entry->module())); |
|
702 |
} |
|
703 |
return NULL; |
|
704 |
} |
|
705 |
||
706 |
||
36508 | 707 |
// This method is called by JFR and by the above method. |
708 |
jobject Modules::get_module(Symbol* package_name, Handle h_loader, TRAPS) { |
|
709 |
const PackageEntry* const pkg_entry = |
|
710 |
get_package_entry_by_name(package_name, h_loader, THREAD); |
|
711 |
const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL); |
|
712 |
||
713 |
if (module_entry != NULL && |
|
714 |
module_entry->module() != NULL) { |
|
715 |
return JNIHandles::make_local(THREAD, JNIHandles::resolve(module_entry->module())); |
|
716 |
} |
|
717 |
||
718 |
return NULL; |
|
719 |
} |
|
720 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
721 |
void Modules::add_module_package(jobject module, const char* package_name, TRAPS) { |
36508 | 722 |
ResourceMark rm(THREAD); |
723 |
||
724 |
if (module == NULL) { |
|
725 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
726 |
"module is null"); |
|
727 |
} |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
728 |
if (package_name == NULL) { |
36508 | 729 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
730 |
"package is null"); |
|
731 |
} |
|
732 |
ModuleEntry* module_entry = get_module_entry(module, CHECK); |
|
733 |
if (module_entry == NULL) { |
|
734 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
735 |
"module is invalid"); |
|
736 |
} |
|
737 |
if (!module_entry->is_named()) { |
|
738 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
739 |
"module cannot be an unnamed module"); |
|
740 |
} |
|
741 |
if (!verify_package_name(package_name)) { |
|
742 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
743 |
err_msg("Invalid package name: %s", package_name)); |
|
744 |
} |
|
745 |
||
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
746 |
ClassLoaderData *loader_data = module_entry->loader_data(); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
747 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
748 |
// Only modules defined to either the boot or platform class loader, can define a "java/" package. |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
749 |
if (!loader_data->is_the_null_class_loader_data() && |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
750 |
!loader_data->is_platform_class_loader_data() && |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
751 |
strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) { |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
752 |
const char* class_loader_name = SystemDictionary::loader_name(loader_data); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
753 |
size_t pkg_len = strlen(package_name); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
754 |
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
755 |
strncpy(pkg_name, package_name, pkg_len); |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
756 |
StringUtils::replace_no_expand(pkg_name, "/", "."); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
757 |
const char* msg_text1 = "Class loader (instance of): "; |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
758 |
const char* msg_text2 = " tried to define prohibited package name: "; |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
759 |
size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + pkg_len + 1; |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
760 |
char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
761 |
jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, pkg_name); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
762 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), message); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
763 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
764 |
|
36508 | 765 |
log_debug(modules)("add_module_package(): Adding package %s to module %s", |
766 |
package_name, module_entry->name()->as_C_string()); |
|
767 |
||
768 |
TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name, CHECK); |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
769 |
PackageEntryTable* package_table = loader_data->packages(); |
36508 | 770 |
assert(package_table != NULL, "Missing package_table"); |
771 |
||
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
772 |
PackageEntry* existing_pkg = NULL; |
36508 | 773 |
{ |
774 |
MutexLocker ml(Module_lock, THREAD); |
|
775 |
||
776 |
// Check that the package does not exist in the class loader's package table. |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
777 |
existing_pkg = package_table->lookup_only(pkg_symbol); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
778 |
if (existing_pkg == NULL) { |
36508 | 779 |
PackageEntry* pkg = package_table->locked_create_entry_or_null(pkg_symbol, module_entry); |
780 |
assert(pkg != NULL, "Unable to create a module's package entry"); |
|
781 |
} |
|
782 |
} |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
783 |
if (existing_pkg != NULL) { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
784 |
throw_dup_pkg_exception(module_entry->name()->as_C_string(), existing_pkg, CHECK); |
36508 | 785 |
} |
786 |
} |
|
787 |
||
788 |
// Export package in module to all unnamed modules. |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
789 |
void Modules::add_module_exports_to_all_unnamed(jobject module, const char* package_name, TRAPS) { |
36508 | 790 |
if (module == NULL) { |
791 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
792 |
"module is null"); |
|
793 |
} |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
794 |
if (package_name == NULL) { |
36508 | 795 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
796 |
"package is null"); |
|
797 |
} |
|
798 |
ModuleEntry* module_entry = get_module_entry(module, CHECK); |
|
799 |
if (module_entry == NULL) { |
|
800 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
801 |
"module is invalid"); |
|
802 |
} |
|
803 |
||
804 |
if (module_entry->is_named()) { // No-op for unnamed module. |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
805 |
PackageEntry *package_entry = get_package_entry(module_entry, package_name, CHECK); |
36508 | 806 |
ResourceMark rm(THREAD); |
807 |
if (package_entry == NULL) { |
|
808 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
809 |
err_msg("Package %s not found in module %s", |
|
810 |
package_name != NULL ? package_name : "", |
|
811 |
module_entry->name()->as_C_string())); |
|
812 |
} |
|
813 |
if (package_entry->module() != module_entry) { |
|
814 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
815 |
err_msg("Package: %s found in module %s, not in module: %s", |
|
816 |
package_entry->name()->as_C_string(), |
|
817 |
package_entry->module()->name()->as_C_string(), |
|
818 |
module_entry->name()->as_C_string())); |
|
819 |
} |
|
820 |
||
821 |
log_debug(modules)("add_module_exports_to_all_unnamed(): package %s in module" |
|
822 |
" %s is exported to all unnamed modules", |
|
823 |
package_entry->name()->as_C_string(), |
|
824 |
module_entry->name()->as_C_string()); |
|
825 |
||
43471
bfb383279a16
8171971: Fix timing bug in JVM management of package export lists
hseigel
parents:
43466
diff
changeset
|
826 |
// Mark package as exported to all unnamed modules. |
bfb383279a16
8171971: Fix timing bug in JVM management of package export lists
hseigel
parents:
43466
diff
changeset
|
827 |
package_entry->set_is_exported_allUnnamed(); |
36508 | 828 |
} |
829 |
} |