818 set_array_klass(comp_mirror(), k()); 819 } else { 820 assert(k->is_instance_klass(), "Must be"); 821 822 initialize_mirror_fields(k, mirror, protection_domain, THREAD); 823 if (HAS_PENDING_EXCEPTION) { 824 // If any of the fields throws an exception like OOM remove the klass field 825 // from the mirror so GC doesn't follow it after the klass has been deallocated. 826 // This mirror looks like a primitive type, which logically it is because it 827 // it represents no class. 828 java_lang_Class::set_klass(mirror(), NULL); 829 return; 830 } 831 } 832 833 // set the classLoader field in the java_lang_Class instance 834 assert(class_loader() == k->class_loader(), "should be same"); 835 set_class_loader(mirror(), class_loader()); 836 837 // set the module field in the java_lang_Class instance 838 // This may be null during bootstrap but will get fixed up later on. 839 set_module(mirror(), module()); 840 841 // Setup indirection from klass->mirror last 842 // after any exceptions can happen during allocations. 843 if (!k.is_null()) { 844 k->set_java_mirror(mirror()); 845 } 846 847 // Keep list of classes needing java.base module fixup. 848 if (!ModuleEntryTable::javabase_defined()) { 849 if (fixup_module_field_list() == NULL) { 850 GrowableArray<Klass*>* list = 851 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true); 852 set_fixup_module_field_list(list); 853 } 854 k->class_loader_data()->inc_keep_alive(); 855 fixup_module_field_list()->push(k()); 856 } 857 } else { 858 if (fixup_mirror_list() == NULL) { 859 GrowableArray<Klass*>* list = 860 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true); 861 set_fixup_mirror_list(list); 862 } 863 fixup_mirror_list()->push(k()); 864 } 865 } 866 867 void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) { 868 assert(_module_offset != 0, "must have been computed already"); 869 java_lang_Class::set_module(k->java_mirror(), module()); 870 } 871 872 int java_lang_Class::oop_size(oop java_class) { 873 assert(_oop_size_offset != 0, "must be set"); 874 int size = java_class->int_field(_oop_size_offset); 875 assert(size > 0, "Oop size must be greater than zero, not %d", size); | 818 set_array_klass(comp_mirror(), k()); 819 } else { 820 assert(k->is_instance_klass(), "Must be"); 821 822 initialize_mirror_fields(k, mirror, protection_domain, THREAD); 823 if (HAS_PENDING_EXCEPTION) { 824 // If any of the fields throws an exception like OOM remove the klass field 825 // from the mirror so GC doesn't follow it after the klass has been deallocated. 826 // This mirror looks like a primitive type, which logically it is because it 827 // it represents no class. 828 java_lang_Class::set_klass(mirror(), NULL); 829 return; 830 } 831 } 832 833 // set the classLoader field in the java_lang_Class instance 834 assert(class_loader() == k->class_loader(), "should be same"); 835 set_class_loader(mirror(), class_loader()); 836 837 // set the module field in the java_lang_Class instance 838 if (module.is_null()) { 839 // During startup, the module may be NULL only if java.base has not been defined yet. 840 // Put the class on the fixup_module_list to patch later when the java.lang.reflect.Module 841 // for java.base is known. 842 assert(!Universe::is_module_initialized(), "Incorrect java.lang.reflect.Module pre module system initialization"); 843 MutexLocker m1(Module_lock, THREAD); 844 // Keep list of classes needing java.base module fixup 845 if (!ModuleEntryTable::javabase_defined()) { 846 if (fixup_module_field_list() == NULL) { 847 GrowableArray<Klass*>* list = 848 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true); 849 set_fixup_module_field_list(list); 850 } 851 k->class_loader_data()->inc_keep_alive(); 852 fixup_module_field_list()->push(k()); 853 } else { 854 // java.base was defined at some point between calling create_mirror() 855 // and obtaining the Module_lock, patch this particular class with java.base. 856 ModuleEntry *javabase_entry = ModuleEntryTable::javabase_moduleEntry(); 857 assert(javabase_entry != NULL && javabase_entry->module() != NULL, 858 "Setting class module field, java.base should be defined"); 859 Handle javabase_handle(THREAD, JNIHandles::resolve(javabase_entry->module())); 860 set_module(mirror(), javabase_handle()); 861 } 862 } else { 863 assert(Universe::is_module_initialized() || 864 (ModuleEntryTable::javabase_defined() && 865 (module() == JNIHandles::resolve(ModuleEntryTable::javabase_moduleEntry()->module()))), 866 "Incorrect java.lang.reflect.Module specification while creating mirror"); 867 set_module(mirror(), module()); 868 } 869 870 // Setup indirection from klass->mirror last 871 // after any exceptions can happen during allocations. 872 if (!k.is_null()) { 873 k->set_java_mirror(mirror()); 874 } 875 } else { 876 if (fixup_mirror_list() == NULL) { 877 GrowableArray<Klass*>* list = 878 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true); 879 set_fixup_mirror_list(list); 880 } 881 fixup_mirror_list()->push(k()); 882 } 883 } 884 885 void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) { 886 assert(_module_offset != 0, "must have been computed already"); 887 java_lang_Class::set_module(k->java_mirror(), module()); 888 } 889 890 int java_lang_Class::oop_size(oop java_class) { 891 assert(_oop_size_offset != 0, "must be set"); 892 int size = java_class->int_field(_oop_size_offset); 893 assert(size > 0, "Oop size must be greater than zero, not %d", size); |