< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

  32 #include "classfile/javaClasses.inline.hpp"
  33 #include "classfile/javaThreadStatus.hpp"
  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/stringTable.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/debugInfo.hpp"
  41 #include "code/dependencyContext.hpp"
  42 #include "code/pcDesc.hpp"
  43 #include "gc/shared/collectedHeap.inline.hpp"
  44 #include "interpreter/interpreter.hpp"
  45 #include "interpreter/linkResolver.hpp"
  46 #include "logging/log.hpp"
  47 #include "logging/logStream.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/fieldStreams.inline.hpp"


  52 #include "oops/instanceKlass.inline.hpp"
  53 #include "oops/instanceMirrorKlass.hpp"
  54 #include "oops/klass.hpp"
  55 #include "oops/klass.inline.hpp"
  56 #include "oops/method.inline.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/oop.inline.hpp"
  59 #include "oops/symbol.hpp"
  60 #include "oops/recordComponent.hpp"
  61 #include "oops/typeArrayOop.inline.hpp"
  62 #include "prims/jvmtiExport.hpp"
  63 #include "prims/methodHandles.hpp"
  64 #include "prims/resolvedMethodTable.hpp"
  65 #include "runtime/fieldDescriptor.inline.hpp"
  66 #include "runtime/frame.inline.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/init.hpp"
  69 #include "runtime/interfaceSupport.inline.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jniHandles.inline.hpp"
  73 #include "runtime/reflectionUtils.hpp"

 766   bool is_latin1 = java_lang_String::is_latin1(java_string);
 767 
 768   st->print("\"");
 769   for (int index = 0; index < length; index++) {
 770     st->print("%c", (!is_latin1) ?  value->char_at(index) :
 771                            ((jchar) value->byte_at(index)) & 0xff );
 772   }
 773   st->print("\"");
 774 }
 775 
 776 // java_lang_Class
 777 
 778 int java_lang_Class::_klass_offset;
 779 int java_lang_Class::_array_klass_offset;
 780 int java_lang_Class::_oop_size_offset;
 781 int java_lang_Class::_static_oop_field_count_offset;
 782 int java_lang_Class::_class_loader_offset;
 783 int java_lang_Class::_module_offset;
 784 int java_lang_Class::_protection_domain_offset;
 785 int java_lang_Class::_component_mirror_offset;


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

 996   int computed_modifiers = k->compute_modifier_flags();
 997   k->set_modifier_flags(computed_modifiers);
 998   // Class_klass has to be loaded because it is used to allocate
 999   // the mirror.
1000   if (vmClasses::Class_klass_loaded()) {
1001     // Allocate mirror (java.lang.Class instance)
1002     oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1003     Handle mirror(THREAD, mirror_oop);
1004     Handle comp_mirror;
1005 
1006     // Setup indirection from mirror->klass
1007     java_lang_Class::set_klass(mirror(), k);
1008 
1009     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1010     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1011 
1012     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1013 
1014     // It might also have a component mirror.  This mirror must already exist.
1015     if (k->is_array_klass()) {
1016       if (k->is_typeArray_klass()) {





1017         BasicType type = TypeArrayKlass::cast(k)->element_type();
1018         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1019       } else {
1020         assert(k->is_objArray_klass(), "Must be");
1021         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1022         assert(element_klass != NULL, "Must have an element klass");
1023         comp_mirror = Handle(THREAD, element_klass->java_mirror());





1024       }
1025       assert(comp_mirror() != NULL, "must have a mirror");
1026 
1027       // Two-way link between the array klass and its component mirror:
1028       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1029       set_component_mirror(mirror(), comp_mirror());
1030       // See below for ordering dependencies between field array_klass in component mirror
1031       // and java_mirror in this klass.
1032     } else {
1033       assert(k->is_instance_klass(), "Must be");
1034 
1035       initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1036       if (HAS_PENDING_EXCEPTION) {
1037         // If any of the fields throws an exception like OOM remove the klass field
1038         // from the mirror so GC doesn't follow it after the klass has been deallocated.
1039         // This mirror looks like a primitive type, which logically it is because it
1040         // it represents no class.
1041         java_lang_Class::set_klass(mirror(), NULL);
1042         return;
1043       }
1044     }
1045 
1046     // set the classLoader field in the java_lang_Class instance
1047     assert(class_loader() == k->class_loader(), "should be same");
1048     set_class_loader(mirror(), class_loader());
1049 
1050     // Setup indirection from klass->mirror
1051     // after any exceptions can happen during allocations.
1052     k->set_java_mirror(mirror);
1053 
1054     // Set the module field in the java_lang_Class instance.  This must be done
1055     // after the mirror is set.
1056     set_mirror_module_field(THREAD, k, mirror, module);
1057 
1058     if (comp_mirror() != NULL) {
1059       // Set after k->java_mirror() is published, because compiled code running
1060       // concurrently doesn't expect a k to have a null java_mirror.
1061       release_set_array_klass(comp_mirror(), k);
1062     }






1063   } else {
1064     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1065     fixup_mirror_list()->push(k);
1066   }
1067 }





















1068 
1069 #if INCLUDE_CDS_JAVA_HEAP
1070 // Clears mirror fields. Static final fields with initial values are reloaded
1071 // from constant pool. The object identity hash is in the object header and is
1072 // not affected.
1073 class ResetMirrorField: public FieldClosure {
1074  private:
1075   Handle _m;
1076 
1077  public:
1078   ResetMirrorField(Handle mirror) : _m(mirror) {}
1079 
1080   void do_field(fieldDescriptor* fd) {
1081     assert(DumpSharedSpaces, "dump time only");
1082     assert(_m.not_null(), "Mirror cannot be NULL");
1083 
1084     if (fd->is_static() && fd->has_initial_value()) {
1085       initialize_static_field_for_dump(fd, _m);
1086       return;
1087     }

1095         _m()->char_field_put(fd->offset(), 0);
1096         break;
1097       case T_DOUBLE:
1098         _m()->double_field_put(fd->offset(), 0);
1099         break;
1100       case T_FLOAT:
1101         _m()->float_field_put(fd->offset(), 0);
1102         break;
1103       case T_INT:
1104         _m()->int_field_put(fd->offset(), 0);
1105         break;
1106       case T_LONG:
1107         _m()->long_field_put(fd->offset(), 0);
1108         break;
1109       case T_SHORT:
1110         _m()->short_field_put(fd->offset(), 0);
1111         break;
1112       case T_BOOLEAN:
1113         _m()->bool_field_put(fd->offset(), false);
1114         break;

1115       case T_ARRAY:
1116       case T_OBJECT: {
1117         // It might be useful to cache the String field, but
1118         // for now just clear out any reference field
1119         oop o = _m()->obj_field(fd->offset());
1120         _m()->obj_field_put(fd->offset(), NULL);
1121         break;
1122       }
1123       default:
1124         ShouldNotReachHere();
1125         break;
1126      }
1127   }
1128 };
1129 
1130 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1131   assert(java_lang_Class::is_instance(mirror_obj), "must be");
1132   // this is the copy of k in the output buffer
1133   Klass* copy = ArchiveBuilder::get_relocated_klass(k);
1134 

1190   }
1191 
1192   // No mirror
1193   oop mirror = k->java_mirror();
1194   if (mirror == NULL) {
1195     return NULL;
1196   }
1197 
1198   if (k->is_instance_klass()) {
1199     InstanceKlass *ik = InstanceKlass::cast(k);
1200     assert(ik->signers() == NULL, "class with signer should have been excluded");
1201 
1202     if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1203           ik->is_shared_app_class())) {
1204       // Archiving mirror for classes from non-builtin loaders is not
1205       // supported.
1206       return NULL;
1207     }
1208   }
1209 






1210   // Now start archiving the mirror object
1211   oop archived_mirror = HeapShared::archive_object(mirror);
1212   if (archived_mirror == NULL) {
1213     return NULL;
1214   }
1215 
1216   archived_mirror = process_archived_mirror(k, mirror, archived_mirror);
1217   if (archived_mirror == NULL) {
1218     return NULL;
1219   }
1220 
1221   k->set_archived_java_mirror(archived_mirror);
1222 
1223   ResourceMark rm;
1224   log_trace(cds, heap, mirror)(
1225     "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1226     k->external_name(), p2i(mirror), p2i(archived_mirror));
1227 
1228   return archived_mirror;
1229 }

1394 }
1395 
1396 oop java_lang_Class::protection_domain(oop java_class) {
1397   assert(_protection_domain_offset != 0, "must be set");
1398   return java_class->obj_field(_protection_domain_offset);
1399 }
1400 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1401   assert(_protection_domain_offset != 0, "must be set");
1402   java_class->obj_field_put(_protection_domain_offset, pd);
1403 }
1404 
1405 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1406   assert(_component_mirror_offset != 0, "must be set");
1407     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1408   }
1409 oop java_lang_Class::component_mirror(oop java_class) {
1410   assert(_component_mirror_offset != 0, "must be set");
1411   return java_class->obj_field(_component_mirror_offset);
1412 }
1413 




















1414 oop java_lang_Class::init_lock(oop java_class) {
1415   assert(_init_lock_offset != 0, "must be set");
1416   return java_class->obj_field(_init_lock_offset);
1417 }
1418 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1419   assert(_init_lock_offset != 0, "must be set");
1420   java_class->obj_field_put(_init_lock_offset, init_lock);
1421 }
1422 
1423 objArrayOop java_lang_Class::signers(oop java_class) {
1424   assert(_signers_offset != 0, "must be set");
1425   return (objArrayOop)java_class->obj_field(_signers_offset);
1426 }
1427 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1428   assert(_signers_offset != 0, "must be set");
1429   java_class->obj_field_put(_signers_offset, signers);
1430 }
1431 
1432 oop java_lang_Class::class_data(oop java_class) {
1433   assert(_classData_offset != 0, "must be set");

1487     assert(aklass != NULL, "correct bootstrap");
1488     release_set_array_klass(java_class, aklass);
1489   }
1490 #ifdef ASSERT
1491   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1492   assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1493 #endif
1494   return java_class;
1495 }
1496 
1497 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1498   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1499   java_class->metadata_field_put(_klass_offset, klass);
1500 }
1501 
1502 
1503 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1504   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1505   Symbol* name = NULL;
1506   bool is_instance = false;

1507   if (is_primitive(java_class)) {
1508     name = vmSymbols::type_signature(primitive_type(java_class));
1509   } else {
1510     Klass* k = as_Klass(java_class);
1511     is_instance = k->is_instance_klass();

1512     name = k->name();
1513   }
1514   if (name == NULL) {
1515     st->print("<null>");
1516     return;
1517   }
1518   if (is_instance)  st->print("L");


1519   st->write((char*) name->base(), (int) name->utf8_length());
1520   if (is_instance)  st->print(";");
1521 }
1522 
1523 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1524   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1525   Symbol* name;
1526   if (is_primitive(java_class)) {
1527     name = vmSymbols::type_signature(primitive_type(java_class));
1528     // Because this can create a new symbol, the caller has to decrement
1529     // the refcount, so make adjustment here and below for symbols returned
1530     // that are not created or incremented due to a successful lookup.
1531     name->increment_refcount();
1532   } else {
1533     Klass* k = as_Klass(java_class);
1534     if (!k->is_instance_klass()) {
1535       name = k->name();
1536       name->increment_refcount();
1537     } else {
1538       ResourceMark rm;
1539       const char* sigstr = k->signature_name();
1540       int         siglen = (int) strlen(sigstr);





1541       if (!intern_if_not_found) {
1542         name = SymbolTable::probe(sigstr, siglen);
1543       } else {
1544         name = SymbolTable::new_symbol(sigstr, siglen);
1545       }
1546     }
1547   }
1548   return name;
1549 }
1550 
1551 // Returns the Java name for this Java mirror (Resource allocated)
1552 // See Klass::external_name().
1553 // For primitive type Java mirrors, its type name is returned.
1554 const char* java_lang_Class::as_external_name(oop java_class) {
1555   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1556   const char* name = NULL;
1557   if (is_primitive(java_class)) {
1558     name = type2name(primitive_type(java_class));
1559   } else {
1560     name = as_Klass(java_class)->external_name();

1600     return primitive_type(java_class);
1601   } else {
1602     if (reference_klass != NULL)
1603       (*reference_klass) = as_Klass(java_class);
1604     return T_OBJECT;
1605   }
1606 }
1607 
1608 
1609 oop java_lang_Class::primitive_mirror(BasicType t) {
1610   oop mirror = Universe::java_mirror(t);
1611   assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1612   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1613   return mirror;
1614 }
1615 
1616 #define CLASS_FIELDS_DO(macro) \
1617   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1618   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1619   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \


1620   macro(_module_offset,              k, "module",              module_signature,      false); \
1621   macro(_name_offset,                k, "name",                string_signature,      false); \
1622   macro(_classData_offset,           k, "classData",           object_signature,      false);
1623 
1624 void java_lang_Class::compute_offsets() {
1625   if (_offsets_computed) {
1626     return;
1627   }
1628 
1629   _offsets_computed = true;
1630 
1631   InstanceKlass* k = vmClasses::Class_klass();
1632   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1633 
1634   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1635   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1636   // GC treats them the same.
1637   _init_lock_offset = _component_mirror_offset;
1638 
1639   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);

2490 #endif
2491 
2492     // the format of the stacktrace will be:
2493     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2494     // - 0 or more <init> methods for the exception class (skipped)
2495     // - rest of the stack
2496 
2497     if (!skip_fillInStackTrace_check) {
2498       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2499           throwable->is_a(method->method_holder())) {
2500         continue;
2501       }
2502       else {
2503         skip_fillInStackTrace_check = true; // gone past them all
2504       }
2505     }
2506     if (!skip_throwableInit_check) {
2507       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2508 
2509       // skip <init> methods of the exception class and superclasses
2510       // This is simlar to classic VM.
2511       if (method->name() == vmSymbols::object_initializer_name() &&
2512           throwable->is_a(method->method_holder())) {
2513         continue;
2514       } else {
2515         // there are none or we've seen them all - either way stop checking
2516         skip_throwableInit_check = true;
2517       }
2518     }
2519     if (method->is_hidden()) {
2520       if (skip_hidden) {
2521         if (total_count == 0) {
2522           // The top frame will be hidden from the stack trace.
2523           bt.set_has_hidden_top_frame();
2524         }
2525         continue;
2526       }
2527     }
2528     bt.push(method, bci, CHECK);
2529     total_count++;
2530   }
2531 

3964 int java_lang_invoke_MemberName::flags(oop mname) {
3965   assert(is_instance(mname), "wrong type");
3966   return mname->int_field(_flags_offset);
3967 }
3968 
3969 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
3970   assert(is_instance(mname), "wrong type");
3971   mname->int_field_put(_flags_offset, flags);
3972 }
3973 
3974 
3975 // Return vmtarget from ResolvedMethodName method field through indirection
3976 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
3977   assert(is_instance(mname), "wrong type");
3978   oop method = mname->obj_field(_method_offset);
3979   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
3980 }
3981 
3982 bool java_lang_invoke_MemberName::is_method(oop mname) {
3983   assert(is_instance(mname), "must be MemberName");
3984   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
3985 }
3986 
3987 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
3988   assert(is_instance(mname), "wrong type");
3989   mname->obj_field_put(_method_offset, resolved_method);
3990 }
3991 
3992 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
3993   assert(is_instance(mname), "wrong type");
3994   return (intptr_t) mname->address_field(_vmindex_offset);
3995 }
3996 
3997 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3998   assert(is_instance(mname), "wrong type");
3999   mname->address_field_put(_vmindex_offset, (address) index);
4000 }
4001 
4002 
4003 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4004   assert(is_instance(resolved_method), "wrong type");

  32 #include "classfile/javaClasses.inline.hpp"
  33 #include "classfile/javaThreadStatus.hpp"
  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/stringTable.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/debugInfo.hpp"
  41 #include "code/dependencyContext.hpp"
  42 #include "code/pcDesc.hpp"
  43 #include "gc/shared/collectedHeap.inline.hpp"
  44 #include "interpreter/interpreter.hpp"
  45 #include "interpreter/linkResolver.hpp"
  46 #include "logging/log.hpp"
  47 #include "logging/logStream.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/fieldStreams.inline.hpp"
  52 #include "oops/flatArrayKlass.hpp"
  53 #include "oops/inlineKlass.inline.hpp"
  54 #include "oops/instanceKlass.inline.hpp"
  55 #include "oops/instanceMirrorKlass.inline.hpp"
  56 #include "oops/klass.hpp"
  57 #include "oops/klass.inline.hpp"
  58 #include "oops/method.inline.hpp"
  59 #include "oops/objArrayOop.inline.hpp"
  60 #include "oops/oop.inline.hpp"
  61 #include "oops/symbol.hpp"
  62 #include "oops/recordComponent.hpp"
  63 #include "oops/typeArrayOop.inline.hpp"
  64 #include "prims/jvmtiExport.hpp"
  65 #include "prims/methodHandles.hpp"
  66 #include "prims/resolvedMethodTable.hpp"
  67 #include "runtime/fieldDescriptor.inline.hpp"
  68 #include "runtime/frame.inline.hpp"
  69 #include "runtime/handles.inline.hpp"
  70 #include "runtime/init.hpp"
  71 #include "runtime/interfaceSupport.inline.hpp"
  72 #include "runtime/java.hpp"
  73 #include "runtime/javaCalls.hpp"
  74 #include "runtime/jniHandles.inline.hpp"
  75 #include "runtime/reflectionUtils.hpp"

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

1000   int computed_modifiers = k->compute_modifier_flags();
1001   k->set_modifier_flags(computed_modifiers);
1002   // Class_klass has to be loaded because it is used to allocate
1003   // the mirror.
1004   if (vmClasses::Class_klass_loaded()) {
1005     // Allocate mirror (java.lang.Class instance)
1006     oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1007     Handle mirror(THREAD, mirror_oop);
1008     Handle comp_mirror;
1009 
1010     // Setup indirection from mirror->klass
1011     java_lang_Class::set_klass(mirror(), k);
1012 
1013     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1014     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1015 
1016     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1017 
1018     // It might also have a component mirror.  This mirror must already exist.
1019     if (k->is_array_klass()) {
1020       if (k->is_flatArray_klass()) {
1021         Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1022         assert(element_klass->is_inline_klass(), "Must be inline type component");
1023         InlineKlass* vk = InlineKlass::cast(element_klass);
1024         comp_mirror = Handle(THREAD, vk->val_mirror());
1025       } else if (k->is_typeArray_klass()) {
1026         BasicType type = TypeArrayKlass::cast(k)->element_type();
1027         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1028       } else {
1029         assert(k->is_objArray_klass(), "Must be");
1030         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1031         assert(element_klass != NULL, "Must have an element klass");
1032         oop comp_oop = element_klass->java_mirror();
1033         if (element_klass->is_inline_klass()) {
1034           InlineKlass* ik = InlineKlass::cast(element_klass);
1035           comp_oop = k->name()->is_Q_array_signature() ? ik->val_mirror() : ik->ref_mirror();
1036         }
1037         comp_mirror = Handle(THREAD, comp_oop);
1038       }
1039       assert(comp_mirror() != NULL, "must have a mirror");
1040 
1041       // Two-way link between the array klass and its component mirror:
1042       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1043       set_component_mirror(mirror(), comp_mirror());
1044       // See below for ordering dependencies between field array_klass in component mirror
1045       // and java_mirror in this klass.
1046     } else {
1047       assert(k->is_instance_klass(), "Must be");
1048 
1049       initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1050       if (HAS_PENDING_EXCEPTION) {
1051         // If any of the fields throws an exception like OOM remove the klass field
1052         // from the mirror so GC doesn't follow it after the klass has been deallocated.
1053         // This mirror looks like a primitive type, which logically it is because it
1054         // it represents no class.
1055         java_lang_Class::set_klass(mirror(), NULL);
1056         return;
1057       }
1058     }
1059 
1060     // set the classLoader field in the java_lang_Class instance
1061     assert(class_loader() == k->class_loader(), "should be same");
1062     set_class_loader(mirror(), class_loader());
1063 
1064     // Setup indirection from klass->mirror
1065     // after any exceptions can happen during allocations.
1066     k->set_java_mirror(mirror);
1067 
1068     // Set the module field in the java_lang_Class instance.  This must be done
1069     // after the mirror is set.
1070     set_mirror_module_field(THREAD, k, mirror, module);
1071 
1072     if (comp_mirror() != NULL) {
1073       // Set after k->java_mirror() is published, because compiled code running
1074       // concurrently doesn't expect a k to have a null java_mirror.
1075       release_set_array_klass(comp_mirror(), k);
1076     }
1077 
1078     if (k->is_inline_klass()) {
1079       oop secondary_mirror = create_secondary_mirror(k, mirror, CHECK);
1080       set_primary_mirror(mirror(), mirror());
1081       set_secondary_mirror(mirror(), secondary_mirror);
1082     }
1083   } else {
1084     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1085     fixup_mirror_list()->push(k);
1086   }
1087 }
1088 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1089 // instance with the same value as the primary mirror
1090 oop java_lang_Class::create_secondary_mirror(Klass* k, Handle mirror, TRAPS) {
1091   assert(k->is_inline_klass(), "primitive class");
1092   // Allocate mirror (java.lang.Class instance)
1093   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK_0);
1094   Handle secondary_mirror(THREAD, mirror_oop);
1095 
1096   java_lang_Class::set_klass(secondary_mirror(), k);
1097   java_lang_Class::set_static_oop_field_count(secondary_mirror(), static_oop_field_count(mirror()));
1098   // ## do we need to set init lock?
1099   java_lang_Class::set_init_lock(secondary_mirror(), init_lock(mirror()));
1100 
1101   set_protection_domain(secondary_mirror(), protection_domain(mirror()));
1102   set_class_loader(secondary_mirror(), class_loader(mirror()));
1103   // ## handle if java.base is not yet defined
1104   set_module(secondary_mirror(), module(mirror()));
1105   set_primary_mirror(secondary_mirror(), mirror());
1106   set_secondary_mirror(secondary_mirror(), secondary_mirror());
1107   return secondary_mirror();
1108 }
1109 
1110 #if INCLUDE_CDS_JAVA_HEAP
1111 // Clears mirror fields. Static final fields with initial values are reloaded
1112 // from constant pool. The object identity hash is in the object header and is
1113 // not affected.
1114 class ResetMirrorField: public FieldClosure {
1115  private:
1116   Handle _m;
1117 
1118  public:
1119   ResetMirrorField(Handle mirror) : _m(mirror) {}
1120 
1121   void do_field(fieldDescriptor* fd) {
1122     assert(DumpSharedSpaces, "dump time only");
1123     assert(_m.not_null(), "Mirror cannot be NULL");
1124 
1125     if (fd->is_static() && fd->has_initial_value()) {
1126       initialize_static_field_for_dump(fd, _m);
1127       return;
1128     }

1136         _m()->char_field_put(fd->offset(), 0);
1137         break;
1138       case T_DOUBLE:
1139         _m()->double_field_put(fd->offset(), 0);
1140         break;
1141       case T_FLOAT:
1142         _m()->float_field_put(fd->offset(), 0);
1143         break;
1144       case T_INT:
1145         _m()->int_field_put(fd->offset(), 0);
1146         break;
1147       case T_LONG:
1148         _m()->long_field_put(fd->offset(), 0);
1149         break;
1150       case T_SHORT:
1151         _m()->short_field_put(fd->offset(), 0);
1152         break;
1153       case T_BOOLEAN:
1154         _m()->bool_field_put(fd->offset(), false);
1155         break;
1156       case T_INLINE_TYPE:
1157       case T_ARRAY:
1158       case T_OBJECT: {
1159         // It might be useful to cache the String field, but
1160         // for now just clear out any reference field
1161         oop o = _m()->obj_field(fd->offset());
1162         _m()->obj_field_put(fd->offset(), NULL);
1163         break;
1164       }
1165       default:
1166         ShouldNotReachHere();
1167         break;
1168      }
1169   }
1170 };
1171 
1172 static void set_klass_field_in_archived_mirror(oop mirror_obj, int offset, Klass* k) {
1173   assert(java_lang_Class::is_instance(mirror_obj), "must be");
1174   // this is the copy of k in the output buffer
1175   Klass* copy = ArchiveBuilder::get_relocated_klass(k);
1176 

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

1442 }
1443 
1444 oop java_lang_Class::protection_domain(oop java_class) {
1445   assert(_protection_domain_offset != 0, "must be set");
1446   return java_class->obj_field(_protection_domain_offset);
1447 }
1448 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
1449   assert(_protection_domain_offset != 0, "must be set");
1450   java_class->obj_field_put(_protection_domain_offset, pd);
1451 }
1452 
1453 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) {
1454   assert(_component_mirror_offset != 0, "must be set");
1455     java_class->obj_field_put(_component_mirror_offset, comp_mirror);
1456   }
1457 oop java_lang_Class::component_mirror(oop java_class) {
1458   assert(_component_mirror_offset != 0, "must be set");
1459   return java_class->obj_field(_component_mirror_offset);
1460 }
1461 
1462 oop java_lang_Class::primary_mirror(oop java_class) {
1463   assert(_primary_mirror_offset != 0, "must be set");
1464   return java_class->obj_field(_primary_mirror_offset);
1465 }
1466 
1467 void java_lang_Class::set_primary_mirror(oop java_class, oop mirror) {
1468   assert(_primary_mirror_offset != 0, "must be set");
1469   java_class->obj_field_put(_primary_mirror_offset, mirror);
1470 }
1471 
1472 oop java_lang_Class::secondary_mirror(oop java_class) {
1473   assert(_secondary_mirror_offset != 0, "must be set");
1474   return java_class->obj_field(_secondary_mirror_offset);
1475 }
1476 
1477 void java_lang_Class::set_secondary_mirror(oop java_class, oop mirror) {
1478   assert(_secondary_mirror_offset != 0, "must be set");
1479   java_class->obj_field_put(_secondary_mirror_offset, mirror);
1480 }
1481 
1482 oop java_lang_Class::init_lock(oop java_class) {
1483   assert(_init_lock_offset != 0, "must be set");
1484   return java_class->obj_field(_init_lock_offset);
1485 }
1486 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1487   assert(_init_lock_offset != 0, "must be set");
1488   java_class->obj_field_put(_init_lock_offset, init_lock);
1489 }
1490 
1491 objArrayOop java_lang_Class::signers(oop java_class) {
1492   assert(_signers_offset != 0, "must be set");
1493   return (objArrayOop)java_class->obj_field(_signers_offset);
1494 }
1495 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1496   assert(_signers_offset != 0, "must be set");
1497   java_class->obj_field_put(_signers_offset, signers);
1498 }
1499 
1500 oop java_lang_Class::class_data(oop java_class) {
1501   assert(_classData_offset != 0, "must be set");

1555     assert(aklass != NULL, "correct bootstrap");
1556     release_set_array_klass(java_class, aklass);
1557   }
1558 #ifdef ASSERT
1559   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
1560   assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1561 #endif
1562   return java_class;
1563 }
1564 
1565 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1566   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1567   java_class->metadata_field_put(_klass_offset, klass);
1568 }
1569 
1570 
1571 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1572   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1573   Symbol* name = NULL;
1574   bool is_instance = false;
1575   bool is_Q_descriptor = false;
1576   if (is_primitive(java_class)) {
1577     name = vmSymbols::type_signature(primitive_type(java_class));
1578   } else {
1579     Klass* k = as_Klass(java_class);
1580     is_instance = k->is_instance_klass();
1581     is_Q_descriptor = k->is_inline_klass() && is_secondary_mirror(java_class);
1582     name = k->name();
1583   }
1584   if (name == NULL) {
1585     st->print("<null>");
1586     return;
1587   }
1588   if (is_instance)  {
1589     st->print(is_Q_descriptor ? "Q" : "L");
1590   }
1591   st->write((char*) name->base(), (int) name->utf8_length());
1592   if (is_instance)  st->print(";");
1593 }
1594 
1595 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1596   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1597   Symbol* name;
1598   if (is_primitive(java_class)) {
1599     name = vmSymbols::type_signature(primitive_type(java_class));
1600     // Because this can create a new symbol, the caller has to decrement
1601     // the refcount, so make adjustment here and below for symbols returned
1602     // that are not created or incremented due to a successful lookup.
1603     name->increment_refcount();
1604   } else {
1605     Klass* k = as_Klass(java_class);
1606     if (!k->is_instance_klass()) {
1607       name = k->name();
1608       name->increment_refcount();
1609     } else {
1610       ResourceMark rm;
1611       const char* sigstr;
1612       if (k->is_inline_klass() && is_secondary_mirror(java_class)) {
1613         sigstr = InlineKlass::cast(k)->val_signature_name();
1614       } else {
1615         sigstr = k->signature_name();
1616       }
1617       int siglen = (int) strlen(sigstr);
1618       if (!intern_if_not_found) {
1619         name = SymbolTable::probe(sigstr, siglen);
1620       } else {
1621         name = SymbolTable::new_symbol(sigstr, siglen);
1622       }
1623     }
1624   }
1625   return name;
1626 }
1627 
1628 // Returns the Java name for this Java mirror (Resource allocated)
1629 // See Klass::external_name().
1630 // For primitive type Java mirrors, its type name is returned.
1631 const char* java_lang_Class::as_external_name(oop java_class) {
1632   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1633   const char* name = NULL;
1634   if (is_primitive(java_class)) {
1635     name = type2name(primitive_type(java_class));
1636   } else {
1637     name = as_Klass(java_class)->external_name();

1677     return primitive_type(java_class);
1678   } else {
1679     if (reference_klass != NULL)
1680       (*reference_klass) = as_Klass(java_class);
1681     return T_OBJECT;
1682   }
1683 }
1684 
1685 
1686 oop java_lang_Class::primitive_mirror(BasicType t) {
1687   oop mirror = Universe::java_mirror(t);
1688   assert(mirror != NULL && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1689   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1690   return mirror;
1691 }
1692 
1693 #define CLASS_FIELDS_DO(macro) \
1694   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1695   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1696   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \
1697   macro(_primary_mirror_offset,      k, "primaryType",         class_signature,       false); \
1698   macro(_secondary_mirror_offset,    k, "secondaryType",       class_signature,       false); \
1699   macro(_module_offset,              k, "module",              module_signature,      false); \
1700   macro(_name_offset,                k, "name",                string_signature,      false); \
1701   macro(_classData_offset,           k, "classData",           object_signature,      false);
1702 
1703 void java_lang_Class::compute_offsets() {
1704   if (_offsets_computed) {
1705     return;
1706   }
1707 
1708   _offsets_computed = true;
1709 
1710   InstanceKlass* k = vmClasses::Class_klass();
1711   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1712 
1713   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1714   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1715   // GC treats them the same.
1716   _init_lock_offset = _component_mirror_offset;
1717 
1718   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);

2569 #endif
2570 
2571     // the format of the stacktrace will be:
2572     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2573     // - 0 or more <init> methods for the exception class (skipped)
2574     // - rest of the stack
2575 
2576     if (!skip_fillInStackTrace_check) {
2577       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2578           throwable->is_a(method->method_holder())) {
2579         continue;
2580       }
2581       else {
2582         skip_fillInStackTrace_check = true; // gone past them all
2583       }
2584     }
2585     if (!skip_throwableInit_check) {
2586       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2587 
2588       // skip <init> methods of the exception class and superclasses
2589       // This is similar to classic VM (before HotSpot).
2590       if (method->is_object_constructor() &&
2591           throwable->is_a(method->method_holder())) {
2592         continue;
2593       } else {
2594         // there are none or we've seen them all - either way stop checking
2595         skip_throwableInit_check = true;
2596       }
2597     }
2598     if (method->is_hidden()) {
2599       if (skip_hidden) {
2600         if (total_count == 0) {
2601           // The top frame will be hidden from the stack trace.
2602           bt.set_has_hidden_top_frame();
2603         }
2604         continue;
2605       }
2606     }
2607     bt.push(method, bci, CHECK);
2608     total_count++;
2609   }
2610 

4043 int java_lang_invoke_MemberName::flags(oop mname) {
4044   assert(is_instance(mname), "wrong type");
4045   return mname->int_field(_flags_offset);
4046 }
4047 
4048 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4049   assert(is_instance(mname), "wrong type");
4050   mname->int_field_put(_flags_offset, flags);
4051 }
4052 
4053 
4054 // Return vmtarget from ResolvedMethodName method field through indirection
4055 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4056   assert(is_instance(mname), "wrong type");
4057   oop method = mname->obj_field(_method_offset);
4058   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4059 }
4060 
4061 bool java_lang_invoke_MemberName::is_method(oop mname) {
4062   assert(is_instance(mname), "must be MemberName");
4063   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4064 }
4065 
4066 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4067   assert(is_instance(mname), "wrong type");
4068   mname->obj_field_put(_method_offset, resolved_method);
4069 }
4070 
4071 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4072   assert(is_instance(mname), "wrong type");
4073   return (intptr_t) mname->address_field(_vmindex_offset);
4074 }
4075 
4076 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4077   assert(is_instance(mname), "wrong type");
4078   mname->address_field_put(_vmindex_offset, (address) index);
4079 }
4080 
4081 
4082 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4083   assert(is_instance(resolved_method), "wrong type");
< prev index next >