808 // update all the static field offsets to included the size.
809 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
810 if (fs.access_flags().is_static()) {
811 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
812 fs.set_offset(real_offset);
813 }
814 }
815 }
816 }
817
818 if (k->is_shared() && k->has_raw_archived_mirror()) {
819 if (HeapShared::open_archive_heap_region_mapped()) {
820 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
821 assert(present, "Missing archived mirror for %s", k->external_name());
822 return;
823 } else {
824 k->set_java_mirror_handle(NULL);
825 k->clear_has_raw_archived_mirror();
826 }
827 }
828 create_mirror(k, Handle(), Handle(), Handle(), CHECK);
829 }
830
831 void java_lang_Class::initialize_mirror_fields(Klass* k,
832 Handle mirror,
833 Handle protection_domain,
834 TRAPS) {
835 // Allocate a simple java object for a lock.
836 // This needs to be a java object because during class initialization
837 // it can be held across a java call.
838 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
839 set_init_lock(mirror(), r);
840
841 // Set protection domain also
842 set_protection_domain(mirror(), protection_domain());
843
844 // Initialize static fields
845 InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
846 }
847
848 // Set the java.lang.Module module field in the java_lang_Class mirror
849 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
850 if (module.is_null()) {
851 // During startup, the module may be NULL only if java.base has not been defined yet.
852 // Put the class on the fixup_module_list to patch later when the java.lang.Module
853 // for java.base is known. But note that since we captured the NULL module another
854 // thread may have completed that initialization.
855
856 bool javabase_was_defined = false;
857 {
858 MutexLocker m1(Module_lock, THREAD);
859 // Keep list of classes needing java.base module fixup
860 if (!ModuleEntryTable::javabase_defined()) {
861 assert(k->java_mirror() != NULL, "Class's mirror is null");
862 k->class_loader_data()->inc_keep_alive();
863 assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
864 fixup_module_field_list()->push(k);
865 } else {
879 assert(Universe::is_module_initialized() ||
880 (ModuleEntryTable::javabase_defined() &&
881 (module() == ModuleEntryTable::javabase_moduleEntry()->module())),
882 "Incorrect java.lang.Module specification while creating mirror");
883 set_module(mirror(), module());
884 }
885 }
886
887 // Statically allocate fixup lists because they always get created.
888 void java_lang_Class::allocate_fixup_lists() {
889 GrowableArray<Klass*>* mirror_list =
890 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
891 set_fixup_mirror_list(mirror_list);
892
893 GrowableArray<Klass*>* module_list =
894 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
895 set_fixup_module_field_list(module_list);
896 }
897
898 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
899 Handle module, Handle protection_domain, TRAPS) {
900 assert(k != NULL, "Use create_basic_type_mirror for primitive types");
901 assert(k->java_mirror() == NULL, "should only assign mirror once");
902
903 // Use this moment of initialization to cache modifier_flags also,
904 // to support Class.getModifiers(). Instance classes recalculate
905 // the cached flags after the class file is parsed, but before the
906 // class is put into the system dictionary.
907 int computed_modifiers = k->compute_modifier_flags(CHECK);
908 k->set_modifier_flags(computed_modifiers);
909 // Class_klass has to be loaded because it is used to allocate
910 // the mirror.
911 if (SystemDictionary::Class_klass_loaded()) {
912 // Allocate mirror (java.lang.Class instance)
913 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
914 Handle mirror(THREAD, mirror_oop);
915 Handle comp_mirror;
916
917 // Setup indirection from mirror->klass
918 java_lang_Class::set_klass(mirror(), k);
919
926 if (k->is_array_klass()) {
927 if (k->is_typeArray_klass()) {
928 BasicType type = TypeArrayKlass::cast(k)->element_type();
929 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
930 } else {
931 assert(k->is_objArray_klass(), "Must be");
932 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
933 assert(element_klass != NULL, "Must have an element klass");
934 comp_mirror = Handle(THREAD, element_klass->java_mirror());
935 }
936 assert(comp_mirror() != NULL, "must have a mirror");
937
938 // Two-way link between the array klass and its component mirror:
939 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
940 set_component_mirror(mirror(), comp_mirror());
941 // See below for ordering dependencies between field array_klass in component mirror
942 // and java_mirror in this klass.
943 } else {
944 assert(k->is_instance_klass(), "Must be");
945
946 initialize_mirror_fields(k, mirror, protection_domain, THREAD);
947 if (HAS_PENDING_EXCEPTION) {
948 // If any of the fields throws an exception like OOM remove the klass field
949 // from the mirror so GC doesn't follow it after the klass has been deallocated.
950 // This mirror looks like a primitive type, which logically it is because it
951 // it represents no class.
952 java_lang_Class::set_klass(mirror(), NULL);
953 return;
954 }
955 }
956
957 // set the classLoader field in the java_lang_Class instance
958 assert(class_loader() == k->class_loader(), "should be same");
959 set_class_loader(mirror(), class_loader());
960
961 // Setup indirection from klass->mirror
962 // after any exceptions can happen during allocations.
963 k->set_java_mirror(mirror);
964
965 // Set the module field in the java_lang_Class instance. This must be done
966 // after the mirror is set.
1324 }
1325
1326 oop java_lang_Class::init_lock(oop java_class) {
1327 assert(_init_lock_offset != 0, "must be set");
1328 return java_class->obj_field(_init_lock_offset);
1329 }
1330 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1331 assert(_init_lock_offset != 0, "must be set");
1332 java_class->obj_field_put(_init_lock_offset, init_lock);
1333 }
1334
1335 objArrayOop java_lang_Class::signers(oop java_class) {
1336 assert(_signers_offset != 0, "must be set");
1337 return (objArrayOop)java_class->obj_field(_signers_offset);
1338 }
1339 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1340 assert(_signers_offset != 0, "must be set");
1341 java_class->obj_field_put(_signers_offset, (oop)signers);
1342 }
1343
1344
1345 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1346 // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1347 if (_class_loader_offset != 0) {
1348 java_class->obj_field_put(_class_loader_offset, loader);
1349 }
1350 }
1351
1352 oop java_lang_Class::class_loader(oop java_class) {
1353 assert(_class_loader_offset != 0, "must be set");
1354 return java_class->obj_field(_class_loader_offset);
1355 }
1356
1357 oop java_lang_Class::module(oop java_class) {
1358 assert(_module_offset != 0, "must be set");
1359 return java_class->obj_field(_module_offset);
1360 }
1361
1362 void java_lang_Class::set_module(oop java_class, oop module) {
1363 assert(_module_offset != 0, "must be set");
4060 }
4061 };
4062
4063 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4064 UnsafeConstantsFixup fixup;
4065 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4066 }
4067
4068 int java_lang_Class::_klass_offset;
4069 int java_lang_Class::_array_klass_offset;
4070 int java_lang_Class::_oop_size_offset;
4071 int java_lang_Class::_static_oop_field_count_offset;
4072 int java_lang_Class::_class_loader_offset;
4073 int java_lang_Class::_module_offset;
4074 int java_lang_Class::_protection_domain_offset;
4075 int java_lang_Class::_component_mirror_offset;
4076 int java_lang_Class::_init_lock_offset;
4077 int java_lang_Class::_signers_offset;
4078 int java_lang_Class::_name_offset;
4079 int java_lang_Class::_source_file_offset;
4080 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4081 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4082 int java_lang_Throwable::backtrace_offset;
4083 int java_lang_Throwable::detailMessage_offset;
4084 int java_lang_Throwable::stackTrace_offset;
4085 int java_lang_Throwable::depth_offset;
4086 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4087 int java_lang_reflect_AccessibleObject::override_offset;
4088 int java_lang_reflect_Method::clazz_offset;
4089 int java_lang_reflect_Method::name_offset;
4090 int java_lang_reflect_Method::returnType_offset;
4091 int java_lang_reflect_Method::parameterTypes_offset;
4092 int java_lang_reflect_Method::exceptionTypes_offset;
4093 int java_lang_reflect_Method::slot_offset;
4094 int java_lang_reflect_Method::modifiers_offset;
4095 int java_lang_reflect_Method::signature_offset;
4096 int java_lang_reflect_Method::annotations_offset;
4097 int java_lang_reflect_Method::parameter_annotations_offset;
4098 int java_lang_reflect_Method::annotation_default_offset;
4099 int java_lang_reflect_Constructor::clazz_offset;
|
808 // update all the static field offsets to included the size.
809 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
810 if (fs.access_flags().is_static()) {
811 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
812 fs.set_offset(real_offset);
813 }
814 }
815 }
816 }
817
818 if (k->is_shared() && k->has_raw_archived_mirror()) {
819 if (HeapShared::open_archive_heap_region_mapped()) {
820 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
821 assert(present, "Missing archived mirror for %s", k->external_name());
822 return;
823 } else {
824 k->set_java_mirror_handle(NULL);
825 k->clear_has_raw_archived_mirror();
826 }
827 }
828 create_mirror(k, Handle(), Handle(), Handle(), Handle(), CHECK);
829 }
830
831 void java_lang_Class::initialize_mirror_fields(Klass* k,
832 Handle mirror,
833 Handle protection_domain,
834 Handle classData,
835 TRAPS) {
836 // Allocate a simple java object for a lock.
837 // This needs to be a java object because during class initialization
838 // it can be held across a java call.
839 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
840 set_init_lock(mirror(), r);
841
842 // Set protection domain also
843 set_protection_domain(mirror(), protection_domain());
844
845 // Initialize static fields
846 InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
847
848 // Set classData
849 set_class_data(mirror(), classData());
850 }
851
852 // Set the java.lang.Module module field in the java_lang_Class mirror
853 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
854 if (module.is_null()) {
855 // During startup, the module may be NULL only if java.base has not been defined yet.
856 // Put the class on the fixup_module_list to patch later when the java.lang.Module
857 // for java.base is known. But note that since we captured the NULL module another
858 // thread may have completed that initialization.
859
860 bool javabase_was_defined = false;
861 {
862 MutexLocker m1(Module_lock, THREAD);
863 // Keep list of classes needing java.base module fixup
864 if (!ModuleEntryTable::javabase_defined()) {
865 assert(k->java_mirror() != NULL, "Class's mirror is null");
866 k->class_loader_data()->inc_keep_alive();
867 assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
868 fixup_module_field_list()->push(k);
869 } else {
883 assert(Universe::is_module_initialized() ||
884 (ModuleEntryTable::javabase_defined() &&
885 (module() == ModuleEntryTable::javabase_moduleEntry()->module())),
886 "Incorrect java.lang.Module specification while creating mirror");
887 set_module(mirror(), module());
888 }
889 }
890
891 // Statically allocate fixup lists because they always get created.
892 void java_lang_Class::allocate_fixup_lists() {
893 GrowableArray<Klass*>* mirror_list =
894 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
895 set_fixup_mirror_list(mirror_list);
896
897 GrowableArray<Klass*>* module_list =
898 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
899 set_fixup_module_field_list(module_list);
900 }
901
902 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
903 Handle module, Handle protection_domain,
904 Handle classData, TRAPS) {
905 assert(k != NULL, "Use create_basic_type_mirror for primitive types");
906 assert(k->java_mirror() == NULL, "should only assign mirror once");
907
908 // Use this moment of initialization to cache modifier_flags also,
909 // to support Class.getModifiers(). Instance classes recalculate
910 // the cached flags after the class file is parsed, but before the
911 // class is put into the system dictionary.
912 int computed_modifiers = k->compute_modifier_flags(CHECK);
913 k->set_modifier_flags(computed_modifiers);
914 // Class_klass has to be loaded because it is used to allocate
915 // the mirror.
916 if (SystemDictionary::Class_klass_loaded()) {
917 // Allocate mirror (java.lang.Class instance)
918 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
919 Handle mirror(THREAD, mirror_oop);
920 Handle comp_mirror;
921
922 // Setup indirection from mirror->klass
923 java_lang_Class::set_klass(mirror(), k);
924
931 if (k->is_array_klass()) {
932 if (k->is_typeArray_klass()) {
933 BasicType type = TypeArrayKlass::cast(k)->element_type();
934 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
935 } else {
936 assert(k->is_objArray_klass(), "Must be");
937 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
938 assert(element_klass != NULL, "Must have an element klass");
939 comp_mirror = Handle(THREAD, element_klass->java_mirror());
940 }
941 assert(comp_mirror() != NULL, "must have a mirror");
942
943 // Two-way link between the array klass and its component mirror:
944 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
945 set_component_mirror(mirror(), comp_mirror());
946 // See below for ordering dependencies between field array_klass in component mirror
947 // and java_mirror in this klass.
948 } else {
949 assert(k->is_instance_klass(), "Must be");
950
951 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
952 if (HAS_PENDING_EXCEPTION) {
953 // If any of the fields throws an exception like OOM remove the klass field
954 // from the mirror so GC doesn't follow it after the klass has been deallocated.
955 // This mirror looks like a primitive type, which logically it is because it
956 // it represents no class.
957 java_lang_Class::set_klass(mirror(), NULL);
958 return;
959 }
960 }
961
962 // set the classLoader field in the java_lang_Class instance
963 assert(class_loader() == k->class_loader(), "should be same");
964 set_class_loader(mirror(), class_loader());
965
966 // Setup indirection from klass->mirror
967 // after any exceptions can happen during allocations.
968 k->set_java_mirror(mirror);
969
970 // Set the module field in the java_lang_Class instance. This must be done
971 // after the mirror is set.
1329 }
1330
1331 oop java_lang_Class::init_lock(oop java_class) {
1332 assert(_init_lock_offset != 0, "must be set");
1333 return java_class->obj_field(_init_lock_offset);
1334 }
1335 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1336 assert(_init_lock_offset != 0, "must be set");
1337 java_class->obj_field_put(_init_lock_offset, init_lock);
1338 }
1339
1340 objArrayOop java_lang_Class::signers(oop java_class) {
1341 assert(_signers_offset != 0, "must be set");
1342 return (objArrayOop)java_class->obj_field(_signers_offset);
1343 }
1344 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1345 assert(_signers_offset != 0, "must be set");
1346 java_class->obj_field_put(_signers_offset, (oop)signers);
1347 }
1348
1349 oop java_lang_Class::class_data(oop java_class) {
1350 assert(_classData_offset != 0, "must be set");
1351 return java_class->obj_field(_classData_offset);
1352 }
1353 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1354 assert(_classData_offset != 0, "must be set");
1355 java_class->obj_field_put(_classData_offset, class_data);
1356 }
1357
1358
1359 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1360 // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1361 if (_class_loader_offset != 0) {
1362 java_class->obj_field_put(_class_loader_offset, loader);
1363 }
1364 }
1365
1366 oop java_lang_Class::class_loader(oop java_class) {
1367 assert(_class_loader_offset != 0, "must be set");
1368 return java_class->obj_field(_class_loader_offset);
1369 }
1370
1371 oop java_lang_Class::module(oop java_class) {
1372 assert(_module_offset != 0, "must be set");
1373 return java_class->obj_field(_module_offset);
1374 }
1375
1376 void java_lang_Class::set_module(oop java_class, oop module) {
1377 assert(_module_offset != 0, "must be set");
4074 }
4075 };
4076
4077 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4078 UnsafeConstantsFixup fixup;
4079 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4080 }
4081
4082 int java_lang_Class::_klass_offset;
4083 int java_lang_Class::_array_klass_offset;
4084 int java_lang_Class::_oop_size_offset;
4085 int java_lang_Class::_static_oop_field_count_offset;
4086 int java_lang_Class::_class_loader_offset;
4087 int java_lang_Class::_module_offset;
4088 int java_lang_Class::_protection_domain_offset;
4089 int java_lang_Class::_component_mirror_offset;
4090 int java_lang_Class::_init_lock_offset;
4091 int java_lang_Class::_signers_offset;
4092 int java_lang_Class::_name_offset;
4093 int java_lang_Class::_source_file_offset;
4094 int java_lang_Class::_classData_offset;
4095 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4096 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4097 int java_lang_Throwable::backtrace_offset;
4098 int java_lang_Throwable::detailMessage_offset;
4099 int java_lang_Throwable::stackTrace_offset;
4100 int java_lang_Throwable::depth_offset;
4101 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4102 int java_lang_reflect_AccessibleObject::override_offset;
4103 int java_lang_reflect_Method::clazz_offset;
4104 int java_lang_reflect_Method::name_offset;
4105 int java_lang_reflect_Method::returnType_offset;
4106 int java_lang_reflect_Method::parameterTypes_offset;
4107 int java_lang_reflect_Method::exceptionTypes_offset;
4108 int java_lang_reflect_Method::slot_offset;
4109 int java_lang_reflect_Method::modifiers_offset;
4110 int java_lang_reflect_Method::signature_offset;
4111 int java_lang_reflect_Method::annotations_offset;
4112 int java_lang_reflect_Method::parameter_annotations_offset;
4113 int java_lang_reflect_Method::annotation_default_offset;
4114 int java_lang_reflect_Constructor::clazz_offset;
|