32 #include "classfile/javaClasses.inline.hpp"
33 #include "classfile/javaThreadStatus.hpp"
34 #include "classfile/moduleEntry.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/symbolTable.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/vmClasses.hpp"
39 #include "classfile/vmSymbols.hpp"
40 #include "code/debugInfo.hpp"
41 #include "code/dependencyContext.hpp"
42 #include "code/pcDesc.hpp"
43 #include "gc/shared/collectedHeap.inline.hpp"
44 #include "interpreter/interpreter.hpp"
45 #include "interpreter/linkResolver.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/oopFactory.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "memory/universe.hpp"
51 #include "oops/fieldStreams.inline.hpp"
52 #include "oops/instanceKlass.inline.hpp"
53 #include "oops/instanceMirrorKlass.hpp"
54 #include "oops/klass.hpp"
55 #include "oops/klass.inline.hpp"
56 #include "oops/method.inline.hpp"
57 #include "oops/objArrayOop.inline.hpp"
58 #include "oops/oop.inline.hpp"
59 #include "oops/symbol.hpp"
60 #include "oops/recordComponent.hpp"
61 #include "oops/typeArrayOop.inline.hpp"
62 #include "prims/jvmtiExport.hpp"
63 #include "prims/methodHandles.hpp"
64 #include "prims/resolvedMethodTable.hpp"
65 #include "runtime/fieldDescriptor.inline.hpp"
66 #include "runtime/frame.inline.hpp"
67 #include "runtime/handles.inline.hpp"
68 #include "runtime/init.hpp"
69 #include "runtime/interfaceSupport.inline.hpp"
70 #include "runtime/java.hpp"
71 #include "runtime/javaCalls.hpp"
72 #include "runtime/jniHandles.inline.hpp"
73 #include "runtime/reflectionUtils.hpp"
766 bool is_latin1 = java_lang_String::is_latin1(java_string);
767
768 st->print("\"");
769 for (int index = 0; index < length; index++) {
770 st->print("%c", (!is_latin1) ? value->char_at(index) :
771 ((jchar) value->byte_at(index)) & 0xff );
772 }
773 st->print("\"");
774 }
775
776 // java_lang_Class
777
778 int java_lang_Class::_klass_offset;
779 int java_lang_Class::_array_klass_offset;
780 int java_lang_Class::_oop_size_offset;
781 int java_lang_Class::_static_oop_field_count_offset;
782 int java_lang_Class::_class_loader_offset;
783 int java_lang_Class::_module_offset;
784 int java_lang_Class::_protection_domain_offset;
785 int java_lang_Class::_component_mirror_offset;
786 int java_lang_Class::_init_lock_offset;
787 int java_lang_Class::_signers_offset;
788 int java_lang_Class::_name_offset;
789 int java_lang_Class::_source_file_offset;
790 int java_lang_Class::_classData_offset;
791 int java_lang_Class::_classRedefinedCount_offset;
792
793 bool java_lang_Class::_offsets_computed = false;
794 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
795 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
796
797 #ifdef ASSERT
798 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
799 assert(fd->has_initial_value(), "caller should have checked this");
800 assert(fd->field_type() == T_OBJECT, "caller should have checked this");
801 // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated
802 // during DumpSharedSpaces
803 assert(fd->signature()->equals("Ljava/lang/String;"), "just checking");
804 }
805 #endif
996 int computed_modifiers = k->compute_modifier_flags();
997 k->set_modifier_flags(computed_modifiers);
998 // Class_klass has to be loaded because it is used to allocate
999 // the mirror.
1000 if (vmClasses::Class_klass_loaded()) {
1001 // Allocate mirror (java.lang.Class instance)
1002 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1003 Handle mirror(THREAD, mirror_oop);
1004 Handle comp_mirror;
1005
1006 // Setup indirection from mirror->klass
1007 set_klass(mirror(), k);
1008
1009 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1010 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1011
1012 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1013
1014 // It might also have a component mirror. This mirror must already exist.
1015 if (k->is_array_klass()) {
1016 if (k->is_typeArray_klass()) {
1017 BasicType type = TypeArrayKlass::cast(k)->element_type();
1018 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1019 } else {
1020 assert(k->is_objArray_klass(), "Must be");
1021 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1022 assert(element_klass != NULL, "Must have an element klass");
1023 comp_mirror = Handle(THREAD, element_klass->java_mirror());
1024 }
1025 assert(comp_mirror() != NULL, "must have a mirror");
1026
1027 // Two-way link between the array klass and its component mirror:
1028 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1029 set_component_mirror(mirror(), comp_mirror());
1030 // See below for ordering dependencies between field array_klass in component mirror
1031 // and java_mirror in this klass.
1032 } else {
1033 assert(k->is_instance_klass(), "Must be");
1034
1035 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1036 if (HAS_PENDING_EXCEPTION) {
1037 // If any of the fields throws an exception like OOM remove the klass field
1038 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1039 // This mirror looks like a primitive type, which logically it is because it
1040 // it represents no class.
1041 set_klass(mirror(), NULL);
1042 return;
1043 }
1044 }
1045
1046 // set the classLoader field in the java_lang_Class instance
1047 assert(class_loader() == k->class_loader(), "should be same");
1048 set_class_loader(mirror(), class_loader());
1049
1050 // Setup indirection from klass->mirror
1051 // after any exceptions can happen during allocations.
1052 k->set_java_mirror(mirror);
1053
1054 // Set the module field in the java_lang_Class instance. This must be done
1055 // after the mirror is set.
1056 set_mirror_module_field(THREAD, k, mirror, module);
1057
1058 if (comp_mirror() != NULL) {
1059 // Set after k->java_mirror() is published, because compiled code running
1060 // concurrently doesn't expect a k to have a null java_mirror.
1061 release_set_array_klass(comp_mirror(), k);
1062 }
1063 } else {
1064 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1065 fixup_mirror_list()->push(k);
1066 }
1067 }
1068
1069 #if INCLUDE_CDS_JAVA_HEAP
1070 // Clears mirror fields. Static final fields with initial values are reloaded
1071 // from constant pool. The object identity hash is in the object header and is
1072 // not affected.
1073 class ResetMirrorField: public FieldClosure {
1074 private:
1075 Handle _m;
1076
1077 public:
1078 ResetMirrorField(Handle mirror) : _m(mirror) {}
1079
1080 void do_field(fieldDescriptor* fd) {
1081 assert(DumpSharedSpaces, "dump time only");
1082 assert(_m.not_null(), "Mirror cannot be NULL");
1083
1084 if (fd->is_static() && fd->has_initial_value()) {
1085 initialize_static_field_for_dump(fd, _m);
1086 return;
1087 }
1095 _m()->char_field_put(fd->offset(), 0);
1096 break;
1097 case T_DOUBLE:
1098 _m()->double_field_put(fd->offset(), 0);
1099 break;
1100 case T_FLOAT:
1101 _m()->float_field_put(fd->offset(), 0);
1102 break;
1103 case T_INT:
1104 _m()->int_field_put(fd->offset(), 0);
1105 break;
1106 case T_LONG:
1107 _m()->long_field_put(fd->offset(), 0);
1108 break;
1109 case T_SHORT:
1110 _m()->short_field_put(fd->offset(), 0);
1111 break;
1112 case T_BOOLEAN:
1113 _m()->bool_field_put(fd->offset(), false);
1114 break;
1115 case T_ARRAY:
1116 case T_OBJECT: {
1117 // It might be useful to cache the String field, but
1118 // for now just clear out any reference field
1119 oop o = _m()->obj_field(fd->offset());
1120 _m()->obj_field_put(fd->offset(), NULL);
1121 break;
1122 }
1123 default:
1124 ShouldNotReachHere();
1125 break;
1126 }
1127 }
1128 };
1129
1130 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1131 assert(java_lang_Class::is_instance(mirror_obj), "must be");
1132 // this is the copy of k in the output buffer
1133 Klass* copy = ArchiveBuilder::get_relocated_klass(k);
1134
1190 }
1191
1192 // No mirror
1193 oop mirror = k->java_mirror();
1194 if (mirror == NULL) {
1195 return NULL;
1196 }
1197
1198 if (k->is_instance_klass()) {
1199 InstanceKlass *ik = InstanceKlass::cast(k);
1200 assert(ik->signers() == NULL, "class with signer should have been excluded");
1201
1202 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1203 ik->is_shared_app_class())) {
1204 // Archiving mirror for classes from non-builtin loaders is not
1205 // supported.
1206 return NULL;
1207 }
1208 }
1209
1210 // Now start archiving the mirror object
1211 oop archived_mirror = HeapShared::archive_object(mirror);
1212 if (archived_mirror == NULL) {
1213 return NULL;
1214 }
1215
1216 archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1217 if (archived_mirror == NULL) {
1218 return NULL;
1219 }
1220
1221 k->set_archived_java_mirror(archived_mirror);
1222
1223 ResourceMark rm;
1224 log_trace(cds, heap, mirror)(
1225 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1226 k->external_name(), p2i(mirror), p2i(archived_mirror));
1227
1228 return archived_mirror;
1229 }
1395 }
1396
1397 oop java_lang_Class::protection_domain(oop java_class) {
1398 assert(_protection_domain_offset != 0, "must be set");
1399 return java_class->obj_field(_protection_domain_offset);
1400 }
1401 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1402 assert(_protection_domain_offset != 0, "must be set");
1403 java_class->obj_field_put(_protection_domain_offset, pd);
1404 }
1405
1406 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1407 assert(_component_mirror_offset != 0, "must be set");
1408 java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1409 }
1410 oop java_lang_Class::component_mirror(oop java_class) {
1411 assert(_component_mirror_offset != 0, "must be set");
1412 return java_class->obj_field(_component_mirror_offset);
1413 }
1414
1415 oop java_lang_Class::init_lock(oop java_class) {
1416 assert(_init_lock_offset != 0, "must be set");
1417 return java_class->obj_field(_init_lock_offset);
1418 }
1419 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1420 assert(_init_lock_offset != 0, "must be set");
1421 java_class->obj_field_put(_init_lock_offset, init_lock);
1422 }
1423
1424 objArrayOop java_lang_Class::signers(oop java_class) {
1425 assert(_signers_offset != 0, "must be set");
1426 return (objArrayOop)java_class->obj_field(_signers_offset);
1427 }
1428 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1429 assert(_signers_offset != 0, "must be set");
1430 java_class->obj_field_put(_signers_offset, signers);
1431 }
1432
1433 oop java_lang_Class::class_data(oop java_class) {
1434 assert(_classData_offset != 0, "must be set");
1488 assert(aklass != NULL, "correct bootstrap");
1489 release_set_array_klass(java_class, aklass);
1490 }
1491 #ifdef ASSERT
1492 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1493 assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1494 #endif
1495 return java_class;
1496 }
1497
1498 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1499 assert(is_instance(java_class), "must be a Class object");
1500 java_class->metadata_field_put(_klass_offset, klass);
1501 }
1502
1503
1504 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1505 assert(is_instance(java_class), "must be a Class object");
1506 Symbol* name = NULL;
1507 bool is_instance = false;
1508 if (is_primitive(java_class)) {
1509 name = vmSymbols::type_signature(primitive_type(java_class));
1510 } else {
1511 Klass* k = as_Klass(java_class);
1512 is_instance = k->is_instance_klass();
1513 name = k->name();
1514 }
1515 if (name == NULL) {
1516 st->print("<null>");
1517 return;
1518 }
1519 if (is_instance) st->print("L");
1520 st->write((char*) name->base(), (int) name->utf8_length());
1521 if (is_instance) st->print(";");
1522 }
1523
1524 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1525 assert(is_instance(java_class), "must be a Class object");
1526 Symbol* name;
1527 if (is_primitive(java_class)) {
1528 name = vmSymbols::type_signature(primitive_type(java_class));
1529 // Because this can create a new symbol, the caller has to decrement
1530 // the refcount, so make adjustment here and below for symbols returned
1531 // that are not created or incremented due to a successful lookup.
1532 name->increment_refcount();
1533 } else {
1534 Klass* k = as_Klass(java_class);
1535 if (!k->is_instance_klass()) {
1536 name = k->name();
1537 name->increment_refcount();
1538 } else {
1539 ResourceMark rm;
1540 const char* sigstr = k->signature_name();
1541 int siglen = (int) strlen(sigstr);
1542 if (!intern_if_not_found) {
1543 name = SymbolTable::probe(sigstr, siglen);
1544 } else {
1545 name = SymbolTable::new_symbol(sigstr, siglen);
1546 }
1547 }
1548 }
1549 return name;
1550 }
1551
1552 // Returns the Java name for this Java mirror (Resource allocated)
1553 // See Klass::external_name().
1554 // For primitive type Java mirrors, its type name is returned.
1555 const char* java_lang_Class::as_external_name(oop java_class) {
1556 assert(is_instance(java_class), "must be a Class object");
1557 const char* name = NULL;
1558 if (is_primitive(java_class)) {
1559 name = type2name(primitive_type(java_class));
1560 } else {
1561 name = as_Klass(java_class)->external_name();
1601 return primitive_type(java_class);
1602 } else {
1603 if (reference_klass != NULL)
1604 (*reference_klass) = as_Klass(java_class);
1605 return T_OBJECT;
1606 }
1607 }
1608
1609
1610 oop java_lang_Class::primitive_mirror(BasicType t) {
1611 oop mirror = Universe::java_mirror(t);
1612 assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1613 assert(is_primitive(mirror), "must be primitive");
1614 return mirror;
1615 }
1616
1617 #define CLASS_FIELDS_DO(macro) \
1618 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1619 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1620 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1621 macro(_module_offset, k, "module", module_signature, false); \
1622 macro(_name_offset, k, "name", string_signature, false); \
1623 macro(_classData_offset, k, "classData", object_signature, false);
1624
1625 void java_lang_Class::compute_offsets() {
1626 if (_offsets_computed) {
1627 return;
1628 }
1629
1630 _offsets_computed = true;
1631
1632 InstanceKlass* k = vmClasses::Class_klass();
1633 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1634
1635 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1636 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1637 // GC treats them the same.
1638 _init_lock_offset = _component_mirror_offset;
1639
1640 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2491 #endif
2492
2493 // the format of the stacktrace will be:
2494 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2495 // - 0 or more <init> methods for the exception class (skipped)
2496 // - rest of the stack
2497
2498 if (!skip_fillInStackTrace_check) {
2499 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2500 throwable->is_a(method->method_holder())) {
2501 continue;
2502 }
2503 else {
2504 skip_fillInStackTrace_check = true; // gone past them all
2505 }
2506 }
2507 if (!skip_throwableInit_check) {
2508 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2509
2510 // skip <init> methods of the exception class and superclasses
2511 // This is simlar to classic VM.
2512 if (method->name() == vmSymbols::object_initializer_name() &&
2513 throwable->is_a(method->method_holder())) {
2514 continue;
2515 } else {
2516 // there are none or we've seen them all - either way stop checking
2517 skip_throwableInit_check = true;
2518 }
2519 }
2520 if (method->is_hidden()) {
2521 if (skip_hidden) {
2522 if (total_count == 0) {
2523 // The top frame will be hidden from the stack trace.
2524 bt.set_has_hidden_top_frame();
2525 }
2526 continue;
2527 }
2528 }
2529 bt.push(method, bci, CHECK);
2530 total_count++;
2531 }
2532
3965 int java_lang_invoke_MemberName::flags(oop mname) {
3966 assert(is_instance(mname), "wrong type");
3967 return mname->int_field(_flags_offset);
3968 }
3969
3970 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
3971 assert(is_instance(mname), "wrong type");
3972 mname->int_field_put(_flags_offset, flags);
3973 }
3974
3975
3976 // Return vmtarget from ResolvedMethodName method field through indirection
3977 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
3978 assert(is_instance(mname), "wrong type");
3979 oop method = mname->obj_field(_method_offset);
3980 return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
3981 }
3982
3983 bool java_lang_invoke_MemberName::is_method(oop mname) {
3984 assert(is_instance(mname), "must be MemberName");
3985 return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
3986 }
3987
3988 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
3989 assert(is_instance(mname), "wrong type");
3990 mname->obj_field_put(_method_offset, resolved_method);
3991 }
3992
3993 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
3994 assert(is_instance(mname), "wrong type");
3995 return (intptr_t) mname->address_field(_vmindex_offset);
3996 }
3997
3998 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3999 assert(is_instance(mname), "wrong type");
4000 mname->address_field_put(_vmindex_offset, (address) index);
4001 }
4002
4003
4004 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4005 assert(is_instance(resolved_method), "wrong type");
|
32 #include "classfile/javaClasses.inline.hpp"
33 #include "classfile/javaThreadStatus.hpp"
34 #include "classfile/moduleEntry.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/symbolTable.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/vmClasses.hpp"
39 #include "classfile/vmSymbols.hpp"
40 #include "code/debugInfo.hpp"
41 #include "code/dependencyContext.hpp"
42 #include "code/pcDesc.hpp"
43 #include "gc/shared/collectedHeap.inline.hpp"
44 #include "interpreter/interpreter.hpp"
45 #include "interpreter/linkResolver.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/oopFactory.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "memory/universe.hpp"
51 #include "oops/fieldStreams.inline.hpp"
52 #include "oops/flatArrayKlass.hpp"
53 #include "oops/inlineKlass.inline.hpp"
54 #include "oops/instanceKlass.inline.hpp"
55 #include "oops/instanceMirrorKlass.inline.hpp"
56 #include "oops/klass.hpp"
57 #include "oops/klass.inline.hpp"
58 #include "oops/method.inline.hpp"
59 #include "oops/objArrayOop.inline.hpp"
60 #include "oops/oop.inline.hpp"
61 #include "oops/symbol.hpp"
62 #include "oops/recordComponent.hpp"
63 #include "oops/typeArrayOop.inline.hpp"
64 #include "prims/jvmtiExport.hpp"
65 #include "prims/methodHandles.hpp"
66 #include "prims/resolvedMethodTable.hpp"
67 #include "runtime/fieldDescriptor.inline.hpp"
68 #include "runtime/frame.inline.hpp"
69 #include "runtime/handles.inline.hpp"
70 #include "runtime/init.hpp"
71 #include "runtime/interfaceSupport.inline.hpp"
72 #include "runtime/java.hpp"
73 #include "runtime/javaCalls.hpp"
74 #include "runtime/jniHandles.inline.hpp"
75 #include "runtime/reflectionUtils.hpp"
768 bool is_latin1 = java_lang_String::is_latin1(java_string);
769
770 st->print("\"");
771 for (int index = 0; index < length; index++) {
772 st->print("%c", (!is_latin1) ? value->char_at(index) :
773 ((jchar) value->byte_at(index)) & 0xff );
774 }
775 st->print("\"");
776 }
777
778 // java_lang_Class
779
780 int java_lang_Class::_klass_offset;
781 int java_lang_Class::_array_klass_offset;
782 int java_lang_Class::_oop_size_offset;
783 int java_lang_Class::_static_oop_field_count_offset;
784 int java_lang_Class::_class_loader_offset;
785 int java_lang_Class::_module_offset;
786 int java_lang_Class::_protection_domain_offset;
787 int java_lang_Class::_component_mirror_offset;
788 int java_lang_Class::_primary_mirror_offset;
789 int java_lang_Class::_secondary_mirror_offset;
790 int java_lang_Class::_init_lock_offset;
791 int java_lang_Class::_signers_offset;
792 int java_lang_Class::_name_offset;
793 int java_lang_Class::_source_file_offset;
794 int java_lang_Class::_classData_offset;
795 int java_lang_Class::_classRedefinedCount_offset;
796
797 bool java_lang_Class::_offsets_computed = false;
798 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
799 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
800
801 #ifdef ASSERT
802 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
803 assert(fd->has_initial_value(), "caller should have checked this");
804 assert(fd->field_type() == T_OBJECT, "caller should have checked this");
805 // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated
806 // during DumpSharedSpaces
807 assert(fd->signature()->equals("Ljava/lang/String;"), "just checking");
808 }
809 #endif
1000 int computed_modifiers = k->compute_modifier_flags();
1001 k->set_modifier_flags(computed_modifiers);
1002 // Class_klass has to be loaded because it is used to allocate
1003 // the mirror.
1004 if (vmClasses::Class_klass_loaded()) {
1005 // Allocate mirror (java.lang.Class instance)
1006 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1007 Handle mirror(THREAD, mirror_oop);
1008 Handle comp_mirror;
1009
1010 // Setup indirection from mirror->klass
1011 set_klass(mirror(), k);
1012
1013 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1014 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1015
1016 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1017
1018 // It might also have a component mirror. This mirror must already exist.
1019 if (k->is_array_klass()) {
1020 if (k->is_flatArray_klass()) {
1021 Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1022 assert(element_klass->is_inline_klass(), "Must be inline type component");
1023 InlineKlass* vk = InlineKlass::cast(element_klass);
1024 comp_mirror = Handle(THREAD, vk->val_mirror());
1025 } else if (k->is_typeArray_klass()) {
1026 BasicType type = TypeArrayKlass::cast(k)->element_type();
1027 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1028 } else {
1029 assert(k->is_objArray_klass(), "Must be");
1030 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1031 assert(element_klass != NULL, "Must have an element klass");
1032 oop comp_oop = element_klass->java_mirror();
1033 if (element_klass->is_inline_klass()) {
1034 InlineKlass* ik = InlineKlass::cast(element_klass);
1035 comp_oop = k->name()->is_Q_array_signature() ? ik->val_mirror() : ik->ref_mirror();
1036 }
1037 comp_mirror = Handle(THREAD, comp_oop);
1038 }
1039 assert(comp_mirror() != NULL, "must have a mirror");
1040
1041 // Two-way link between the array klass and its component mirror:
1042 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1043 set_component_mirror(mirror(), comp_mirror());
1044 // See below for ordering dependencies between field array_klass in component mirror
1045 // and java_mirror in this klass.
1046 } else {
1047 assert(k->is_instance_klass(), "Must be");
1048
1049 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1050 if (HAS_PENDING_EXCEPTION) {
1051 // If any of the fields throws an exception like OOM remove the klass field
1052 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1053 // This mirror looks like a primitive type, which logically it is because it
1054 // it represents no class.
1055 set_klass(mirror(), NULL);
1056 return;
1057 }
1058 }
1059
1060 // set the classLoader field in the java_lang_Class instance
1061 assert(class_loader() == k->class_loader(), "should be same");
1062 set_class_loader(mirror(), class_loader());
1063
1064 // Setup indirection from klass->mirror
1065 // after any exceptions can happen during allocations.
1066 k->set_java_mirror(mirror);
1067
1068 // Set the module field in the java_lang_Class instance. This must be done
1069 // after the mirror is set.
1070 set_mirror_module_field(THREAD, k, mirror, module);
1071
1072 if (comp_mirror() != NULL) {
1073 // Set after k->java_mirror() is published, because compiled code running
1074 // concurrently doesn't expect a k to have a null java_mirror.
1075 release_set_array_klass(comp_mirror(), k);
1076 }
1077
1078 if (k->is_inline_klass()) {
1079 oop secondary_mirror = create_secondary_mirror(k, mirror, CHECK);
1080 set_primary_mirror(mirror(), mirror());
1081 set_secondary_mirror(mirror(), secondary_mirror);
1082 }
1083 } else {
1084 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1085 fixup_mirror_list()->push(k);
1086 }
1087 }
1088 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1089 // instance with the same value as the primary mirror
1090 oop java_lang_Class::create_secondary_mirror(Klass* k, Handle mirror, TRAPS) {
1091 assert(k->is_inline_klass(), "primitive class");
1092 // Allocate mirror (java.lang.Class instance)
1093 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK_0);
1094 Handle secondary_mirror(THREAD, mirror_oop);
1095
1096 java_lang_Class::set_klass(secondary_mirror(), k);
1097 java_lang_Class::set_static_oop_field_count(secondary_mirror(), static_oop_field_count(mirror()));
1098 // ## do we need to set init lock?
1099 java_lang_Class::set_init_lock(secondary_mirror(), init_lock(mirror()));
1100
1101 set_protection_domain(secondary_mirror(), protection_domain(mirror()));
1102 set_class_loader(secondary_mirror(), class_loader(mirror()));
1103 // ## handle if java.base is not yet defined
1104 set_module(secondary_mirror(), module(mirror()));
1105 set_primary_mirror(secondary_mirror(), mirror());
1106 set_secondary_mirror(secondary_mirror(), secondary_mirror());
1107 return secondary_mirror();
1108 }
1109
1110 #if INCLUDE_CDS_JAVA_HEAP
1111 // Clears mirror fields. Static final fields with initial values are reloaded
1112 // from constant pool. The object identity hash is in the object header and is
1113 // not affected.
1114 class ResetMirrorField: public FieldClosure {
1115 private:
1116 Handle _m;
1117
1118 public:
1119 ResetMirrorField(Handle mirror) : _m(mirror) {}
1120
1121 void do_field(fieldDescriptor* fd) {
1122 assert(DumpSharedSpaces, "dump time only");
1123 assert(_m.not_null(), "Mirror cannot be NULL");
1124
1125 if (fd->is_static() && fd->has_initial_value()) {
1126 initialize_static_field_for_dump(fd, _m);
1127 return;
1128 }
1136 _m()->char_field_put(fd->offset(), 0);
1137 break;
1138 case T_DOUBLE:
1139 _m()->double_field_put(fd->offset(), 0);
1140 break;
1141 case T_FLOAT:
1142 _m()->float_field_put(fd->offset(), 0);
1143 break;
1144 case T_INT:
1145 _m()->int_field_put(fd->offset(), 0);
1146 break;
1147 case T_LONG:
1148 _m()->long_field_put(fd->offset(), 0);
1149 break;
1150 case T_SHORT:
1151 _m()->short_field_put(fd->offset(), 0);
1152 break;
1153 case T_BOOLEAN:
1154 _m()->bool_field_put(fd->offset(), false);
1155 break;
1156 case T_PRIMITIVE_OBJECT:
1157 case T_ARRAY:
1158 case T_OBJECT: {
1159 // It might be useful to cache the String field, but
1160 // for now just clear out any reference field
1161 oop o = _m()->obj_field(fd->offset());
1162 _m()->obj_field_put(fd->offset(), NULL);
1163 break;
1164 }
1165 default:
1166 ShouldNotReachHere();
1167 break;
1168 }
1169 }
1170 };
1171
1172 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1173 assert(java_lang_Class::is_instance(mirror_obj), "must be");
1174 // this is the copy of k in the output buffer
1175 Klass* copy = ArchiveBuilder::get_relocated_klass(k);
1176
1232 }
1233
1234 // No mirror
1235 oop mirror = k->java_mirror();
1236 if (mirror == NULL) {
1237 return NULL;
1238 }
1239
1240 if (k->is_instance_klass()) {
1241 InstanceKlass *ik = InstanceKlass::cast(k);
1242 assert(ik->signers() == NULL, "class with signer should have been excluded");
1243
1244 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1245 ik->is_shared_app_class())) {
1246 // Archiving mirror for classes from non-builtin loaders is not
1247 // supported.
1248 return NULL;
1249 }
1250 }
1251
1252 if (k->is_inline_klass()) {
1253 // Inline types have a primary mirror and a secondary mirror. Don't handle this for now. TODO:CDS
1254 k->clear_java_mirror_handle();
1255 return NULL;
1256 }
1257
1258 // Now start archiving the mirror object
1259 oop archived_mirror = HeapShared::archive_object(mirror);
1260 if (archived_mirror == NULL) {
1261 return NULL;
1262 }
1263
1264 archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1265 if (archived_mirror == NULL) {
1266 return NULL;
1267 }
1268
1269 k->set_archived_java_mirror(archived_mirror);
1270
1271 ResourceMark rm;
1272 log_trace(cds, heap, mirror)(
1273 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1274 k->external_name(), p2i(mirror), p2i(archived_mirror));
1275
1276 return archived_mirror;
1277 }
1443 }
1444
1445 oop java_lang_Class::protection_domain(oop java_class) {
1446 assert(_protection_domain_offset != 0, "must be set");
1447 return java_class->obj_field(_protection_domain_offset);
1448 }
1449 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1450 assert(_protection_domain_offset != 0, "must be set");
1451 java_class->obj_field_put(_protection_domain_offset, pd);
1452 }
1453
1454 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1455 assert(_component_mirror_offset != 0, "must be set");
1456 java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1457 }
1458 oop java_lang_Class::component_mirror(oop java_class) {
1459 assert(_component_mirror_offset != 0, "must be set");
1460 return java_class->obj_field(_component_mirror_offset);
1461 }
1462
1463 oop java_lang_Class::primary_mirror(oop java_class) {
1464 assert(_primary_mirror_offset != 0, "must be set");
1465 return java_class->obj_field(_primary_mirror_offset);
1466 }
1467
1468 void java_lang_Class::set_primary_mirror(oop java_class, oop mirror) {
1469 assert(_primary_mirror_offset != 0, "must be set");
1470 java_class->obj_field_put(_primary_mirror_offset, mirror);
1471 }
1472
1473 oop java_lang_Class::secondary_mirror(oop java_class) {
1474 assert(_secondary_mirror_offset != 0, "must be set");
1475 return java_class->obj_field(_secondary_mirror_offset);
1476 }
1477
1478 void java_lang_Class::set_secondary_mirror(oop java_class, oop mirror) {
1479 assert(_secondary_mirror_offset != 0, "must be set");
1480 java_class->obj_field_put(_secondary_mirror_offset, mirror);
1481 }
1482
1483 oop java_lang_Class::init_lock(oop java_class) {
1484 assert(_init_lock_offset != 0, "must be set");
1485 return java_class->obj_field(_init_lock_offset);
1486 }
1487 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1488 assert(_init_lock_offset != 0, "must be set");
1489 java_class->obj_field_put(_init_lock_offset, init_lock);
1490 }
1491
1492 objArrayOop java_lang_Class::signers(oop java_class) {
1493 assert(_signers_offset != 0, "must be set");
1494 return (objArrayOop)java_class->obj_field(_signers_offset);
1495 }
1496 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1497 assert(_signers_offset != 0, "must be set");
1498 java_class->obj_field_put(_signers_offset, signers);
1499 }
1500
1501 oop java_lang_Class::class_data(oop java_class) {
1502 assert(_classData_offset != 0, "must be set");
1556 assert(aklass != NULL, "correct bootstrap");
1557 release_set_array_klass(java_class, aklass);
1558 }
1559 #ifdef ASSERT
1560 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1561 assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1562 #endif
1563 return java_class;
1564 }
1565
1566 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1567 assert(is_instance(java_class), "must be a Class object");
1568 java_class->metadata_field_put(_klass_offset, klass);
1569 }
1570
1571
1572 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1573 assert(is_instance(java_class), "must be a Class object");
1574 Symbol* name = NULL;
1575 bool is_instance = false;
1576 bool is_Q_descriptor = false;
1577 if (is_primitive(java_class)) {
1578 name = vmSymbols::type_signature(primitive_type(java_class));
1579 } else {
1580 Klass* k = as_Klass(java_class);
1581 is_instance = k->is_instance_klass();
1582 is_Q_descriptor = k->is_inline_klass() && is_secondary_mirror(java_class);
1583 name = k->name();
1584 }
1585 if (name == NULL) {
1586 st->print("<null>");
1587 return;
1588 }
1589 if (is_instance) {
1590 st->print(is_Q_descriptor ? "Q" : "L");
1591 }
1592 st->write((char*) name->base(), (int) name->utf8_length());
1593 if (is_instance) st->print(";");
1594 }
1595
1596 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1597 assert(is_instance(java_class), "must be a Class object");
1598 Symbol* name;
1599 if (is_primitive(java_class)) {
1600 name = vmSymbols::type_signature(primitive_type(java_class));
1601 // Because this can create a new symbol, the caller has to decrement
1602 // the refcount, so make adjustment here and below for symbols returned
1603 // that are not created or incremented due to a successful lookup.
1604 name->increment_refcount();
1605 } else {
1606 Klass* k = as_Klass(java_class);
1607 if (!k->is_instance_klass()) {
1608 name = k->name();
1609 name->increment_refcount();
1610 } else {
1611 ResourceMark rm;
1612 const char* sigstr;
1613 if (k->is_inline_klass() && is_secondary_mirror(java_class)) {
1614 sigstr = InlineKlass::cast(k)->val_signature_name();
1615 } else {
1616 sigstr = k->signature_name();
1617 }
1618 int siglen = (int) strlen(sigstr);
1619 if (!intern_if_not_found) {
1620 name = SymbolTable::probe(sigstr, siglen);
1621 } else {
1622 name = SymbolTable::new_symbol(sigstr, siglen);
1623 }
1624 }
1625 }
1626 return name;
1627 }
1628
1629 // Returns the Java name for this Java mirror (Resource allocated)
1630 // See Klass::external_name().
1631 // For primitive type Java mirrors, its type name is returned.
1632 const char* java_lang_Class::as_external_name(oop java_class) {
1633 assert(is_instance(java_class), "must be a Class object");
1634 const char* name = NULL;
1635 if (is_primitive(java_class)) {
1636 name = type2name(primitive_type(java_class));
1637 } else {
1638 name = as_Klass(java_class)->external_name();
1678 return primitive_type(java_class);
1679 } else {
1680 if (reference_klass != NULL)
1681 (*reference_klass) = as_Klass(java_class);
1682 return T_OBJECT;
1683 }
1684 }
1685
1686
1687 oop java_lang_Class::primitive_mirror(BasicType t) {
1688 oop mirror = Universe::java_mirror(t);
1689 assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1690 assert(is_primitive(mirror), "must be primitive");
1691 return mirror;
1692 }
1693
1694 #define CLASS_FIELDS_DO(macro) \
1695 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1696 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1697 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1698 macro(_primary_mirror_offset, k, "primaryType", class_signature, false); \
1699 macro(_secondary_mirror_offset, k, "secondaryType", class_signature, false); \
1700 macro(_module_offset, k, "module", module_signature, false); \
1701 macro(_name_offset, k, "name", string_signature, false); \
1702 macro(_classData_offset, k, "classData", object_signature, false);
1703
1704 void java_lang_Class::compute_offsets() {
1705 if (_offsets_computed) {
1706 return;
1707 }
1708
1709 _offsets_computed = true;
1710
1711 InstanceKlass* k = vmClasses::Class_klass();
1712 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1713
1714 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1715 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1716 // GC treats them the same.
1717 _init_lock_offset = _component_mirror_offset;
1718
1719 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2570 #endif
2571
2572 // the format of the stacktrace will be:
2573 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2574 // - 0 or more <init> methods for the exception class (skipped)
2575 // - rest of the stack
2576
2577 if (!skip_fillInStackTrace_check) {
2578 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2579 throwable->is_a(method->method_holder())) {
2580 continue;
2581 }
2582 else {
2583 skip_fillInStackTrace_check = true; // gone past them all
2584 }
2585 }
2586 if (!skip_throwableInit_check) {
2587 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2588
2589 // skip <init> methods of the exception class and superclasses
2590 // This is similar to classic VM (before HotSpot).
2591 if (method->is_object_constructor() &&
2592 throwable->is_a(method->method_holder())) {
2593 continue;
2594 } else {
2595 // there are none or we've seen them all - either way stop checking
2596 skip_throwableInit_check = true;
2597 }
2598 }
2599 if (method->is_hidden()) {
2600 if (skip_hidden) {
2601 if (total_count == 0) {
2602 // The top frame will be hidden from the stack trace.
2603 bt.set_has_hidden_top_frame();
2604 }
2605 continue;
2606 }
2607 }
2608 bt.push(method, bci, CHECK);
2609 total_count++;
2610 }
2611
4044 int java_lang_invoke_MemberName::flags(oop mname) {
4045 assert(is_instance(mname), "wrong type");
4046 return mname->int_field(_flags_offset);
4047 }
4048
4049 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4050 assert(is_instance(mname), "wrong type");
4051 mname->int_field_put(_flags_offset, flags);
4052 }
4053
4054
4055 // Return vmtarget from ResolvedMethodName method field through indirection
4056 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4057 assert(is_instance(mname), "wrong type");
4058 oop method = mname->obj_field(_method_offset);
4059 return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4060 }
4061
4062 bool java_lang_invoke_MemberName::is_method(oop mname) {
4063 assert(is_instance(mname), "must be MemberName");
4064 return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4065 }
4066
4067 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4068 assert(is_instance(mname), "wrong type");
4069 mname->obj_field_put(_method_offset, resolved_method);
4070 }
4071
4072 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4073 assert(is_instance(mname), "wrong type");
4074 return (intptr_t) mname->address_field(_vmindex_offset);
4075 }
4076
4077 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4078 assert(is_instance(mname), "wrong type");
4079 mname->address_field_put(_vmindex_offset, (address) index);
4080 }
4081
4082
4083 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4084 assert(is_instance(resolved_method), "wrong type");
|