< 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"

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


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

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









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





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

1046 
1047     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1048 
1049     // set the classLoader field in the java_lang_Class instance
1050     assert(class_loader() == k->class_loader(), "should be same");
1051     set_class_loader(mirror(), class_loader());
1052 
1053     // Setup indirection from klass->mirror
1054     // after any exceptions can happen during allocations.
1055     k->set_java_mirror(mirror);
1056 
1057     // Set the module field in the java_lang_Class instance.  This must be done
1058     // after the mirror is set.
1059     set_mirror_module_field(THREAD, k, mirror, module);
1060 
1061     if (comp_mirror() != nullptr) {
1062       // Set after k->java_mirror() is published, because compiled code running
1063       // concurrently doesn't expect a k to have a null java_mirror.
1064       release_set_array_klass(comp_mirror(), k);
1065     }






1066     if (DumpSharedSpaces) {
1067       create_scratch_mirror(k, CHECK);
1068     }
1069   } else {
1070     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1071     fixup_mirror_list()->push(k);
1072   }
1073 }



















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

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




















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

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

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

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


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





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

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


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

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

4203 int java_lang_invoke_MemberName::flags(oop mname) {
4204   assert(is_instance(mname), "wrong type");
4205   return mname->int_field(_flags_offset);
4206 }
4207 
4208 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4209   assert(is_instance(mname), "wrong type");
4210   mname->int_field_put(_flags_offset, flags);
4211 }
4212 
4213 
4214 // Return vmtarget from ResolvedMethodName method field through indirection
4215 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4216   assert(is_instance(mname), "wrong type");
4217   oop method = mname->obj_field(_method_offset);
4218   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4219 }
4220 
4221 bool java_lang_invoke_MemberName::is_method(oop mname) {
4222   assert(is_instance(mname), "must be MemberName");
4223   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4224 }
4225 
4226 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4227   assert(is_instance(mname), "wrong type");
4228   mname->obj_field_put(_method_offset, resolved_method);
4229 }
4230 
4231 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4232   assert(is_instance(mname), "wrong type");
4233   return (intptr_t) mname->address_field(_vmindex_offset);
4234 }
4235 
4236 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4237   assert(is_instance(mname), "wrong type");
4238   mname->address_field_put(_vmindex_offset, (address) index);
4239 }
4240 
4241 
4242 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4243   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"

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

 974     new (mtModule) GrowableArray<Klass*>(500, mtModule);
 975   set_fixup_module_field_list(module_list);
 976 }
 977 
 978 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
 979                                       Handle& mirror, Handle& comp_mirror, TRAPS) {
 980   // Allocate mirror (java.lang.Class instance)
 981   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
 982   mirror = Handle(THREAD, mirror_oop);
 983 
 984   // Setup indirection from mirror->klass
 985   set_klass(mirror(), k);
 986 
 987   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 988   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 989 
 990   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 991 
 992   // It might also have a component mirror.  This mirror must already exist.
 993   if (k->is_array_klass()) {
 994     if (k->is_flatArray_klass()) {
 995       Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
 996       assert(element_klass->is_inline_klass(), "Must be inline type component");
 997       if (is_scratch) {
 998         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
 999       } else {
1000         InlineKlass* vk = InlineKlass::cast(element_klass);
1001         comp_mirror = Handle(THREAD, vk->val_mirror());
1002       }
1003     } else if (k->is_typeArray_klass()) {
1004       BasicType type = TypeArrayKlass::cast(k)->element_type();
1005       if (is_scratch) {
1006         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1007       } else {
1008         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1009       }
1010     } else {
1011       assert(k->is_objArray_klass(), "Must be");
1012       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1013       assert(element_klass != nullptr, "Must have an element klass");
1014       oop comp_oop = element_klass->java_mirror();
1015       if (element_klass->is_inline_klass()) {
1016         InlineKlass* ik = InlineKlass::cast(element_klass);
1017         comp_oop = k->name()->is_Q_array_signature() ? ik->val_mirror() : ik->ref_mirror();
1018       }
1019       if (is_scratch) {
1020         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1021       } else {
1022         comp_mirror = Handle(THREAD, comp_oop);
1023       }
1024     }
1025     assert(comp_mirror() != nullptr, "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(), nullptr);
1042       return;

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

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

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

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

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

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