author | naoto |
Tue, 09 Jul 2019 08:05:38 -0700 | |
changeset 55627 | 9c1885fb2a42 |
parent 54847 | 59ea39bb2809 |
child 58177 | 4932dce35882 |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
53441 | 2 |
* Copyright (c) 2016, 2019, 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" |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
26 |
#include "jvm.h" |
36508 | 27 |
#include "classfile/classFileParser.hpp" |
28 |
#include "classfile/classLoader.hpp" |
|
29 |
#include "classfile/classLoaderData.inline.hpp" |
|
30 |
#include "classfile/javaAssertions.hpp" |
|
31 |
#include "classfile/javaClasses.hpp" |
|
32 |
#include "classfile/javaClasses.inline.hpp" |
|
33 |
#include "classfile/moduleEntry.hpp" |
|
34 |
#include "classfile/modules.hpp" |
|
35 |
#include "classfile/packageEntry.hpp" |
|
36 |
#include "classfile/stringTable.hpp" |
|
37 |
#include "classfile/symbolTable.hpp" |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
38 |
#include "classfile/systemDictionary.hpp" |
36508 | 39 |
#include "classfile/vmSymbols.hpp" |
40 |
#include "logging/log.hpp" |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
41 |
#include "logging/logStream.hpp" |
37248 | 42 |
#include "memory/resourceArea.hpp" |
36508 | 43 |
#include "oops/instanceKlass.hpp" |
44 |
#include "runtime/arguments.hpp" |
|
45 |
#include "runtime/handles.inline.hpp" |
|
46 |
#include "runtime/javaCalls.hpp" |
|
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47765
diff
changeset
|
47 |
#include "runtime/jniHandles.inline.hpp" |
36508 | 48 |
#include "runtime/reflection.hpp" |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
49 |
#include "utilities/stringUtils.hpp" |
36508 | 50 |
#include "utilities/utf8.hpp" |
51 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
52 |
static bool verify_module_name(const char *module_name) { |
36508 | 53 |
if (module_name == NULL) return false; |
54 |
int len = (int)strlen(module_name); |
|
42630
ae91fbc4b59f
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42307
diff
changeset
|
55 |
return (len > 0 && len <= Symbol::max_length()); |
36508 | 56 |
} |
57 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
58 |
bool Modules::verify_package_name(const char* package_name) { |
36508 | 59 |
if (package_name == NULL) return false; |
60 |
int len = (int)strlen(package_name); |
|
61 |
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
|
62 |
UTF8::is_legal_utf8((const unsigned char *)package_name, len, false) && |
36508 | 63 |
ClassFileParser::verify_unqualified_name(package_name, len, |
64 |
ClassFileParser::LegalClass)); |
|
65 |
} |
|
66 |
||
67 |
static char* get_module_name(oop module, TRAPS) { |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
68 |
oop name_oop = java_lang_Module::name(module); |
36508 | 69 |
if (name_oop == NULL) { |
70 |
THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "Null module name"); |
|
71 |
} |
|
72 |
char* module_name = java_lang_String::as_utf8_string(name_oop); |
|
73 |
if (!verify_module_name(module_name)) { |
|
74 |
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), |
|
75 |
err_msg("Invalid module name: %s", |
|
76 |
module_name != NULL ? module_name : "NULL")); |
|
77 |
} |
|
78 |
return module_name; |
|
79 |
} |
|
80 |
||
81 |
static const char* get_module_version(jstring version) { |
|
82 |
if (version == NULL) { |
|
83 |
return NULL; |
|
84 |
} |
|
85 |
return java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(version)); |
|
86 |
} |
|
87 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49348
diff
changeset
|
88 |
ModuleEntryTable* Modules::get_module_entry_table(Handle h_loader) { |
36508 | 89 |
// This code can be called during start-up, before the classLoader's classLoader data got |
90 |
// created. So, call register_loader() to make sure the classLoader data gets created. |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
91 |
ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader); |
36508 | 92 |
return loader_cld->modules(); |
93 |
} |
|
94 |
||
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
95 |
static PackageEntryTable* get_package_entry_table(Handle h_loader) { |
36508 | 96 |
// This code can be called during start-up, before the classLoader's classLoader data got |
97 |
// created. So, call register_loader() to make sure the classLoader data gets created. |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
98 |
ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader); |
36508 | 99 |
return loader_cld->packages(); |
100 |
} |
|
101 |
||
102 |
static ModuleEntry* get_module_entry(jobject module, TRAPS) { |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
103 |
oop m = JNIHandles::resolve(module); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
104 |
if (!java_lang_Module::is_instance(m)) { |
40020
20738e6bef83
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents:
40013
diff
changeset
|
105 |
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
106 |
"module is not an instance of type java.lang.Module"); |
36508 | 107 |
} |
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
108 |
return java_lang_Module::module_entry(m); |
36508 | 109 |
} |
110 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
111 |
static PackageEntry* get_package_entry(ModuleEntry* module_entry, const char* package_name, TRAPS) { |
36508 | 112 |
ResourceMark rm(THREAD); |
113 |
if (package_name == NULL) return NULL; |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
114 |
TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name); |
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
|
115 |
PackageEntryTable* package_entry_table = module_entry->loader_data()->packages(); |
36508 | 116 |
assert(package_entry_table != NULL, "Unexpected null package entry table"); |
117 |
return package_entry_table->lookup_only(pkg_symbol); |
|
118 |
} |
|
119 |
||
120 |
static PackageEntry* get_package_entry_by_name(Symbol* package, |
|
121 |
Handle h_loader, |
|
122 |
TRAPS) { |
|
123 |
if (package != NULL) { |
|
124 |
ResourceMark rm(THREAD); |
|
125 |
if (Modules::verify_package_name(package->as_C_string())) { |
|
126 |
PackageEntryTable* const package_entry_table = |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
127 |
get_package_entry_table(h_loader); |
36508 | 128 |
assert(package_entry_table != NULL, "Unexpected null package entry table"); |
129 |
return package_entry_table->lookup_only(package); |
|
130 |
} |
|
131 |
} |
|
132 |
return NULL; |
|
133 |
} |
|
134 |
||
135 |
bool Modules::is_package_defined(Symbol* package, Handle h_loader, TRAPS) { |
|
136 |
PackageEntry* res = get_package_entry_by_name(package, h_loader, CHECK_false); |
|
137 |
return res != NULL; |
|
138 |
} |
|
139 |
||
140 |
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
|
141 |
jstring location, const char* const* packages, |
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
142 |
jsize num_packages, TRAPS) { |
36508 | 143 |
ResourceMark rm(THREAD); |
144 |
||
145 |
Handle module_handle(THREAD, JNIHandles::resolve(module)); |
|
146 |
||
147 |
// Obtain java.base's module version |
|
148 |
const char* module_version = get_module_version(version); |
|
149 |
TempNewSymbol version_symbol; |
|
150 |
if (module_version != NULL) { |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
151 |
version_symbol = SymbolTable::new_symbol(module_version); |
36508 | 152 |
} else { |
153 |
version_symbol = NULL; |
|
154 |
} |
|
155 |
||
156 |
// Obtain java.base's location |
|
157 |
const char* module_location = NULL; |
|
158 |
TempNewSymbol location_symbol = NULL; |
|
159 |
if (location != NULL) { |
|
160 |
module_location = |
|
161 |
java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location)); |
|
162 |
if (module_location != NULL) { |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
163 |
location_symbol = SymbolTable::new_symbol(module_location); |
36508 | 164 |
} |
165 |
} |
|
166 |
||
167 |
||
46322
25836096c89d
8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents:
46296
diff
changeset
|
168 |
// Check that the packages are syntactically ok. |
36508 | 169 |
GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages); |
170 |
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
|
171 |
const char *package_name = packages[x]; |
36508 | 172 |
if (!Modules::verify_package_name(package_name)) { |
173 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
174 |
err_msg("Invalid package name: %s for module: " JAVA_BASE_NAME, package_name)); |
36508 | 175 |
} |
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
176 |
Symbol* pkg_symbol = SymbolTable::new_symbol(package_name); |
46322
25836096c89d
8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents:
46296
diff
changeset
|
177 |
pkg_list->append(pkg_symbol); |
36508 | 178 |
} |
179 |
||
180 |
// Validate java_base's loader is the boot loader. |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
181 |
oop loader = java_lang_Module::loader(module_handle()); |
36508 | 182 |
if (loader != NULL) { |
183 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
184 |
"Class loader must be the boot class loader"); |
|
185 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42656
diff
changeset
|
186 |
Handle h_loader(THREAD, loader); |
36508 | 187 |
|
188 |
// Ensure the boot loader's PackageEntryTable has been created |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
189 |
PackageEntryTable* package_table = get_package_entry_table(h_loader); |
36508 | 190 |
assert(pkg_list->length() == 0 || package_table != NULL, "Bad package_table"); |
191 |
||
192 |
// Ensure java.base's ModuleEntry has been created |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
193 |
assert(ModuleEntryTable::javabase_moduleEntry() != NULL, "No ModuleEntry for " JAVA_BASE_NAME); |
36508 | 194 |
|
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
195 |
bool duplicate_javabase = false; |
36508 | 196 |
{ |
197 |
MutexLocker m1(Module_lock, THREAD); |
|
198 |
||
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37248
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
} else { |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37248
diff
changeset
|
202 |
|
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 |
// 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
|
204 |
// 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
|
205 |
// 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
|
206 |
package_table->verify_javabase_packages(pkg_list); |
36508 | 207 |
|
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
208 |
// 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
|
209 |
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
|
210 |
// Some of java.base's packages were added early in bootstrapping, ignore duplicates. |
53471
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
211 |
package_table->locked_create_entry_if_not_exist(pkg_list->at(x), |
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
212 |
ModuleEntryTable::javabase_moduleEntry()); |
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
213 |
assert(package_table->locked_lookup_only(pkg_list->at(x)) != NULL, |
53441 | 214 |
"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
|
215 |
// 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
|
216 |
// 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
|
217 |
// 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
|
218 |
pkg_list->at(x)->decrement_refcount(); |
36508 | 219 |
} |
38732
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
220 |
|
bb77e0dcc7e5
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents:
38207
diff
changeset
|
221 |
// 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
|
222 |
ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol); |
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 |
if (duplicate_javabase) { |
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
226 |
THROW_MSG(vmSymbols::java_lang_InternalError(), |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
227 |
"Module " JAVA_BASE_NAME " is already defined"); |
36508 | 228 |
} |
229 |
||
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
|
230 |
// 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
|
231 |
// 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
|
232 |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
233 |
// Patch any previously loaded class's module field with java.base's java.lang.Module. |
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 |
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
|
235 |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
236 |
log_info(module, load)(JAVA_BASE_NAME " location: %s", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
237 |
module_location != NULL ? module_location : "NULL"); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
238 |
log_debug(module)("define_javabase_module(): Definition of module: " |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
239 |
JAVA_BASE_NAME ", version: %s, location: %s, package #: %d", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
240 |
module_version != NULL ? module_version : "NULL", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
241 |
module_location != NULL ? module_location : "NULL", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
242 |
pkg_list->length()); |
36508 | 243 |
|
244 |
// packages defined to java.base |
|
46458 | 245 |
if (log_is_enabled(Trace, module)) { |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
246 |
for (int x = 0; x < pkg_list->length(); x++) { |
46458 | 247 |
log_trace(module)("define_javabase_module(): creation of package %s for module " JAVA_BASE_NAME, |
248 |
(pkg_list->at(x))->as_C_string()); |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
249 |
} |
36508 | 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 |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
267 |
void Modules::define_module(jobject module, jboolean is_open, 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)); |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
287 |
if (!java_lang_Module::is_instance(module_handle())) { |
36508 | 288 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
289 |
"module is not an instance of type java.lang.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) { |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
300 |
assert(is_open == JNI_FALSE, "java.base module cannot be open"); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
301 |
define_javabase_module(module, version, location, packages, num_packages, CHECK); |
36508 | 302 |
return; |
303 |
} |
|
304 |
||
305 |
const char* module_version = get_module_version(version); |
|
306 |
||
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
307 |
oop loader = java_lang_Module::loader(module_handle()); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
308 |
// Make sure loader is not the jdk.internal.reflect.DelegatingClassLoader. |
51197
3a6be93c9660
8204970: Remaing object comparisons need to use oopDesc::equals()
rkennke
parents:
50634
diff
changeset
|
309 |
if (!oopDesc::equals(loader, java_lang_ClassLoader::non_reflection_class_loader(loader))) { |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
310 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
311 |
"Class loader is an invalid delegating class loader"); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
312 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
313 |
Handle h_loader = Handle(THREAD, loader); |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
49739
diff
changeset
|
314 |
// define_module can be called during start-up, before the class loader's ClassLoaderData |
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
49739
diff
changeset
|
315 |
// has been created. SystemDictionary::register_loader ensures creation, if needed. |
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
49739
diff
changeset
|
316 |
ClassLoaderData* loader_data = SystemDictionary::register_loader(h_loader); |
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
49739
diff
changeset
|
317 |
assert(loader_data != NULL, "class loader data shouldn't be null"); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
318 |
|
36508 | 319 |
// Check that the list of packages has no duplicates and that the |
320 |
// packages are syntactically ok. |
|
321 |
GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages); |
|
322 |
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
|
323 |
const char* package_name = packages[x]; |
36508 | 324 |
if (!verify_package_name(package_name)) { |
325 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
326 |
err_msg("Invalid package name: %s for module: %s", |
|
327 |
package_name, module_name)); |
|
328 |
} |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
329 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
330 |
// 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
|
331 |
if (!h_loader.is_null() && |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42656
diff
changeset
|
332 |
!SystemDictionary::is_platform_class_loader(h_loader()) && |
44326
6c59cca7ff07
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43471
diff
changeset
|
333 |
(strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 && |
6c59cca7ff07
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43471
diff
changeset
|
334 |
(package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) { |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
49739
diff
changeset
|
335 |
const char* class_loader_name = loader_data->loader_name_and_id(); |
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
336 |
size_t pkg_len = strlen(package_name); |
53664 | 337 |
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len + 1); |
338 |
strncpy(pkg_name, package_name, pkg_len + 1); |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
339 |
StringUtils::replace_no_expand(pkg_name, "/", "."); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
340 |
const char* msg_text1 = "Class loader (instance of): "; |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), message); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
346 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41691
diff
changeset
|
347 |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
348 |
Symbol* pkg_symbol = SymbolTable::new_symbol(package_name); |
46322
25836096c89d
8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents:
46296
diff
changeset
|
349 |
pkg_list->append(pkg_symbol); |
36508 | 350 |
} |
351 |
||
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
352 |
ModuleEntryTable* module_table = get_module_entry_table(h_loader); |
36508 | 353 |
assert(module_table != NULL, "module entry table shouldn't be null"); |
354 |
||
355 |
// Create symbol* entry for module name. |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
356 |
TempNewSymbol module_symbol = SymbolTable::new_symbol(module_name); |
36508 | 357 |
|
358 |
bool dupl_modules = false; |
|
359 |
||
360 |
// Create symbol* entry for module version. |
|
361 |
TempNewSymbol version_symbol; |
|
362 |
if (module_version != NULL) { |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
363 |
version_symbol = SymbolTable::new_symbol(module_version); |
36508 | 364 |
} else { |
365 |
version_symbol = NULL; |
|
366 |
} |
|
367 |
||
368 |
// Create symbol* entry for module location. |
|
369 |
const char* module_location = NULL; |
|
370 |
TempNewSymbol location_symbol = NULL; |
|
371 |
if (location != NULL) { |
|
372 |
module_location = |
|
373 |
java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location)); |
|
374 |
if (module_location != NULL) { |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
375 |
location_symbol = SymbolTable::new_symbol(module_location); |
36508 | 376 |
} |
377 |
} |
|
378 |
||
379 |
PackageEntryTable* package_table = NULL; |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
380 |
PackageEntry* existing_pkg = NULL; |
36508 | 381 |
{ |
382 |
MutexLocker ml(Module_lock, THREAD); |
|
383 |
||
384 |
if (num_packages > 0) { |
|
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49192
diff
changeset
|
385 |
package_table = get_package_entry_table(h_loader); |
36508 | 386 |
assert(package_table != NULL, "Missing package_table"); |
387 |
||
388 |
// Check that none of the packages exist in the class loader's package table. |
|
389 |
for (int x = 0; x < pkg_list->length(); x++) { |
|
53441 | 390 |
existing_pkg = package_table->locked_lookup_only(pkg_list->at(x)); |
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
391 |
if (existing_pkg != NULL) { |
36508 | 392 |
// This could be because the module was already defined. If so, |
393 |
// report that error instead of the package error. |
|
394 |
if (module_table->lookup_only(module_symbol) != NULL) { |
|
395 |
dupl_modules = true; |
|
396 |
} |
|
397 |
break; |
|
398 |
} |
|
399 |
} |
|
400 |
} // if (num_packages > 0)... |
|
401 |
||
402 |
// 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
|
403 |
if (!dupl_modules && existing_pkg == NULL) { |
53471
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
404 |
if (module_table->lookup_only(module_symbol) == NULL) { |
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
405 |
// Create the entry for this module in the class loader's module entry table. |
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
406 |
ModuleEntry* module_entry = module_table->locked_create_entry(module_handle, |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
407 |
(is_open == JNI_TRUE), module_symbol, |
36508 | 408 |
version_symbol, location_symbol, loader_data); |
53471
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
409 |
assert(module_entry != NULL, "module_entry creation failed"); |
36508 | 410 |
|
411 |
// Add the packages. |
|
412 |
assert(pkg_list->length() == 0 || package_table != NULL, "Bad package table"); |
|
413 |
for (int y = 0; y < pkg_list->length(); y++) { |
|
53471
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
414 |
package_table->locked_create_entry(pkg_list->at(y), module_entry); |
36508 | 415 |
|
416 |
// Unable to have a GrowableArray of TempNewSymbol. Must decrement the refcount of |
|
417 |
// the Symbol* that was created above for each package. The refcount was incremented |
|
418 |
// by SymbolTable::new_symbol and as well by the PackageEntry creation. |
|
419 |
pkg_list->at(y)->decrement_refcount(); |
|
420 |
} |
|
421 |
||
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
422 |
// Store pointer to ModuleEntry record in java.lang.Module object. |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
423 |
java_lang_Module::set_module_entry(module_handle(), module_entry); |
53471
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
424 |
} else { |
525f212f1bda
8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents:
53441
diff
changeset
|
425 |
dupl_modules = true; |
36508 | 426 |
} |
427 |
} |
|
428 |
} // Release the lock |
|
429 |
||
430 |
// any errors ? |
|
431 |
if (dupl_modules) { |
|
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
432 |
THROW_MSG(vmSymbols::java_lang_IllegalStateException(), |
36508 | 433 |
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
|
434 |
} else if (existing_pkg != NULL) { |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42656
diff
changeset
|
435 |
throw_dup_pkg_exception(module_name, existing_pkg, CHECK); |
36508 | 436 |
} |
437 |
||
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
438 |
log_info(module, load)("%s location: %s", module_name, |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
439 |
module_location != NULL ? module_location : "NULL"); |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
440 |
LogTarget(Debug, module) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
441 |
if (lt.is_enabled()) { |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
442 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
443 |
ls.print("define_module(): creation of module: %s, version: %s, location: %s, ", |
36508 | 444 |
module_name, module_version != NULL ? module_version : "NULL", |
445 |
module_location != NULL ? module_location : "NULL"); |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
446 |
loader_data->print_value_on(&ls); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
447 |
ls.print_cr(", package #: %d", pkg_list->length()); |
36508 | 448 |
for (int y = 0; y < pkg_list->length(); y++) { |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
449 |
log_trace(module)("define_module(): creation of package %s for module %s", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
450 |
(pkg_list->at(y))->as_C_string(), module_name); |
36508 | 451 |
} |
452 |
} |
|
453 |
||
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37248
diff
changeset
|
454 |
// If the module is defined to the boot loader and an exploded build is being |
46463
4bd2ca84df7a
8178604: JVM does not allow defining boot loader modules in exploded build after module system initialization
hseigel
parents:
46458
diff
changeset
|
455 |
// used, prepend <java.home>/modules/modules_name to the system boot class path. |
4bd2ca84df7a
8178604: JVM does not allow defining boot loader modules in exploded build after module system initialization
hseigel
parents:
46458
diff
changeset
|
456 |
if (loader == NULL && !ClassLoader::has_jrt_entry()) { |
40013 | 457 |
ClassLoader::add_to_exploded_build_list(module_symbol, CHECK); |
36508 | 458 |
} |
459 |
} |
|
460 |
||
461 |
void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) { |
|
462 |
ResourceMark rm(THREAD); |
|
463 |
||
464 |
if (module == NULL) { |
|
465 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object"); |
|
466 |
} |
|
467 |
Handle module_handle(THREAD, JNIHandles::resolve(module)); |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
468 |
if (!java_lang_Module::is_instance(module_handle())) { |
36508 | 469 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
470 |
"module is not an instance of type java.lang.Module"); |
36508 | 471 |
} |
472 |
||
473 |
// Ensure that this is an unnamed module |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
474 |
oop name = java_lang_Module::name(module_handle()); |
36508 | 475 |
if (name != NULL) { |
476 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
477 |
"boot loader's unnamed module's java.lang.Module has a name"); |
36508 | 478 |
} |
479 |
||
480 |
// Validate java_base's loader is the boot loader. |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
481 |
oop loader = java_lang_Module::loader(module_handle()); |
36508 | 482 |
if (loader != NULL) { |
483 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
484 |
"Class loader must be the boot class loader"); |
|
485 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42656
diff
changeset
|
486 |
Handle h_loader(THREAD, loader); |
36508 | 487 |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
488 |
log_debug(module)("set_bootloader_unnamed_module(): recording unnamed module for boot loader"); |
36508 | 489 |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
490 |
// Set java.lang.Module for the boot loader's unnamed module |
46387 | 491 |
ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data(); |
492 |
ModuleEntry* unnamed_module = boot_loader_data->unnamed_module(); |
|
36508 | 493 |
assert(unnamed_module != NULL, "boot loader's unnamed ModuleEntry not defined"); |
46387 | 494 |
unnamed_module->set_module(boot_loader_data->add_handle(module_handle)); |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
495 |
// Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object. |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
496 |
java_lang_Module::set_module_entry(module_handle(), unnamed_module); |
36508 | 497 |
} |
498 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
499 |
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
|
500 |
if (package_name == NULL) { |
36508 | 501 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
502 |
"package is null"); |
|
503 |
} |
|
504 |
if (from_module == NULL) { |
|
505 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
506 |
"from_module is null"); |
|
507 |
} |
|
508 |
ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK); |
|
509 |
if (from_module_entry == NULL) { |
|
510 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
511 |
"from_module cannot be found"); |
|
512 |
} |
|
513 |
||
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
514 |
// All packages in unnamed and open modules are exported by default. |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
515 |
if (!from_module_entry->is_named() || from_module_entry->is_open()) return; |
36508 | 516 |
|
517 |
ModuleEntry* to_module_entry; |
|
518 |
if (to_module == NULL) { |
|
519 |
to_module_entry = NULL; // It's an unqualified export. |
|
520 |
} else { |
|
521 |
to_module_entry = get_module_entry(to_module, CHECK); |
|
522 |
if (to_module_entry == NULL) { |
|
523 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
524 |
"to_module is invalid"); |
|
525 |
} |
|
526 |
} |
|
527 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
528 |
PackageEntry *package_entry = get_package_entry(from_module_entry, package_name, CHECK); |
36508 | 529 |
ResourceMark rm(THREAD); |
530 |
if (package_entry == NULL) { |
|
531 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
532 |
err_msg("Package %s not found in from_module %s", |
|
533 |
package_name != NULL ? package_name : "", |
|
534 |
from_module_entry->name()->as_C_string())); |
|
535 |
} |
|
536 |
if (package_entry->module() != from_module_entry) { |
|
537 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
538 |
err_msg("Package: %s found in module %s, not in from_module: %s", |
|
539 |
package_entry->name()->as_C_string(), |
|
540 |
package_entry->module()->name()->as_C_string(), |
|
541 |
from_module_entry->name()->as_C_string())); |
|
542 |
} |
|
543 |
||
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
544 |
log_debug(module)("add_module_exports(): package %s in module %s is exported to module %s", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
545 |
package_entry->name()->as_C_string(), |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
546 |
from_module_entry->name()->as_C_string(), |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
547 |
to_module_entry == NULL ? "NULL" : |
36508 | 548 |
to_module_entry->is_named() ? |
549 |
to_module_entry->name()->as_C_string() : UNNAMED_MODULE); |
|
550 |
||
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
551 |
// Do nothing if modules are the same. |
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
552 |
if (from_module_entry != to_module_entry) { |
36508 | 553 |
package_entry->set_exported(to_module_entry); |
554 |
} |
|
555 |
} |
|
556 |
||
557 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
558 |
void Modules::add_module_exports_qualified(jobject from_module, const char* package, |
36508 | 559 |
jobject to_module, TRAPS) { |
560 |
if (to_module == NULL) { |
|
561 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
562 |
"to_module is null"); |
|
563 |
} |
|
564 |
add_module_exports(from_module, package, to_module, CHECK); |
|
565 |
} |
|
566 |
||
567 |
void Modules::add_reads_module(jobject from_module, jobject to_module, TRAPS) { |
|
568 |
if (from_module == NULL) { |
|
569 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
570 |
"from_module is null"); |
|
571 |
} |
|
572 |
||
573 |
ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK); |
|
574 |
if (from_module_entry == NULL) { |
|
575 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
576 |
"from_module is not valid"); |
|
577 |
} |
|
578 |
||
579 |
ModuleEntry* to_module_entry; |
|
580 |
if (to_module != NULL) { |
|
581 |
to_module_entry = get_module_entry(to_module, CHECK); |
|
582 |
if (to_module_entry == NULL) { |
|
583 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
584 |
"to_module is invalid"); |
|
585 |
} |
|
586 |
} else { |
|
587 |
to_module_entry = NULL; |
|
588 |
} |
|
589 |
||
590 |
ResourceMark rm(THREAD); |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
591 |
log_debug(module)("add_reads_module(): Adding read from module %s to module %s", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
592 |
from_module_entry->is_named() ? |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
593 |
from_module_entry->name()->as_C_string() : UNNAMED_MODULE, |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
594 |
to_module_entry == NULL ? "all unnamed" : |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
595 |
(to_module_entry->is_named() ? |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
596 |
to_module_entry->name()->as_C_string() : UNNAMED_MODULE)); |
36508 | 597 |
|
598 |
// if modules are the same or if from_module is unnamed then no need to add the read. |
|
599 |
if (from_module_entry != to_module_entry && from_module_entry->is_named()) { |
|
600 |
from_module_entry->add_read(to_module_entry); |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
// This method is called by JFR and JNI. |
|
605 |
jobject Modules::get_module(jclass clazz, TRAPS) { |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
606 |
assert(ModuleEntryTable::javabase_defined(), |
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
607 |
"Attempt to call get_module before " JAVA_BASE_NAME " is defined"); |
36508 | 608 |
|
609 |
if (clazz == NULL) { |
|
610 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), |
|
611 |
"class is null", JNI_FALSE); |
|
612 |
} |
|
613 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
|
614 |
if (mirror == NULL) { |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
615 |
log_debug(module)("get_module(): no mirror, returning NULL"); |
36508 | 616 |
return NULL; |
617 |
} |
|
618 |
if (!java_lang_Class::is_instance(mirror)) { |
|
619 |
THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
|
620 |
"Invalid class", JNI_FALSE); |
|
621 |
} |
|
622 |
||
623 |
oop module = java_lang_Class::module(mirror); |
|
624 |
||
625 |
assert(module != NULL, "java.lang.Class module field not set"); |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
626 |
assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module"); |
36508 | 627 |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
628 |
LogTarget(Debug,module) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
629 |
if (lt.is_enabled()) { |
36508 | 630 |
ResourceMark rm(THREAD); |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
631 |
LogStream ls(lt); |
36508 | 632 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
633 |
oop module_name = java_lang_Module::name(module); |
36508 | 634 |
if (module_name != NULL) { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
635 |
ls.print("get_module(): module "); |
36508 | 636 |
java_lang_String::print(module_name, tty); |
637 |
} else { |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
638 |
ls.print("get_module(): Unamed Module"); |
36508 | 639 |
} |
640 |
if (klass != NULL) { |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
641 |
ls.print_cr(" for class %s", klass->external_name()); |
36508 | 642 |
} else { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46632
diff
changeset
|
643 |
ls.print_cr(" for primitive class"); |
36508 | 644 |
} |
645 |
} |
|
646 |
||
647 |
return JNIHandles::make_local(THREAD, module); |
|
648 |
} |
|
649 |
||
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
650 |
jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) { |
39706 | 651 |
assert(ModuleEntryTable::javabase_defined(), |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
41691
diff
changeset
|
652 |
"Attempt to call get_named_module before " JAVA_BASE_NAME " is defined"); |
39706 | 653 |
assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()), |
654 |
"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
|
655 |
assert(package_name != NULL, "the package_name should not be NULL"); |
39706 | 656 |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
657 |
if (strlen(package_name) == 0) { |
39706 | 658 |
return NULL; |
659 |
} |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
53664
diff
changeset
|
660 |
TempNewSymbol package_sym = SymbolTable::new_symbol(package_name); |
39706 | 661 |
const PackageEntry* const pkg_entry = |
662 |
get_package_entry_by_name(package_sym, h_loader, THREAD); |
|
663 |
const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL); |
|
664 |
||
665 |
if (module_entry != NULL && module_entry->module() != NULL && module_entry->is_named()) { |
|
46773
fb17cc9a6847
8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents:
46701
diff
changeset
|
666 |
return JNIHandles::make_local(THREAD, module_entry->module()); |
39706 | 667 |
} |
668 |
return NULL; |
|
669 |
} |
|
670 |
||
671 |
||
36508 | 672 |
// This method is called by JFR and by the above method. |
673 |
jobject Modules::get_module(Symbol* package_name, Handle h_loader, TRAPS) { |
|
674 |
const PackageEntry* const pkg_entry = |
|
675 |
get_package_entry_by_name(package_name, h_loader, THREAD); |
|
676 |
const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL); |
|
677 |
||
678 |
if (module_entry != NULL && |
|
679 |
module_entry->module() != NULL) { |
|
46773
fb17cc9a6847
8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents:
46701
diff
changeset
|
680 |
return JNIHandles::make_local(THREAD, module_entry->module()); |
36508 | 681 |
} |
682 |
||
683 |
return NULL; |
|
684 |
} |
|
685 |
||
686 |
// 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
|
687 |
void Modules::add_module_exports_to_all_unnamed(jobject module, const char* package_name, TRAPS) { |
36508 | 688 |
if (module == NULL) { |
689 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
|
690 |
"module is null"); |
|
691 |
} |
|
43466
add500644443
8171855: Move package name transformations during module bootstrap into native code
redestad
parents:
43446
diff
changeset
|
692 |
if (package_name == NULL) { |
36508 | 693 |
THROW_MSG(vmSymbols::java_lang_NullPointerException(), |
694 |
"package is null"); |
|
695 |
} |
|
696 |
ModuleEntry* module_entry = get_module_entry(module, CHECK); |
|
697 |
if (module_entry == NULL) { |
|
698 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
699 |
"module is invalid"); |
|
700 |
} |
|
701 |
||
702 |
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
|
703 |
PackageEntry *package_entry = get_package_entry(module_entry, package_name, CHECK); |
36508 | 704 |
ResourceMark rm(THREAD); |
705 |
if (package_entry == NULL) { |
|
706 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
707 |
err_msg("Package %s not found in module %s", |
|
708 |
package_name != NULL ? package_name : "", |
|
709 |
module_entry->name()->as_C_string())); |
|
710 |
} |
|
711 |
if (package_entry->module() != module_entry) { |
|
712 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
713 |
err_msg("Package: %s found in module %s, not in module: %s", |
|
714 |
package_entry->name()->as_C_string(), |
|
715 |
package_entry->module()->name()->as_C_string(), |
|
716 |
module_entry->name()->as_C_string())); |
|
717 |
} |
|
718 |
||
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
719 |
log_debug(module)("add_module_exports_to_all_unnamed(): package %s in module" |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
720 |
" %s is exported to all unnamed modules", |
36508 | 721 |
package_entry->name()->as_C_string(), |
722 |
module_entry->name()->as_C_string()); |
|
723 |
||
43471
bfb383279a16
8171971: Fix timing bug in JVM management of package export lists
hseigel
parents:
43466
diff
changeset
|
724 |
// 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
|
725 |
package_entry->set_is_exported_allUnnamed(); |
36508 | 726 |
} |
727 |
} |