34 #include "classfile/javaThreadStatus.hpp"
35 #include "classfile/moduleEntry.hpp"
36 #include "classfile/stringTable.hpp"
37 #include "classfile/symbolTable.hpp"
38 #include "classfile/systemDictionary.hpp"
39 #include "classfile/vmClasses.hpp"
40 #include "classfile/vmSymbols.hpp"
41 #include "code/debugInfo.hpp"
42 #include "code/dependencyContext.hpp"
43 #include "code/pcDesc.hpp"
44 #include "gc/shared/collectedHeap.inline.hpp"
45 #include "interpreter/interpreter.hpp"
46 #include "interpreter/linkResolver.hpp"
47 #include "jvm.h"
48 #include "logging/log.hpp"
49 #include "logging/logStream.hpp"
50 #include "memory/oopFactory.hpp"
51 #include "memory/resourceArea.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/fieldStreams.inline.hpp"
54 #include "oops/instanceKlass.inline.hpp"
55 #include "oops/instanceMirrorKlass.hpp"
56 #include "oops/klass.hpp"
57 #include "oops/klass.inline.hpp"
58 #include "oops/method.inline.hpp"
59 #include "oops/objArrayKlass.hpp"
60 #include "oops/objArrayOop.inline.hpp"
61 #include "oops/oopCast.inline.hpp"
62 #include "oops/oop.inline.hpp"
63 #include "oops/symbol.hpp"
64 #include "oops/recordComponent.hpp"
65 #include "oops/typeArrayOop.inline.hpp"
66 #include "prims/jvmtiExport.hpp"
67 #include "prims/methodHandles.hpp"
68 #include "prims/resolvedMethodTable.hpp"
69 #include "runtime/continuationEntry.inline.hpp"
70 #include "runtime/continuationJavaClasses.inline.hpp"
71 #include "runtime/fieldDescriptor.inline.hpp"
72 #include "runtime/frame.inline.hpp"
73 #include "runtime/handles.inline.hpp"
74 #include "runtime/handshake.hpp"
75 #include "runtime/init.hpp"
763 bool is_latin1 = java_lang_String::is_latin1(java_string);
764
765 st->print("\"");
766 for (int index = 0; index < length; index++) {
767 st->print("%c", (!is_latin1) ? value->char_at(index) :
768 ((jchar) value->byte_at(index)) & 0xff );
769 }
770 st->print("\"");
771 }
772
773 // java_lang_Class
774
775 int java_lang_Class::_klass_offset;
776 int java_lang_Class::_array_klass_offset;
777 int java_lang_Class::_oop_size_offset;
778 int java_lang_Class::_static_oop_field_count_offset;
779 int java_lang_Class::_class_loader_offset;
780 int java_lang_Class::_module_offset;
781 int java_lang_Class::_protection_domain_offset;
782 int java_lang_Class::_component_mirror_offset;
783 int java_lang_Class::_signers_offset;
784 int java_lang_Class::_name_offset;
785 int java_lang_Class::_source_file_offset;
786 int java_lang_Class::_classData_offset;
787 int java_lang_Class::_classRedefinedCount_offset;
788
789 bool java_lang_Class::_offsets_computed = false;
790 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
791 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
792
793 #ifdef ASSERT
794 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
795 assert(fd->has_initial_value(), "caller should have checked this");
796 assert(fd->field_type() == T_OBJECT, "caller should have checked this");
797 // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated
798 // during DumpSharedSpaces
799 assert(fd->signature()->equals("Ljava/lang/String;"), "just checking");
800 }
801 #endif
802
986 int computed_modifiers = k->compute_modifier_flags();
987 k->set_modifier_flags(computed_modifiers);
988 // Class_klass has to be loaded because it is used to allocate
989 // the mirror.
990 if (vmClasses::Class_klass_loaded()) {
991 // Allocate mirror (java.lang.Class instance)
992 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
993 Handle mirror(THREAD, mirror_oop);
994 Handle comp_mirror;
995
996 // Setup indirection from mirror->klass
997 set_klass(mirror(), k);
998
999 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1000 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1001
1002 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1003
1004 // It might also have a component mirror. This mirror must already exist.
1005 if (k->is_array_klass()) {
1006 if (k->is_typeArray_klass()) {
1007 BasicType type = TypeArrayKlass::cast(k)->element_type();
1008 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1009 } else {
1010 assert(k->is_objArray_klass(), "Must be");
1011 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1012 assert(element_klass != NULL, "Must have an element klass");
1013 comp_mirror = Handle(THREAD, element_klass->java_mirror());
1014 }
1015 assert(comp_mirror() != NULL, "must have a mirror");
1016
1017 // Two-way link between the array klass and its component mirror:
1018 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1019 set_component_mirror(mirror(), comp_mirror());
1020 // See below for ordering dependencies between field array_klass in component mirror
1021 // and java_mirror in this klass.
1022 } else {
1023 assert(k->is_instance_klass(), "Must be");
1024
1025 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1026 if (HAS_PENDING_EXCEPTION) {
1027 // If any of the fields throws an exception like OOM remove the klass field
1028 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1029 // This mirror looks like a primitive type, which logically it is because it
1030 // it represents no class.
1031 set_klass(mirror(), NULL);
1032 return;
1033 }
1034 }
1035
1036 // set the classLoader field in the java_lang_Class instance
1037 assert(class_loader() == k->class_loader(), "should be same");
1038 set_class_loader(mirror(), class_loader());
1039
1040 // Setup indirection from klass->mirror
1041 // after any exceptions can happen during allocations.
1042 k->set_java_mirror(mirror);
1043
1044 // Set the module field in the java_lang_Class instance. This must be done
1045 // after the mirror is set.
1046 set_mirror_module_field(THREAD, k, mirror, module);
1047
1048 if (comp_mirror() != NULL) {
1049 // Set after k->java_mirror() is published, because compiled code running
1050 // concurrently doesn't expect a k to have a null java_mirror.
1051 release_set_array_klass(comp_mirror(), k);
1052 }
1053 } else {
1054 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1055 fixup_mirror_list()->push(k);
1056 }
1057 }
1058
1059 #if INCLUDE_CDS_JAVA_HEAP
1060 // Clears mirror fields. Static final fields with initial values are reloaded
1061 // from constant pool. The object identity hash is in the object header and is
1062 // not affected.
1063 class ResetMirrorField: public FieldClosure {
1064 private:
1065 Handle _m;
1066
1067 public:
1068 ResetMirrorField(Handle mirror) : _m(mirror) {}
1069
1070 void do_field(fieldDescriptor* fd) {
1071 assert(DumpSharedSpaces, "dump time only");
1072 assert(_m.not_null(), "Mirror cannot be NULL");
1073
1074 if (fd->is_static() && fd->has_initial_value()) {
1075 initialize_static_field_for_dump(fd, _m);
1076 return;
1077 }
1085 _m()->char_field_put(fd->offset(), 0);
1086 break;
1087 case T_DOUBLE:
1088 _m()->double_field_put(fd->offset(), 0);
1089 break;
1090 case T_FLOAT:
1091 _m()->float_field_put(fd->offset(), 0);
1092 break;
1093 case T_INT:
1094 _m()->int_field_put(fd->offset(), 0);
1095 break;
1096 case T_LONG:
1097 _m()->long_field_put(fd->offset(), 0);
1098 break;
1099 case T_SHORT:
1100 _m()->short_field_put(fd->offset(), 0);
1101 break;
1102 case T_BOOLEAN:
1103 _m()->bool_field_put(fd->offset(), false);
1104 break;
1105 case T_ARRAY:
1106 case T_OBJECT: {
1107 // It might be useful to cache the String field, but
1108 // for now just clear out any reference field
1109 oop o = _m()->obj_field(fd->offset());
1110 _m()->obj_field_put(fd->offset(), NULL);
1111 break;
1112 }
1113 default:
1114 ShouldNotReachHere();
1115 break;
1116 }
1117 }
1118 };
1119
1120 void java_lang_Class::archive_basic_type_mirrors() {
1121 assert(HeapShared::can_write(), "must be");
1122
1123 for (int t = T_BOOLEAN; t < T_VOID+1; t++) {
1124 BasicType bt = (BasicType)t;
1161 }
1162
1163 // No mirror
1164 oop mirror = k->java_mirror();
1165 if (mirror == NULL) {
1166 return NULL;
1167 }
1168
1169 if (k->is_instance_klass()) {
1170 InstanceKlass *ik = InstanceKlass::cast(k);
1171 assert(ik->signers() == NULL, "class with signer should have been excluded");
1172
1173 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1174 ik->is_shared_app_class())) {
1175 // Archiving mirror for classes from non-builtin loaders is not
1176 // supported.
1177 return NULL;
1178 }
1179 }
1180
1181 // Now start archiving the mirror object
1182 oop archived_mirror = HeapShared::archive_object(mirror);
1183 if (archived_mirror == NULL) {
1184 return NULL;
1185 }
1186
1187 archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1188 if (archived_mirror == NULL) {
1189 return NULL;
1190 }
1191
1192 k->set_archived_java_mirror(archived_mirror);
1193
1194 ResourceMark rm;
1195 log_trace(cds, heap, mirror)(
1196 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1197 k->external_name(), p2i(mirror), p2i(archived_mirror));
1198
1199 return archived_mirror;
1200 }
1322 }
1323
1324 oop java_lang_Class::protection_domain(oop java_class) {
1325 assert(_protection_domain_offset != 0, "must be set");
1326 return java_class->obj_field(_protection_domain_offset);
1327 }
1328 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1329 assert(_protection_domain_offset != 0, "must be set");
1330 java_class->obj_field_put(_protection_domain_offset, pd);
1331 }
1332
1333 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1334 assert(_component_mirror_offset != 0, "must be set");
1335 java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1336 }
1337 oop java_lang_Class::component_mirror(oop java_class) {
1338 assert(_component_mirror_offset != 0, "must be set");
1339 return java_class->obj_field(_component_mirror_offset);
1340 }
1341
1342 objArrayOop java_lang_Class::signers(oop java_class) {
1343 assert(_signers_offset != 0, "must be set");
1344 return (objArrayOop)java_class->obj_field(_signers_offset);
1345 }
1346 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1347 assert(_signers_offset != 0, "must be set");
1348 java_class->obj_field_put(_signers_offset, signers);
1349 }
1350
1351 oop java_lang_Class::class_data(oop java_class) {
1352 assert(_classData_offset != 0, "must be set");
1353 return java_class->obj_field(_classData_offset);
1354 }
1355 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1356 assert(_classData_offset != 0, "must be set");
1357 java_class->obj_field_put(_classData_offset, class_data);
1358 }
1359
1360 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1361 assert(_class_loader_offset != 0, "offsets should have been initialized");
1406 assert(aklass != NULL, "correct bootstrap");
1407 release_set_array_klass(java_class, aklass);
1408 }
1409 #ifdef ASSERT
1410 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1411 assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1412 #endif
1413 return java_class;
1414 }
1415
1416 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1417 assert(is_instance(java_class), "must be a Class object");
1418 java_class->metadata_field_put(_klass_offset, klass);
1419 }
1420
1421
1422 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1423 assert(is_instance(java_class), "must be a Class object");
1424 Symbol* name = NULL;
1425 bool is_instance = false;
1426 if (is_primitive(java_class)) {
1427 name = vmSymbols::type_signature(primitive_type(java_class));
1428 } else {
1429 Klass* k = as_Klass(java_class);
1430 is_instance = k->is_instance_klass();
1431 name = k->name();
1432 }
1433 if (name == NULL) {
1434 st->print("<null>");
1435 return;
1436 }
1437 if (is_instance) st->print("L");
1438 st->write((char*) name->base(), (int) name->utf8_length());
1439 if (is_instance) st->print(";");
1440 }
1441
1442 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1443 assert(is_instance(java_class), "must be a Class object");
1444 Symbol* name;
1445 if (is_primitive(java_class)) {
1446 name = vmSymbols::type_signature(primitive_type(java_class));
1447 // Because this can create a new symbol, the caller has to decrement
1448 // the refcount, so make adjustment here and below for symbols returned
1449 // that are not created or incremented due to a successful lookup.
1450 name->increment_refcount();
1451 } else {
1452 Klass* k = as_Klass(java_class);
1453 if (!k->is_instance_klass()) {
1454 name = k->name();
1455 name->increment_refcount();
1456 } else {
1457 ResourceMark rm;
1458 const char* sigstr = k->signature_name();
1459 int siglen = (int) strlen(sigstr);
1460 if (!intern_if_not_found) {
1461 name = SymbolTable::probe(sigstr, siglen);
1462 } else {
1463 name = SymbolTable::new_symbol(sigstr, siglen);
1464 }
1465 }
1466 }
1467 return name;
1468 }
1469
1470 // Returns the Java name for this Java mirror (Resource allocated)
1471 // See Klass::external_name().
1472 // For primitive type Java mirrors, its type name is returned.
1473 const char* java_lang_Class::as_external_name(oop java_class) {
1474 assert(is_instance(java_class), "must be a Class object");
1475 const char* name = NULL;
1476 if (is_primitive(java_class)) {
1477 name = type2name(primitive_type(java_class));
1478 } else {
1479 name = as_Klass(java_class)->external_name();
1519 return primitive_type(java_class);
1520 } else {
1521 if (reference_klass != NULL)
1522 (*reference_klass) = as_Klass(java_class);
1523 return T_OBJECT;
1524 }
1525 }
1526
1527
1528 oop java_lang_Class::primitive_mirror(BasicType t) {
1529 oop mirror = Universe::java_mirror(t);
1530 assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1531 assert(is_primitive(mirror), "must be primitive");
1532 return mirror;
1533 }
1534
1535 #define CLASS_FIELDS_DO(macro) \
1536 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1537 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1538 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1539 macro(_module_offset, k, "module", module_signature, false); \
1540 macro(_name_offset, k, "name", string_signature, false); \
1541 macro(_classData_offset, k, "classData", object_signature, false);
1542
1543 void java_lang_Class::compute_offsets() {
1544 if (_offsets_computed) {
1545 return;
1546 }
1547
1548 _offsets_computed = true;
1549
1550 InstanceKlass* k = vmClasses::Class_klass();
1551 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1552
1553 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1554 }
1555
1556 #if INCLUDE_CDS
1557 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1558 f->do_bool(&_offsets_computed);
2718
2719 // the format of the stacktrace will be:
2720 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2721 // - 0 or more <init> methods for the exception class (skipped)
2722 // - rest of the stack
2723
2724 if (!skip_fillInStackTrace_check) {
2725 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2726 throwable->is_a(method->method_holder())) {
2727 continue;
2728 }
2729 else {
2730 skip_fillInStackTrace_check = true; // gone past them all
2731 }
2732 }
2733 if (!skip_throwableInit_check) {
2734 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2735
2736 // skip <init> methods of the exception class and superclasses
2737 // This is similar to classic VM.
2738 if (method->name() == vmSymbols::object_initializer_name() &&
2739 throwable->is_a(method->method_holder())) {
2740 continue;
2741 } else {
2742 // there are none or we've seen them all - either way stop checking
2743 skip_throwableInit_check = true;
2744 }
2745 }
2746 if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2747 if (skip_hidden) {
2748 if (total_count == 0) {
2749 // The top frame will be hidden from the stack trace.
2750 bt.set_has_hidden_top_frame();
2751 }
2752 continue;
2753 }
2754 }
2755
2756 bt.push(method, bci, CHECK);
2757 total_count++;
2758 }
4312 int java_lang_invoke_MemberName::flags(oop mname) {
4313 assert(is_instance(mname), "wrong type");
4314 return mname->int_field(_flags_offset);
4315 }
4316
4317 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4318 assert(is_instance(mname), "wrong type");
4319 mname->int_field_put(_flags_offset, flags);
4320 }
4321
4322
4323 // Return vmtarget from ResolvedMethodName method field through indirection
4324 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4325 assert(is_instance(mname), "wrong type");
4326 oop method = mname->obj_field(_method_offset);
4327 return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4328 }
4329
4330 bool java_lang_invoke_MemberName::is_method(oop mname) {
4331 assert(is_instance(mname), "must be MemberName");
4332 return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4333 }
4334
4335 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4336 assert(is_instance(mname), "wrong type");
4337 mname->obj_field_put(_method_offset, resolved_method);
4338 }
4339
4340 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4341 assert(is_instance(mname), "wrong type");
4342 return (intptr_t) mname->address_field(_vmindex_offset);
4343 }
4344
4345 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4346 assert(is_instance(mname), "wrong type");
4347 mname->address_field_put(_vmindex_offset, (address) index);
4348 }
4349
4350
4351 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4352 assert(is_instance(resolved_method), "wrong type");
|
34 #include "classfile/javaThreadStatus.hpp"
35 #include "classfile/moduleEntry.hpp"
36 #include "classfile/stringTable.hpp"
37 #include "classfile/symbolTable.hpp"
38 #include "classfile/systemDictionary.hpp"
39 #include "classfile/vmClasses.hpp"
40 #include "classfile/vmSymbols.hpp"
41 #include "code/debugInfo.hpp"
42 #include "code/dependencyContext.hpp"
43 #include "code/pcDesc.hpp"
44 #include "gc/shared/collectedHeap.inline.hpp"
45 #include "interpreter/interpreter.hpp"
46 #include "interpreter/linkResolver.hpp"
47 #include "jvm.h"
48 #include "logging/log.hpp"
49 #include "logging/logStream.hpp"
50 #include "memory/oopFactory.hpp"
51 #include "memory/resourceArea.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/fieldStreams.inline.hpp"
54 #include "oops/flatArrayKlass.hpp"
55 #include "oops/inlineKlass.inline.hpp"
56 #include "oops/instanceKlass.inline.hpp"
57 #include "oops/instanceMirrorKlass.inline.hpp"
58 #include "oops/klass.hpp"
59 #include "oops/klass.inline.hpp"
60 #include "oops/method.inline.hpp"
61 #include "oops/objArrayKlass.hpp"
62 #include "oops/objArrayOop.inline.hpp"
63 #include "oops/oopCast.inline.hpp"
64 #include "oops/oop.inline.hpp"
65 #include "oops/symbol.hpp"
66 #include "oops/recordComponent.hpp"
67 #include "oops/typeArrayOop.inline.hpp"
68 #include "prims/jvmtiExport.hpp"
69 #include "prims/methodHandles.hpp"
70 #include "prims/resolvedMethodTable.hpp"
71 #include "runtime/continuationEntry.inline.hpp"
72 #include "runtime/continuationJavaClasses.inline.hpp"
73 #include "runtime/fieldDescriptor.inline.hpp"
74 #include "runtime/frame.inline.hpp"
75 #include "runtime/handles.inline.hpp"
76 #include "runtime/handshake.hpp"
77 #include "runtime/init.hpp"
765 bool is_latin1 = java_lang_String::is_latin1(java_string);
766
767 st->print("\"");
768 for (int index = 0; index < length; index++) {
769 st->print("%c", (!is_latin1) ? value->char_at(index) :
770 ((jchar) value->byte_at(index)) & 0xff );
771 }
772 st->print("\"");
773 }
774
775 // java_lang_Class
776
777 int java_lang_Class::_klass_offset;
778 int java_lang_Class::_array_klass_offset;
779 int java_lang_Class::_oop_size_offset;
780 int java_lang_Class::_static_oop_field_count_offset;
781 int java_lang_Class::_class_loader_offset;
782 int java_lang_Class::_module_offset;
783 int java_lang_Class::_protection_domain_offset;
784 int java_lang_Class::_component_mirror_offset;
785 int java_lang_Class::_primary_mirror_offset;
786 int java_lang_Class::_secondary_mirror_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
806
990 int computed_modifiers = k->compute_modifier_flags();
991 k->set_modifier_flags(computed_modifiers);
992 // Class_klass has to be loaded because it is used to allocate
993 // the mirror.
994 if (vmClasses::Class_klass_loaded()) {
995 // Allocate mirror (java.lang.Class instance)
996 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
997 Handle mirror(THREAD, mirror_oop);
998 Handle comp_mirror;
999
1000 // Setup indirection from mirror->klass
1001 set_klass(mirror(), k);
1002
1003 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1004 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1005
1006 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1007
1008 // It might also have a component mirror. This mirror must already exist.
1009 if (k->is_array_klass()) {
1010 if (k->is_flatArray_klass()) {
1011 Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1012 assert(element_klass->is_inline_klass(), "Must be inline type component");
1013 InlineKlass* vk = InlineKlass::cast(element_klass);
1014 comp_mirror = Handle(THREAD, vk->val_mirror());
1015 } else if (k->is_typeArray_klass()) {
1016 BasicType type = TypeArrayKlass::cast(k)->element_type();
1017 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1018 } else {
1019 assert(k->is_objArray_klass(), "Must be");
1020 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1021 assert(element_klass != NULL, "Must have an element klass");
1022 oop comp_oop = element_klass->java_mirror();
1023 if (element_klass->is_inline_klass()) {
1024 InlineKlass* ik = InlineKlass::cast(element_klass);
1025 comp_oop = k->name()->is_Q_array_signature() ? ik->val_mirror() : ik->ref_mirror();
1026 }
1027 comp_mirror = Handle(THREAD, comp_oop);
1028 }
1029 assert(comp_mirror() != NULL, "must have a mirror");
1030
1031 // Two-way link between the array klass and its component mirror:
1032 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1033 set_component_mirror(mirror(), comp_mirror());
1034 // See below for ordering dependencies between field array_klass in component mirror
1035 // and java_mirror in this klass.
1036 } else {
1037 assert(k->is_instance_klass(), "Must be");
1038
1039 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1040 if (HAS_PENDING_EXCEPTION) {
1041 // If any of the fields throws an exception like OOM remove the klass field
1042 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1043 // This mirror looks like a primitive type, which logically it is because it
1044 // it represents no class.
1045 set_klass(mirror(), NULL);
1046 return;
1047 }
1048 }
1049
1050 // set the classLoader field in the java_lang_Class instance
1051 assert(class_loader() == k->class_loader(), "should be same");
1052 set_class_loader(mirror(), class_loader());
1053
1054 // Setup indirection from klass->mirror
1055 // after any exceptions can happen during allocations.
1056 k->set_java_mirror(mirror);
1057
1058 // Set the module field in the java_lang_Class instance. This must be done
1059 // after the mirror is set.
1060 set_mirror_module_field(THREAD, k, mirror, module);
1061
1062 if (comp_mirror() != NULL) {
1063 // Set after k->java_mirror() is published, because compiled code running
1064 // concurrently doesn't expect a k to have a null java_mirror.
1065 release_set_array_klass(comp_mirror(), k);
1066 }
1067
1068 if (k->is_inline_klass()) {
1069 oop secondary_mirror = create_secondary_mirror(k, mirror, CHECK);
1070 set_primary_mirror(mirror(), mirror());
1071 set_secondary_mirror(mirror(), secondary_mirror);
1072 }
1073 } else {
1074 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1075 fixup_mirror_list()->push(k);
1076 }
1077 }
1078 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1079 // instance with the same value as the primary mirror
1080 oop java_lang_Class::create_secondary_mirror(Klass* k, Handle mirror, TRAPS) {
1081 assert(k->is_inline_klass(), "primitive class");
1082 // Allocate mirror (java.lang.Class instance)
1083 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK_0);
1084 Handle secondary_mirror(THREAD, mirror_oop);
1085
1086 java_lang_Class::set_klass(secondary_mirror(), k);
1087 java_lang_Class::set_static_oop_field_count(secondary_mirror(), static_oop_field_count(mirror()));
1088
1089 set_protection_domain(secondary_mirror(), protection_domain(mirror()));
1090 set_class_loader(secondary_mirror(), class_loader(mirror()));
1091 // ## handle if java.base is not yet defined
1092 set_module(secondary_mirror(), module(mirror()));
1093 set_primary_mirror(secondary_mirror(), mirror());
1094 set_secondary_mirror(secondary_mirror(), secondary_mirror());
1095 return secondary_mirror();
1096 }
1097
1098 #if INCLUDE_CDS_JAVA_HEAP
1099 // Clears mirror fields. Static final fields with initial values are reloaded
1100 // from constant pool. The object identity hash is in the object header and is
1101 // not affected.
1102 class ResetMirrorField: public FieldClosure {
1103 private:
1104 Handle _m;
1105
1106 public:
1107 ResetMirrorField(Handle mirror) : _m(mirror) {}
1108
1109 void do_field(fieldDescriptor* fd) {
1110 assert(DumpSharedSpaces, "dump time only");
1111 assert(_m.not_null(), "Mirror cannot be NULL");
1112
1113 if (fd->is_static() && fd->has_initial_value()) {
1114 initialize_static_field_for_dump(fd, _m);
1115 return;
1116 }
1124 _m()->char_field_put(fd->offset(), 0);
1125 break;
1126 case T_DOUBLE:
1127 _m()->double_field_put(fd->offset(), 0);
1128 break;
1129 case T_FLOAT:
1130 _m()->float_field_put(fd->offset(), 0);
1131 break;
1132 case T_INT:
1133 _m()->int_field_put(fd->offset(), 0);
1134 break;
1135 case T_LONG:
1136 _m()->long_field_put(fd->offset(), 0);
1137 break;
1138 case T_SHORT:
1139 _m()->short_field_put(fd->offset(), 0);
1140 break;
1141 case T_BOOLEAN:
1142 _m()->bool_field_put(fd->offset(), false);
1143 break;
1144 case T_PRIMITIVE_OBJECT:
1145 case T_ARRAY:
1146 case T_OBJECT: {
1147 // It might be useful to cache the String field, but
1148 // for now just clear out any reference field
1149 oop o = _m()->obj_field(fd->offset());
1150 _m()->obj_field_put(fd->offset(), NULL);
1151 break;
1152 }
1153 default:
1154 ShouldNotReachHere();
1155 break;
1156 }
1157 }
1158 };
1159
1160 void java_lang_Class::archive_basic_type_mirrors() {
1161 assert(HeapShared::can_write(), "must be");
1162
1163 for (int t = T_BOOLEAN; t < T_VOID+1; t++) {
1164 BasicType bt = (BasicType)t;
1201 }
1202
1203 // No mirror
1204 oop mirror = k->java_mirror();
1205 if (mirror == NULL) {
1206 return NULL;
1207 }
1208
1209 if (k->is_instance_klass()) {
1210 InstanceKlass *ik = InstanceKlass::cast(k);
1211 assert(ik->signers() == NULL, "class with signer should have been excluded");
1212
1213 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1214 ik->is_shared_app_class())) {
1215 // Archiving mirror for classes from non-builtin loaders is not
1216 // supported.
1217 return NULL;
1218 }
1219 }
1220
1221 if (k->is_inline_klass()) {
1222 // Inline types have a primary mirror and a secondary mirror. Don't handle this for now. TODO:CDS
1223 k->clear_java_mirror_handle();
1224 return NULL;
1225 }
1226
1227 // Now start archiving the mirror object
1228 oop archived_mirror = HeapShared::archive_object(mirror);
1229 if (archived_mirror == NULL) {
1230 return NULL;
1231 }
1232
1233 archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1234 if (archived_mirror == NULL) {
1235 return NULL;
1236 }
1237
1238 k->set_archived_java_mirror(archived_mirror);
1239
1240 ResourceMark rm;
1241 log_trace(cds, heap, mirror)(
1242 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1243 k->external_name(), p2i(mirror), p2i(archived_mirror));
1244
1245 return archived_mirror;
1246 }
1368 }
1369
1370 oop java_lang_Class::protection_domain(oop java_class) {
1371 assert(_protection_domain_offset != 0, "must be set");
1372 return java_class->obj_field(_protection_domain_offset);
1373 }
1374 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1375 assert(_protection_domain_offset != 0, "must be set");
1376 java_class->obj_field_put(_protection_domain_offset, pd);
1377 }
1378
1379 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1380 assert(_component_mirror_offset != 0, "must be set");
1381 java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1382 }
1383 oop java_lang_Class::component_mirror(oop java_class) {
1384 assert(_component_mirror_offset != 0, "must be set");
1385 return java_class->obj_field(_component_mirror_offset);
1386 }
1387
1388 oop java_lang_Class::primary_mirror(oop java_class) {
1389 assert(_primary_mirror_offset != 0, "must be set");
1390 return java_class->obj_field(_primary_mirror_offset);
1391 }
1392
1393 void java_lang_Class::set_primary_mirror(oop java_class, oop mirror) {
1394 assert(_primary_mirror_offset != 0, "must be set");
1395 java_class->obj_field_put(_primary_mirror_offset, mirror);
1396 }
1397
1398 oop java_lang_Class::secondary_mirror(oop java_class) {
1399 assert(_secondary_mirror_offset != 0, "must be set");
1400 return java_class->obj_field(_secondary_mirror_offset);
1401 }
1402
1403 void java_lang_Class::set_secondary_mirror(oop java_class, oop mirror) {
1404 assert(_secondary_mirror_offset != 0, "must be set");
1405 java_class->obj_field_put(_secondary_mirror_offset, mirror);
1406 }
1407
1408 objArrayOop java_lang_Class::signers(oop java_class) {
1409 assert(_signers_offset != 0, "must be set");
1410 return (objArrayOop)java_class->obj_field(_signers_offset);
1411 }
1412 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1413 assert(_signers_offset != 0, "must be set");
1414 java_class->obj_field_put(_signers_offset, signers);
1415 }
1416
1417 oop java_lang_Class::class_data(oop java_class) {
1418 assert(_classData_offset != 0, "must be set");
1419 return java_class->obj_field(_classData_offset);
1420 }
1421 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1422 assert(_classData_offset != 0, "must be set");
1423 java_class->obj_field_put(_classData_offset, class_data);
1424 }
1425
1426 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1427 assert(_class_loader_offset != 0, "offsets should have been initialized");
1472 assert(aklass != NULL, "correct bootstrap");
1473 release_set_array_klass(java_class, aklass);
1474 }
1475 #ifdef ASSERT
1476 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1477 assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1478 #endif
1479 return java_class;
1480 }
1481
1482 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1483 assert(is_instance(java_class), "must be a Class object");
1484 java_class->metadata_field_put(_klass_offset, klass);
1485 }
1486
1487
1488 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1489 assert(is_instance(java_class), "must be a Class object");
1490 Symbol* name = NULL;
1491 bool is_instance = false;
1492 bool is_Q_descriptor = 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_Q_descriptor = k->is_inline_klass() && is_secondary_mirror(java_class);
1499 name = k->name();
1500 }
1501 if (name == NULL) {
1502 st->print("<null>");
1503 return;
1504 }
1505 if (is_instance) {
1506 st->print(is_Q_descriptor ? "Q" : "L");
1507 }
1508 st->write((char*) name->base(), (int) name->utf8_length());
1509 if (is_instance) st->print(";");
1510 }
1511
1512 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1513 assert(is_instance(java_class), "must be a Class object");
1514 Symbol* name;
1515 if (is_primitive(java_class)) {
1516 name = vmSymbols::type_signature(primitive_type(java_class));
1517 // Because this can create a new symbol, the caller has to decrement
1518 // the refcount, so make adjustment here and below for symbols returned
1519 // that are not created or incremented due to a successful lookup.
1520 name->increment_refcount();
1521 } else {
1522 Klass* k = as_Klass(java_class);
1523 if (!k->is_instance_klass()) {
1524 name = k->name();
1525 name->increment_refcount();
1526 } else {
1527 ResourceMark rm;
1528 const char* sigstr;
1529 if (k->is_inline_klass() && is_secondary_mirror(java_class)) {
1530 sigstr = InlineKlass::cast(k)->val_signature_name();
1531 } else {
1532 sigstr = k->signature_name();
1533 }
1534 int siglen = (int) strlen(sigstr);
1535 if (!intern_if_not_found) {
1536 name = SymbolTable::probe(sigstr, siglen);
1537 } else {
1538 name = SymbolTable::new_symbol(sigstr, siglen);
1539 }
1540 }
1541 }
1542 return name;
1543 }
1544
1545 // Returns the Java name for this Java mirror (Resource allocated)
1546 // See Klass::external_name().
1547 // For primitive type Java mirrors, its type name is returned.
1548 const char* java_lang_Class::as_external_name(oop java_class) {
1549 assert(is_instance(java_class), "must be a Class object");
1550 const char* name = NULL;
1551 if (is_primitive(java_class)) {
1552 name = type2name(primitive_type(java_class));
1553 } else {
1554 name = as_Klass(java_class)->external_name();
1594 return primitive_type(java_class);
1595 } else {
1596 if (reference_klass != NULL)
1597 (*reference_klass) = as_Klass(java_class);
1598 return T_OBJECT;
1599 }
1600 }
1601
1602
1603 oop java_lang_Class::primitive_mirror(BasicType t) {
1604 oop mirror = Universe::java_mirror(t);
1605 assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1606 assert(is_primitive(mirror), "must be primitive");
1607 return mirror;
1608 }
1609
1610 #define CLASS_FIELDS_DO(macro) \
1611 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1612 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1613 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1614 macro(_primary_mirror_offset, k, "primaryType", class_signature, false); \
1615 macro(_secondary_mirror_offset, k, "secondaryType", class_signature, false); \
1616 macro(_module_offset, k, "module", module_signature, false); \
1617 macro(_name_offset, k, "name", string_signature, false); \
1618 macro(_classData_offset, k, "classData", object_signature, false);
1619
1620 void java_lang_Class::compute_offsets() {
1621 if (_offsets_computed) {
1622 return;
1623 }
1624
1625 _offsets_computed = true;
1626
1627 InstanceKlass* k = vmClasses::Class_klass();
1628 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1629
1630 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1631 }
1632
1633 #if INCLUDE_CDS
1634 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1635 f->do_bool(&_offsets_computed);
2795
2796 // the format of the stacktrace will be:
2797 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2798 // - 0 or more <init> methods for the exception class (skipped)
2799 // - rest of the stack
2800
2801 if (!skip_fillInStackTrace_check) {
2802 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2803 throwable->is_a(method->method_holder())) {
2804 continue;
2805 }
2806 else {
2807 skip_fillInStackTrace_check = true; // gone past them all
2808 }
2809 }
2810 if (!skip_throwableInit_check) {
2811 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2812
2813 // skip <init> methods of the exception class and superclasses
2814 // This is similar to classic VM.
2815 if (method->is_object_constructor() &&
2816 throwable->is_a(method->method_holder())) {
2817 continue;
2818 } else {
2819 // there are none or we've seen them all - either way stop checking
2820 skip_throwableInit_check = true;
2821 }
2822 }
2823 if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2824 if (skip_hidden) {
2825 if (total_count == 0) {
2826 // The top frame will be hidden from the stack trace.
2827 bt.set_has_hidden_top_frame();
2828 }
2829 continue;
2830 }
2831 }
2832
2833 bt.push(method, bci, CHECK);
2834 total_count++;
2835 }
4389 int java_lang_invoke_MemberName::flags(oop mname) {
4390 assert(is_instance(mname), "wrong type");
4391 return mname->int_field(_flags_offset);
4392 }
4393
4394 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4395 assert(is_instance(mname), "wrong type");
4396 mname->int_field_put(_flags_offset, flags);
4397 }
4398
4399
4400 // Return vmtarget from ResolvedMethodName method field through indirection
4401 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4402 assert(is_instance(mname), "wrong type");
4403 oop method = mname->obj_field(_method_offset);
4404 return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4405 }
4406
4407 bool java_lang_invoke_MemberName::is_method(oop mname) {
4408 assert(is_instance(mname), "must be MemberName");
4409 return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4410 }
4411
4412 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4413 assert(is_instance(mname), "wrong type");
4414 mname->obj_field_put(_method_offset, resolved_method);
4415 }
4416
4417 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4418 assert(is_instance(mname), "wrong type");
4419 return (intptr_t) mname->address_field(_vmindex_offset);
4420 }
4421
4422 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4423 assert(is_instance(mname), "wrong type");
4424 mname->address_field_put(_vmindex_offset, (address) index);
4425 }
4426
4427
4428 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4429 assert(is_instance(resolved_method), "wrong type");
|