< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page




  34 #include "code/dependencyContext.hpp"
  35 #include "code/pcDesc.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "interpreter/linkResolver.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/heapShared.inline.hpp"
  41 #include "memory/metaspaceShared.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/fieldStreams.hpp"
  46 #include "oops/instanceKlass.hpp"
  47 #include "oops/instanceMirrorKlass.hpp"
  48 #include "oops/klass.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/objArrayOop.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/symbol.hpp"
  53 #include "oops/typeArrayOop.inline.hpp"

  54 #include "prims/jvmtiExport.hpp"
  55 #include "prims/resolvedMethodTable.hpp"
  56 #include "runtime/fieldDescriptor.inline.hpp"
  57 #include "runtime/frame.inline.hpp"
  58 #include "runtime/handles.inline.hpp"
  59 #include "runtime/interfaceSupport.inline.hpp"
  60 #include "runtime/java.hpp"
  61 #include "runtime/javaCalls.hpp"
  62 #include "runtime/jniHandles.inline.hpp"
  63 #include "runtime/safepoint.hpp"
  64 #include "runtime/safepointVerifiers.hpp"
  65 #include "runtime/thread.inline.hpp"
  66 #include "runtime/vframe.inline.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/preserveException.hpp"
  69 #include "utilities/utf8.hpp"
  70 #if INCLUDE_JVMCI
  71 #include "jvmci/jvmciJavaClasses.hpp"
  72 #endif
  73 


 906   int computed_modifiers = k->compute_modifier_flags(CHECK);
 907   k->set_modifier_flags(computed_modifiers);
 908   // Class_klass has to be loaded because it is used to allocate
 909   // the mirror.
 910   if (SystemDictionary::Class_klass_loaded()) {
 911     // Allocate mirror (java.lang.Class instance)
 912     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 913     Handle mirror(THREAD, mirror_oop);
 914     Handle comp_mirror;
 915 
 916     // Setup indirection from mirror->klass
 917     java_lang_Class::set_klass(mirror(), k);
 918 
 919     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 920     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 921 
 922     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 923 
 924     // It might also have a component mirror.  This mirror must already exist.
 925     if (k->is_array_klass()) {
 926       if (k->is_typeArray_klass()) {





 927         BasicType type = TypeArrayKlass::cast(k)->element_type();
 928         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
 929       } else {
 930         assert(k->is_objArray_klass(), "Must be");
 931         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
 932         assert(element_klass != NULL, "Must have an element klass");
 933         comp_mirror = Handle(THREAD, element_klass->java_mirror());








 934       }
 935       assert(comp_mirror() != NULL, "must have a mirror");
 936 
 937       // Two-way link between the array klass and its component mirror:
 938       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
 939       set_component_mirror(mirror(), comp_mirror());
 940       // See below for ordering dependencies between field array_klass in component mirror
 941       // and java_mirror in this klass.
 942     } else {
 943       assert(k->is_instance_klass(), "Must be");
 944 
 945       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 946       if (HAS_PENDING_EXCEPTION) {
 947         // If any of the fields throws an exception like OOM remove the klass field
 948         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 949         // This mirror looks like a primitive type, which logically it is because it
 950         // it represents no class.
 951         java_lang_Class::set_klass(mirror(), NULL);
 952         return;
 953       }
 954     }
 955 
 956     // set the classLoader field in the java_lang_Class instance
 957     assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
 958     set_class_loader(mirror(), class_loader());
 959 
 960     // Setup indirection from klass->mirror
 961     // after any exceptions can happen during allocations.
 962     k->set_java_mirror(mirror);
 963 
 964     // Set the module field in the java_lang_Class instance.  This must be done
 965     // after the mirror is set.
 966     set_mirror_module_field(k, mirror, module, THREAD);
 967 
 968     if (comp_mirror() != NULL) {
 969       // Set after k->java_mirror() is published, because compiled code running
 970       // concurrently doesn't expect a k to have a null java_mirror.
 971       release_set_array_klass(comp_mirror(), k);
 972     }







 973   } else {
 974     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
 975     fixup_mirror_list()->push(k);
 976   }
 977 }
 978 






















 979 #if INCLUDE_CDS_JAVA_HEAP
 980 // Clears mirror fields. Static final fields with initial values are reloaded
 981 // from constant pool. The object identity hash is in the object header and is
 982 // not affected.
 983 class ResetMirrorField: public FieldClosure {
 984  private:
 985   Handle _m;
 986 
 987  public:
 988   ResetMirrorField(Handle mirror) : _m(mirror) {}
 989 
 990   void do_field(fieldDescriptor* fd) {
 991     assert(DumpSharedSpaces, "dump time only");
 992     assert(_m.not_null(), "Mirror cannot be NULL");
 993 
 994     if (fd->is_static() && fd->has_initial_value()) {
 995       initialize_static_field(fd, _m, Thread::current());
 996       return;
 997     }
 998 


1366 oop java_lang_Class::name(Handle java_class, TRAPS) {
1367   assert(_name_offset != 0, "must be set");
1368   oop o = java_class->obj_field(_name_offset);
1369   if (o == NULL) {
1370     o = StringTable::intern(java_lang_Class::as_external_name(java_class()), THREAD);
1371     java_class->obj_field_put(_name_offset, o);
1372   }
1373   return o;
1374 }
1375 
1376 oop java_lang_Class::source_file(oop java_class) {
1377   assert(_source_file_offset != 0, "must be set");
1378   return java_class->obj_field(_source_file_offset);
1379 }
1380 
1381 void java_lang_Class::set_source_file(oop java_class, oop source_file) {
1382   assert(_source_file_offset != 0, "must be set");
1383   java_class->obj_field_put(_source_file_offset, source_file);
1384 }
1385 




















1386 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
1387   // This should be improved by adding a field at the Java level or by
1388   // introducing a new VM klass (see comment in ClassFileParser)
1389   oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0);
1390   if (type != T_VOID) {
1391     Klass* aklass = Universe::typeArrayKlassObj(type);
1392     assert(aklass != NULL, "correct bootstrap");
1393     release_set_array_klass(java_class, aklass);
1394   }
1395 #ifdef ASSERT
1396   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass());
1397   assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1398 #endif
1399   return java_class;
1400 }
1401 
1402 
1403 Klass* java_lang_Class::as_Klass(oop java_class) {
1404   //%note memory_2
1405   assert(java_lang_Class::is_instance(java_class), "must be a Class object");


1410 
1411 Klass* java_lang_Class::as_Klass_raw(oop java_class) {
1412   //%note memory_2
1413   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1414   Klass* k = ((Klass*)java_class->metadata_field_raw(_klass_offset));
1415   assert(k == NULL || k->is_klass(), "type check");
1416   return k;
1417 }
1418 
1419 
1420 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1421   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1422   java_class->metadata_field_put(_klass_offset, klass);
1423 }
1424 
1425 
1426 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1427   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1428   Symbol* name = NULL;
1429   bool is_instance = false;

1430   if (is_primitive(java_class)) {
1431     name = vmSymbols::type_signature(primitive_type(java_class));
1432   } else {
1433     Klass* k = as_Klass(java_class);
1434     is_instance = k->is_instance_klass();

1435     name = k->name();
1436   }
1437   if (name == NULL) {
1438     st->print("<null>");
1439     return;
1440   }
1441   if (is_instance)  st->print("L");






1442   st->write((char*) name->base(), (int) name->utf8_length());
1443   if (is_instance)  st->print(";");
1444 }
1445 
1446 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1447   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1448   Symbol* name;
1449   if (is_primitive(java_class)) {
1450     name = vmSymbols::type_signature(primitive_type(java_class));
1451     // Because this can create a new symbol, the caller has to decrement
1452     // the refcount, so make adjustment here and below for symbols returned
1453     // that are not created or incremented due to a successful lookup.
1454     name->increment_refcount();
1455   } else {
1456     Klass* k = as_Klass(java_class);
1457     if (!k->is_instance_klass()) {
1458       name = k->name();
1459       name->increment_refcount();
1460     } else {
1461       ResourceMark rm;
1462       const char* sigstr = k->signature_name();
1463       int         siglen = (int) strlen(sigstr);






1464       if (!intern_if_not_found) {
1465         name = SymbolTable::probe(sigstr, siglen);
1466       } else {
1467         name = SymbolTable::new_symbol(sigstr, siglen);
1468       }
1469     }
1470   }
1471   return name;
1472 }
1473 
1474 // Returns the Java name for this Java mirror (Resource allocated)
1475 // See Klass::external_name().
1476 // For primitive type Java mirrors, its type name is returned.
1477 const char* java_lang_Class::as_external_name(oop java_class) {
1478   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1479   const char* name = NULL;
1480   if (is_primitive(java_class)) {
1481     name = type2name(primitive_type(java_class));
1482   } else {
1483     name = as_Klass(java_class)->external_name();


1528   }
1529 }
1530 
1531 
1532 oop java_lang_Class::primitive_mirror(BasicType t) {
1533   oop mirror = Universe::java_mirror(t);
1534   assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1535   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1536   return mirror;
1537 }
1538 
1539 bool java_lang_Class::offsets_computed = false;
1540 int  java_lang_Class::classRedefinedCount_offset = -1;
1541 
1542 #define CLASS_FIELDS_DO(macro) \
1543   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
1544   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1545   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1546   macro(_module_offset,             k, "module",              module_signature,      false); \
1547   macro(_name_offset,               k, "name",                string_signature,      false); \


1548 
1549 void java_lang_Class::compute_offsets() {
1550   if (offsets_computed) {
1551     return;
1552   }
1553 
1554   offsets_computed = true;
1555 
1556   InstanceKlass* k = SystemDictionary::Class_klass();
1557   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1558 
1559   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1560   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1561   // GC treats them the same.
1562   _init_lock_offset = _component_mirror_offset;
1563 
1564   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1565 }
1566 
1567 #if INCLUDE_CDS


2374 #endif
2375 
2376     // the format of the stacktrace will be:
2377     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2378     // - 0 or more <init> methods for the exception class (skipped)
2379     // - rest of the stack
2380 
2381     if (!skip_fillInStackTrace_check) {
2382       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2383           throwable->is_a(method->method_holder())) {
2384         continue;
2385       }
2386       else {
2387         skip_fillInStackTrace_check = true; // gone past them all
2388       }
2389     }
2390     if (!skip_throwableInit_check) {
2391       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2392 
2393       // skip <init> methods of the exception class and superclasses
2394       // This is simlar to classic VM.
2395       if (method->name() == vmSymbols::object_initializer_name() &&
2396           throwable->is_a(method->method_holder())) {
2397         continue;
2398       } else {
2399         // there are none or we've seen them all - either way stop checking
2400         skip_throwableInit_check = true;
2401       }
2402     }
2403     if (method->is_hidden()) {
2404       if (skip_hidden)  continue;
2405     }
2406     bt.push(method, bci, CHECK);
2407     total_count++;
2408   }
2409 
2410   log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), total_count);
2411 
2412   // Put completed stack trace into throwable object
2413   set_backtrace(throwable(), bt.backtrace());
2414   set_depth(throwable(), total_count);
2415 }


3574 int java_lang_invoke_MemberName::flags(oop mname) {
3575   assert(is_instance(mname), "wrong type");
3576   return mname->int_field(_flags_offset);
3577 }
3578 
3579 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
3580   assert(is_instance(mname), "wrong type");
3581   mname->int_field_put(_flags_offset, flags);
3582 }
3583 
3584 
3585 // Return vmtarget from ResolvedMethodName method field through indirection
3586 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
3587   assert(is_instance(mname), "wrong type");
3588   oop method = mname->obj_field(_method_offset);
3589   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
3590 }
3591 
3592 bool java_lang_invoke_MemberName::is_method(oop mname) {
3593   assert(is_instance(mname), "must be MemberName");
3594   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
3595 }
3596 
3597 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
3598   assert(is_instance(mname), "wrong type");
3599   mname->obj_field_put(_method_offset, resolved_method);
3600 }
3601 
3602 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
3603   assert(is_instance(mname), "wrong type");
3604   return (intptr_t) mname->address_field(_vmindex_offset);
3605 }
3606 
3607 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3608   assert(is_instance(mname), "wrong type");
3609   mname->address_field_put(_vmindex_offset, (address) index);
3610 }
3611 
3612 
3613 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
3614   assert(is_instance(resolved_method), "wrong type");


4059       mirror->bool_field_put(fd->offset(), _use_unaligned_access);
4060     } else {
4061       assert(false, "unexpected UnsafeConstants field");
4062     }
4063   }
4064 };
4065 
4066 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4067   UnsafeConstantsFixup fixup;
4068   SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4069 }
4070 
4071 int java_lang_Class::_klass_offset;
4072 int java_lang_Class::_array_klass_offset;
4073 int java_lang_Class::_oop_size_offset;
4074 int java_lang_Class::_static_oop_field_count_offset;
4075 int java_lang_Class::_class_loader_offset;
4076 int java_lang_Class::_module_offset;
4077 int java_lang_Class::_protection_domain_offset;
4078 int java_lang_Class::_component_mirror_offset;


4079 int java_lang_Class::_init_lock_offset;
4080 int java_lang_Class::_signers_offset;
4081 int java_lang_Class::_name_offset;
4082 int java_lang_Class::_source_file_offset;
4083 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4084 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4085 int java_lang_Throwable::backtrace_offset;
4086 int java_lang_Throwable::detailMessage_offset;
4087 int java_lang_Throwable::stackTrace_offset;
4088 int java_lang_Throwable::depth_offset;
4089 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4090 int java_lang_reflect_AccessibleObject::override_offset;
4091 int java_lang_reflect_Method::clazz_offset;
4092 int java_lang_reflect_Method::name_offset;
4093 int java_lang_reflect_Method::returnType_offset;
4094 int java_lang_reflect_Method::parameterTypes_offset;
4095 int java_lang_reflect_Method::exceptionTypes_offset;
4096 int java_lang_reflect_Method::slot_offset;
4097 int java_lang_reflect_Method::modifiers_offset;
4098 int java_lang_reflect_Method::signature_offset;




  34 #include "code/dependencyContext.hpp"
  35 #include "code/pcDesc.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "interpreter/linkResolver.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/heapShared.inline.hpp"
  41 #include "memory/metaspaceShared.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/fieldStreams.hpp"
  46 #include "oops/instanceKlass.hpp"
  47 #include "oops/instanceMirrorKlass.hpp"
  48 #include "oops/klass.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/objArrayOop.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/symbol.hpp"
  53 #include "oops/typeArrayOop.inline.hpp"
  54 #include "oops/valueArrayKlass.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "prims/resolvedMethodTable.hpp"
  57 #include "runtime/fieldDescriptor.inline.hpp"
  58 #include "runtime/frame.inline.hpp"
  59 #include "runtime/handles.inline.hpp"
  60 #include "runtime/interfaceSupport.inline.hpp"
  61 #include "runtime/java.hpp"
  62 #include "runtime/javaCalls.hpp"
  63 #include "runtime/jniHandles.inline.hpp"
  64 #include "runtime/safepoint.hpp"
  65 #include "runtime/safepointVerifiers.hpp"
  66 #include "runtime/thread.inline.hpp"
  67 #include "runtime/vframe.inline.hpp"
  68 #include "utilities/align.hpp"
  69 #include "utilities/preserveException.hpp"
  70 #include "utilities/utf8.hpp"
  71 #if INCLUDE_JVMCI
  72 #include "jvmci/jvmciJavaClasses.hpp"
  73 #endif
  74 


 907   int computed_modifiers = k->compute_modifier_flags(CHECK);
 908   k->set_modifier_flags(computed_modifiers);
 909   // Class_klass has to be loaded because it is used to allocate
 910   // the mirror.
 911   if (SystemDictionary::Class_klass_loaded()) {
 912     // Allocate mirror (java.lang.Class instance)
 913     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 914     Handle mirror(THREAD, mirror_oop);
 915     Handle comp_mirror;
 916 
 917     // Setup indirection from mirror->klass
 918     java_lang_Class::set_klass(mirror(), k);
 919 
 920     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 921     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 922 
 923     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 924 
 925     // It might also have a component mirror.  This mirror must already exist.
 926     if (k->is_array_klass()) {
 927       if (k->is_valueArray_klass()) {
 928         Klass* element_klass = (Klass*) ValueArrayKlass::cast(k)->element_klass();
 929         assert(element_klass->is_value(), "Must be value type component");
 930         ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
 931         comp_mirror = Handle(THREAD, vk->value_mirror());
 932       } else if (k->is_typeArray_klass()) {
 933         BasicType type = TypeArrayKlass::cast(k)->element_type();
 934         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
 935       } else {
 936         assert(k->is_objArray_klass(), "Must be");
 937         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
 938         assert(element_klass != NULL, "Must have an element klass");
 939         if (element_klass->is_value()) {
 940           ValueKlass* vk = ValueKlass::cast(InstanceKlass::cast(element_klass));
 941           assert(vk->java_mirror() == vk->value_mirror(), "primary mirror is the value mirror");
 942           assert(vk->indirect_mirror() != NULL, "must have an indirect class mirror");
 943           comp_mirror = k->name()->is_Q_array_signature() ? Handle(THREAD, vk->value_mirror())
 944                                                           : Handle(THREAD, vk->indirect_mirror());
 945         } else {
 946           comp_mirror = Handle(THREAD, element_klass->java_mirror());
 947         }
 948       }
 949       assert(comp_mirror() != NULL, "must have a mirror");
 950 
 951       // Two-way link between the array klass and its component mirror:
 952       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
 953       set_component_mirror(mirror(), comp_mirror());
 954       // See below for ordering dependencies between field array_klass in component mirror
 955       // and java_mirror in this klass.
 956     } else {
 957       assert(k->is_instance_klass(), "Must be");
 958 
 959       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 960       if (HAS_PENDING_EXCEPTION) {
 961         // If any of the fields throws an exception like OOM remove the klass field
 962         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 963         // This mirror looks like a primitive type, which logically it is because it
 964         // it represents no class.
 965         java_lang_Class::set_klass(mirror(), NULL);
 966         return;
 967       }
 968     }
 969 
 970     // set the classLoader field in the java_lang_Class instance
 971     assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
 972     set_class_loader(mirror(), class_loader());
 973 
 974     // Setup indirection from klass->mirror
 975     // after any exceptions can happen during allocations.
 976     k->set_java_mirror(mirror);
 977 
 978     // Set the module field in the java_lang_Class instance.  This must be done
 979     // after the mirror is set.
 980     set_mirror_module_field(k, mirror, module, THREAD);
 981 
 982     if (comp_mirror() != NULL) {
 983       // Set after k->java_mirror() is published, because compiled code running
 984       // concurrently doesn't expect a k to have a null java_mirror.
 985       release_set_array_klass(comp_mirror(), k);
 986     }
 987 
 988     if (k->is_value()) {
 989       // create the secondary mirror for an inline class
 990       oop indirect_mirror_oop = create_indirect_type_mirror(k, mirror, CHECK);
 991       set_inline_type_mirror(mirror(), mirror());
 992       set_indirect_type_mirror(mirror(), indirect_mirror_oop);
 993     }
 994   } else {
 995     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
 996     fixup_mirror_list()->push(k);
 997   }
 998 }
 999 
1000 // Create the secondary mirror for inline class. Sets all the fields of this java.lang.Class
1001 // instance with the same value as the primary mirror
1002 oop java_lang_Class::create_indirect_type_mirror(Klass* k, Handle mirror, TRAPS) {
1003   assert(k->is_value(), "inline class");
1004   // Allocate mirror (java.lang.Class instance)
1005   oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK_0);
1006   Handle indirect_mirror(THREAD, mirror_oop);
1007 
1008   java_lang_Class::set_klass(indirect_mirror(), k);
1009   java_lang_Class::set_static_oop_field_count(indirect_mirror(), static_oop_field_count(mirror()));
1010   // ## do we need to set init lock?
1011   java_lang_Class::set_init_lock(indirect_mirror(), init_lock(mirror()));
1012 
1013   set_protection_domain(indirect_mirror(), protection_domain(mirror()));
1014   set_class_loader(indirect_mirror(), class_loader(mirror()));
1015   // ## handle if java.base is not yet defined
1016   set_module(indirect_mirror(), module(mirror()));
1017   set_inline_type_mirror(indirect_mirror(), mirror());
1018   set_indirect_type_mirror(indirect_mirror(), indirect_mirror());
1019   return indirect_mirror();
1020 }
1021 
1022 #if INCLUDE_CDS_JAVA_HEAP
1023 // Clears mirror fields. Static final fields with initial values are reloaded
1024 // from constant pool. The object identity hash is in the object header and is
1025 // not affected.
1026 class ResetMirrorField: public FieldClosure {
1027  private:
1028   Handle _m;
1029 
1030  public:
1031   ResetMirrorField(Handle mirror) : _m(mirror) {}
1032 
1033   void do_field(fieldDescriptor* fd) {
1034     assert(DumpSharedSpaces, "dump time only");
1035     assert(_m.not_null(), "Mirror cannot be NULL");
1036 
1037     if (fd->is_static() && fd->has_initial_value()) {
1038       initialize_static_field(fd, _m, Thread::current());
1039       return;
1040     }
1041 


1409 oop java_lang_Class::name(Handle java_class, TRAPS) {
1410   assert(_name_offset != 0, "must be set");
1411   oop o = java_class->obj_field(_name_offset);
1412   if (o == NULL) {
1413     o = StringTable::intern(java_lang_Class::as_external_name(java_class()), THREAD);
1414     java_class->obj_field_put(_name_offset, o);
1415   }
1416   return o;
1417 }
1418 
1419 oop java_lang_Class::source_file(oop java_class) {
1420   assert(_source_file_offset != 0, "must be set");
1421   return java_class->obj_field(_source_file_offset);
1422 }
1423 
1424 void java_lang_Class::set_source_file(oop java_class, oop source_file) {
1425   assert(_source_file_offset != 0, "must be set");
1426   java_class->obj_field_put(_source_file_offset, source_file);
1427 }
1428 
1429 oop java_lang_Class::inline_type_mirror(oop java_class) {
1430   assert(_inline_mirror_offset != 0, "must be set");
1431   return java_class->obj_field(_inline_mirror_offset);
1432 }
1433 
1434 void java_lang_Class::set_inline_type_mirror(oop java_class, oop mirror) {
1435   assert(_inline_mirror_offset != 0, "must be set");
1436   java_class->obj_field_put(_inline_mirror_offset, mirror);
1437 }
1438 
1439 oop java_lang_Class::indirect_type_mirror(oop java_class) {
1440   assert(_indirect_mirror_offset != 0, "must be set");
1441   return java_class->obj_field(_indirect_mirror_offset);
1442 }
1443 
1444 void java_lang_Class::set_indirect_type_mirror(oop java_class, oop mirror) {
1445   assert(_indirect_mirror_offset != 0, "must be set");
1446   java_class->obj_field_put(_indirect_mirror_offset, mirror);
1447 }
1448 
1449 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
1450   // This should be improved by adding a field at the Java level or by
1451   // introducing a new VM klass (see comment in ClassFileParser)
1452   oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0);
1453   if (type != T_VOID) {
1454     Klass* aklass = Universe::typeArrayKlassObj(type);
1455     assert(aklass != NULL, "correct bootstrap");
1456     release_set_array_klass(java_class, aklass);
1457   }
1458 #ifdef ASSERT
1459   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass());
1460   assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
1461 #endif
1462   return java_class;
1463 }
1464 
1465 
1466 Klass* java_lang_Class::as_Klass(oop java_class) {
1467   //%note memory_2
1468   assert(java_lang_Class::is_instance(java_class), "must be a Class object");


1473 
1474 Klass* java_lang_Class::as_Klass_raw(oop java_class) {
1475   //%note memory_2
1476   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1477   Klass* k = ((Klass*)java_class->metadata_field_raw(_klass_offset));
1478   assert(k == NULL || k->is_klass(), "type check");
1479   return k;
1480 }
1481 
1482 
1483 void java_lang_Class::set_klass(oop java_class, Klass* klass) {
1484   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1485   java_class->metadata_field_put(_klass_offset, klass);
1486 }
1487 
1488 
1489 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1490   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1491   Symbol* name = NULL;
1492   bool is_instance = false;
1493   bool is_value = false;
1494   if (is_primitive(java_class)) {
1495     name = vmSymbols::type_signature(primitive_type(java_class));
1496   } else {
1497     Klass* k = as_Klass(java_class);
1498     is_instance = k->is_instance_klass();
1499     is_value = k->is_value();
1500     name = k->name();
1501   }
1502   if (name == NULL) {
1503     st->print("<null>");
1504     return;
1505   }
1506   if (is_instance)  {
1507     if (is_value && (java_class == inline_type_mirror(java_class))) {
1508       st->print("Q");
1509     } else {
1510       st->print("L");
1511     }
1512   }
1513   st->write((char*) name->base(), (int) name->utf8_length());
1514   if (is_instance)  st->print(";");
1515 }
1516 
1517 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1518   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
1519   Symbol* name;
1520   if (is_primitive(java_class)) {
1521     name = vmSymbols::type_signature(primitive_type(java_class));
1522     // Because this can create a new symbol, the caller has to decrement
1523     // the refcount, so make adjustment here and below for symbols returned
1524     // that are not created or incremented due to a successful lookup.
1525     name->increment_refcount();
1526   } else {
1527     Klass* k = as_Klass(java_class);
1528     if (!k->is_instance_klass()) {
1529       name = k->name();
1530       name->increment_refcount();
1531     } else {
1532       ResourceMark rm;
1533       const char* sigstr;
1534       if (k->is_value()) {
1535         char c = (java_class == inline_type_mirror(java_class)) ? 'Q' : 'L';
1536         sigstr = InstanceKlass::cast(k)->signature_name_of(c);
1537       } else {
1538         sigstr = k->signature_name();
1539       }
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();


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(SystemDictionary::Class_klass()), "must be a Class");
1612   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1613   return mirror;
1614 }
1615 
1616 bool java_lang_Class::offsets_computed = false;
1617 int  java_lang_Class::classRedefinedCount_offset = -1;
1618 
1619 #define CLASS_FIELDS_DO(macro) \
1620   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
1621   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1622   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1623   macro(_module_offset,             k, "module",              module_signature,      false); \
1624   macro(_name_offset,               k, "name",                string_signature,      false); \
1625   macro(_inline_mirror_offset,      k, "inlineType",          class_signature,       false); \
1626   macro(_indirect_mirror_offset,    k, "indirectType",        class_signature,       false); \
1627 
1628 void java_lang_Class::compute_offsets() {
1629   if (offsets_computed) {
1630     return;
1631   }
1632 
1633   offsets_computed = true;
1634 
1635   InstanceKlass* k = SystemDictionary::Class_klass();
1636   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1637 
1638   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1639   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1640   // GC treats them the same.
1641   _init_lock_offset = _component_mirror_offset;
1642 
1643   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1644 }
1645 
1646 #if INCLUDE_CDS


2453 #endif
2454 
2455     // the format of the stacktrace will be:
2456     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2457     // - 0 or more <init> methods for the exception class (skipped)
2458     // - rest of the stack
2459 
2460     if (!skip_fillInStackTrace_check) {
2461       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2462           throwable->is_a(method->method_holder())) {
2463         continue;
2464       }
2465       else {
2466         skip_fillInStackTrace_check = true; // gone past them all
2467       }
2468     }
2469     if (!skip_throwableInit_check) {
2470       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2471 
2472       // skip <init> methods of the exception class and superclasses
2473       // This is similar to classic VM (before HotSpot).
2474       if (method->is_object_constructor() &&
2475           throwable->is_a(method->method_holder())) {
2476         continue;
2477       } else {
2478         // there are none or we've seen them all - either way stop checking
2479         skip_throwableInit_check = true;
2480       }
2481     }
2482     if (method->is_hidden()) {
2483       if (skip_hidden)  continue;
2484     }
2485     bt.push(method, bci, CHECK);
2486     total_count++;
2487   }
2488 
2489   log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), total_count);
2490 
2491   // Put completed stack trace into throwable object
2492   set_backtrace(throwable(), bt.backtrace());
2493   set_depth(throwable(), total_count);
2494 }


3653 int java_lang_invoke_MemberName::flags(oop mname) {
3654   assert(is_instance(mname), "wrong type");
3655   return mname->int_field(_flags_offset);
3656 }
3657 
3658 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
3659   assert(is_instance(mname), "wrong type");
3660   mname->int_field_put(_flags_offset, flags);
3661 }
3662 
3663 
3664 // Return vmtarget from ResolvedMethodName method field through indirection
3665 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
3666   assert(is_instance(mname), "wrong type");
3667   oop method = mname->obj_field(_method_offset);
3668   return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method);
3669 }
3670 
3671 bool java_lang_invoke_MemberName::is_method(oop mname) {
3672   assert(is_instance(mname), "must be MemberName");
3673   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
3674 }
3675 
3676 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
3677   assert(is_instance(mname), "wrong type");
3678   mname->obj_field_put(_method_offset, resolved_method);
3679 }
3680 
3681 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
3682   assert(is_instance(mname), "wrong type");
3683   return (intptr_t) mname->address_field(_vmindex_offset);
3684 }
3685 
3686 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3687   assert(is_instance(mname), "wrong type");
3688   mname->address_field_put(_vmindex_offset, (address) index);
3689 }
3690 
3691 
3692 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
3693   assert(is_instance(resolved_method), "wrong type");


4138       mirror->bool_field_put(fd->offset(), _use_unaligned_access);
4139     } else {
4140       assert(false, "unexpected UnsafeConstants field");
4141     }
4142   }
4143 };
4144 
4145 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4146   UnsafeConstantsFixup fixup;
4147   SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4148 }
4149 
4150 int java_lang_Class::_klass_offset;
4151 int java_lang_Class::_array_klass_offset;
4152 int java_lang_Class::_oop_size_offset;
4153 int java_lang_Class::_static_oop_field_count_offset;
4154 int java_lang_Class::_class_loader_offset;
4155 int java_lang_Class::_module_offset;
4156 int java_lang_Class::_protection_domain_offset;
4157 int java_lang_Class::_component_mirror_offset;
4158 int java_lang_Class::_inline_mirror_offset;
4159 int java_lang_Class::_indirect_mirror_offset;
4160 int java_lang_Class::_init_lock_offset;
4161 int java_lang_Class::_signers_offset;
4162 int java_lang_Class::_name_offset;
4163 int java_lang_Class::_source_file_offset;
4164 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4165 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4166 int java_lang_Throwable::backtrace_offset;
4167 int java_lang_Throwable::detailMessage_offset;
4168 int java_lang_Throwable::stackTrace_offset;
4169 int java_lang_Throwable::depth_offset;
4170 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4171 int java_lang_reflect_AccessibleObject::override_offset;
4172 int java_lang_reflect_Method::clazz_offset;
4173 int java_lang_reflect_Method::name_offset;
4174 int java_lang_reflect_Method::returnType_offset;
4175 int java_lang_reflect_Method::parameterTypes_offset;
4176 int java_lang_reflect_Method::exceptionTypes_offset;
4177 int java_lang_reflect_Method::slot_offset;
4178 int java_lang_reflect_Method::modifiers_offset;
4179 int java_lang_reflect_Method::signature_offset;


< prev index next >