75
76 // Set the shared ProtectionDomain atomically
77 void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data,
78 Handle pd_h) {
79 // Create a JNI handle for the shared ProtectionDomain and save it atomically.
80 // If someone beats us setting the _pd cache, the created JNI handle is destroyed.
81 jobject obj = loader_data->add_handle(pd_h);
82 if (Atomic::cmpxchg_ptr(obj, &_pd, NULL) != NULL) {
83 loader_data->remove_handle(obj);
84 }
85 }
86
87 // Returns true if this module can read module m
88 bool ModuleEntry::can_read(ModuleEntry* m) const {
89 assert(m != NULL, "No module to lookup in this module's reads list");
90
91 // Unnamed modules read everyone and all modules
92 // read java.base. If either of these conditions
93 // hold, readability has been established.
94 if (!this->is_named() ||
95 (m == ModuleEntryTable::javabase_module())) {
96 return true;
97 }
98
99 MutexLocker m1(Module_lock);
100 if (!has_reads()) {
101 return false;
102 } else {
103 return _reads->contains(m);
104 }
105 }
106
107 // Add a new module to this module's reads list
108 void ModuleEntry::add_read(ModuleEntry* m) {
109 MutexLocker m1(Module_lock);
110 if (m == NULL) {
111 set_can_read_all_unnamed();
112 } else {
113 if (_reads == NULL) {
114 // Lazily create a module's reads list
115 _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
341 for (ModuleEntry* entry = bucket(i);
342 entry != NULL;
343 entry = entry->next()) {
344 entry->purge_reads();
345 }
346 }
347 }
348
349 void ModuleEntryTable::finalize_javabase(Handle module_handle, Symbol* version, Symbol* location) {
350 assert(Module_lock->owned_by_self(), "should have the Module_lock");
351 ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();
352 ModuleEntryTable* module_table = boot_loader_data->modules();
353
354 assert(module_table != NULL, "boot loader's ModuleEntryTable not defined");
355
356 if (module_handle.is_null()) {
357 fatal("Unable to finalize module definition for java.base");
358 }
359
360 // Set java.lang.reflect.Module, version and location for java.base
361 ModuleEntry* jb_module = javabase_module();
362 assert(jb_module != NULL, "java.base ModuleEntry not defined");
363 jb_module->set_module(boot_loader_data->add_handle(module_handle));
364 jb_module->set_version(version);
365 jb_module->set_location(location);
366 // Store pointer to the ModuleEntry for java.base in the java.lang.reflect.Module object.
367 java_lang_reflect_Module::set_module_entry(module_handle(), jb_module);
368 }
369
370 void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
371 if (module_handle.is_null()) {
372 fatal("Unable to patch the module field of classes loaded prior to java.base's definition, invalid java.lang.reflect.Module");
373 }
374
375 // Do the fixups for the basic primitive types
376 java_lang_Class::set_module(Universe::int_mirror(), module_handle());
377 java_lang_Class::set_module(Universe::float_mirror(), module_handle());
378 java_lang_Class::set_module(Universe::double_mirror(), module_handle());
379 java_lang_Class::set_module(Universe::byte_mirror(), module_handle());
380 java_lang_Class::set_module(Universe::bool_mirror(), module_handle());
381 java_lang_Class::set_module(Universe::char_mirror(), module_handle());
382 java_lang_Class::set_module(Universe::long_mirror(), module_handle());
383 java_lang_Class::set_module(Universe::short_mirror(), module_handle());
384 java_lang_Class::set_module(Universe::void_mirror(), module_handle());
385
386 // Do the fixups for classes that have already been created.
387 GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
388 int list_length = list->length();
389 for (int i = 0; i < list_length; i++) {
390 Klass* k = list->at(i);
|
75
76 // Set the shared ProtectionDomain atomically
77 void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data,
78 Handle pd_h) {
79 // Create a JNI handle for the shared ProtectionDomain and save it atomically.
80 // If someone beats us setting the _pd cache, the created JNI handle is destroyed.
81 jobject obj = loader_data->add_handle(pd_h);
82 if (Atomic::cmpxchg_ptr(obj, &_pd, NULL) != NULL) {
83 loader_data->remove_handle(obj);
84 }
85 }
86
87 // Returns true if this module can read module m
88 bool ModuleEntry::can_read(ModuleEntry* m) const {
89 assert(m != NULL, "No module to lookup in this module's reads list");
90
91 // Unnamed modules read everyone and all modules
92 // read java.base. If either of these conditions
93 // hold, readability has been established.
94 if (!this->is_named() ||
95 (m == ModuleEntryTable::javabase_moduleEntry())) {
96 return true;
97 }
98
99 MutexLocker m1(Module_lock);
100 if (!has_reads()) {
101 return false;
102 } else {
103 return _reads->contains(m);
104 }
105 }
106
107 // Add a new module to this module's reads list
108 void ModuleEntry::add_read(ModuleEntry* m) {
109 MutexLocker m1(Module_lock);
110 if (m == NULL) {
111 set_can_read_all_unnamed();
112 } else {
113 if (_reads == NULL) {
114 // Lazily create a module's reads list
115 _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
341 for (ModuleEntry* entry = bucket(i);
342 entry != NULL;
343 entry = entry->next()) {
344 entry->purge_reads();
345 }
346 }
347 }
348
349 void ModuleEntryTable::finalize_javabase(Handle module_handle, Symbol* version, Symbol* location) {
350 assert(Module_lock->owned_by_self(), "should have the Module_lock");
351 ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();
352 ModuleEntryTable* module_table = boot_loader_data->modules();
353
354 assert(module_table != NULL, "boot loader's ModuleEntryTable not defined");
355
356 if (module_handle.is_null()) {
357 fatal("Unable to finalize module definition for java.base");
358 }
359
360 // Set java.lang.reflect.Module, version and location for java.base
361 ModuleEntry* jb_module = javabase_moduleEntry();
362 assert(jb_module != NULL, "java.base ModuleEntry not defined");
363 jb_module->set_version(version);
364 jb_module->set_location(location);
365 // Once java.base's ModuleEntry _module field is set with the known
366 // java.lang.reflect.Module, java.base is considered "defined" to the VM.
367 jb_module->set_module_release_store(boot_loader_data->add_handle(module_handle));
368
369 // Store pointer to the ModuleEntry for java.base in the java.lang.reflect.Module object.
370 java_lang_reflect_Module::set_module_entry(module_handle(), jb_module);
371
372 // Patch any previously loaded classes' module field with java.base's java.lang.reflect.Module.
373 patch_javabase_entries(module_handle);
374 }
375
376 void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
377 assert(Module_lock->owned_by_self(), "should have the Module_lock");
378 if (module_handle.is_null()) {
379 fatal("Unable to patch the module field of classes loaded prior to java.base's definition, invalid java.lang.reflect.Module");
380 }
381
382 // Do the fixups for the basic primitive types
383 java_lang_Class::set_module(Universe::int_mirror(), module_handle());
384 java_lang_Class::set_module(Universe::float_mirror(), module_handle());
385 java_lang_Class::set_module(Universe::double_mirror(), module_handle());
386 java_lang_Class::set_module(Universe::byte_mirror(), module_handle());
387 java_lang_Class::set_module(Universe::bool_mirror(), module_handle());
388 java_lang_Class::set_module(Universe::char_mirror(), module_handle());
389 java_lang_Class::set_module(Universe::long_mirror(), module_handle());
390 java_lang_Class::set_module(Universe::short_mirror(), module_handle());
391 java_lang_Class::set_module(Universe::void_mirror(), module_handle());
392
393 // Do the fixups for classes that have already been created.
394 GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
395 int list_length = list->length();
396 for (int i = 0; i < list_length; i++) {
397 Klass* k = list->at(i);
|