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 "jni.h"
27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "logging/log.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/oopHandle.inline.hpp"
33 #include "oops/symbol.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "runtime/safepoint.hpp"
36 #include "utilities/events.hpp"
37 #include "utilities/growableArray.hpp"
38 #include "utilities/hashtable.inline.hpp"
39 #include "utilities/ostream.hpp"
40
41 ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
42
43 oop ModuleEntry::module() const { return _module.resolve(); }
44
45 void ModuleEntry::set_location(Symbol* location) {
46 if (_location != NULL) {
47 // _location symbol's refcounts are managed by ModuleEntry,
48 // must decrement the old one before updating.
219 assert(f != NULL, "invariant");
220
221 if (has_reads_list()) {
222 int reads_len = _reads->length();
223 for (int i = 0; i < reads_len; ++i) {
224 f->do_module(_reads->at(i));
225 }
226 }
227 }
228
229 void ModuleEntry::delete_reads() {
230 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
231 delete _reads;
232 _reads = NULL;
233 }
234
235 ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {
236 // The java.lang.Module for this loader's
237 // corresponding unnamed module can be found in the java.lang.ClassLoader object.
238 oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());
239 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);
240
241 // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module
242 // object.
243 java_lang_Module::set_module_entry(module, unnamed_module);
244
245 return unnamed_module;
246 }
247
248 ModuleEntry* ModuleEntry::create_boot_unnamed_module(ClassLoaderData* cld) {
249 // For the boot loader, the java.lang.Module for the unnamed module
250 // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
251 // this point initially create the ModuleEntry for the unnamed module.
252 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(), cld);
253 assert(unnamed_module != NULL, "boot loader unnamed module should not be null");
254 return unnamed_module;
255 }
256
257 // When creating an unnamed module, this is called without holding the Module_lock.
258 // This is okay because the unnamed module gets created before the ClassLoaderData
259 // is available to other threads.
260 ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) {
261 ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, sizeof(ModuleEntry), mtModule);
262
|
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 "jni.h"
27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "logging/log.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/oopHandle.inline.hpp"
33 #include "oops/symbol.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "runtime/safepoint.hpp"
36 #include "utilities/events.hpp"
37 #include "utilities/growableArray.hpp"
38 #include "utilities/hashtable.inline.hpp"
39 #include "utilities/ostream.hpp"
40
41 ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
42
43 oop ModuleEntry::module() const { return _module.resolve(); }
44
45 void ModuleEntry::set_location(Symbol* location) {
46 if (_location != NULL) {
47 // _location symbol's refcounts are managed by ModuleEntry,
48 // must decrement the old one before updating.
219 assert(f != NULL, "invariant");
220
221 if (has_reads_list()) {
222 int reads_len = _reads->length();
223 for (int i = 0; i < reads_len; ++i) {
224 f->do_module(_reads->at(i));
225 }
226 }
227 }
228
229 void ModuleEntry::delete_reads() {
230 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
231 delete _reads;
232 _reads = NULL;
233 }
234
235 ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {
236 // The java.lang.Module for this loader's
237 // corresponding unnamed module can be found in the java.lang.ClassLoader object.
238 oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());
239
240 // Ensure that the unnamed module was correctly set when
241 // the class loader was constructed.
242 guarantee(java_lang_Module::is_instance(module), "unnamed module is not an instance of type java.lang.Module");
243
244 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);
245
246 // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.
247 java_lang_Module::set_module_entry(module, unnamed_module);
248
249 return unnamed_module;
250 }
251
252 ModuleEntry* ModuleEntry::create_boot_unnamed_module(ClassLoaderData* cld) {
253 // For the boot loader, the java.lang.Module for the unnamed module
254 // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
255 // this point initially create the ModuleEntry for the unnamed module.
256 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(), cld);
257 assert(unnamed_module != NULL, "boot loader unnamed module should not be null");
258 return unnamed_module;
259 }
260
261 // When creating an unnamed module, this is called without holding the Module_lock.
262 // This is okay because the unnamed module gets created before the ClassLoaderData
263 // is available to other threads.
264 ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) {
265 ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, sizeof(ModuleEntry), mtModule);
266
|