hotspot/src/share/vm/classfile/moduleEntry.cpp
changeset 41183 207b92e69457
parent 39625 8702e5b9bfed
child 41691 1be281ee5de4
equal deleted inserted replaced
41182:dbd59c1da636 41183:207b92e69457
    90 
    90 
    91   // Unnamed modules read everyone and all modules
    91   // Unnamed modules read everyone and all modules
    92   // read java.base.  If either of these conditions
    92   // read java.base.  If either of these conditions
    93   // hold, readability has been established.
    93   // hold, readability has been established.
    94   if (!this->is_named() ||
    94   if (!this->is_named() ||
    95       (m == ModuleEntryTable::javabase_module())) {
    95       (m == ModuleEntryTable::javabase_moduleEntry())) {
    96     return true;
    96     return true;
    97   }
    97   }
    98 
    98 
    99   MutexLocker m1(Module_lock);
    99   MutexLocker m1(Module_lock);
   100   if (!has_reads()) {
   100   if (!has_reads()) {
   356   if (module_handle.is_null()) {
   356   if (module_handle.is_null()) {
   357     fatal("Unable to finalize module definition for java.base");
   357     fatal("Unable to finalize module definition for java.base");
   358   }
   358   }
   359 
   359 
   360   // Set java.lang.reflect.Module, version and location for java.base
   360   // Set java.lang.reflect.Module, version and location for java.base
   361   ModuleEntry* jb_module = javabase_module();
   361   ModuleEntry* jb_module = javabase_moduleEntry();
   362   assert(jb_module != NULL, "java.base ModuleEntry not defined");
   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);
   363   jb_module->set_version(version);
   365   jb_module->set_location(location);
   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(boot_loader_data->add_handle(module_handle));
       
   368 
   366   // Store pointer to the ModuleEntry for java.base in the java.lang.reflect.Module object.
   369   // 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);
   370   java_lang_reflect_Module::set_module_entry(module_handle(), jb_module);
   368 }
   371 
   369 
   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.
   370 void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
   380 void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
       
   381   assert(Module_lock->owned_by_self(), "should have the Module_lock");
   371   if (module_handle.is_null()) {
   382   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");
   383     fatal("Unable to patch the module field of classes loaded prior to java.base's definition, invalid java.lang.reflect.Module");
   373   }
   384   }
   374 
   385 
   375   // Do the fixups for the basic primitive types
   386   // Do the fixups for the basic primitive types
   387   GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
   398   GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
   388   int list_length = list->length();
   399   int list_length = list->length();
   389   for (int i = 0; i < list_length; i++) {
   400   for (int i = 0; i < list_length; i++) {
   390     Klass* k = list->at(i);
   401     Klass* k = list->at(i);
   391     assert(k->is_klass(), "List should only hold classes");
   402     assert(k->is_klass(), "List should only hold classes");
   392     Thread* THREAD = Thread::current();
   403     java_lang_Class::fixup_module_field(KlassHandle(k), module_handle);
   393     KlassHandle kh(THREAD, k);
       
   394     java_lang_Class::fixup_module_field(kh, module_handle);
       
   395     k->class_loader_data()->dec_keep_alive();
   404     k->class_loader_data()->dec_keep_alive();
   396   }
   405   }
   397 
   406 
   398   delete java_lang_Class::fixup_module_field_list();
   407   delete java_lang_Class::fixup_module_field_list();
   399   java_lang_Class::set_fixup_module_field_list(NULL);
   408   java_lang_Class::set_fixup_module_field_list(NULL);