834 // update all the static field offsets to included the size.
835 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
836 if (fs.access_flags().is_static()) {
837 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
838 fs.set_offset(real_offset);
839 }
840 }
841 }
842 }
843
844 if (k->is_shared() && k->has_raw_archived_mirror()) {
845 if (HeapShared::open_archive_heap_region_mapped()) {
846 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
847 assert(present, "Missing archived mirror for %s", k->external_name());
848 return;
849 } else {
850 k->set_java_mirror_handle(NULL);
851 k->clear_has_raw_archived_mirror();
852 }
853 }
854 create_mirror(k, Handle(), Handle(), Handle(), CHECK);
855 }
856
857 void java_lang_Class::initialize_mirror_fields(Klass* k,
858 Handle mirror,
859 Handle protection_domain,
860 TRAPS) {
861 // Allocate a simple java object for a lock.
862 // This needs to be a java object because during class initialization
863 // it can be held across a java call.
864 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
865 set_init_lock(mirror(), r);
866
867 // Set protection domain also
868 set_protection_domain(mirror(), protection_domain());
869
870 // Initialize static fields
871 InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
872 }
873
874 // Set the java.lang.Module module field in the java_lang_Class mirror
875 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
876 if (module.is_null()) {
877 // During startup, the module may be NULL only if java.base has not been defined yet.
878 // Put the class on the fixup_module_list to patch later when the java.lang.Module
879 // for java.base is known. But note that since we captured the NULL module another
880 // thread may have completed that initialization.
881
882 bool javabase_was_defined = false;
883 {
884 MutexLocker m1(Module_lock, THREAD);
885 // Keep list of classes needing java.base module fixup
886 if (!ModuleEntryTable::javabase_defined()) {
887 assert(k->java_mirror() != NULL, "Class's mirror is null");
888 k->class_loader_data()->inc_keep_alive();
889 assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
890 fixup_module_field_list()->push(k);
891 } else {
905 assert(Universe::is_module_initialized() ||
906 (ModuleEntryTable::javabase_defined() &&
907 (module() == ModuleEntryTable::javabase_moduleEntry()->module())),
908 "Incorrect java.lang.Module specification while creating mirror");
909 set_module(mirror(), module());
910 }
911 }
912
913 // Statically allocate fixup lists because they always get created.
914 void java_lang_Class::allocate_fixup_lists() {
915 GrowableArray<Klass*>* mirror_list =
916 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
917 set_fixup_mirror_list(mirror_list);
918
919 GrowableArray<Klass*>* module_list =
920 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
921 set_fixup_module_field_list(module_list);
922 }
923
924 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
925 Handle module, Handle protection_domain, TRAPS) {
926 assert(k != NULL, "Use create_basic_type_mirror for primitive types");
927 assert(k->java_mirror() == NULL, "should only assign mirror once");
928
929 // Use this moment of initialization to cache modifier_flags also,
930 // to support Class.getModifiers(). Instance classes recalculate
931 // the cached flags after the class file is parsed, but before the
932 // class is put into the system dictionary.
933 int computed_modifiers = k->compute_modifier_flags(CHECK);
934 k->set_modifier_flags(computed_modifiers);
935 // Class_klass has to be loaded because it is used to allocate
936 // the mirror.
937 if (SystemDictionary::Class_klass_loaded()) {
938 // Allocate mirror (java.lang.Class instance)
939 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
940 Handle mirror(THREAD, mirror_oop);
941 Handle comp_mirror;
942
943 // Setup indirection from mirror->klass
944 java_lang_Class::set_klass(mirror(), k);
945
952 if (k->is_array_klass()) {
953 if (k->is_typeArray_klass()) {
954 BasicType type = TypeArrayKlass::cast(k)->element_type();
955 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
956 } else {
957 assert(k->is_objArray_klass(), "Must be");
958 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
959 assert(element_klass != NULL, "Must have an element klass");
960 comp_mirror = Handle(THREAD, element_klass->java_mirror());
961 }
962 assert(comp_mirror() != NULL, "must have a mirror");
963
964 // Two-way link between the array klass and its component mirror:
965 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
966 set_component_mirror(mirror(), comp_mirror());
967 // See below for ordering dependencies between field array_klass in component mirror
968 // and java_mirror in this klass.
969 } else {
970 assert(k->is_instance_klass(), "Must be");
971
972 initialize_mirror_fields(k, mirror, protection_domain, THREAD);
973 if (HAS_PENDING_EXCEPTION) {
974 // If any of the fields throws an exception like OOM remove the klass field
975 // from the mirror so GC doesn't follow it after the klass has been deallocated.
976 // This mirror looks like a primitive type, which logically it is because it
977 // it represents no class.
978 java_lang_Class::set_klass(mirror(), NULL);
979 return;
980 }
981 }
982
983 // set the classLoader field in the java_lang_Class instance
984 assert(class_loader() == k->class_loader(), "should be same");
985 set_class_loader(mirror(), class_loader());
986
987 // Setup indirection from klass->mirror
988 // after any exceptions can happen during allocations.
989 k->set_java_mirror(mirror);
990
991 // Set the module field in the java_lang_Class instance. This must be done
992 // after the mirror is set.
1377 }
1378
1379 oop java_lang_Class::init_lock(oop java_class) {
1380 assert(_init_lock_offset != 0, "must be set");
1381 return java_class->obj_field(_init_lock_offset);
1382 }
1383 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1384 assert(_init_lock_offset != 0, "must be set");
1385 java_class->obj_field_put(_init_lock_offset, init_lock);
1386 }
1387
1388 objArrayOop java_lang_Class::signers(oop java_class) {
1389 assert(_signers_offset != 0, "must be set");
1390 return (objArrayOop)java_class->obj_field(_signers_offset);
1391 }
1392 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1393 assert(_signers_offset != 0, "must be set");
1394 java_class->obj_field_put(_signers_offset, (oop)signers);
1395 }
1396
1397
1398 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1399 // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1400 if (_class_loader_offset != 0) {
1401 java_class->obj_field_put(_class_loader_offset, loader);
1402 }
1403 }
1404
1405 oop java_lang_Class::class_loader(oop java_class) {
1406 assert(_class_loader_offset != 0, "must be set");
1407 return java_class->obj_field(_class_loader_offset);
1408 }
1409
1410 oop java_lang_Class::module(oop java_class) {
1411 assert(_module_offset != 0, "must be set");
1412 return java_class->obj_field(_module_offset);
1413 }
1414
1415 void java_lang_Class::set_module(oop java_class, oop module) {
1416 assert(_module_offset != 0, "must be set");
4191 }
4192 };
4193
4194 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4195 UnsafeConstantsFixup fixup;
4196 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4197 }
4198
4199 int java_lang_Class::_klass_offset;
4200 int java_lang_Class::_array_klass_offset;
4201 int java_lang_Class::_oop_size_offset;
4202 int java_lang_Class::_static_oop_field_count_offset;
4203 int java_lang_Class::_class_loader_offset;
4204 int java_lang_Class::_module_offset;
4205 int java_lang_Class::_protection_domain_offset;
4206 int java_lang_Class::_component_mirror_offset;
4207 int java_lang_Class::_init_lock_offset;
4208 int java_lang_Class::_signers_offset;
4209 int java_lang_Class::_name_offset;
4210 int java_lang_Class::_source_file_offset;
4211 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4212 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4213 int java_lang_Throwable::backtrace_offset;
4214 int java_lang_Throwable::detailMessage_offset;
4215 int java_lang_Throwable::stackTrace_offset;
4216 int java_lang_Throwable::depth_offset;
4217 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4218 int java_lang_reflect_AccessibleObject::override_offset;
4219 int java_lang_reflect_Method::clazz_offset;
4220 int java_lang_reflect_Method::name_offset;
4221 int java_lang_reflect_Method::returnType_offset;
4222 int java_lang_reflect_Method::parameterTypes_offset;
4223 int java_lang_reflect_Method::exceptionTypes_offset;
4224 int java_lang_reflect_Method::slot_offset;
4225 int java_lang_reflect_Method::modifiers_offset;
4226 int java_lang_reflect_Method::signature_offset;
4227 int java_lang_reflect_Method::annotations_offset;
4228 int java_lang_reflect_Method::parameter_annotations_offset;
4229 int java_lang_reflect_Method::annotation_default_offset;
4230 int java_lang_reflect_Constructor::clazz_offset;
|
834 // update all the static field offsets to included the size.
835 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
836 if (fs.access_flags().is_static()) {
837 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
838 fs.set_offset(real_offset);
839 }
840 }
841 }
842 }
843
844 if (k->is_shared() && k->has_raw_archived_mirror()) {
845 if (HeapShared::open_archive_heap_region_mapped()) {
846 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
847 assert(present, "Missing archived mirror for %s", k->external_name());
848 return;
849 } else {
850 k->set_java_mirror_handle(NULL);
851 k->clear_has_raw_archived_mirror();
852 }
853 }
854 create_mirror(k, Handle(), Handle(), Handle(), Handle(), CHECK);
855 }
856
857 void java_lang_Class::initialize_mirror_fields(Klass* k,
858 Handle mirror,
859 Handle protection_domain,
860 Handle classData,
861 TRAPS) {
862 // Allocate a simple java object for a lock.
863 // This needs to be a java object because during class initialization
864 // it can be held across a java call.
865 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
866 set_init_lock(mirror(), r);
867
868 // Set protection domain also
869 set_protection_domain(mirror(), protection_domain());
870
871 // Initialize static fields
872 InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
873
874 // Set classData
875 set_class_data(mirror(), classData());
876 }
877
878 // Set the java.lang.Module module field in the java_lang_Class mirror
879 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
880 if (module.is_null()) {
881 // During startup, the module may be NULL only if java.base has not been defined yet.
882 // Put the class on the fixup_module_list to patch later when the java.lang.Module
883 // for java.base is known. But note that since we captured the NULL module another
884 // thread may have completed that initialization.
885
886 bool javabase_was_defined = false;
887 {
888 MutexLocker m1(Module_lock, THREAD);
889 // Keep list of classes needing java.base module fixup
890 if (!ModuleEntryTable::javabase_defined()) {
891 assert(k->java_mirror() != NULL, "Class's mirror is null");
892 k->class_loader_data()->inc_keep_alive();
893 assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
894 fixup_module_field_list()->push(k);
895 } else {
909 assert(Universe::is_module_initialized() ||
910 (ModuleEntryTable::javabase_defined() &&
911 (module() == ModuleEntryTable::javabase_moduleEntry()->module())),
912 "Incorrect java.lang.Module specification while creating mirror");
913 set_module(mirror(), module());
914 }
915 }
916
917 // Statically allocate fixup lists because they always get created.
918 void java_lang_Class::allocate_fixup_lists() {
919 GrowableArray<Klass*>* mirror_list =
920 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
921 set_fixup_mirror_list(mirror_list);
922
923 GrowableArray<Klass*>* module_list =
924 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
925 set_fixup_module_field_list(module_list);
926 }
927
928 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
929 Handle module, Handle protection_domain,
930 Handle classData, TRAPS) {
931 assert(k != NULL, "Use create_basic_type_mirror for primitive types");
932 assert(k->java_mirror() == NULL, "should only assign mirror once");
933
934 // Use this moment of initialization to cache modifier_flags also,
935 // to support Class.getModifiers(). Instance classes recalculate
936 // the cached flags after the class file is parsed, but before the
937 // class is put into the system dictionary.
938 int computed_modifiers = k->compute_modifier_flags(CHECK);
939 k->set_modifier_flags(computed_modifiers);
940 // Class_klass has to be loaded because it is used to allocate
941 // the mirror.
942 if (SystemDictionary::Class_klass_loaded()) {
943 // Allocate mirror (java.lang.Class instance)
944 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
945 Handle mirror(THREAD, mirror_oop);
946 Handle comp_mirror;
947
948 // Setup indirection from mirror->klass
949 java_lang_Class::set_klass(mirror(), k);
950
957 if (k->is_array_klass()) {
958 if (k->is_typeArray_klass()) {
959 BasicType type = TypeArrayKlass::cast(k)->element_type();
960 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
961 } else {
962 assert(k->is_objArray_klass(), "Must be");
963 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
964 assert(element_klass != NULL, "Must have an element klass");
965 comp_mirror = Handle(THREAD, element_klass->java_mirror());
966 }
967 assert(comp_mirror() != NULL, "must have a mirror");
968
969 // Two-way link between the array klass and its component mirror:
970 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
971 set_component_mirror(mirror(), comp_mirror());
972 // See below for ordering dependencies between field array_klass in component mirror
973 // and java_mirror in this klass.
974 } else {
975 assert(k->is_instance_klass(), "Must be");
976
977 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
978 if (HAS_PENDING_EXCEPTION) {
979 // If any of the fields throws an exception like OOM remove the klass field
980 // from the mirror so GC doesn't follow it after the klass has been deallocated.
981 // This mirror looks like a primitive type, which logically it is because it
982 // it represents no class.
983 java_lang_Class::set_klass(mirror(), NULL);
984 return;
985 }
986 }
987
988 // set the classLoader field in the java_lang_Class instance
989 assert(class_loader() == k->class_loader(), "should be same");
990 set_class_loader(mirror(), class_loader());
991
992 // Setup indirection from klass->mirror
993 // after any exceptions can happen during allocations.
994 k->set_java_mirror(mirror);
995
996 // Set the module field in the java_lang_Class instance. This must be done
997 // after the mirror is set.
1382 }
1383
1384 oop java_lang_Class::init_lock(oop java_class) {
1385 assert(_init_lock_offset != 0, "must be set");
1386 return java_class->obj_field(_init_lock_offset);
1387 }
1388 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1389 assert(_init_lock_offset != 0, "must be set");
1390 java_class->obj_field_put(_init_lock_offset, init_lock);
1391 }
1392
1393 objArrayOop java_lang_Class::signers(oop java_class) {
1394 assert(_signers_offset != 0, "must be set");
1395 return (objArrayOop)java_class->obj_field(_signers_offset);
1396 }
1397 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1398 assert(_signers_offset != 0, "must be set");
1399 java_class->obj_field_put(_signers_offset, (oop)signers);
1400 }
1401
1402 oop java_lang_Class::class_data(oop java_class) {
1403 assert(_classData_offset != 0, "must be set");
1404 return java_class->obj_field(_classData_offset);
1405 }
1406 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1407 assert(_classData_offset != 0, "must be set");
1408 java_class->obj_field_put(_classData_offset, class_data);
1409 }
1410
1411
1412 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1413 // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1414 if (_class_loader_offset != 0) {
1415 java_class->obj_field_put(_class_loader_offset, loader);
1416 }
1417 }
1418
1419 oop java_lang_Class::class_loader(oop java_class) {
1420 assert(_class_loader_offset != 0, "must be set");
1421 return java_class->obj_field(_class_loader_offset);
1422 }
1423
1424 oop java_lang_Class::module(oop java_class) {
1425 assert(_module_offset != 0, "must be set");
1426 return java_class->obj_field(_module_offset);
1427 }
1428
1429 void java_lang_Class::set_module(oop java_class, oop module) {
1430 assert(_module_offset != 0, "must be set");
4205 }
4206 };
4207
4208 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4209 UnsafeConstantsFixup fixup;
4210 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4211 }
4212
4213 int java_lang_Class::_klass_offset;
4214 int java_lang_Class::_array_klass_offset;
4215 int java_lang_Class::_oop_size_offset;
4216 int java_lang_Class::_static_oop_field_count_offset;
4217 int java_lang_Class::_class_loader_offset;
4218 int java_lang_Class::_module_offset;
4219 int java_lang_Class::_protection_domain_offset;
4220 int java_lang_Class::_component_mirror_offset;
4221 int java_lang_Class::_init_lock_offset;
4222 int java_lang_Class::_signers_offset;
4223 int java_lang_Class::_name_offset;
4224 int java_lang_Class::_source_file_offset;
4225 int java_lang_Class::_classData_offset;
4226 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4227 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4228 int java_lang_Throwable::backtrace_offset;
4229 int java_lang_Throwable::detailMessage_offset;
4230 int java_lang_Throwable::stackTrace_offset;
4231 int java_lang_Throwable::depth_offset;
4232 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4233 int java_lang_reflect_AccessibleObject::override_offset;
4234 int java_lang_reflect_Method::clazz_offset;
4235 int java_lang_reflect_Method::name_offset;
4236 int java_lang_reflect_Method::returnType_offset;
4237 int java_lang_reflect_Method::parameterTypes_offset;
4238 int java_lang_reflect_Method::exceptionTypes_offset;
4239 int java_lang_reflect_Method::slot_offset;
4240 int java_lang_reflect_Method::modifiers_offset;
4241 int java_lang_reflect_Method::signature_offset;
4242 int java_lang_reflect_Method::annotations_offset;
4243 int java_lang_reflect_Method::parameter_annotations_offset;
4244 int java_lang_reflect_Method::annotation_default_offset;
4245 int java_lang_reflect_Constructor::clazz_offset;
|