< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

  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/fieldInfo.hpp"
  54 #include "oops/fieldStreams.inline.hpp"


  55 #include "oops/instanceKlass.inline.hpp"
  56 #include "oops/instanceMirrorKlass.hpp"
  57 #include "oops/klass.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/method.inline.hpp"
  60 #include "oops/objArrayKlass.hpp"
  61 #include "oops/objArrayOop.inline.hpp"
  62 #include "oops/oopCast.inline.hpp"
  63 #include "oops/oop.inline.hpp"
  64 #include "oops/symbol.hpp"
  65 #include "oops/recordComponent.hpp"
  66 #include "oops/typeArrayOop.inline.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/methodHandles.hpp"
  69 #include "prims/resolvedMethodTable.hpp"
  70 #include "runtime/continuationEntry.inline.hpp"
  71 #include "runtime/continuationJavaClasses.inline.hpp"
  72 #include "runtime/fieldDescriptor.inline.hpp"
  73 #include "runtime/frame.inline.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/handshake.hpp"
  76 #include "runtime/init.hpp"

 770                              ((jchar) value->byte_at(index)) & 0xff;
 771     if (c < ' ') {
 772       st->print("\\x%02X", c); // print control characters e.g. \x0A
 773     } else {
 774       st->print("%c", c);
 775     }
 776   }
 777   st->print("\"");
 778 }
 779 
 780 // java_lang_Class
 781 
 782 int java_lang_Class::_klass_offset;
 783 int java_lang_Class::_array_klass_offset;
 784 int java_lang_Class::_oop_size_offset;
 785 int java_lang_Class::_static_oop_field_count_offset;
 786 int java_lang_Class::_class_loader_offset;
 787 int java_lang_Class::_module_offset;
 788 int java_lang_Class::_protection_domain_offset;
 789 int java_lang_Class::_component_mirror_offset;


 790 int java_lang_Class::_signers_offset;
 791 int java_lang_Class::_name_offset;
 792 int java_lang_Class::_source_file_offset;
 793 int java_lang_Class::_classData_offset;
 794 int java_lang_Class::_classRedefinedCount_offset;
 795 
 796 bool java_lang_Class::_offsets_computed = false;
 797 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = nullptr;
 798 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = nullptr;
 799 
 800 #ifdef ASSERT
 801 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
 802   assert(fd->has_initial_value(), "caller should have checked this");
 803   assert(fd->field_type() == T_OBJECT, "caller should have checked this");
 804   // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated
 805   // during DumpSharedSpaces
 806   assert(fd->signature()->equals("Ljava/lang/String;"), "just checking");
 807 }
 808 #endif
 809 

 971     new (mtModule) GrowableArray<Klass*>(500, mtModule);
 972   set_fixup_module_field_list(module_list);
 973 }
 974 
 975 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
 976                                       Handle& mirror, Handle& comp_mirror, TRAPS) {
 977   // Allocate mirror (java.lang.Class instance)
 978   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
 979   mirror = Handle(THREAD, mirror_oop);
 980 
 981   // Setup indirection from mirror->klass
 982   set_klass(mirror(), k);
 983 
 984   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 985   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 986 
 987   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 988 
 989   // It might also have a component mirror.  This mirror must already exist.
 990   if (k->is_array_klass()) {
 991     if (k->is_typeArray_klass()) {









 992       BasicType type = TypeArrayKlass::cast(k)->element_type();
 993       if (is_scratch) {
 994         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
 995       } else {
 996         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
 997       }
 998     } else {
 999       assert(k->is_objArray_klass(), "Must be");
1000       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1001       assert(element_klass != nullptr, "Must have an element klass");





1002       if (is_scratch) {
1003         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1004       } else {
1005         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1006       }
1007     }
1008     assert(comp_mirror() != nullptr, "must have a mirror");
1009 
1010     // Two-way link between the array klass and its component mirror:
1011     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1012     set_component_mirror(mirror(), comp_mirror());
1013     // See below for ordering dependencies between field array_klass in component mirror
1014     // and java_mirror in this klass.
1015   } else {
1016     assert(k->is_instance_klass(), "Must be");
1017 
1018     initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1019     if (HAS_PENDING_EXCEPTION) {
1020       // If any of the fields throws an exception like OOM remove the klass field
1021       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1022       // This mirror looks like a primitive type, which logically it is because it
1023       // it represents no class.
1024       set_klass(mirror(), nullptr);
1025       return;

1047 
1048     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
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() != nullptr) {
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     if (DumpSharedSpaces) {
1068       create_scratch_mirror(k, CHECK);
1069     }
1070   } else {
1071     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1072     fixup_mirror_list()->push(k);
1073   }
1074 }



















1075 
1076 #if INCLUDE_CDS_JAVA_HEAP
1077 // The "scratch mirror" stores the states of the mirror object that can be
1078 // decided at dump time (such as the initial values of the static fields, the
1079 // component mirror, etc). At runtime, more information is added to it by
1080 // java_lang_Class::restore_archived_mirror().
1081 //
1082 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1083 // produces the same result as /*runtime*/create_mirror().
1084 //
1085 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1086 // latter may contain dumptime-specific information that cannot be archived
1087 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1088 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1089   if (k->class_loader() != nullptr &&
1090       k->class_loader() != SystemDictionary::java_platform_loader() &&
1091       k->class_loader() != SystemDictionary::java_system_loader()) {





1092     // We only archive the mirrors of classes loaded by the built-in loaders
1093     return;
1094   }
1095 
1096   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1097   Handle mirror;
1098   Handle comp_mirror;
1099   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1100 
1101   if (comp_mirror() != nullptr) {
1102     release_set_array_klass(comp_mirror(), k);
1103   }
1104 
1105   HeapShared::set_scratch_java_mirror(k, mirror());
1106 }
1107 
1108 // Returns true if the mirror is updated, false if no archived mirror
1109 // data is present. After the archived mirror object is restored, the
1110 // shared klass' _has_raw_archived_mirror flag is cleared.
1111 bool java_lang_Class::restore_archived_mirror(Klass *k,

1180 }
1181 
1182 oop java_lang_Class::protection_domain(oop java_class) {
1183   assert(_protection_domain_offset != 0, "must be set");
1184   return java_class->obj_field(_protection_domain_offset);
1185 }
1186 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1187   assert(_protection_domain_offset != 0, "must be set");
1188   java_class->obj_field_put(_protection_domain_offset, pd);
1189 }
1190 
1191 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1192   assert(_component_mirror_offset != 0, "must be set");
1193     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1194   }
1195 oop java_lang_Class::component_mirror(oop java_class) {
1196   assert(_component_mirror_offset != 0, "must be set");
1197   return java_class->obj_field(_component_mirror_offset);
1198 }
1199 




















1200 objArrayOop java_lang_Class::signers(oop java_class) {
1201   assert(_signers_offset != 0, "must be set");
1202   return (objArrayOop)java_class->obj_field(_signers_offset);
1203 }
1204 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1205   assert(_signers_offset != 0, "must be set");
1206   java_class->obj_field_put(_signers_offset, signers);
1207 }
1208 
1209 oop java_lang_Class::class_data(oop java_class) {
1210   assert(_classData_offset != 0, "must be set");
1211   return java_class->obj_field(_classData_offset);
1212 }
1213 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1214   assert(_classData_offset != 0, "must be set");
1215   java_class->obj_field_put(_classData_offset, class_data);
1216 }
1217 
1218 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1219   assert(_class_loader_offset != 0, "offsets should have been initialized");

1264     assert(aklass != nullptr, "correct bootstrap");
1265     release_set_array_klass(java_class, aklass);
1266   }
1267 #ifdef ASSERT
1268   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1269   assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1270 #endif
1271   return java_class;
1272 }
1273 
1274 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1275   assert(is_instance(java_class), "must be a Class object");
1276   java_class->metadata_field_put(_klass_offset, klass);
1277 }
1278 
1279 
1280 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1281   assert(is_instance(java_class), "must be a Class object");
1282   Symbol* name = nullptr;
1283   bool is_instance = false;

1284   if (is_primitive(java_class)) {
1285     name = vmSymbols::type_signature(primitive_type(java_class));
1286   } else {
1287     Klass* k = as_Klass(java_class);
1288     is_instance = k->is_instance_klass();

1289     name = k->name();
1290   }
1291   if (name == nullptr) {
1292     st->print("<null>");
1293     return;
1294   }
1295   if (is_instance)  st->print("L");


1296   st->write((char*) name->base(), (int) name->utf8_length());
1297   if (is_instance)  st->print(";");
1298 }
1299 
1300 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1301   assert(is_instance(java_class), "must be a Class object");
1302   Symbol* name;
1303   if (is_primitive(java_class)) {
1304     name = vmSymbols::type_signature(primitive_type(java_class));
1305     // Because this can create a new symbol, the caller has to decrement
1306     // the refcount, so make adjustment here and below for symbols returned
1307     // that are not created or incremented due to a successful lookup.
1308     name->increment_refcount();
1309   } else {
1310     Klass* k = as_Klass(java_class);
1311     if (!k->is_instance_klass()) {
1312       name = k->name();
1313       name->increment_refcount();
1314     } else {
1315       ResourceMark rm;
1316       const char* sigstr = k->signature_name();
1317       int         siglen = (int) strlen(sigstr);





1318       if (!intern_if_not_found) {
1319         name = SymbolTable::probe(sigstr, siglen);
1320       } else {
1321         name = SymbolTable::new_symbol(sigstr, siglen);
1322       }
1323     }
1324   }
1325   return name;
1326 }
1327 
1328 // Returns the Java name for this Java mirror (Resource allocated)
1329 // See Klass::external_name().
1330 // For primitive type Java mirrors, its type name is returned.
1331 const char* java_lang_Class::as_external_name(oop java_class) {
1332   assert(is_instance(java_class), "must be a Class object");
1333   const char* name = nullptr;
1334   if (is_primitive(java_class)) {
1335     name = type2name(primitive_type(java_class));
1336   } else {
1337     name = as_Klass(java_class)->external_name();

1385     return primitive_type(java_class);
1386   } else {
1387     if (reference_klass != nullptr)
1388       (*reference_klass) = as_Klass(java_class);
1389     return T_OBJECT;
1390   }
1391 }
1392 
1393 
1394 oop java_lang_Class::primitive_mirror(BasicType t) {
1395   oop mirror = Universe::java_mirror(t);
1396   assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1397   assert(is_primitive(mirror), "must be primitive");
1398   return mirror;
1399 }
1400 
1401 #define CLASS_FIELDS_DO(macro) \
1402   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1403   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1404   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \


1405   macro(_module_offset,              k, "module",              module_signature,      false); \
1406   macro(_name_offset,                k, "name",                string_signature,      false); \
1407   macro(_classData_offset,           k, "classData",           object_signature,      false);
1408 
1409 void java_lang_Class::compute_offsets() {
1410   if (_offsets_computed) {
1411     return;
1412   }
1413 
1414   _offsets_computed = true;
1415 
1416   InstanceKlass* k = vmClasses::Class_klass();
1417   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1418 
1419   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1420 }
1421 
1422 #if INCLUDE_CDS
1423 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1424   f->do_bool(&_offsets_computed);

2602 
2603     // the format of the stacktrace will be:
2604     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2605     // - 0 or more <init> methods for the exception class (skipped)
2606     // - rest of the stack
2607 
2608     if (!skip_fillInStackTrace_check) {
2609       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2610           throwable->is_a(method->method_holder())) {
2611         continue;
2612       }
2613       else {
2614         skip_fillInStackTrace_check = true; // gone past them all
2615       }
2616     }
2617     if (!skip_throwableInit_check) {
2618       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2619 
2620       // skip <init> methods of the exception class and superclasses
2621       // This is similar to classic VM.
2622       if (method->name() == vmSymbols::object_initializer_name() &&
2623           throwable->is_a(method->method_holder())) {
2624         continue;
2625       } else {
2626         // there are none or we've seen them all - either way stop checking
2627         skip_throwableInit_check = true;
2628       }
2629     }
2630     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2631       if (skip_hidden) {
2632         if (total_count == 0) {
2633           // The top frame will be hidden from the stack trace.
2634           bt.set_has_hidden_top_frame();
2635         }
2636         continue;
2637       }
2638     }
2639 
2640     bt.push(method, bci, CHECK);
2641     total_count++;
2642   }

2961 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
2962 int java_lang_ClassFrameInfo::_flags_offset;
2963 
2964 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
2965   macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature,  false); \
2966   macro(_flags_offset,             k, vmSymbols::flags_name(), int_signature, false)
2967 
2968 void java_lang_ClassFrameInfo::compute_offsets() {
2969   InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
2970   CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2971 }
2972 
2973 #if INCLUDE_CDS
2974 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
2975   CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
2976 }
2977 #endif
2978 
2979 static int get_flags(const methodHandle& m) {
2980   int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
2981   if (m->is_initializer()) {
2982     flags |= java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR;
2983   } else {
2984     flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
2985   }
2986   if (m->caller_sensitive()) {
2987     flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
2988   }
2989   if (m->is_hidden()) {
2990     flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
2991   }
2992   assert((flags & 0xFF000000) == 0, "unexpected flags");
2993   return flags;
2994 }
2995 
2996 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
2997   return obj->obj_field(_classOrMemberName_offset);
2998 }
2999 
3000 int java_lang_ClassFrameInfo::flags(oop obj) {
3001   return obj->int_field(_flags_offset);
3002 }

4270 int java_lang_invoke_MemberName::flags(oop mname) {
4271   assert(is_instance(mname), "wrong type");
4272   return mname->int_field(_flags_offset);
4273 }
4274 
4275 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4276   assert(is_instance(mname), "wrong type");
4277   mname->int_field_put(_flags_offset, flags);
4278 }
4279 
4280 
4281 // Return vmtarget from ResolvedMethodName method field through indirection
4282 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4283   assert(is_instance(mname), "wrong type");
4284   oop method = mname->obj_field(_method_offset);
4285   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4286 }
4287 
4288 bool java_lang_invoke_MemberName::is_method(oop mname) {
4289   assert(is_instance(mname), "must be MemberName");
4290   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4291 }
4292 
4293 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4294   assert(is_instance(mname), "wrong type");
4295   mname->obj_field_put(_method_offset, resolved_method);
4296 }
4297 
4298 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4299   assert(is_instance(mname), "wrong type");
4300   return (intptr_t) mname->address_field(_vmindex_offset);
4301 }
4302 
4303 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4304   assert(is_instance(mname), "wrong type");
4305   mname->address_field_put(_vmindex_offset, (address) index);
4306 }
4307 
4308 
4309 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4310   assert(is_instance(resolved_method), "wrong type");

  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/fieldInfo.hpp"
  54 #include "oops/fieldStreams.inline.hpp"
  55 #include "oops/flatArrayKlass.hpp"
  56 #include "oops/inlineKlass.inline.hpp"
  57 #include "oops/instanceKlass.inline.hpp"
  58 #include "oops/instanceMirrorKlass.inline.hpp"
  59 #include "oops/klass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/objArrayKlass.hpp"
  63 #include "oops/objArrayOop.inline.hpp"
  64 #include "oops/oopCast.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/symbol.hpp"
  67 #include "oops/recordComponent.hpp"
  68 #include "oops/typeArrayOop.inline.hpp"
  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/methodHandles.hpp"
  71 #include "prims/resolvedMethodTable.hpp"
  72 #include "runtime/continuationEntry.inline.hpp"
  73 #include "runtime/continuationJavaClasses.inline.hpp"
  74 #include "runtime/fieldDescriptor.inline.hpp"
  75 #include "runtime/frame.inline.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/handshake.hpp"
  78 #include "runtime/init.hpp"

 772                              ((jchar) value->byte_at(index)) & 0xff;
 773     if (c < ' ') {
 774       st->print("\\x%02X", c); // print control characters e.g. \x0A
 775     } else {
 776       st->print("%c", c);
 777     }
 778   }
 779   st->print("\"");
 780 }
 781 
 782 // java_lang_Class
 783 
 784 int java_lang_Class::_klass_offset;
 785 int java_lang_Class::_array_klass_offset;
 786 int java_lang_Class::_oop_size_offset;
 787 int java_lang_Class::_static_oop_field_count_offset;
 788 int java_lang_Class::_class_loader_offset;
 789 int java_lang_Class::_module_offset;
 790 int java_lang_Class::_protection_domain_offset;
 791 int java_lang_Class::_component_mirror_offset;
 792 int java_lang_Class::_primary_mirror_offset;
 793 int java_lang_Class::_secondary_mirror_offset;
 794 int java_lang_Class::_signers_offset;
 795 int java_lang_Class::_name_offset;
 796 int java_lang_Class::_source_file_offset;
 797 int java_lang_Class::_classData_offset;
 798 int java_lang_Class::_classRedefinedCount_offset;
 799 
 800 bool java_lang_Class::_offsets_computed = false;
 801 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = nullptr;
 802 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = nullptr;
 803 
 804 #ifdef ASSERT
 805 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
 806   assert(fd->has_initial_value(), "caller should have checked this");
 807   assert(fd->field_type() == T_OBJECT, "caller should have checked this");
 808   // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated
 809   // during DumpSharedSpaces
 810   assert(fd->signature()->equals("Ljava/lang/String;"), "just checking");
 811 }
 812 #endif
 813 

 975     new (mtModule) GrowableArray<Klass*>(500, mtModule);
 976   set_fixup_module_field_list(module_list);
 977 }
 978 
 979 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
 980                                       Handle& mirror, Handle& comp_mirror, TRAPS) {
 981   // Allocate mirror (java.lang.Class instance)
 982   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
 983   mirror = Handle(THREAD, mirror_oop);
 984 
 985   // Setup indirection from mirror->klass
 986   set_klass(mirror(), k);
 987 
 988   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 989   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 990 
 991   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 992 
 993   // It might also have a component mirror.  This mirror must already exist.
 994   if (k->is_array_klass()) {
 995     if (k->is_flatArray_klass()) {
 996       Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
 997       assert(element_klass->is_inline_klass(), "Must be inline type component");
 998       if (is_scratch) {
 999         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1000       } else {
1001         InlineKlass* vk = InlineKlass::cast(element_klass);
1002         comp_mirror = Handle(THREAD, vk->val_mirror());
1003       }
1004     } else if (k->is_typeArray_klass()) {
1005       BasicType type = TypeArrayKlass::cast(k)->element_type();
1006       if (is_scratch) {
1007         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1008       } else {
1009         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1010       }
1011     } else {
1012       assert(k->is_objArray_klass(), "Must be");
1013       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1014       assert(element_klass != nullptr, "Must have an element klass");
1015       oop comp_oop = element_klass->java_mirror();
1016       if (element_klass->is_inline_klass()) {
1017         InlineKlass* ik = InlineKlass::cast(element_klass);
1018         comp_oop = k->name()->is_Q_array_signature() ? ik->val_mirror() : ik->ref_mirror();
1019       }
1020       if (is_scratch) {
1021         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1022       } else {
1023         comp_mirror = Handle(THREAD, comp_oop);
1024       }
1025     }
1026     assert(comp_mirror() != nullptr, "must have a mirror");
1027 
1028     // Two-way link between the array klass and its component mirror:
1029     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1030     set_component_mirror(mirror(), comp_mirror());
1031     // See below for ordering dependencies between field array_klass in component mirror
1032     // and java_mirror in this klass.
1033   } else {
1034     assert(k->is_instance_klass(), "Must be");
1035 
1036     initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1037     if (HAS_PENDING_EXCEPTION) {
1038       // If any of the fields throws an exception like OOM remove the klass field
1039       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1040       // This mirror looks like a primitive type, which logically it is because it
1041       // it represents no class.
1042       set_klass(mirror(), nullptr);
1043       return;

1065 
1066     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1067 
1068     // set the classLoader field in the java_lang_Class instance
1069     assert(class_loader() == k->class_loader(), "should be same");
1070     set_class_loader(mirror(), class_loader());
1071 
1072     // Setup indirection from klass->mirror
1073     // after any exceptions can happen during allocations.
1074     k->set_java_mirror(mirror);
1075 
1076     // Set the module field in the java_lang_Class instance.  This must be done
1077     // after the mirror is set.
1078     set_mirror_module_field(THREAD, k, mirror, module);
1079 
1080     if (comp_mirror() != nullptr) {
1081       // Set after k->java_mirror() is published, because compiled code running
1082       // concurrently doesn't expect a k to have a null java_mirror.
1083       release_set_array_klass(comp_mirror(), k);
1084     }
1085 
1086     if (k->is_inline_klass()) {
1087       oop secondary_mirror = create_secondary_mirror(k, mirror, CHECK);
1088       set_primary_mirror(mirror(), mirror());
1089       set_secondary_mirror(mirror(), secondary_mirror);
1090     }
1091     if (DumpSharedSpaces) {
1092       create_scratch_mirror(k, CHECK);
1093     }
1094   } else {
1095     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1096     fixup_mirror_list()->push(k);
1097   }
1098 }
1099 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1100 // instance with the same value as the primary mirror
1101 oop java_lang_Class::create_secondary_mirror(Klass* k, Handle mirror, TRAPS) {
1102   assert(k->is_inline_klass(), "primitive class");
1103   // Allocate mirror (java.lang.Class instance)
1104   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK_0);
1105   Handle secondary_mirror(THREAD, mirror_oop);
1106 
1107   java_lang_Class::set_klass(secondary_mirror(), k);
1108   java_lang_Class::set_static_oop_field_count(secondary_mirror(), static_oop_field_count(mirror()));
1109 
1110   set_protection_domain(secondary_mirror(), protection_domain(mirror()));
1111   set_class_loader(secondary_mirror(), class_loader(mirror()));
1112   // ## handle if java.base is not yet defined
1113   set_module(secondary_mirror(), module(mirror()));
1114   set_primary_mirror(secondary_mirror(), mirror());
1115   set_secondary_mirror(secondary_mirror(), secondary_mirror());
1116   return secondary_mirror();
1117 }
1118 
1119 #if INCLUDE_CDS_JAVA_HEAP
1120 // The "scratch mirror" stores the states of the mirror object that can be
1121 // decided at dump time (such as the initial values of the static fields, the
1122 // component mirror, etc). At runtime, more information is added to it by
1123 // java_lang_Class::restore_archived_mirror().
1124 //
1125 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1126 // produces the same result as /*runtime*/create_mirror().
1127 //
1128 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1129 // latter may contain dumptime-specific information that cannot be archived
1130 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1131 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1132   // Inline classes encapsulate two mirror objects, a value mirror (primitive value mirror)
1133   // and a reference mirror (primitive class mirror), skip over scratch mirror allocation
1134   // for inline classes, they will not be part of shared archive and will be created while
1135   // restoring unshared fileds. Refer Klass::restore_unshareable_info() for more details.
1136   if (k->is_inline_klass() ||
1137       (k->class_loader() != nullptr &&
1138        k->class_loader() != SystemDictionary::java_platform_loader() &&
1139        k->class_loader() != SystemDictionary::java_system_loader())) {
1140     // We only archive the mirrors of classes loaded by the built-in loaders
1141     return;
1142   }
1143 
1144   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1145   Handle mirror;
1146   Handle comp_mirror;
1147   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1148 
1149   if (comp_mirror() != nullptr) {
1150     release_set_array_klass(comp_mirror(), k);
1151   }
1152 
1153   HeapShared::set_scratch_java_mirror(k, mirror());
1154 }
1155 
1156 // Returns true if the mirror is updated, false if no archived mirror
1157 // data is present. After the archived mirror object is restored, the
1158 // shared klass' _has_raw_archived_mirror flag is cleared.
1159 bool java_lang_Class::restore_archived_mirror(Klass *k,

1228 }
1229 
1230 oop java_lang_Class::protection_domain(oop java_class) {
1231   assert(_protection_domain_offset != 0, "must be set");
1232   return java_class->obj_field(_protection_domain_offset);
1233 }
1234 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1235   assert(_protection_domain_offset != 0, "must be set");
1236   java_class->obj_field_put(_protection_domain_offset, pd);
1237 }
1238 
1239 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1240   assert(_component_mirror_offset != 0, "must be set");
1241     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1242   }
1243 oop java_lang_Class::component_mirror(oop java_class) {
1244   assert(_component_mirror_offset != 0, "must be set");
1245   return java_class->obj_field(_component_mirror_offset);
1246 }
1247 
1248 oop java_lang_Class::primary_mirror(oop java_class) {
1249   assert(_primary_mirror_offset != 0, "must be set");
1250   return java_class->obj_field(_primary_mirror_offset);
1251 }
1252 
1253 void java_lang_Class::set_primary_mirror(oop java_class, oop mirror) {
1254   assert(_primary_mirror_offset != 0, "must be set");
1255   java_class->obj_field_put(_primary_mirror_offset, mirror);
1256 }
1257 
1258 oop java_lang_Class::secondary_mirror(oop java_class) {
1259   assert(_secondary_mirror_offset != 0, "must be set");
1260   return java_class->obj_field(_secondary_mirror_offset);
1261 }
1262 
1263 void java_lang_Class::set_secondary_mirror(oop java_class, oop mirror) {
1264   assert(_secondary_mirror_offset != 0, "must be set");
1265   java_class->obj_field_put(_secondary_mirror_offset, mirror);
1266 }
1267 
1268 objArrayOop java_lang_Class::signers(oop java_class) {
1269   assert(_signers_offset != 0, "must be set");
1270   return (objArrayOop)java_class->obj_field(_signers_offset);
1271 }
1272 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1273   assert(_signers_offset != 0, "must be set");
1274   java_class->obj_field_put(_signers_offset, signers);
1275 }
1276 
1277 oop java_lang_Class::class_data(oop java_class) {
1278   assert(_classData_offset != 0, "must be set");
1279   return java_class->obj_field(_classData_offset);
1280 }
1281 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1282   assert(_classData_offset != 0, "must be set");
1283   java_class->obj_field_put(_classData_offset, class_data);
1284 }
1285 
1286 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1287   assert(_class_loader_offset != 0, "offsets should have been initialized");

1332     assert(aklass != nullptr, "correct bootstrap");
1333     release_set_array_klass(java_class, aklass);
1334   }
1335 #ifdef ASSERT
1336   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1337   assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1338 #endif
1339   return java_class;
1340 }
1341 
1342 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1343   assert(is_instance(java_class), "must be a Class object");
1344   java_class->metadata_field_put(_klass_offset, klass);
1345 }
1346 
1347 
1348 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1349   assert(is_instance(java_class), "must be a Class object");
1350   Symbol* name = nullptr;
1351   bool is_instance = false;
1352   bool is_Q_descriptor = false;
1353   if (is_primitive(java_class)) {
1354     name = vmSymbols::type_signature(primitive_type(java_class));
1355   } else {
1356     Klass* k = as_Klass(java_class);
1357     is_instance = k->is_instance_klass();
1358     is_Q_descriptor = k->is_inline_klass() && is_secondary_mirror(java_class);
1359     name = k->name();
1360   }
1361   if (name == nullptr) {
1362     st->print("<null>");
1363     return;
1364   }
1365   if (is_instance)  {
1366     st->print(is_Q_descriptor ? "Q" : "L");
1367   }
1368   st->write((char*) name->base(), (int) name->utf8_length());
1369   if (is_instance)  st->print(";");
1370 }
1371 
1372 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1373   assert(is_instance(java_class), "must be a Class object");
1374   Symbol* name;
1375   if (is_primitive(java_class)) {
1376     name = vmSymbols::type_signature(primitive_type(java_class));
1377     // Because this can create a new symbol, the caller has to decrement
1378     // the refcount, so make adjustment here and below for symbols returned
1379     // that are not created or incremented due to a successful lookup.
1380     name->increment_refcount();
1381   } else {
1382     Klass* k = as_Klass(java_class);
1383     if (!k->is_instance_klass()) {
1384       name = k->name();
1385       name->increment_refcount();
1386     } else {
1387       ResourceMark rm;
1388       const char* sigstr;
1389       if (k->is_inline_klass() && is_secondary_mirror(java_class)) {
1390         sigstr = InlineKlass::cast(k)->val_signature_name();
1391       } else {
1392         sigstr = k->signature_name();
1393       }
1394       int siglen = (int) strlen(sigstr);
1395       if (!intern_if_not_found) {
1396         name = SymbolTable::probe(sigstr, siglen);
1397       } else {
1398         name = SymbolTable::new_symbol(sigstr, siglen);
1399       }
1400     }
1401   }
1402   return name;
1403 }
1404 
1405 // Returns the Java name for this Java mirror (Resource allocated)
1406 // See Klass::external_name().
1407 // For primitive type Java mirrors, its type name is returned.
1408 const char* java_lang_Class::as_external_name(oop java_class) {
1409   assert(is_instance(java_class), "must be a Class object");
1410   const char* name = nullptr;
1411   if (is_primitive(java_class)) {
1412     name = type2name(primitive_type(java_class));
1413   } else {
1414     name = as_Klass(java_class)->external_name();

1462     return primitive_type(java_class);
1463   } else {
1464     if (reference_klass != nullptr)
1465       (*reference_klass) = as_Klass(java_class);
1466     return T_OBJECT;
1467   }
1468 }
1469 
1470 
1471 oop java_lang_Class::primitive_mirror(BasicType t) {
1472   oop mirror = Universe::java_mirror(t);
1473   assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1474   assert(is_primitive(mirror), "must be primitive");
1475   return mirror;
1476 }
1477 
1478 #define CLASS_FIELDS_DO(macro) \
1479   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1480   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1481   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \
1482   macro(_primary_mirror_offset,      k, "primaryType",         class_signature,       false); \
1483   macro(_secondary_mirror_offset,    k, "secondaryType",       class_signature,       false); \
1484   macro(_module_offset,              k, "module",              module_signature,      false); \
1485   macro(_name_offset,                k, "name",                string_signature,      false); \
1486   macro(_classData_offset,           k, "classData",           object_signature,      false);
1487 
1488 void java_lang_Class::compute_offsets() {
1489   if (_offsets_computed) {
1490     return;
1491   }
1492 
1493   _offsets_computed = true;
1494 
1495   InstanceKlass* k = vmClasses::Class_klass();
1496   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1497 
1498   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1499 }
1500 
1501 #if INCLUDE_CDS
1502 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1503   f->do_bool(&_offsets_computed);

2681 
2682     // the format of the stacktrace will be:
2683     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2684     // - 0 or more <init> methods for the exception class (skipped)
2685     // - rest of the stack
2686 
2687     if (!skip_fillInStackTrace_check) {
2688       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2689           throwable->is_a(method->method_holder())) {
2690         continue;
2691       }
2692       else {
2693         skip_fillInStackTrace_check = true; // gone past them all
2694       }
2695     }
2696     if (!skip_throwableInit_check) {
2697       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2698 
2699       // skip <init> methods of the exception class and superclasses
2700       // This is similar to classic VM.
2701       if (method->is_object_constructor() &&
2702           throwable->is_a(method->method_holder())) {
2703         continue;
2704       } else {
2705         // there are none or we've seen them all - either way stop checking
2706         skip_throwableInit_check = true;
2707       }
2708     }
2709     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2710       if (skip_hidden) {
2711         if (total_count == 0) {
2712           // The top frame will be hidden from the stack trace.
2713           bt.set_has_hidden_top_frame();
2714         }
2715         continue;
2716       }
2717     }
2718 
2719     bt.push(method, bci, CHECK);
2720     total_count++;
2721   }

3040 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3041 int java_lang_ClassFrameInfo::_flags_offset;
3042 
3043 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3044   macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature,  false); \
3045   macro(_flags_offset,             k, vmSymbols::flags_name(), int_signature, false)
3046 
3047 void java_lang_ClassFrameInfo::compute_offsets() {
3048   InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3049   CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3050 }
3051 
3052 #if INCLUDE_CDS
3053 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3054   CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3055 }
3056 #endif
3057 
3058 static int get_flags(const methodHandle& m) {
3059   int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
3060   if (m->is_object_constructor()) {
3061     flags |= java_lang_invoke_MemberName::MN_IS_OBJECT_CONSTRUCTOR;
3062   } else {
3063     flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3064   }
3065   if (m->caller_sensitive()) {
3066     flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3067   }
3068   if (m->is_hidden()) {
3069     flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3070   }
3071   assert((flags & 0xFF000000) == 0, "unexpected flags");
3072   return flags;
3073 }
3074 
3075 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3076   return obj->obj_field(_classOrMemberName_offset);
3077 }
3078 
3079 int java_lang_ClassFrameInfo::flags(oop obj) {
3080   return obj->int_field(_flags_offset);
3081 }

4349 int java_lang_invoke_MemberName::flags(oop mname) {
4350   assert(is_instance(mname), "wrong type");
4351   return mname->int_field(_flags_offset);
4352 }
4353 
4354 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4355   assert(is_instance(mname), "wrong type");
4356   mname->int_field_put(_flags_offset, flags);
4357 }
4358 
4359 
4360 // Return vmtarget from ResolvedMethodName method field through indirection
4361 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4362   assert(is_instance(mname), "wrong type");
4363   oop method = mname->obj_field(_method_offset);
4364   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4365 }
4366 
4367 bool java_lang_invoke_MemberName::is_method(oop mname) {
4368   assert(is_instance(mname), "must be MemberName");
4369   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4370 }
4371 
4372 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4373   assert(is_instance(mname), "wrong type");
4374   mname->obj_field_put(_method_offset, resolved_method);
4375 }
4376 
4377 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4378   assert(is_instance(mname), "wrong type");
4379   return (intptr_t) mname->address_field(_vmindex_offset);
4380 }
4381 
4382 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4383   assert(is_instance(mname), "wrong type");
4384   mname->address_field_put(_vmindex_offset, (address) index);
4385 }
4386 
4387 
4388 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4389   assert(is_instance(resolved_method), "wrong type");
< prev index next >