911 // Allocate mirror (java.lang.Class instance)
912 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
913 Handle mirror(THREAD, mirror_oop);
914 Handle comp_mirror;
915
916 // Setup indirection from mirror->klass
917 java_lang_Class::set_klass(mirror(), k);
918
919 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
920 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
921
922 java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
923
924 // It might also have a component mirror. This mirror must already exist.
925 if (k->is_array_klass()) {
926 if (k->is_valueArray_klass()) {
927 Klass* element_klass = (Klass*) ValueArrayKlass::cast(k)->element_klass();
928 assert(element_klass->is_value(), "Must be value type component");
929 ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
930 comp_mirror = Handle(THREAD, vk->value_mirror());
931 }
932 else 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 if (element_klass->is_value() && k->name()->is_Q_array_signature()) {
940 ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
941 comp_mirror = Handle(THREAD, vk->value_mirror());
942 } else {
943 comp_mirror = Handle(THREAD, element_klass->java_mirror());
944 }
945 }
946 assert(comp_mirror() != NULL, "must have a mirror");
947
948 // Two-way link between the array klass and its component mirror:
949 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
950 set_component_mirror(mirror(), comp_mirror());
951 // See below for ordering dependencies between field array_klass in component mirror
952 // and java_mirror in this klass.
953 } else {
954 assert(k->is_instance_klass(), "Must be");
955
956 initialize_mirror_fields(k, mirror, protection_domain, THREAD);
957 if (HAS_PENDING_EXCEPTION) {
958 // If any of the fields throws an exception like OOM remove the klass field
959 // from the mirror so GC doesn't follow it after the klass has been deallocated.
960 // This mirror looks like a primitive type, which logically it is because it
961 // it represents no class.
966
967 // set the classLoader field in the java_lang_Class instance
968 assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
969 set_class_loader(mirror(), class_loader());
970
971 // Setup indirection from klass->mirror
972 // after any exceptions can happen during allocations.
973 k->set_java_mirror(mirror);
974
975 // Set the module field in the java_lang_Class instance. This must be done
976 // after the mirror is set.
977 set_mirror_module_field(k, mirror, module, THREAD);
978
979 if (comp_mirror() != NULL) {
980 // Set after k->java_mirror() is published, because compiled code running
981 // concurrently doesn't expect a k to have a null java_mirror.
982 release_set_array_klass(comp_mirror(), k);
983 }
984
985 if (k->is_value()) {
986 // create the secondary mirror for value class
987 oop value_mirror_oop = create_value_mirror(k, mirror, CHECK);
988 set_box_mirror(mirror(), mirror());
989 set_value_mirror(mirror(), value_mirror_oop);
990 }
991 } else {
992 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
993 fixup_mirror_list()->push(k);
994 }
995 }
996
997 // Create the secondary mirror for value type. Sets all the fields of this java.lang.Class
998 // instance with the same value as the primary mirror except signers.
999 // Class::setSigners and getSigners will use the primary mirror when passed to the JVM.
1000 oop java_lang_Class::create_value_mirror(Klass* k, Handle mirror, TRAPS) {
1001 // Allocate mirror (java.lang.Class instance)
1002 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK_0);
1003 Handle value_mirror(THREAD, mirror_oop);
1004
1005 java_lang_Class::set_klass(value_mirror(), k);
1006 java_lang_Class::set_static_oop_field_count(value_mirror(), static_oop_field_count(mirror()));
1007 // ## do we need to set init lock?
1008 java_lang_Class::set_init_lock(value_mirror(), init_lock(mirror()));
1009
1010 if (k->is_array_klass()) {
1011 assert(component_mirror(mirror()) != NULL, "must have a mirror");
1012 set_component_mirror(value_mirror(), component_mirror(mirror()));
1013 }
1014
1015 set_protection_domain(value_mirror(), protection_domain(mirror()));
1016 set_class_loader(value_mirror(), class_loader(mirror()));
1017 // ## handle if java.base is not yet defined
1018 set_module(value_mirror(), module(mirror()));
1019 set_box_mirror(value_mirror(), mirror());
1020 set_value_mirror(value_mirror(), value_mirror());
1021 return value_mirror();
1022 }
1023
1024 #if INCLUDE_CDS_JAVA_HEAP
1025 // Clears mirror fields. Static final fields with initial values are reloaded
1026 // from constant pool. The object identity hash is in the object header and is
1027 // not affected.
1028 class ResetMirrorField: public FieldClosure {
1029 private:
1030 Handle _m;
1031
1032 public:
1033 ResetMirrorField(Handle mirror) : _m(mirror) {}
1034
1035 void do_field(fieldDescriptor* fd) {
1036 assert(DumpSharedSpaces, "dump time only");
1037 assert(_m.not_null(), "Mirror cannot be NULL");
1038
1039 if (fd->is_static() && fd->has_initial_value()) {
1040 initialize_static_field(fd, _m, Thread::current());
1041 return;
1411 oop java_lang_Class::name(Handle java_class, TRAPS) {
1412 assert(_name_offset != 0, "must be set");
1413 oop o = java_class->obj_field(_name_offset);
1414 if (o == NULL) {
1415 o = StringTable::intern(java_lang_Class::as_external_name(java_class()), THREAD);
1416 java_class->obj_field_put(_name_offset, o);
1417 }
1418 return o;
1419 }
1420
1421 oop java_lang_Class::source_file(oop java_class) {
1422 assert(_source_file_offset != 0, "must be set");
1423 return java_class->obj_field(_source_file_offset);
1424 }
1425
1426 void java_lang_Class::set_source_file(oop java_class, oop source_file) {
1427 assert(_source_file_offset != 0, "must be set");
1428 java_class->obj_field_put(_source_file_offset, source_file);
1429 }
1430
1431 oop java_lang_Class::value_mirror(oop java_class) {
1432 assert(_value_mirror_offset != 0, "must be set");
1433 return java_class->obj_field(_value_mirror_offset);
1434 }
1435
1436 void java_lang_Class::set_value_mirror(oop java_class, oop mirror) {
1437 assert(_value_mirror_offset != 0, "must be set");
1438 java_class->obj_field_put(_value_mirror_offset, mirror);
1439 }
1440
1441 oop java_lang_Class::box_mirror(oop java_class) {
1442 assert(_box_mirror_offset != 0, "must be set");
1443 return java_class->obj_field(_box_mirror_offset);
1444 }
1445
1446 void java_lang_Class::set_box_mirror(oop java_class, oop mirror) {
1447 assert(_box_mirror_offset != 0, "must be set");
1448 java_class->obj_field_put(_box_mirror_offset, mirror);
1449 }
1450
1451 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
1452 // This should be improved by adding a field at the Java level or by
1453 // introducing a new VM klass (see comment in ClassFileParser)
1454 oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0);
1455 if (type != T_VOID) {
1456 Klass* aklass = Universe::typeArrayKlassObj(type);
1457 assert(aklass != NULL, "correct bootstrap");
1458 release_set_array_klass(java_class, aklass);
1459 }
1460 #ifdef ASSERT
1461 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass());
1462 assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1463 #endif
1464 return java_class;
1465 }
1466
1467
1468 Klass* java_lang_Class::as_Klass(oop java_class) {
1489
1490
1491 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1492 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1493 Symbol* name = NULL;
1494 bool is_instance = false;
1495 bool is_value = false;
1496 if (is_primitive(java_class)) {
1497 name = vmSymbols::type_signature(primitive_type(java_class));
1498 } else {
1499 Klass* k = as_Klass(java_class);
1500 is_instance = k->is_instance_klass();
1501 is_value = k->is_value();
1502 name = k->name();
1503 }
1504 if (name == NULL) {
1505 st->print("<null>");
1506 return;
1507 }
1508 if (is_instance) {
1509 if (is_value && (java_class == value_mirror(java_class))) {
1510 st->print("Q");
1511 } else {
1512 st->print("L");
1513 }
1514 }
1515 st->write((char*) name->base(), (int) name->utf8_length());
1516 if (is_instance) st->print(";");
1517 }
1518
1519 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found, TRAPS) {
1520 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1521 Symbol* name;
1522 if (is_primitive(java_class)) {
1523 name = vmSymbols::type_signature(primitive_type(java_class));
1524 // Because this can create a new symbol, the caller has to decrement
1525 // the refcount, so make adjustment here and below for symbols returned
1526 // that are not created or incremented due to a successful lookup.
1527 name->increment_refcount();
1528 } else {
1529 Klass* k = as_Klass(java_class);
1530 if (!k->is_instance_klass()) {
1531 name = k->name();
1532 name->increment_refcount();
1533 } else {
1534 ResourceMark rm;
1535 const char* sigstr;
1536 if (k->is_value()) {
1537 char c = (java_class == value_mirror(java_class)) ? 'Q' : 'L';
1538 sigstr = InstanceKlass::cast(k)->signature_name_of(c);
1539 } else {
1540 sigstr = k->signature_name();
1541 }
1542 int siglen = (int) strlen(sigstr);
1543 if (!intern_if_not_found) {
1544 name = SymbolTable::probe(sigstr, siglen);
1545 } else {
1546 name = SymbolTable::new_symbol(sigstr, siglen, THREAD);
1547 }
1548 }
1549 }
1550 return name;
1551 }
1552
1553 // Returns the Java name for this Java mirror (Resource allocated)
1554 // See Klass::external_name().
1555 // For primitive type Java mirrors, its type name is returned.
1556 const char* java_lang_Class::as_external_name(oop java_class) {
1557 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1607 }
1608 }
1609
1610
1611 oop java_lang_Class::primitive_mirror(BasicType t) {
1612 oop mirror = Universe::java_mirror(t);
1613 assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1614 assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1615 return mirror;
1616 }
1617
1618 bool java_lang_Class::offsets_computed = false;
1619 int java_lang_Class::classRedefinedCount_offset = -1;
1620
1621 #define CLASS_FIELDS_DO(macro) \
1622 macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false) ; \
1623 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1624 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1625 macro(_module_offset, k, "module", module_signature, false); \
1626 macro(_name_offset, k, "name", string_signature, false); \
1627 macro(_box_mirror_offset, k, "boxType", class_signature, false); \
1628 macro(_value_mirror_offset, k, "valueType", class_signature, false); \
1629
1630 void java_lang_Class::compute_offsets() {
1631 if (offsets_computed) {
1632 return;
1633 }
1634
1635 offsets_computed = true;
1636
1637 InstanceKlass* k = SystemDictionary::Class_klass();
1638 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1639
1640 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1641 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1642 // GC treats them the same.
1643 _init_lock_offset = _component_mirror_offset;
1644
1645 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1646 }
1647
1648 #if INCLUDE_CDS
4128 mirror->bool_field_put(fd->offset(), _use_unaligned_access);
4129 } else {
4130 assert(false, "unexpected UnsafeConstants field");
4131 }
4132 }
4133 };
4134
4135 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4136 UnsafeConstantsFixup fixup;
4137 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4138 }
4139
4140 int java_lang_Class::_klass_offset;
4141 int java_lang_Class::_array_klass_offset;
4142 int java_lang_Class::_oop_size_offset;
4143 int java_lang_Class::_static_oop_field_count_offset;
4144 int java_lang_Class::_class_loader_offset;
4145 int java_lang_Class::_module_offset;
4146 int java_lang_Class::_protection_domain_offset;
4147 int java_lang_Class::_component_mirror_offset;
4148 int java_lang_Class::_box_mirror_offset;
4149 int java_lang_Class::_value_mirror_offset;
4150 int java_lang_Class::_init_lock_offset;
4151 int java_lang_Class::_signers_offset;
4152 int java_lang_Class::_name_offset;
4153 int java_lang_Class::_source_file_offset;
4154 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4155 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4156 int java_lang_Throwable::backtrace_offset;
4157 int java_lang_Throwable::detailMessage_offset;
4158 int java_lang_Throwable::stackTrace_offset;
4159 int java_lang_Throwable::depth_offset;
4160 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4161 int java_lang_reflect_AccessibleObject::override_offset;
4162 int java_lang_reflect_Method::clazz_offset;
4163 int java_lang_reflect_Method::name_offset;
4164 int java_lang_reflect_Method::returnType_offset;
4165 int java_lang_reflect_Method::parameterTypes_offset;
4166 int java_lang_reflect_Method::exceptionTypes_offset;
4167 int java_lang_reflect_Method::slot_offset;
4168 int java_lang_reflect_Method::modifiers_offset;
4169 int java_lang_reflect_Method::signature_offset;
|
911 // Allocate mirror (java.lang.Class instance)
912 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
913 Handle mirror(THREAD, mirror_oop);
914 Handle comp_mirror;
915
916 // Setup indirection from mirror->klass
917 java_lang_Class::set_klass(mirror(), k);
918
919 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
920 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
921
922 java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
923
924 // It might also have a component mirror. This mirror must already exist.
925 if (k->is_array_klass()) {
926 if (k->is_valueArray_klass()) {
927 Klass* element_klass = (Klass*) ValueArrayKlass::cast(k)->element_klass();
928 assert(element_klass->is_value(), "Must be value type component");
929 ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
930 comp_mirror = Handle(THREAD, vk->value_mirror());
931 } else if (k->is_typeArray_klass()) {
932 BasicType type = TypeArrayKlass::cast(k)->element_type();
933 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
934 } else {
935 assert(k->is_objArray_klass(), "Must be");
936 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
937 assert(element_klass != NULL, "Must have an element klass");
938 if (element_klass->is_value()) {
939 ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
940 assert(vk->java_mirror() == vk->value_mirror(), "primary mirror is the value mirror");
941 assert(vk->nullable_mirror() != NULL, "must have a nullable class mirror");
942 comp_mirror = k->name()->is_Q_array_signature() ? Handle(THREAD, vk->value_mirror())
943 : Handle(THREAD, vk->nullable_mirror());
944 } else {
945 comp_mirror = Handle(THREAD, element_klass->java_mirror());
946 }
947 }
948 assert(comp_mirror() != NULL, "must have a mirror");
949
950 // Two-way link between the array klass and its component mirror:
951 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
952 set_component_mirror(mirror(), comp_mirror());
953 // See below for ordering dependencies between field array_klass in component mirror
954 // and java_mirror in this klass.
955 } else {
956 assert(k->is_instance_klass(), "Must be");
957
958 initialize_mirror_fields(k, mirror, protection_domain, THREAD);
959 if (HAS_PENDING_EXCEPTION) {
960 // If any of the fields throws an exception like OOM remove the klass field
961 // from the mirror so GC doesn't follow it after the klass has been deallocated.
962 // This mirror looks like a primitive type, which logically it is because it
963 // it represents no class.
968
969 // set the classLoader field in the java_lang_Class instance
970 assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
971 set_class_loader(mirror(), class_loader());
972
973 // Setup indirection from klass->mirror
974 // after any exceptions can happen during allocations.
975 k->set_java_mirror(mirror);
976
977 // Set the module field in the java_lang_Class instance. This must be done
978 // after the mirror is set.
979 set_mirror_module_field(k, mirror, module, THREAD);
980
981 if (comp_mirror() != NULL) {
982 // Set after k->java_mirror() is published, because compiled code running
983 // concurrently doesn't expect a k to have a null java_mirror.
984 release_set_array_klass(comp_mirror(), k);
985 }
986
987 if (k->is_value()) {
988 // create the secondary mirror for an inline class
989 oop nullable_mirror_oop = create_nullable_inline_type_mirror(k, mirror, CHECK);
990 set_inline_type_mirror(mirror(), mirror());
991 set_nullable_type_mirror(mirror(), nullable_mirror_oop);
992 }
993 } else {
994 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
995 fixup_mirror_list()->push(k);
996 }
997 }
998
999 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1000 // instance with the same value as the primary mirror
1001 oop java_lang_Class::create_nullable_inline_type_mirror(Klass* k, Handle mirror, TRAPS) {
1002 assert(k->is_value(), "inline class");
1003 // Allocate mirror (java.lang.Class instance)
1004 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK_0);
1005 Handle nullable_mirror(THREAD, mirror_oop);
1006
1007 java_lang_Class::set_klass(nullable_mirror(), k);
1008 java_lang_Class::set_static_oop_field_count(nullable_mirror(), static_oop_field_count(mirror()));
1009 // ## do we need to set init lock?
1010 java_lang_Class::set_init_lock(nullable_mirror(), init_lock(mirror()));
1011
1012 set_protection_domain(nullable_mirror(), protection_domain(mirror()));
1013 set_class_loader(nullable_mirror(), class_loader(mirror()));
1014 // ## handle if java.base is not yet defined
1015 set_module(nullable_mirror(), module(mirror()));
1016 set_inline_type_mirror(nullable_mirror(), mirror());
1017 set_nullable_type_mirror(nullable_mirror(), nullable_mirror());
1018 return nullable_mirror();
1019 }
1020
1021 #if INCLUDE_CDS_JAVA_HEAP
1022 // Clears mirror fields. Static final fields with initial values are reloaded
1023 // from constant pool. The object identity hash is in the object header and is
1024 // not affected.
1025 class ResetMirrorField: public FieldClosure {
1026 private:
1027 Handle _m;
1028
1029 public:
1030 ResetMirrorField(Handle mirror) : _m(mirror) {}
1031
1032 void do_field(fieldDescriptor* fd) {
1033 assert(DumpSharedSpaces, "dump time only");
1034 assert(_m.not_null(), "Mirror cannot be NULL");
1035
1036 if (fd->is_static() && fd->has_initial_value()) {
1037 initialize_static_field(fd, _m, Thread::current());
1038 return;
1408 oop java_lang_Class::name(Handle java_class, TRAPS) {
1409 assert(_name_offset != 0, "must be set");
1410 oop o = java_class->obj_field(_name_offset);
1411 if (o == NULL) {
1412 o = StringTable::intern(java_lang_Class::as_external_name(java_class()), THREAD);
1413 java_class->obj_field_put(_name_offset, o);
1414 }
1415 return o;
1416 }
1417
1418 oop java_lang_Class::source_file(oop java_class) {
1419 assert(_source_file_offset != 0, "must be set");
1420 return java_class->obj_field(_source_file_offset);
1421 }
1422
1423 void java_lang_Class::set_source_file(oop java_class, oop source_file) {
1424 assert(_source_file_offset != 0, "must be set");
1425 java_class->obj_field_put(_source_file_offset, source_file);
1426 }
1427
1428 oop java_lang_Class::inline_type_mirror(oop java_class) {
1429 assert(_inline_mirror_offset != 0, "must be set");
1430 return java_class->obj_field(_inline_mirror_offset);
1431 }
1432
1433 void java_lang_Class::set_inline_type_mirror(oop java_class, oop mirror) {
1434 assert(_inline_mirror_offset != 0, "must be set");
1435 java_class->obj_field_put(_inline_mirror_offset, mirror);
1436 }
1437
1438 oop java_lang_Class::nullable_type_mirror(oop java_class) {
1439 assert(_nullable_mirror_offset != 0, "must be set");
1440 return java_class->obj_field(_nullable_mirror_offset);
1441 }
1442
1443 void java_lang_Class::set_nullable_type_mirror(oop java_class, oop mirror) {
1444 assert(_nullable_mirror_offset != 0, "must be set");
1445 java_class->obj_field_put(_nullable_mirror_offset, mirror);
1446 }
1447
1448 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
1449 // This should be improved by adding a field at the Java level or by
1450 // introducing a new VM klass (see comment in ClassFileParser)
1451 oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0);
1452 if (type != T_VOID) {
1453 Klass* aklass = Universe::typeArrayKlassObj(type);
1454 assert(aklass != NULL, "correct bootstrap");
1455 release_set_array_klass(java_class, aklass);
1456 }
1457 #ifdef ASSERT
1458 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass());
1459 assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1460 #endif
1461 return java_class;
1462 }
1463
1464
1465 Klass* java_lang_Class::as_Klass(oop java_class) {
1486
1487
1488 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1489 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1490 Symbol* name = NULL;
1491 bool is_instance = false;
1492 bool is_value = false;
1493 if (is_primitive(java_class)) {
1494 name = vmSymbols::type_signature(primitive_type(java_class));
1495 } else {
1496 Klass* k = as_Klass(java_class);
1497 is_instance = k->is_instance_klass();
1498 is_value = k->is_value();
1499 name = k->name();
1500 }
1501 if (name == NULL) {
1502 st->print("<null>");
1503 return;
1504 }
1505 if (is_instance) {
1506 if (is_value && (java_class == inline_type_mirror(java_class))) {
1507 st->print("Q");
1508 } else {
1509 st->print("L");
1510 }
1511 }
1512 st->write((char*) name->base(), (int) name->utf8_length());
1513 if (is_instance) st->print(";");
1514 }
1515
1516 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found, TRAPS) {
1517 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1518 Symbol* name;
1519 if (is_primitive(java_class)) {
1520 name = vmSymbols::type_signature(primitive_type(java_class));
1521 // Because this can create a new symbol, the caller has to decrement
1522 // the refcount, so make adjustment here and below for symbols returned
1523 // that are not created or incremented due to a successful lookup.
1524 name->increment_refcount();
1525 } else {
1526 Klass* k = as_Klass(java_class);
1527 if (!k->is_instance_klass()) {
1528 name = k->name();
1529 name->increment_refcount();
1530 } else {
1531 ResourceMark rm;
1532 const char* sigstr;
1533 if (k->is_value()) {
1534 char c = (java_class == inline_type_mirror(java_class)) ? 'Q' : 'L';
1535 sigstr = InstanceKlass::cast(k)->signature_name_of(c);
1536 } else {
1537 sigstr = k->signature_name();
1538 }
1539 int siglen = (int) strlen(sigstr);
1540 if (!intern_if_not_found) {
1541 name = SymbolTable::probe(sigstr, siglen);
1542 } else {
1543 name = SymbolTable::new_symbol(sigstr, siglen, THREAD);
1544 }
1545 }
1546 }
1547 return name;
1548 }
1549
1550 // Returns the Java name for this Java mirror (Resource allocated)
1551 // See Klass::external_name().
1552 // For primitive type Java mirrors, its type name is returned.
1553 const char* java_lang_Class::as_external_name(oop java_class) {
1554 assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1604 }
1605 }
1606
1607
1608 oop java_lang_Class::primitive_mirror(BasicType t) {
1609 oop mirror = Universe::java_mirror(t);
1610 assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1611 assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1612 return mirror;
1613 }
1614
1615 bool java_lang_Class::offsets_computed = false;
1616 int java_lang_Class::classRedefinedCount_offset = -1;
1617
1618 #define CLASS_FIELDS_DO(macro) \
1619 macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false) ; \
1620 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1621 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1622 macro(_module_offset, k, "module", module_signature, false); \
1623 macro(_name_offset, k, "name", string_signature, false); \
1624 macro(_inline_mirror_offset, k, "inlineType", class_signature, false); \
1625 macro(_nullable_mirror_offset, k, "nullableType", class_signature, false); \
1626
1627 void java_lang_Class::compute_offsets() {
1628 if (offsets_computed) {
1629 return;
1630 }
1631
1632 offsets_computed = true;
1633
1634 InstanceKlass* k = SystemDictionary::Class_klass();
1635 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1636
1637 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1638 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1639 // GC treats them the same.
1640 _init_lock_offset = _component_mirror_offset;
1641
1642 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1643 }
1644
1645 #if INCLUDE_CDS
4125 mirror->bool_field_put(fd->offset(), _use_unaligned_access);
4126 } else {
4127 assert(false, "unexpected UnsafeConstants field");
4128 }
4129 }
4130 };
4131
4132 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4133 UnsafeConstantsFixup fixup;
4134 SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4135 }
4136
4137 int java_lang_Class::_klass_offset;
4138 int java_lang_Class::_array_klass_offset;
4139 int java_lang_Class::_oop_size_offset;
4140 int java_lang_Class::_static_oop_field_count_offset;
4141 int java_lang_Class::_class_loader_offset;
4142 int java_lang_Class::_module_offset;
4143 int java_lang_Class::_protection_domain_offset;
4144 int java_lang_Class::_component_mirror_offset;
4145 int java_lang_Class::_inline_mirror_offset;
4146 int java_lang_Class::_nullable_mirror_offset;
4147 int java_lang_Class::_init_lock_offset;
4148 int java_lang_Class::_signers_offset;
4149 int java_lang_Class::_name_offset;
4150 int java_lang_Class::_source_file_offset;
4151 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4152 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4153 int java_lang_Throwable::backtrace_offset;
4154 int java_lang_Throwable::detailMessage_offset;
4155 int java_lang_Throwable::stackTrace_offset;
4156 int java_lang_Throwable::depth_offset;
4157 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4158 int java_lang_reflect_AccessibleObject::override_offset;
4159 int java_lang_reflect_Method::clazz_offset;
4160 int java_lang_reflect_Method::name_offset;
4161 int java_lang_reflect_Method::returnType_offset;
4162 int java_lang_reflect_Method::parameterTypes_offset;
4163 int java_lang_reflect_Method::exceptionTypes_offset;
4164 int java_lang_reflect_Method::slot_offset;
4165 int java_lang_reflect_Method::modifiers_offset;
4166 int java_lang_reflect_Method::signature_offset;
|