< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page




 806       // update all the static field offsets to included the size.
 807       for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
 808         if (fs.access_flags().is_static()) {
 809           int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
 810           fs.set_offset(real_offset);
 811         }
 812       }
 813     }
 814   }
 815 
 816   if (k->is_shared() && k->has_raw_archived_mirror()) {
 817     if (HeapShared::open_archive_heap_region_mapped()) {
 818       bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
 819       assert(present, "Missing archived mirror for %s", k->external_name());
 820       return;
 821     } else {
 822       k->set_java_mirror_handle(NULL);
 823       k->clear_has_raw_archived_mirror();
 824     }
 825   }
 826   create_mirror(k, Handle(), Handle(), Handle(), CHECK);
 827 }
 828 
 829 void java_lang_Class::initialize_mirror_fields(Klass* k,
 830                                                Handle mirror,
 831                                                Handle protection_domain,

 832                                                TRAPS) {
 833   // Allocate a simple java object for a lock.
 834   // This needs to be a java object because during class initialization
 835   // it can be held across a java call.
 836   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 837   set_init_lock(mirror(), r);
 838 
 839   // Set protection domain also
 840   set_protection_domain(mirror(), protection_domain());
 841 
 842   // Initialize static fields
 843   InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);



 844 }
 845 
 846 // Set the java.lang.Module module field in the java_lang_Class mirror
 847 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
 848   if (module.is_null()) {
 849     // During startup, the module may be NULL only if java.base has not been defined yet.
 850     // Put the class on the fixup_module_list to patch later when the java.lang.Module
 851     // for java.base is known. But note that since we captured the NULL module another
 852     // thread may have completed that initialization.
 853 
 854     bool javabase_was_defined = false;
 855     {
 856       MutexLocker m1(Module_lock, THREAD);
 857       // Keep list of classes needing java.base module fixup
 858       if (!ModuleEntryTable::javabase_defined()) {
 859         assert(k->java_mirror() != NULL, "Class's mirror is null");
 860         k->class_loader_data()->inc_keep_alive();
 861         assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
 862         fixup_module_field_list()->push(k);
 863       } else {


 877     assert(Universe::is_module_initialized() ||
 878            (ModuleEntryTable::javabase_defined() &&
 879             (oopDesc::equals(module(), ModuleEntryTable::javabase_moduleEntry()->module()))),
 880            "Incorrect java.lang.Module specification while creating mirror");
 881     set_module(mirror(), module());
 882   }
 883 }
 884 
 885 // Statically allocate fixup lists because they always get created.
 886 void java_lang_Class::allocate_fixup_lists() {
 887   GrowableArray<Klass*>* mirror_list =
 888     new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 889   set_fixup_mirror_list(mirror_list);
 890 
 891   GrowableArray<Klass*>* module_list =
 892     new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 893   set_fixup_module_field_list(module_list);
 894 }
 895 
 896 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
 897                                     Handle module, Handle protection_domain, TRAPS) {

 898   assert(k != NULL, "Use create_basic_type_mirror for primitive types");
 899   assert(k->java_mirror() == NULL, "should only assign mirror once");
 900 
 901   // Use this moment of initialization to cache modifier_flags also,
 902   // to support Class.getModifiers().  Instance classes recalculate
 903   // the cached flags after the class file is parsed, but before the
 904   // class is put into the system dictionary.
 905   int computed_modifiers = k->compute_modifier_flags(CHECK);
 906   k->set_modifier_flags(computed_modifiers);
 907   // Class_klass has to be loaded because it is used to allocate
 908   // the mirror.
 909   if (SystemDictionary::Class_klass_loaded()) {
 910     // Allocate mirror (java.lang.Class instance)
 911     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 912     Handle mirror(THREAD, mirror_oop);
 913     Handle comp_mirror;
 914 
 915     // Setup indirection from mirror->klass
 916     java_lang_Class::set_klass(mirror(), k);
 917 


 924     if (k->is_array_klass()) {
 925       if (k->is_typeArray_klass()) {
 926         BasicType type = TypeArrayKlass::cast(k)->element_type();
 927         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
 928       } else {
 929         assert(k->is_objArray_klass(), "Must be");
 930         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
 931         assert(element_klass != NULL, "Must have an element klass");
 932         comp_mirror = Handle(THREAD, element_klass->java_mirror());
 933       }
 934       assert(comp_mirror() != NULL, "must have a mirror");
 935 
 936       // Two-way link between the array klass and its component mirror:
 937       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
 938       set_component_mirror(mirror(), comp_mirror());
 939       // See below for ordering dependencies between field array_klass in component mirror
 940       // and java_mirror in this klass.
 941     } else {
 942       assert(k->is_instance_klass(), "Must be");
 943 
 944       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 945       if (HAS_PENDING_EXCEPTION) {
 946         // If any of the fields throws an exception like OOM remove the klass field
 947         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 948         // This mirror looks like a primitive type, which logically it is because it
 949         // it represents no class.
 950         java_lang_Class::set_klass(mirror(), NULL);
 951         return;
 952       }
 953     }
 954 
 955     // set the classLoader field in the java_lang_Class instance
 956     assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
 957     set_class_loader(mirror(), class_loader());
 958 
 959     // Setup indirection from klass->mirror
 960     // after any exceptions can happen during allocations.
 961     k->set_java_mirror(mirror);
 962 
 963     // Set the module field in the java_lang_Class instance.  This must be done
 964     // after the mirror is set.


1322 }
1323 
1324 oop java_lang_Class::init_lock(oop java_class) {
1325   assert(_init_lock_offset != 0, "must be set");
1326   return java_class->obj_field(_init_lock_offset);
1327 }
1328 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1329   assert(_init_lock_offset != 0, "must be set");
1330   java_class->obj_field_put(_init_lock_offset, init_lock);
1331 }
1332 
1333 objArrayOop java_lang_Class::signers(oop java_class) {
1334   assert(_signers_offset != 0, "must be set");
1335   return (objArrayOop)java_class->obj_field(_signers_offset);
1336 }
1337 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1338   assert(_signers_offset != 0, "must be set");
1339   java_class->obj_field_put(_signers_offset, (oop)signers);
1340 }
1341 









1342 
1343 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1344   // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1345   if (_class_loader_offset != 0) {
1346     java_class->obj_field_put(_class_loader_offset, loader);
1347   }
1348 }
1349 
1350 oop java_lang_Class::class_loader(oop java_class) {
1351   assert(_class_loader_offset != 0, "must be set");
1352   return java_class->obj_field(_class_loader_offset);
1353 }
1354 
1355 oop java_lang_Class::module(oop java_class) {
1356   assert(_module_offset != 0, "must be set");
1357   return java_class->obj_field(_module_offset);
1358 }
1359 
1360 void java_lang_Class::set_module(oop java_class, oop module) {
1361   assert(_module_offset != 0, "must be set");


1596 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the
1597 //       platform thread structure, and a eetop offset which was used for thread
1598 //       local storage (and unused by the HotSpot VM). In JDK1.2 the two structures
1599 //       merged, so in the HotSpot VM we just use the eetop field for the thread
1600 //       instead of the privateInfo_offset.
1601 //
1602 // Note: The stackSize field is only present starting in 1.4.
1603 
1604 int java_lang_Thread::_name_offset = 0;
1605 int java_lang_Thread::_group_offset = 0;
1606 int java_lang_Thread::_contextClassLoader_offset = 0;
1607 int java_lang_Thread::_inheritedAccessControlContext_offset = 0;
1608 int java_lang_Thread::_priority_offset = 0;
1609 int java_lang_Thread::_eetop_offset = 0;
1610 int java_lang_Thread::_daemon_offset = 0;
1611 int java_lang_Thread::_stillborn_offset = 0;
1612 int java_lang_Thread::_stackSize_offset = 0;
1613 int java_lang_Thread::_tid_offset = 0;
1614 int java_lang_Thread::_thread_status_offset = 0;
1615 int java_lang_Thread::_park_blocker_offset = 0;

1616 
1617 #define THREAD_FIELDS_DO(macro) \
1618   macro(_name_offset,          k, vmSymbols::name_name(), string_signature, false); \
1619   macro(_group_offset,         k, vmSymbols::group_name(), threadgroup_signature, false); \
1620   macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \
1621   macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \
1622   macro(_priority_offset,      k, vmSymbols::priority_name(), int_signature, false); \
1623   macro(_daemon_offset,        k, vmSymbols::daemon_name(), bool_signature, false); \
1624   macro(_eetop_offset,         k, "eetop", long_signature, false); \
1625   macro(_stillborn_offset,     k, "stillborn", bool_signature, false); \
1626   macro(_stackSize_offset,     k, "stackSize", long_signature, false); \
1627   macro(_tid_offset,           k, "tid", long_signature, false); \
1628   macro(_thread_status_offset, k, "threadStatus", int_signature, false); \
1629   macro(_park_blocker_offset,  k, "parkBlocker", object_signature, false)

1630 
1631 void java_lang_Thread::compute_offsets() {
1632   assert(_group_offset == 0, "offsets should be initialized only once");
1633 
1634   InstanceKlass* k = SystemDictionary::Thread_klass();
1635   THREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1636 }
1637 
1638 #if INCLUDE_CDS
1639 void java_lang_Thread::serialize_offsets(SerializeClosure* f) {
1640   THREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1641 }
1642 #endif
1643 
1644 JavaThread* java_lang_Thread::thread(oop java_thread) {
1645   return (JavaThread*)java_thread->address_field(_eetop_offset);
1646 }
1647 
1648 
1649 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) {


1695 
1696 bool java_lang_Thread::is_daemon(oop java_thread) {
1697   return java_thread->bool_field(_daemon_offset) != 0;
1698 }
1699 
1700 
1701 void java_lang_Thread::set_daemon(oop java_thread) {
1702   java_thread->bool_field_put(_daemon_offset, true);
1703 }
1704 
1705 oop java_lang_Thread::context_class_loader(oop java_thread) {
1706   return java_thread->obj_field(_contextClassLoader_offset);
1707 }
1708 
1709 oop java_lang_Thread::inherited_access_control_context(oop java_thread) {
1710   return java_thread->obj_field(_inheritedAccessControlContext_offset);
1711 }
1712 
1713 
1714 jlong java_lang_Thread::stackSize(oop java_thread) {
1715   return java_thread->long_field(_stackSize_offset);




1716 }
1717 
1718 // Write the thread status value to threadStatus field in java.lang.Thread java class.
1719 void java_lang_Thread::set_thread_status(oop java_thread,
1720                                          java_lang_Thread::ThreadStatus status) {
1721   java_thread->int_field_put(_thread_status_offset, status);



1722 }
1723 
1724 // Read thread status value from threadStatus field in java.lang.Thread java class.
1725 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
1726   // Make sure the caller is operating on behalf of the VM or is
1727   // running VM code (state == _thread_in_vm).
1728   assert(Threads_lock->owned_by_self() || Thread::current()->is_VM_thread() ||
1729          JavaThread::current()->thread_state() == _thread_in_vm,
1730          "Java Thread is not running in vm");
1731   return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);














1732 }
1733 
1734 
1735 jlong java_lang_Thread::thread_id(oop java_thread) {
1736   return java_thread->long_field(_tid_offset);





1737 }
1738 
1739 oop java_lang_Thread::park_blocker(oop java_thread) {
1740   assert(JDK_Version::current().supports_thread_park_blocker(),
1741          "Must support parkBlocker field");







1742 
1743   return java_thread->obj_field(_park_blocker_offset);












1744 }
1745 

1746 const char* java_lang_Thread::thread_status_name(oop java_thread) {

1747   ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
1748   switch (status) {
1749     case NEW                      : return "NEW";
1750     case RUNNABLE                 : return "RUNNABLE";
1751     case SLEEPING                 : return "TIMED_WAITING (sleeping)";
1752     case IN_OBJECT_WAIT           : return "WAITING (on object monitor)";
1753     case IN_OBJECT_WAIT_TIMED     : return "TIMED_WAITING (on object monitor)";
1754     case PARKED                   : return "WAITING (parking)";
1755     case PARKED_TIMED             : return "TIMED_WAITING (parking)";
1756     case BLOCKED_ON_MONITOR_ENTER : return "BLOCKED (on object monitor)";
1757     case TERMINATED               : return "TERMINATED";
1758     default                       : return "UNKNOWN";
1759   };
1760 }
1761 int java_lang_ThreadGroup::_parent_offset = 0;
1762 int java_lang_ThreadGroup::_name_offset = 0;
1763 int java_lang_ThreadGroup::_threads_offset = 0;
1764 int java_lang_ThreadGroup::_groups_offset = 0;
1765 int java_lang_ThreadGroup::_maxPriority_offset = 0;
1766 int java_lang_ThreadGroup::_destroyed_offset = 0;


2590         java_lang_Class::set_source_file(java_class(), source_file);
2591       }
2592     } else {
2593       // Class was redefined. Dump the cache if it was set.
2594       if (source_file != NULL) {
2595         source_file = NULL;
2596         java_lang_Class::set_source_file(java_class(), source_file);
2597       }
2598       if (ShowHiddenFrames) {
2599         source = vmSymbols::unknown_class_name();
2600         source_file = StringTable::intern(source, CHECK);
2601       }
2602     }
2603     java_lang_StackTraceElement::set_fileName(element(), source_file);
2604 
2605     int line_number = Backtrace::get_line_number(method, bci);
2606     java_lang_StackTraceElement::set_lineNumber(element(), line_number);
2607   }
2608 }
2609 
2610 #if INCLUDE_JVMCI
2611 void java_lang_StackTraceElement::decode(Handle mirror, methodHandle method, int bci, Symbol*& methodname, Symbol*& filename, int& line_number) {
2612   int method_id = method->orig_method_idnum();
2613   int cpref = method->name_index();
2614   decode(mirror, method_id, method->constants()->version(), bci, cpref, methodname, filename, line_number);
2615 }
2616 
2617 void java_lang_StackTraceElement::decode(Handle mirror, int method_id, int version, int bci, int cpref, Symbol*& methodname, Symbol*& filename, int& line_number) {
2618   // Fill in class name
2619   InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(mirror()));
2620   Method* method = holder->method_with_orig_idnum(method_id, version);
2621 
2622   // The method can be NULL if the requested class version is gone
2623   Symbol* sym = (method != NULL) ? method->name() : holder->constants()->symbol_at(cpref);
2624 
2625   // Fill in method name
2626   methodname = sym;
2627 
2628   if (!version_matches(method, version)) {
2629     // If the method was redefined, accurate line number information isn't available
2630     filename = NULL;
2631     line_number = -1;
2632   } else {
2633     // Fill in source file name and line number.
2634     // Use a specific ik version as a holder since the mirror might
2635     // refer to a version that is now obsolete and no longer accessible
2636     // via the previous versions list.
2637     holder = holder->get_klass_version(version);
2638     assert(holder != NULL, "sanity check");
2639     Symbol* source = holder->source_file_name();
2640     if (ShowHiddenFrames && source == NULL) {
2641       source = vmSymbols::unknown_class_name();
2642     }
2643     filename = source;
2644     line_number = Backtrace::get_line_number(method, bci);
2645   }
2646 }
2647 #endif // INCLUDE_JVMCI
2648 
2649 Method* java_lang_StackFrameInfo::get_method(Handle stackFrame, InstanceKlass* holder, TRAPS) {
2650   HandleMark hm(THREAD);
2651   Handle mname(THREAD, stackFrame->obj_field(_memberName_offset));
2652   Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mname());
2653   // we should expand MemberName::name when Throwable uses StackTrace
2654   // MethodHandles::expand_MemberName(mname, MethodHandles::_suppress_defc|MethodHandles::_suppress_type, CHECK_NULL);
2655   return method;
2656 }
2657 
2658 void java_lang_StackFrameInfo::set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS) {
2659   // set Method* or mid/cpref
2660   HandleMark hm(THREAD);
2661   Handle mname(Thread::current(), stackFrame->obj_field(_memberName_offset));
2662   InstanceKlass* ik = method->method_holder();
2663   CallInfo info(method(), ik, CHECK);
2664   MethodHandles::init_method_MemberName(mname, info);
2665   // set bci
2666   java_lang_StackFrameInfo::set_bci(stackFrame(), bci);
2667   // method may be redefined; store the version
2668   int version = method->constants()->version();


3608 
3609 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3610   assert(is_instance(mname), "wrong type");
3611   mname->address_field_put(_vmindex_offset, (address) index);
3612 }
3613 
3614 
3615 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
3616   assert(is_instance(resolved_method), "wrong type");
3617   Method* m = (Method*)resolved_method->address_field(_vmtarget_offset);
3618   assert(m->is_method(), "must be");
3619   return m;
3620 }
3621 
3622 // Used by redefinition to change Method* to new Method* with same hash (name, signature)
3623 void java_lang_invoke_ResolvedMethodName::set_vmtarget(oop resolved_method, Method* m) {
3624   assert(is_instance(resolved_method), "wrong type");
3625   resolved_method->address_field_put(_vmtarget_offset, (address)m);
3626 }
3627 
3628 void java_lang_invoke_ResolvedMethodName::set_vmholder(oop resolved_method, oop holder) {
3629   assert(is_instance(resolved_method), "wrong type");
3630   resolved_method->obj_field_put(_vmholder_offset, holder);
3631 }
3632 
3633 oop java_lang_invoke_ResolvedMethodName::find_resolved_method(const methodHandle& m, TRAPS) {
3634   const Method* method = m();
3635 
3636   // lookup ResolvedMethod oop in the table, or create a new one and intern it
3637   oop resolved_method = ResolvedMethodTable::find_method(method);
3638   if (resolved_method != NULL) {
3639     return resolved_method;
3640   }
3641 
3642   InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass();
3643   if (!k->is_initialized()) {
3644     k->initialize(CHECK_NULL);
3645   }
3646 
3647   oop new_resolved_method = k->allocate_instance(CHECK_NULL);
3648 
3649   NoSafepointVerifier nsv;
3650 
3651   if (method->is_old()) {
3652     method = (method->is_deleted()) ? Universe::throw_no_such_method_error() :
3653                                       method->get_new_method();
3654   }
3655 
3656   InstanceKlass* holder = method->method_holder();
3657 
3658   set_vmtarget(new_resolved_method, const_cast<Method*>(method));
3659   // Add a reference to the loader (actually mirror because unsafe anonymous classes will not have
3660   // distinct loaders) to ensure the metadata is kept alive.
3661   // This mirror may be different than the one in clazz field.
3662   set_vmholder(new_resolved_method, holder->java_mirror());
3663 
3664   // Set flag in class to indicate this InstanceKlass has entries in the table
3665   // to avoid walking table during redefinition if none of the redefined classes
3666   // have any membernames in the table.
3667   holder->set_has_resolved_methods();
3668 
3669   return ResolvedMethodTable::add_method(method, Handle(THREAD, new_resolved_method));
3670 }
3671 
3672 oop java_lang_invoke_LambdaForm::vmentry(oop lform) {
3673   assert(is_instance(lform), "wrong type");
3674   return lform->obj_field(_vmentry_offset);
3675 }
3676 
3677 
3678 // Support for java_lang_invoke_MethodType
3679 
3680 int java_lang_invoke_MethodType::_rtype_offset;
3681 int java_lang_invoke_MethodType::_ptypes_offset;
3682 
3683 #define METHODTYPE_FIELDS_DO(macro) \
3684   macro(_rtype_offset,  k, "rtype",  class_signature,       false); \
3685   macro(_ptypes_offset, k, "ptypes", class_array_signature, false)
3686 
3687 void java_lang_invoke_MethodType::compute_offsets() {
3688   InstanceKlass* k = SystemDictionary::MethodType_klass();
3689   METHODTYPE_FIELDS_DO(FIELD_COMPUTE_OFFSET);


4065   }
4066 };
4067 
4068 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4069   UnsafeConstantsFixup fixup;
4070   SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4071 }
4072 
4073 int java_lang_Class::_klass_offset;
4074 int java_lang_Class::_array_klass_offset;
4075 int java_lang_Class::_oop_size_offset;
4076 int java_lang_Class::_static_oop_field_count_offset;
4077 int java_lang_Class::_class_loader_offset;
4078 int java_lang_Class::_module_offset;
4079 int java_lang_Class::_protection_domain_offset;
4080 int java_lang_Class::_component_mirror_offset;
4081 int java_lang_Class::_init_lock_offset;
4082 int java_lang_Class::_signers_offset;
4083 int java_lang_Class::_name_offset;
4084 int java_lang_Class::_source_file_offset;

4085 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4086 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4087 int java_lang_Throwable::backtrace_offset;
4088 int java_lang_Throwable::detailMessage_offset;
4089 int java_lang_Throwable::stackTrace_offset;
4090 int java_lang_Throwable::depth_offset;
4091 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4092 int java_lang_reflect_AccessibleObject::override_offset;
4093 int java_lang_reflect_Method::clazz_offset;
4094 int java_lang_reflect_Method::name_offset;
4095 int java_lang_reflect_Method::returnType_offset;
4096 int java_lang_reflect_Method::parameterTypes_offset;
4097 int java_lang_reflect_Method::exceptionTypes_offset;
4098 int java_lang_reflect_Method::slot_offset;
4099 int java_lang_reflect_Method::modifiers_offset;
4100 int java_lang_reflect_Method::signature_offset;
4101 int java_lang_reflect_Method::annotations_offset;
4102 int java_lang_reflect_Method::parameter_annotations_offset;
4103 int java_lang_reflect_Method::annotation_default_offset;
4104 int java_lang_reflect_Constructor::clazz_offset;




 806       // update all the static field offsets to included the size.
 807       for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
 808         if (fs.access_flags().is_static()) {
 809           int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
 810           fs.set_offset(real_offset);
 811         }
 812       }
 813     }
 814   }
 815 
 816   if (k->is_shared() && k->has_raw_archived_mirror()) {
 817     if (HeapShared::open_archive_heap_region_mapped()) {
 818       bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
 819       assert(present, "Missing archived mirror for %s", k->external_name());
 820       return;
 821     } else {
 822       k->set_java_mirror_handle(NULL);
 823       k->clear_has_raw_archived_mirror();
 824     }
 825   }
 826   create_mirror(k, Handle(), Handle(), Handle(), Handle(), CHECK);
 827 }
 828 
 829 void java_lang_Class::initialize_mirror_fields(Klass* k,
 830                                                Handle mirror,
 831                                                Handle protection_domain,
 832                                                Handle classData,
 833                                                TRAPS) {
 834   // Allocate a simple java object for a lock.
 835   // This needs to be a java object because during class initialization
 836   // it can be held across a java call.
 837   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 838   set_init_lock(mirror(), r);
 839 
 840   // Set protection domain also
 841   set_protection_domain(mirror(), protection_domain());
 842 
 843   // Initialize static fields
 844   InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 845 
 846  // Set classData
 847   set_class_data(mirror(), classData());
 848 }
 849 
 850 // Set the java.lang.Module module field in the java_lang_Class mirror
 851 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
 852   if (module.is_null()) {
 853     // During startup, the module may be NULL only if java.base has not been defined yet.
 854     // Put the class on the fixup_module_list to patch later when the java.lang.Module
 855     // for java.base is known. But note that since we captured the NULL module another
 856     // thread may have completed that initialization.
 857 
 858     bool javabase_was_defined = false;
 859     {
 860       MutexLocker m1(Module_lock, THREAD);
 861       // Keep list of classes needing java.base module fixup
 862       if (!ModuleEntryTable::javabase_defined()) {
 863         assert(k->java_mirror() != NULL, "Class's mirror is null");
 864         k->class_loader_data()->inc_keep_alive();
 865         assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized");
 866         fixup_module_field_list()->push(k);
 867       } else {


 881     assert(Universe::is_module_initialized() ||
 882            (ModuleEntryTable::javabase_defined() &&
 883             (oopDesc::equals(module(), ModuleEntryTable::javabase_moduleEntry()->module()))),
 884            "Incorrect java.lang.Module specification while creating mirror");
 885     set_module(mirror(), module());
 886   }
 887 }
 888 
 889 // Statically allocate fixup lists because they always get created.
 890 void java_lang_Class::allocate_fixup_lists() {
 891   GrowableArray<Klass*>* mirror_list =
 892     new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 893   set_fixup_mirror_list(mirror_list);
 894 
 895   GrowableArray<Klass*>* module_list =
 896     new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 897   set_fixup_module_field_list(module_list);
 898 }
 899 
 900 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
 901                                     Handle module, Handle protection_domain,
 902                                     Handle classData, TRAPS) {
 903   assert(k != NULL, "Use create_basic_type_mirror for primitive types");
 904   assert(k->java_mirror() == NULL, "should only assign mirror once");
 905 
 906   // Use this moment of initialization to cache modifier_flags also,
 907   // to support Class.getModifiers().  Instance classes recalculate
 908   // the cached flags after the class file is parsed, but before the
 909   // class is put into the system dictionary.
 910   int computed_modifiers = k->compute_modifier_flags(CHECK);
 911   k->set_modifier_flags(computed_modifiers);
 912   // Class_klass has to be loaded because it is used to allocate
 913   // the mirror.
 914   if (SystemDictionary::Class_klass_loaded()) {
 915     // Allocate mirror (java.lang.Class instance)
 916     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 917     Handle mirror(THREAD, mirror_oop);
 918     Handle comp_mirror;
 919 
 920     // Setup indirection from mirror->klass
 921     java_lang_Class::set_klass(mirror(), k);
 922 


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


1327 }
1328 
1329 oop java_lang_Class::init_lock(oop java_class) {
1330   assert(_init_lock_offset != 0, "must be set");
1331   return java_class->obj_field(_init_lock_offset);
1332 }
1333 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1334   assert(_init_lock_offset != 0, "must be set");
1335   java_class->obj_field_put(_init_lock_offset, init_lock);
1336 }
1337 
1338 objArrayOop java_lang_Class::signers(oop java_class) {
1339   assert(_signers_offset != 0, "must be set");
1340   return (objArrayOop)java_class->obj_field(_signers_offset);
1341 }
1342 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1343   assert(_signers_offset != 0, "must be set");
1344   java_class->obj_field_put(_signers_offset, (oop)signers);
1345 }
1346 
1347 oop java_lang_Class::class_data(oop java_class) {
1348   assert(_classData_offset != 0, "must be set");
1349   return java_class->obj_field(_classData_offset);
1350 }
1351 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1352   assert(_classData_offset != 0, "must be set");
1353   java_class->obj_field_put(_classData_offset, class_data);
1354 }
1355 
1356 
1357 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1358   // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet.
1359   if (_class_loader_offset != 0) {
1360     java_class->obj_field_put(_class_loader_offset, loader);
1361   }
1362 }
1363 
1364 oop java_lang_Class::class_loader(oop java_class) {
1365   assert(_class_loader_offset != 0, "must be set");
1366   return java_class->obj_field(_class_loader_offset);
1367 }
1368 
1369 oop java_lang_Class::module(oop java_class) {
1370   assert(_module_offset != 0, "must be set");
1371   return java_class->obj_field(_module_offset);
1372 }
1373 
1374 void java_lang_Class::set_module(oop java_class, oop module) {
1375   assert(_module_offset != 0, "must be set");


1610 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the
1611 //       platform thread structure, and a eetop offset which was used for thread
1612 //       local storage (and unused by the HotSpot VM). In JDK1.2 the two structures
1613 //       merged, so in the HotSpot VM we just use the eetop field for the thread
1614 //       instead of the privateInfo_offset.
1615 //
1616 // Note: The stackSize field is only present starting in 1.4.
1617 
1618 int java_lang_Thread::_name_offset = 0;
1619 int java_lang_Thread::_group_offset = 0;
1620 int java_lang_Thread::_contextClassLoader_offset = 0;
1621 int java_lang_Thread::_inheritedAccessControlContext_offset = 0;
1622 int java_lang_Thread::_priority_offset = 0;
1623 int java_lang_Thread::_eetop_offset = 0;
1624 int java_lang_Thread::_daemon_offset = 0;
1625 int java_lang_Thread::_stillborn_offset = 0;
1626 int java_lang_Thread::_stackSize_offset = 0;
1627 int java_lang_Thread::_tid_offset = 0;
1628 int java_lang_Thread::_thread_status_offset = 0;
1629 int java_lang_Thread::_park_blocker_offset = 0;
1630 int java_lang_Thread::_park_event_offset = 0 ;
1631 
1632 #define THREAD_FIELDS_DO(macro) \
1633   macro(_name_offset,          k, vmSymbols::name_name(), string_signature, false); \
1634   macro(_group_offset,         k, vmSymbols::group_name(), threadgroup_signature, false); \
1635   macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \
1636   macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \
1637   macro(_priority_offset,      k, vmSymbols::priority_name(), int_signature, false); \
1638   macro(_daemon_offset,        k, vmSymbols::daemon_name(), bool_signature, false); \
1639   macro(_eetop_offset,         k, "eetop", long_signature, false); \
1640   macro(_stillborn_offset,     k, "stillborn", bool_signature, false); \
1641   macro(_stackSize_offset,     k, "stackSize", long_signature, false); \
1642   macro(_tid_offset,           k, "tid", long_signature, false); \
1643   macro(_thread_status_offset, k, "threadStatus", int_signature, false); \
1644   macro(_park_blocker_offset,  k, "parkBlocker", object_signature, false); \
1645   macro(_park_event_offset,    k, "nativeParkEventPointer", long_signature, false)
1646 
1647 void java_lang_Thread::compute_offsets() {
1648   assert(_group_offset == 0, "offsets should be initialized only once");
1649 
1650   InstanceKlass* k = SystemDictionary::Thread_klass();
1651   THREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1652 }
1653 
1654 #if INCLUDE_CDS
1655 void java_lang_Thread::serialize_offsets(SerializeClosure* f) {
1656   THREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1657 }
1658 #endif
1659 
1660 JavaThread* java_lang_Thread::thread(oop java_thread) {
1661   return (JavaThread*)java_thread->address_field(_eetop_offset);
1662 }
1663 
1664 
1665 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) {


1711 
1712 bool java_lang_Thread::is_daemon(oop java_thread) {
1713   return java_thread->bool_field(_daemon_offset) != 0;
1714 }
1715 
1716 
1717 void java_lang_Thread::set_daemon(oop java_thread) {
1718   java_thread->bool_field_put(_daemon_offset, true);
1719 }
1720 
1721 oop java_lang_Thread::context_class_loader(oop java_thread) {
1722   return java_thread->obj_field(_contextClassLoader_offset);
1723 }
1724 
1725 oop java_lang_Thread::inherited_access_control_context(oop java_thread) {
1726   return java_thread->obj_field(_inheritedAccessControlContext_offset);
1727 }
1728 
1729 
1730 jlong java_lang_Thread::stackSize(oop java_thread) {
1731   if (_stackSize_offset > 0) {
1732     return java_thread->long_field(_stackSize_offset);
1733   } else {
1734     return 0;
1735   }
1736 }
1737 
1738 // Write the thread status value to threadStatus field in java.lang.Thread java class.
1739 void java_lang_Thread::set_thread_status(oop java_thread,
1740                                          java_lang_Thread::ThreadStatus status) {
1741   // The threadStatus is only present starting in 1.5
1742   if (_thread_status_offset > 0) {
1743     java_thread->int_field_put(_thread_status_offset, status);
1744   }
1745 }
1746 
1747 // Read thread status value from threadStatus field in java.lang.Thread java class.
1748 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
1749   // Make sure the caller is operating on behalf of the VM or is
1750   // running VM code (state == _thread_in_vm).
1751   assert(Threads_lock->owned_by_self() || Thread::current()->is_VM_thread() ||
1752          JavaThread::current()->thread_state() == _thread_in_vm,
1753          "Java Thread is not running in vm");
1754   // The threadStatus is only present starting in 1.5
1755   if (_thread_status_offset > 0) {
1756     return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
1757   } else {
1758     // All we can easily figure out is if it is alive, but that is
1759     // enough info for a valid unknown status.
1760     // These aren't restricted to valid set ThreadStatus values, so
1761     // use JVMTI values and cast.
1762     JavaThread* thr = java_lang_Thread::thread(java_thread);
1763     if (thr == NULL) {
1764       // the thread hasn't run yet or is in the process of exiting
1765       return NEW;
1766     }
1767     return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
1768   }
1769 }
1770 
1771 
1772 jlong java_lang_Thread::thread_id(oop java_thread) {
1773   // The thread ID field is only present starting in 1.5
1774   if (_tid_offset > 0) {
1775     return java_thread->long_field(_tid_offset);
1776   } else {
1777     return 0;
1778   }
1779 }
1780 
1781 oop java_lang_Thread::park_blocker(oop java_thread) {
1782   assert(JDK_Version::current().supports_thread_park_blocker() &&
1783          _park_blocker_offset != 0, "Must support parkBlocker field");
1784 
1785   if (_park_blocker_offset > 0) {
1786     return java_thread->obj_field(_park_blocker_offset);
1787   }
1788 
1789   return NULL;
1790 }
1791 
1792 jlong java_lang_Thread::park_event(oop java_thread) {
1793   if (_park_event_offset > 0) {
1794     return java_thread->long_field(_park_event_offset);
1795   }
1796   return 0;
1797 }
1798 
1799 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) {
1800   if (_park_event_offset > 0) {
1801     java_thread->long_field_put(_park_event_offset, ptr);
1802     return true;
1803   }
1804   return false;
1805 }
1806 
1807 
1808 const char* java_lang_Thread::thread_status_name(oop java_thread) {
1809   assert(_thread_status_offset != 0, "Must have thread status");
1810   ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
1811   switch (status) {
1812     case NEW                      : return "NEW";
1813     case RUNNABLE                 : return "RUNNABLE";
1814     case SLEEPING                 : return "TIMED_WAITING (sleeping)";
1815     case IN_OBJECT_WAIT           : return "WAITING (on object monitor)";
1816     case IN_OBJECT_WAIT_TIMED     : return "TIMED_WAITING (on object monitor)";
1817     case PARKED                   : return "WAITING (parking)";
1818     case PARKED_TIMED             : return "TIMED_WAITING (parking)";
1819     case BLOCKED_ON_MONITOR_ENTER : return "BLOCKED (on object monitor)";
1820     case TERMINATED               : return "TERMINATED";
1821     default                       : return "UNKNOWN";
1822   };
1823 }
1824 int java_lang_ThreadGroup::_parent_offset = 0;
1825 int java_lang_ThreadGroup::_name_offset = 0;
1826 int java_lang_ThreadGroup::_threads_offset = 0;
1827 int java_lang_ThreadGroup::_groups_offset = 0;
1828 int java_lang_ThreadGroup::_maxPriority_offset = 0;
1829 int java_lang_ThreadGroup::_destroyed_offset = 0;


2653         java_lang_Class::set_source_file(java_class(), source_file);
2654       }
2655     } else {
2656       // Class was redefined. Dump the cache if it was set.
2657       if (source_file != NULL) {
2658         source_file = NULL;
2659         java_lang_Class::set_source_file(java_class(), source_file);
2660       }
2661       if (ShowHiddenFrames) {
2662         source = vmSymbols::unknown_class_name();
2663         source_file = StringTable::intern(source, CHECK);
2664       }
2665     }
2666     java_lang_StackTraceElement::set_fileName(element(), source_file);
2667 
2668     int line_number = Backtrace::get_line_number(method, bci);
2669     java_lang_StackTraceElement::set_lineNumber(element(), line_number);
2670   }
2671 }
2672 







































2673 Method* java_lang_StackFrameInfo::get_method(Handle stackFrame, InstanceKlass* holder, TRAPS) {
2674   HandleMark hm(THREAD);
2675   Handle mname(THREAD, stackFrame->obj_field(_memberName_offset));
2676   Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mname());
2677   // we should expand MemberName::name when Throwable uses StackTrace
2678   // MethodHandles::expand_MemberName(mname, MethodHandles::_suppress_defc|MethodHandles::_suppress_type, CHECK_NULL);
2679   return method;
2680 }
2681 
2682 void java_lang_StackFrameInfo::set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS) {
2683   // set Method* or mid/cpref
2684   HandleMark hm(THREAD);
2685   Handle mname(Thread::current(), stackFrame->obj_field(_memberName_offset));
2686   InstanceKlass* ik = method->method_holder();
2687   CallInfo info(method(), ik, CHECK);
2688   MethodHandles::init_method_MemberName(mname, info);
2689   // set bci
2690   java_lang_StackFrameInfo::set_bci(stackFrame(), bci);
2691   // method may be redefined; store the version
2692   int version = method->constants()->version();


3632 
3633 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
3634   assert(is_instance(mname), "wrong type");
3635   mname->address_field_put(_vmindex_offset, (address) index);
3636 }
3637 
3638 
3639 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
3640   assert(is_instance(resolved_method), "wrong type");
3641   Method* m = (Method*)resolved_method->address_field(_vmtarget_offset);
3642   assert(m->is_method(), "must be");
3643   return m;
3644 }
3645 
3646 // Used by redefinition to change Method* to new Method* with same hash (name, signature)
3647 void java_lang_invoke_ResolvedMethodName::set_vmtarget(oop resolved_method, Method* m) {
3648   assert(is_instance(resolved_method), "wrong type");
3649   resolved_method->address_field_put(_vmtarget_offset, (address)m);
3650 }
3651 





3652 oop java_lang_invoke_ResolvedMethodName::find_resolved_method(const methodHandle& m, TRAPS) {


3653   // lookup ResolvedMethod oop in the table, or create a new one and intern it
3654   oop resolved_method = ResolvedMethodTable::find_method(m());
3655   if (resolved_method == NULL) {
3656     InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass();
3657     if (!k->is_initialized()) {
3658       k->initialize(CHECK_NULL);
3659     }
3660     oop new_resolved_method = k->allocate_instance(CHECK_NULL);
3661     new_resolved_method->address_field_put(_vmtarget_offset, (address)m());
3662     // Add a reference to the loader (actually mirror because unsafe anonymous classes will not have
3663     // distinct loaders) to ensure the metadata is kept alive.
3664     // This mirror may be different than the one in clazz field.
3665     new_resolved_method->obj_field_put(_vmholder_offset, m->method_holder()->java_mirror());
3666     resolved_method = ResolvedMethodTable::add_method(m, Handle(THREAD, new_resolved_method));




3667   }
3668   return resolved_method;














3669 }
3670 
3671 oop java_lang_invoke_LambdaForm::vmentry(oop lform) {
3672   assert(is_instance(lform), "wrong type");
3673   return lform->obj_field(_vmentry_offset);
3674 }
3675 
3676 
3677 // Support for java_lang_invoke_MethodType
3678 
3679 int java_lang_invoke_MethodType::_rtype_offset;
3680 int java_lang_invoke_MethodType::_ptypes_offset;
3681 
3682 #define METHODTYPE_FIELDS_DO(macro) \
3683   macro(_rtype_offset,  k, "rtype",  class_signature,       false); \
3684   macro(_ptypes_offset, k, "ptypes", class_array_signature, false)
3685 
3686 void java_lang_invoke_MethodType::compute_offsets() {
3687   InstanceKlass* k = SystemDictionary::MethodType_klass();
3688   METHODTYPE_FIELDS_DO(FIELD_COMPUTE_OFFSET);


4064   }
4065 };
4066 
4067 void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
4068   UnsafeConstantsFixup fixup;
4069   SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
4070 }
4071 
4072 int java_lang_Class::_klass_offset;
4073 int java_lang_Class::_array_klass_offset;
4074 int java_lang_Class::_oop_size_offset;
4075 int java_lang_Class::_static_oop_field_count_offset;
4076 int java_lang_Class::_class_loader_offset;
4077 int java_lang_Class::_module_offset;
4078 int java_lang_Class::_protection_domain_offset;
4079 int java_lang_Class::_component_mirror_offset;
4080 int java_lang_Class::_init_lock_offset;
4081 int java_lang_Class::_signers_offset;
4082 int java_lang_Class::_name_offset;
4083 int java_lang_Class::_source_file_offset;
4084 int java_lang_Class::_classData_offset;
4085 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
4086 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
4087 int java_lang_Throwable::backtrace_offset;
4088 int java_lang_Throwable::detailMessage_offset;
4089 int java_lang_Throwable::stackTrace_offset;
4090 int java_lang_Throwable::depth_offset;
4091 int java_lang_Throwable::static_unassigned_stacktrace_offset;
4092 int java_lang_reflect_AccessibleObject::override_offset;
4093 int java_lang_reflect_Method::clazz_offset;
4094 int java_lang_reflect_Method::name_offset;
4095 int java_lang_reflect_Method::returnType_offset;
4096 int java_lang_reflect_Method::parameterTypes_offset;
4097 int java_lang_reflect_Method::exceptionTypes_offset;
4098 int java_lang_reflect_Method::slot_offset;
4099 int java_lang_reflect_Method::modifiers_offset;
4100 int java_lang_reflect_Method::signature_offset;
4101 int java_lang_reflect_Method::annotations_offset;
4102 int java_lang_reflect_Method::parameter_annotations_offset;
4103 int java_lang_reflect_Method::annotation_default_offset;
4104 int java_lang_reflect_Constructor::clazz_offset;


< prev index next >