< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

  34 #include "classfile/javaClassesImpl.hpp"
  35 #include "classfile/javaThreadStatus.hpp"
  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/stringTable.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/debugInfo.hpp"
  43 #include "code/dependencyContext.hpp"
  44 #include "code/pcDesc.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "interpreter/linkResolver.hpp"
  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 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1121   assert(java_lang_Class::is_instance(mirror_obj), "must be");
1122   // this is the copy of k in the output buffer
1123   Klass* copy = ArchiveBuilder::get_buffered_klass(k);
1124 

1180   }
1181 
1182   // No mirror
1183   oop mirror = k->java_mirror();
1184   if (mirror == NULL) {
1185     return NULL;
1186   }
1187 
1188   if (k->is_instance_klass()) {
1189     InstanceKlass *ik = InstanceKlass::cast(k);
1190     assert(ik->signers() == NULL, "class with signer should have been excluded");
1191 
1192     if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1193           ik->is_shared_app_class())) {
1194       // Archiving mirror for classes from non-builtin loaders is not
1195       // supported.
1196       return NULL;
1197     }
1198   }
1199 






1200   // Now start archiving the mirror object
1201   oop archived_mirror = HeapShared::archive_object(mirror);
1202   if (archived_mirror == NULL) {
1203     return NULL;
1204   }
1205 
1206   archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1207   if (archived_mirror == NULL) {
1208     return NULL;
1209   }
1210 
1211   k->set_archived_java_mirror(archived_mirror);
1212 
1213   ResourceMark rm;
1214   log_trace(cds, heap, mirror)(
1215     "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1216     k->external_name(), p2i(mirror), p2i(archived_mirror));
1217 
1218   return archived_mirror;
1219 }

1379 }
1380 
1381 oop java_lang_Class::protection_domain(oop java_class) {
1382   assert(_protection_domain_offset != 0, "must be set");
1383   return java_class->obj_field(_protection_domain_offset);
1384 }
1385 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1386   assert(_protection_domain_offset != 0, "must be set");
1387   java_class->obj_field_put(_protection_domain_offset, pd);
1388 }
1389 
1390 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1391   assert(_component_mirror_offset != 0, "must be set");
1392     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1393   }
1394 oop java_lang_Class::component_mirror(oop java_class) {
1395   assert(_component_mirror_offset != 0, "must be set");
1396   return java_class->obj_field(_component_mirror_offset);
1397 }
1398 




















1399 objArrayOop java_lang_Class::signers(oop java_class) {
1400   assert(_signers_offset != 0, "must be set");
1401   return (objArrayOop)java_class->obj_field(_signers_offset);
1402 }
1403 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1404   assert(_signers_offset != 0, "must be set");
1405   java_class->obj_field_put(_signers_offset, signers);
1406 }
1407 
1408 oop java_lang_Class::class_data(oop java_class) {
1409   assert(_classData_offset != 0, "must be set");
1410   return java_class->obj_field(_classData_offset);
1411 }
1412 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1413   assert(_classData_offset != 0, "must be set");
1414   java_class->obj_field_put(_classData_offset, class_data);
1415 }
1416 
1417 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1418   assert(_class_loader_offset != 0, "offsets should have been initialized");

1463     assert(aklass != NULL, "correct bootstrap");
1464     release_set_array_klass(java_class, aklass);
1465   }
1466 #ifdef ASSERT
1467   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1468   assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1469 #endif
1470   return java_class;
1471 }
1472 
1473 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1474   assert(is_instance(java_class), "must be a Class object");
1475   java_class->metadata_field_put(_klass_offset, klass);
1476 }
1477 
1478 
1479 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1480   assert(is_instance(java_class), "must be a Class object");
1481   Symbol* name = NULL;
1482   bool is_instance = false;

1483   if (is_primitive(java_class)) {
1484     name = vmSymbols::type_signature(primitive_type(java_class));
1485   } else {
1486     Klass* k = as_Klass(java_class);
1487     is_instance = k->is_instance_klass();

1488     name = k->name();
1489   }
1490   if (name == NULL) {
1491     st->print("<null>");
1492     return;
1493   }
1494   if (is_instance)  st->print("L");


1495   st->write((char*) name->base(), (int) name->utf8_length());
1496   if (is_instance)  st->print(";");
1497 }
1498 
1499 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1500   assert(is_instance(java_class), "must be a Class object");
1501   Symbol* name;
1502   if (is_primitive(java_class)) {
1503     name = vmSymbols::type_signature(primitive_type(java_class));
1504     // Because this can create a new symbol, the caller has to decrement
1505     // the refcount, so make adjustment here and below for symbols returned
1506     // that are not created or incremented due to a successful lookup.
1507     name->increment_refcount();
1508   } else {
1509     Klass* k = as_Klass(java_class);
1510     if (!k->is_instance_klass()) {
1511       name = k->name();
1512       name->increment_refcount();
1513     } else {
1514       ResourceMark rm;
1515       const char* sigstr = k->signature_name();
1516       int         siglen = (int) strlen(sigstr);





1517       if (!intern_if_not_found) {
1518         name = SymbolTable::probe(sigstr, siglen);
1519       } else {
1520         name = SymbolTable::new_symbol(sigstr, siglen);
1521       }
1522     }
1523   }
1524   return name;
1525 }
1526 
1527 // Returns the Java name for this Java mirror (Resource allocated)
1528 // See Klass::external_name().
1529 // For primitive type Java mirrors, its type name is returned.
1530 const char* java_lang_Class::as_external_name(oop java_class) {
1531   assert(is_instance(java_class), "must be a Class object");
1532   const char* name = NULL;
1533   if (is_primitive(java_class)) {
1534     name = type2name(primitive_type(java_class));
1535   } else {
1536     name = as_Klass(java_class)->external_name();

1576     return primitive_type(java_class);
1577   } else {
1578     if (reference_klass != NULL)
1579       (*reference_klass) = as_Klass(java_class);
1580     return T_OBJECT;
1581   }
1582 }
1583 
1584 
1585 oop java_lang_Class::primitive_mirror(BasicType t) {
1586   oop mirror = Universe::java_mirror(t);
1587   assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1588   assert(is_primitive(mirror), "must be primitive");
1589   return mirror;
1590 }
1591 
1592 #define CLASS_FIELDS_DO(macro) \
1593   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1594   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1595   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \


1596   macro(_module_offset,              k, "module",              module_signature,      false); \
1597   macro(_name_offset,                k, "name",                string_signature,      false); \
1598   macro(_classData_offset,           k, "classData",           object_signature,      false);
1599 
1600 void java_lang_Class::compute_offsets() {
1601   if (_offsets_computed) {
1602     return;
1603   }
1604 
1605   _offsets_computed = true;
1606 
1607   InstanceKlass* k = vmClasses::Class_klass();
1608   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1609 
1610   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1611 }
1612 
1613 #if INCLUDE_CDS
1614 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1615   f->do_bool(&_offsets_computed);

2823 
2824     // the format of the stacktrace will be:
2825     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2826     // - 0 or more <init> methods for the exception class (skipped)
2827     // - rest of the stack
2828 
2829     if (!skip_fillInStackTrace_check) {
2830       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2831           throwable->is_a(method->method_holder())) {
2832         continue;
2833       }
2834       else {
2835         skip_fillInStackTrace_check = true; // gone past them all
2836       }
2837     }
2838     if (!skip_throwableInit_check) {
2839       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2840 
2841       // skip <init> methods of the exception class and superclasses
2842       // This is similar to classic VM.
2843       if (method->name() == vmSymbols::object_initializer_name() &&
2844           throwable->is_a(method->method_holder())) {
2845         continue;
2846       } else {
2847         // there are none or we've seen them all - either way stop checking
2848         skip_throwableInit_check = true;
2849       }
2850     }
2851     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2852       if (skip_hidden) {
2853         if (total_count == 0) {
2854           // The top frame will be hidden from the stack trace.
2855           bt.set_has_hidden_top_frame();
2856         }
2857         continue;
2858       }
2859     }
2860 
2861     bt.push(method, bci, CHECK);
2862     total_count++;
2863   }

4409 int java_lang_invoke_MemberName::flags(oop mname) {
4410   assert(is_instance(mname), "wrong type");
4411   return mname->int_field(_flags_offset);
4412 }
4413 
4414 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4415   assert(is_instance(mname), "wrong type");
4416   mname->int_field_put(_flags_offset, flags);
4417 }
4418 
4419 
4420 // Return vmtarget from ResolvedMethodName method field through indirection
4421 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4422   assert(is_instance(mname), "wrong type");
4423   oop method = mname->obj_field(_method_offset);
4424   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4425 }
4426 
4427 bool java_lang_invoke_MemberName::is_method(oop mname) {
4428   assert(is_instance(mname), "must be MemberName");
4429   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4430 }
4431 
4432 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4433   assert(is_instance(mname), "wrong type");
4434   mname->obj_field_put(_method_offset, resolved_method);
4435 }
4436 
4437 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4438   assert(is_instance(mname), "wrong type");
4439   return (intptr_t) mname->address_field(_vmindex_offset);
4440 }
4441 
4442 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4443   assert(is_instance(mname), "wrong type");
4444   mname->address_field_put(_vmindex_offset, (address) index);
4445 }
4446 
4447 
4448 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4449   assert(is_instance(resolved_method), "wrong type");

  34 #include "classfile/javaClassesImpl.hpp"
  35 #include "classfile/javaThreadStatus.hpp"
  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/stringTable.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/debugInfo.hpp"
  43 #include "code/dependencyContext.hpp"
  44 #include "code/pcDesc.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "interpreter/linkResolver.hpp"
  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 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1161   assert(java_lang_Class::is_instance(mirror_obj), "must be");
1162   // this is the copy of k in the output buffer
1163   Klass* copy = ArchiveBuilder::get_buffered_klass(k);
1164 

1220   }
1221 
1222   // No mirror
1223   oop mirror = k->java_mirror();
1224   if (mirror == NULL) {
1225     return NULL;
1226   }
1227 
1228   if (k->is_instance_klass()) {
1229     InstanceKlass *ik = InstanceKlass::cast(k);
1230     assert(ik->signers() == NULL, "class with signer should have been excluded");
1231 
1232     if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1233           ik->is_shared_app_class())) {
1234       // Archiving mirror for classes from non-builtin loaders is not
1235       // supported.
1236       return NULL;
1237     }
1238   }
1239 
1240   if (k->is_inline_klass()) {
1241     // Inline types have a primary mirror and a secondary mirror. Don't handle this for now. TODO:CDS
1242     k->clear_java_mirror_handle();
1243     return NULL;
1244   }
1245 
1246   // Now start archiving the mirror object
1247   oop archived_mirror = HeapShared::archive_object(mirror);
1248   if (archived_mirror == NULL) {
1249     return NULL;
1250   }
1251 
1252   archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1253   if (archived_mirror == NULL) {
1254     return NULL;
1255   }
1256 
1257   k->set_archived_java_mirror(archived_mirror);
1258 
1259   ResourceMark rm;
1260   log_trace(cds, heap, mirror)(
1261     "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1262     k->external_name(), p2i(mirror), p2i(archived_mirror));
1263 
1264   return archived_mirror;
1265 }

1425 }
1426 
1427 oop java_lang_Class::protection_domain(oop java_class) {
1428   assert(_protection_domain_offset != 0, "must be set");
1429   return java_class->obj_field(_protection_domain_offset);
1430 }
1431 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1432   assert(_protection_domain_offset != 0, "must be set");
1433   java_class->obj_field_put(_protection_domain_offset, pd);
1434 }
1435 
1436 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1437   assert(_component_mirror_offset != 0, "must be set");
1438     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1439   }
1440 oop java_lang_Class::component_mirror(oop java_class) {
1441   assert(_component_mirror_offset != 0, "must be set");
1442   return java_class->obj_field(_component_mirror_offset);
1443 }
1444 
1445 oop java_lang_Class::primary_mirror(oop java_class) {
1446   assert(_primary_mirror_offset != 0, "must be set");
1447   return java_class->obj_field(_primary_mirror_offset);
1448 }
1449 
1450 void java_lang_Class::set_primary_mirror(oop java_class, oop mirror) {
1451   assert(_primary_mirror_offset != 0, "must be set");
1452   java_class->obj_field_put(_primary_mirror_offset, mirror);
1453 }
1454 
1455 oop java_lang_Class::secondary_mirror(oop java_class) {
1456   assert(_secondary_mirror_offset != 0, "must be set");
1457   return java_class->obj_field(_secondary_mirror_offset);
1458 }
1459 
1460 void java_lang_Class::set_secondary_mirror(oop java_class, oop mirror) {
1461   assert(_secondary_mirror_offset != 0, "must be set");
1462   java_class->obj_field_put(_secondary_mirror_offset, mirror);
1463 }
1464 
1465 objArrayOop java_lang_Class::signers(oop java_class) {
1466   assert(_signers_offset != 0, "must be set");
1467   return (objArrayOop)java_class->obj_field(_signers_offset);
1468 }
1469 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1470   assert(_signers_offset != 0, "must be set");
1471   java_class->obj_field_put(_signers_offset, signers);
1472 }
1473 
1474 oop java_lang_Class::class_data(oop java_class) {
1475   assert(_classData_offset != 0, "must be set");
1476   return java_class->obj_field(_classData_offset);
1477 }
1478 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1479   assert(_classData_offset != 0, "must be set");
1480   java_class->obj_field_put(_classData_offset, class_data);
1481 }
1482 
1483 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1484   assert(_class_loader_offset != 0, "offsets should have been initialized");

1529     assert(aklass != NULL, "correct bootstrap");
1530     release_set_array_klass(java_class, aklass);
1531   }
1532 #ifdef ASSERT
1533   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1534   assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1535 #endif
1536   return java_class;
1537 }
1538 
1539 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1540   assert(is_instance(java_class), "must be a Class object");
1541   java_class->metadata_field_put(_klass_offset, klass);
1542 }
1543 
1544 
1545 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1546   assert(is_instance(java_class), "must be a Class object");
1547   Symbol* name = NULL;
1548   bool is_instance = false;
1549   bool is_Q_descriptor = false;
1550   if (is_primitive(java_class)) {
1551     name = vmSymbols::type_signature(primitive_type(java_class));
1552   } else {
1553     Klass* k = as_Klass(java_class);
1554     is_instance = k->is_instance_klass();
1555     is_Q_descriptor = k->is_inline_klass() && is_secondary_mirror(java_class);
1556     name = k->name();
1557   }
1558   if (name == NULL) {
1559     st->print("<null>");
1560     return;
1561   }
1562   if (is_instance)  {
1563     st->print(is_Q_descriptor ? "Q" : "L");
1564   }
1565   st->write((char*) name->base(), (int) name->utf8_length());
1566   if (is_instance)  st->print(";");
1567 }
1568 
1569 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1570   assert(is_instance(java_class), "must be a Class object");
1571   Symbol* name;
1572   if (is_primitive(java_class)) {
1573     name = vmSymbols::type_signature(primitive_type(java_class));
1574     // Because this can create a new symbol, the caller has to decrement
1575     // the refcount, so make adjustment here and below for symbols returned
1576     // that are not created or incremented due to a successful lookup.
1577     name->increment_refcount();
1578   } else {
1579     Klass* k = as_Klass(java_class);
1580     if (!k->is_instance_klass()) {
1581       name = k->name();
1582       name->increment_refcount();
1583     } else {
1584       ResourceMark rm;
1585       const char* sigstr;
1586       if (k->is_inline_klass() && is_secondary_mirror(java_class)) {
1587         sigstr = InlineKlass::cast(k)->val_signature_name();
1588       } else {
1589         sigstr = k->signature_name();
1590       }
1591       int siglen = (int) strlen(sigstr);
1592       if (!intern_if_not_found) {
1593         name = SymbolTable::probe(sigstr, siglen);
1594       } else {
1595         name = SymbolTable::new_symbol(sigstr, siglen);
1596       }
1597     }
1598   }
1599   return name;
1600 }
1601 
1602 // Returns the Java name for this Java mirror (Resource allocated)
1603 // See Klass::external_name().
1604 // For primitive type Java mirrors, its type name is returned.
1605 const char* java_lang_Class::as_external_name(oop java_class) {
1606   assert(is_instance(java_class), "must be a Class object");
1607   const char* name = NULL;
1608   if (is_primitive(java_class)) {
1609     name = type2name(primitive_type(java_class));
1610   } else {
1611     name = as_Klass(java_class)->external_name();

1651     return primitive_type(java_class);
1652   } else {
1653     if (reference_klass != NULL)
1654       (*reference_klass) = as_Klass(java_class);
1655     return T_OBJECT;
1656   }
1657 }
1658 
1659 
1660 oop java_lang_Class::primitive_mirror(BasicType t) {
1661   oop mirror = Universe::java_mirror(t);
1662   assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1663   assert(is_primitive(mirror), "must be primitive");
1664   return mirror;
1665 }
1666 
1667 #define CLASS_FIELDS_DO(macro) \
1668   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1669   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1670   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \
1671   macro(_primary_mirror_offset,      k, "primaryType",         class_signature,       false); \
1672   macro(_secondary_mirror_offset,    k, "secondaryType",       class_signature,       false); \
1673   macro(_module_offset,              k, "module",              module_signature,      false); \
1674   macro(_name_offset,                k, "name",                string_signature,      false); \
1675   macro(_classData_offset,           k, "classData",           object_signature,      false);
1676 
1677 void java_lang_Class::compute_offsets() {
1678   if (_offsets_computed) {
1679     return;
1680   }
1681 
1682   _offsets_computed = true;
1683 
1684   InstanceKlass* k = vmClasses::Class_klass();
1685   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1686 
1687   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1688 }
1689 
1690 #if INCLUDE_CDS
1691 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1692   f->do_bool(&_offsets_computed);

2900 
2901     // the format of the stacktrace will be:
2902     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2903     // - 0 or more <init> methods for the exception class (skipped)
2904     // - rest of the stack
2905 
2906     if (!skip_fillInStackTrace_check) {
2907       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2908           throwable->is_a(method->method_holder())) {
2909         continue;
2910       }
2911       else {
2912         skip_fillInStackTrace_check = true; // gone past them all
2913       }
2914     }
2915     if (!skip_throwableInit_check) {
2916       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2917 
2918       // skip <init> methods of the exception class and superclasses
2919       // This is similar to classic VM.
2920       if (method->is_object_constructor() &&
2921           throwable->is_a(method->method_holder())) {
2922         continue;
2923       } else {
2924         // there are none or we've seen them all - either way stop checking
2925         skip_throwableInit_check = true;
2926       }
2927     }
2928     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2929       if (skip_hidden) {
2930         if (total_count == 0) {
2931           // The top frame will be hidden from the stack trace.
2932           bt.set_has_hidden_top_frame();
2933         }
2934         continue;
2935       }
2936     }
2937 
2938     bt.push(method, bci, CHECK);
2939     total_count++;
2940   }

4486 int java_lang_invoke_MemberName::flags(oop mname) {
4487   assert(is_instance(mname), "wrong type");
4488   return mname->int_field(_flags_offset);
4489 }
4490 
4491 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4492   assert(is_instance(mname), "wrong type");
4493   mname->int_field_put(_flags_offset, flags);
4494 }
4495 
4496 
4497 // Return vmtarget from ResolvedMethodName method field through indirection
4498 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4499   assert(is_instance(mname), "wrong type");
4500   oop method = mname->obj_field(_method_offset);
4501   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4502 }
4503 
4504 bool java_lang_invoke_MemberName::is_method(oop mname) {
4505   assert(is_instance(mname), "must be MemberName");
4506   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4507 }
4508 
4509 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4510   assert(is_instance(mname), "wrong type");
4511   mname->obj_field_put(_method_offset, resolved_method);
4512 }
4513 
4514 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4515   assert(is_instance(mname), "wrong type");
4516   return (intptr_t) mname->address_field(_vmindex_offset);
4517 }
4518 
4519 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4520   assert(is_instance(mname), "wrong type");
4521   mname->address_field_put(_vmindex_offset, (address) index);
4522 }
4523 
4524 
4525 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4526   assert(is_instance(resolved_method), "wrong type");
< prev index next >