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);
391 assert(k->is_klass(), "List should only hold classes");
392 Thread* THREAD = Thread::current();
393 KlassHandle kh(THREAD, k);
394 java_lang_Class::fixup_module_field(kh, module_handle);
395 k->class_loader_data()->dec_keep_alive();
396 }
397
398 delete java_lang_Class::fixup_module_field_list();
399 java_lang_Class::set_fixup_module_field_list(NULL);
400 }
401
402 void ModuleEntryTable::print(outputStream* st) {
403 st->print_cr("Module Entry Table (table_size=%d, entries=%d)",
404 table_size(), number_of_entries());
405 for (int i = 0; i < table_size(); i++) {
406 for (ModuleEntry* probe = bucket(i);
407 probe != NULL;
408 probe = probe->next()) {
409 probe->print(st);
410 }
411 }
412 }
413
414 void ModuleEntry::print(outputStream* st) {
|
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 // Within java.lang.Class instances there is a java.lang.reflect.Module field
377 // that must be set with the defining module. During startup, prior to java.base's
378 // definition, classes needing their module field set are added to the fixup_module_list.
379 // Their module field is set once java.base's java.lang.reflect.Module is known to the VM.
380 void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
381 assert(Module_lock->owned_by_self(), "should have the Module_lock");
382 if (module_handle.is_null()) {
383 fatal("Unable to patch the module field of classes loaded prior to java.base's definition, invalid java.lang.reflect.Module");
384 }
385
386 // Do the fixups for the basic primitive types
387 java_lang_Class::set_module(Universe::int_mirror(), module_handle());
388 java_lang_Class::set_module(Universe::float_mirror(), module_handle());
389 java_lang_Class::set_module(Universe::double_mirror(), module_handle());
390 java_lang_Class::set_module(Universe::byte_mirror(), module_handle());
391 java_lang_Class::set_module(Universe::bool_mirror(), module_handle());
392 java_lang_Class::set_module(Universe::char_mirror(), module_handle());
393 java_lang_Class::set_module(Universe::long_mirror(), module_handle());
394 java_lang_Class::set_module(Universe::short_mirror(), module_handle());
395 java_lang_Class::set_module(Universe::void_mirror(), module_handle());
396
397 // Do the fixups for classes that have already been created.
398 GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
399 int list_length = list->length();
400 for (int i = 0; i < list_length; i++) {
401 Klass* k = list->at(i);
402 assert(k->is_klass(), "List should only hold classes");
403 java_lang_Class::fixup_module_field(KlassHandle(k), module_handle);
404 k->class_loader_data()->dec_keep_alive();
405 }
406
407 delete java_lang_Class::fixup_module_field_list();
408 java_lang_Class::set_fixup_module_field_list(NULL);
409 }
410
411 void ModuleEntryTable::print(outputStream* st) {
412 st->print_cr("Module Entry Table (table_size=%d, entries=%d)",
413 table_size(), number_of_entries());
414 for (int i = 0; i < table_size(); i++) {
415 for (ModuleEntry* probe = bucket(i);
416 probe != NULL;
417 probe = probe->next()) {
418 probe->print(st);
419 }
420 }
421 }
422
423 void ModuleEntry::print(outputStream* st) {
|