// Call complete_create_array_klass after all instance variables have been initialized. // 初始化TypeArrayKlass中的属性 complete_create_array_klass(ak, ak->super(), ModuleEntryTable::javabase_moduleEntry(), CHECK_NULL);
// Add all classes to our internal class loader list here, // including classes in the bootstrap (null) class loader. // Do this step after creating the mirror so that if the // mirror creation fails, loaded_classes_do() doesn't find // an array class without a mirror. null_loader_data->add_class(ak); JFR_ONLY(ASSIGN_PRIMITIVE_CLASS_ID(ak);) return ak; }
1.3.1 创建实例
1 2 3 4 5 6 7 8 9
TypeArrayKlass* TypeArrayKlass::allocate(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS){ assert(TypeArrayKlass::header_size() <= InstanceKlass::header_size(), "array klasses must be same size as InstanceKlass");
// During bootstrapping, before java.base is defined, the module_entry may not be present yet. // These classes will be put on a fixup list and their module fields will be patched once // java.base is defined. assert((module_entry != nullptr) || ((module_entry == nullptr) && !ModuleEntryTable::javabase_defined()), "module entry not available post " JAVA_BASE_NAME " definition"); oop module = (module_entry != nullptr) ? module_entry->module() : (oop)nullptr; // 初始化了java.lang.Class对象中静态字段的值 这样静态字段就可以正常使用了 java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), Handle(), CHECK); }
// 数组的组件类型 不是元素类型 Klass* _element_klass; // The klass of the elements of this array type // 数组的元素类型 可以是InstanceKlass或者TypeArrayKlass 因此可能是元素类型也可能是TypeArrayKlass // 一维基本类型的数组用TypeArrayKlass表示 // 二维基本类型数组用ObjArrayKlass表示 它的bottom_klass是TypeArrayKlass Klass* _bottom_klass; // The one-dimensional type (InstanceKlass or TypeArrayKlass)