< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page
rev 50073 : [mq]: cont


1548 
1549 
1550 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the
1551 //       platform thread structure, and a eetop offset which was used for thread
1552 //       local storage (and unused by the HotSpot VM). In JDK1.2 the two structures
1553 //       merged, so in the HotSpot VM we just use the eetop field for the thread
1554 //       instead of the privateInfo_offset.
1555 //
1556 // Note: The stackSize field is only present starting in 1.4.
1557 
1558 int java_lang_Thread::_name_offset = 0;
1559 int java_lang_Thread::_group_offset = 0;
1560 int java_lang_Thread::_contextClassLoader_offset = 0;
1561 int java_lang_Thread::_inheritedAccessControlContext_offset = 0;
1562 int java_lang_Thread::_priority_offset = 0;
1563 int java_lang_Thread::_eetop_offset = 0;
1564 int java_lang_Thread::_daemon_offset = 0;
1565 int java_lang_Thread::_stillborn_offset = 0;
1566 int java_lang_Thread::_stackSize_offset = 0;
1567 int java_lang_Thread::_tid_offset = 0;

1568 int java_lang_Thread::_thread_status_offset = 0;
1569 int java_lang_Thread::_park_blocker_offset = 0;
1570 int java_lang_Thread::_park_event_offset = 0 ;
1571 
1572 #define THREAD_FIELDS_DO(macro) \
1573   macro(_name_offset,          k, vmSymbols::name_name(), string_signature, false); \
1574   macro(_group_offset,         k, vmSymbols::group_name(), threadgroup_signature, false); \
1575   macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \
1576   macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \
1577   macro(_priority_offset,      k, vmSymbols::priority_name(), int_signature, false); \
1578   macro(_daemon_offset,        k, vmSymbols::daemon_name(), bool_signature, false); \
1579   macro(_eetop_offset,         k, "eetop", long_signature, false); \
1580   macro(_stillborn_offset,     k, "stillborn", bool_signature, false); \
1581   macro(_stackSize_offset,     k, "stackSize", long_signature, false); \
1582   macro(_tid_offset,           k, "tid", long_signature, false); \
1583   macro(_thread_status_offset, k, "threadStatus", int_signature, false); \
1584   macro(_park_blocker_offset,  k, "parkBlocker", object_signature, false); \
1585   macro(_park_event_offset,    k, "nativeParkEventPointer", long_signature, false)

1586 
1587 void java_lang_Thread::compute_offsets() {
1588   assert(_group_offset == 0, "offsets should be initialized only once");
1589 
1590   InstanceKlass* k = SystemDictionary::Thread_klass();
1591   THREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1592 }
1593 
1594 #if INCLUDE_CDS
1595 void java_lang_Thread::serialize(SerializeClosure* f) {
1596   THREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1597 }
1598 #endif
1599 
1600 JavaThread* java_lang_Thread::thread(oop java_thread) {
1601   return (JavaThread*)java_thread->address_field(_eetop_offset);
1602 }
1603 
1604 
1605 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) {


1701     // use JVMTI values and cast.
1702     JavaThread* thr = java_lang_Thread::thread(java_thread);
1703     if (thr == NULL) {
1704       // the thread hasn't run yet or is in the process of exiting
1705       return NEW;
1706     }
1707     return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
1708   }
1709 }
1710 
1711 
1712 jlong java_lang_Thread::thread_id(oop java_thread) {
1713   // The thread ID field is only present starting in 1.5
1714   if (_tid_offset > 0) {
1715     return java_thread->long_field(_tid_offset);
1716   } else {
1717     return 0;
1718   }
1719 }
1720 








1721 oop java_lang_Thread::park_blocker(oop java_thread) {
1722   assert(JDK_Version::current().supports_thread_park_blocker() &&
1723          _park_blocker_offset != 0, "Must support parkBlocker field");
1724 
1725   if (_park_blocker_offset > 0) {
1726     return java_thread->obj_field(_park_blocker_offset);
1727   }
1728 
1729   return NULL;
1730 }
1731 
1732 jlong java_lang_Thread::park_event(oop java_thread) {
1733   if (_park_event_offset > 0) {
1734     return java_thread->long_field(_park_event_offset);
1735   }
1736   return 0;
1737 }
1738 
1739 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) {
1740   if (_park_event_offset > 0) {


4220 int java_lang_reflect_Field::clazz_offset;
4221 int java_lang_reflect_Field::name_offset;
4222 int java_lang_reflect_Field::type_offset;
4223 int java_lang_reflect_Field::slot_offset;
4224 int java_lang_reflect_Field::modifiers_offset;
4225 int java_lang_reflect_Field::signature_offset;
4226 int java_lang_reflect_Field::annotations_offset;
4227 int java_lang_reflect_Field::type_annotations_offset;
4228 int java_lang_reflect_Parameter::name_offset;
4229 int java_lang_reflect_Parameter::modifiers_offset;
4230 int java_lang_reflect_Parameter::index_offset;
4231 int java_lang_reflect_Parameter::executable_offset;
4232 int java_lang_boxing_object::value_offset;
4233 int java_lang_boxing_object::long_value_offset;
4234 int java_lang_ref_Reference::referent_offset;
4235 int java_lang_ref_Reference::queue_offset;
4236 int java_lang_ref_Reference::next_offset;
4237 int java_lang_ref_Reference::discovered_offset;
4238 int java_lang_ref_SoftReference::timestamp_offset;
4239 int java_lang_ref_SoftReference::static_clock_offset;













4240 int java_lang_ClassLoader::parent_offset;
4241 int java_lang_System::static_in_offset;
4242 int java_lang_System::static_out_offset;
4243 int java_lang_System::static_err_offset;
4244 int java_lang_System::static_security_offset;
4245 int java_lang_StackTraceElement::methodName_offset;
4246 int java_lang_StackTraceElement::fileName_offset;
4247 int java_lang_StackTraceElement::lineNumber_offset;
4248 int java_lang_StackTraceElement::moduleName_offset;
4249 int java_lang_StackTraceElement::moduleVersion_offset;
4250 int java_lang_StackTraceElement::classLoaderName_offset;
4251 int java_lang_StackTraceElement::declaringClass_offset;
4252 int java_lang_StackTraceElement::declaringClassObject_offset;
4253 int java_lang_StackFrameInfo::_memberName_offset;
4254 int java_lang_StackFrameInfo::_bci_offset;
4255 int java_lang_StackFrameInfo::_version_offset;
4256 int java_lang_LiveStackFrameInfo::_monitors_offset;
4257 int java_lang_LiveStackFrameInfo::_locals_offset;
4258 int java_lang_LiveStackFrameInfo::_operands_offset;
4259 int java_lang_LiveStackFrameInfo::_mode_offset;


4367 void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) {
4368   o->obj_field_put(classes_offset, val);
4369 }
4370 
4371 void java_lang_AssertionStatusDirectives::set_classEnabled(oop o, oop val) {
4372   o->obj_field_put(classEnabled_offset, val);
4373 }
4374 
4375 void java_lang_AssertionStatusDirectives::set_packages(oop o, oop val) {
4376   o->obj_field_put(packages_offset, val);
4377 }
4378 
4379 void java_lang_AssertionStatusDirectives::set_packageEnabled(oop o, oop val) {
4380   o->obj_field_put(packageEnabled_offset, val);
4381 }
4382 
4383 void java_lang_AssertionStatusDirectives::set_deflt(oop o, bool val) {
4384   o->bool_field_put(deflt_offset, val);
4385 }
4386 
























4387 
4388 // Support for intrinsification of java.nio.Buffer.checkIndex
4389 int java_nio_Buffer::limit_offset() {
4390   return _limit_offset;
4391 }
4392 
4393 #define BUFFER_FIELDS_DO(macro) \
4394   macro(_limit_offset, k, "limit", int_signature, false)
4395 
4396 void java_nio_Buffer::compute_offsets() {
4397   InstanceKlass* k = SystemDictionary::nio_Buffer_klass();
4398   assert(k != NULL, "must be loaded in 1.4+");
4399   BUFFER_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4400 }
4401 
4402 #if INCLUDE_CDS
4403 void java_nio_Buffer::serialize(SerializeClosure* f) {
4404   BUFFER_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4405 }
4406 #endif


4420 }
4421 
4422 static int member_offset(int hardcoded_offset) {
4423   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
4424 }
4425 
4426 // Compute hard-coded offsets
4427 // Invoked before SystemDictionary::initialize, so pre-loaded classes
4428 // are not available to determine the offset_of_static_fields.
4429 void JavaClasses::compute_hard_coded_offsets() {
4430 
4431   // java_lang_boxing_object
4432   java_lang_boxing_object::value_offset      = member_offset(java_lang_boxing_object::hc_value_offset);
4433   java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong);
4434 
4435   // java_lang_ref_Reference
4436   java_lang_ref_Reference::referent_offset    = member_offset(java_lang_ref_Reference::hc_referent_offset);
4437   java_lang_ref_Reference::queue_offset       = member_offset(java_lang_ref_Reference::hc_queue_offset);
4438   java_lang_ref_Reference::next_offset        = member_offset(java_lang_ref_Reference::hc_next_offset);
4439   java_lang_ref_Reference::discovered_offset  = member_offset(java_lang_ref_Reference::hc_discovered_offset);










4440 }
4441 
4442 
4443 // Compute non-hard-coded field offsets of all the classes in this file
4444 void JavaClasses::compute_offsets() {
4445   if (UseSharedSpaces) {
4446     return; // field offsets are loaded from archive
4447   }
4448 
4449   // java_lang_Class::compute_offsets was called earlier in bootstrap
4450   java_lang_System::compute_offsets();
4451   java_lang_ClassLoader::compute_offsets();
4452   java_lang_Throwable::compute_offsets();
4453   java_lang_Thread::compute_offsets();
4454   java_lang_ThreadGroup::compute_offsets();
4455   java_lang_AssertionStatusDirectives::compute_offsets();
4456   java_lang_ref_SoftReference::compute_offsets();
4457   java_lang_invoke_MethodHandle::compute_offsets();
4458   java_lang_invoke_DirectMethodHandle::compute_offsets();
4459   java_lang_invoke_MemberName::compute_offsets();


4462   java_lang_invoke_MethodType::compute_offsets();
4463   java_lang_invoke_CallSite::compute_offsets();
4464   java_lang_invoke_MethodHandleNatives_CallSiteContext::compute_offsets();
4465   java_security_AccessControlContext::compute_offsets();
4466   // Initialize reflection classes. The layouts of these classes
4467   // changed with the new reflection implementation in JDK 1.4, and
4468   // since the Universe doesn't know what JDK version it is until this
4469   // point we defer computation of these offsets until now.
4470   java_lang_reflect_AccessibleObject::compute_offsets();
4471   java_lang_reflect_Method::compute_offsets();
4472   java_lang_reflect_Constructor::compute_offsets();
4473   java_lang_reflect_Field::compute_offsets();
4474   java_nio_Buffer::compute_offsets();
4475   reflect_ConstantPool::compute_offsets();
4476   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
4477   java_lang_reflect_Parameter::compute_offsets();
4478   java_lang_Module::compute_offsets();
4479   java_lang_StackTraceElement::compute_offsets();
4480   java_lang_StackFrameInfo::compute_offsets();
4481   java_lang_LiveStackFrameInfo::compute_offsets();

4482 
4483   // generated interpreter code wants to know about the offsets we just computed:
4484   AbstractAssembler::update_delayed_values();
4485 }
4486 
4487 #ifndef PRODUCT
4488 
4489 // These functions exist to assert the validity of hard-coded field offsets to guard
4490 // against changes in the class files
4491 
4492 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
4493   EXCEPTION_MARK;
4494   fieldDescriptor fd;
4495   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
4496   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
4497   InstanceKlass* ik = InstanceKlass::cast(k);
4498   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
4499   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
4500   if (!ik->find_local_field(f_name, f_sig, &fd)) {
4501     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);


4527 
4528   // Boxed primitive objects (java_lang_boxing_object)
4529 
4530   CHECK_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
4531   CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
4532   CHECK_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
4533   CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
4534   CHECK_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
4535   CHECK_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
4536   CHECK_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
4537   CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
4538 
4539   // java.lang.ref.Reference
4540 
4541   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, referent, "Ljava/lang/Object;");
4542   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, queue, "Ljava/lang/ref/ReferenceQueue;");
4543   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, next, "Ljava/lang/ref/Reference;");
4544   // Fake field
4545   //CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, discovered, "Ljava/lang/ref/Reference;");
4546 











4547   if (!valid) vm_exit_during_initialization("Hard-coded field offset verification failed");
4548 }
4549 
4550 #endif // PRODUCT
4551 
4552 int InjectedField::compute_offset() {
4553   InstanceKlass* ik = InstanceKlass::cast(klass());
4554   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
4555     if (!may_be_java && !fs.access_flags().is_internal()) {
4556       // Only look at injected fields
4557       continue;
4558     }
4559     if (fs.name() == name() && fs.signature() == signature()) {
4560       return fs.offset();
4561     }
4562   }
4563   ResourceMark rm;
4564   tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
4565 #ifndef PRODUCT
4566   ik->print();


1548 
1549 
1550 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the
1551 //       platform thread structure, and a eetop offset which was used for thread
1552 //       local storage (and unused by the HotSpot VM). In JDK1.2 the two structures
1553 //       merged, so in the HotSpot VM we just use the eetop field for the thread
1554 //       instead of the privateInfo_offset.
1555 //
1556 // Note: The stackSize field is only present starting in 1.4.
1557 
1558 int java_lang_Thread::_name_offset = 0;
1559 int java_lang_Thread::_group_offset = 0;
1560 int java_lang_Thread::_contextClassLoader_offset = 0;
1561 int java_lang_Thread::_inheritedAccessControlContext_offset = 0;
1562 int java_lang_Thread::_priority_offset = 0;
1563 int java_lang_Thread::_eetop_offset = 0;
1564 int java_lang_Thread::_daemon_offset = 0;
1565 int java_lang_Thread::_stillborn_offset = 0;
1566 int java_lang_Thread::_stackSize_offset = 0;
1567 int java_lang_Thread::_tid_offset = 0;
1568 int java_lang_Thread::_continuation_offset = 0;
1569 int java_lang_Thread::_thread_status_offset = 0;
1570 int java_lang_Thread::_park_blocker_offset = 0;
1571 int java_lang_Thread::_park_event_offset = 0 ;
1572 
1573 #define THREAD_FIELDS_DO(macro) \
1574   macro(_name_offset,          k, vmSymbols::name_name(), string_signature, false); \
1575   macro(_group_offset,         k, vmSymbols::group_name(), threadgroup_signature, false); \
1576   macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \
1577   macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \
1578   macro(_priority_offset,      k, vmSymbols::priority_name(), int_signature, false); \
1579   macro(_daemon_offset,        k, vmSymbols::daemon_name(), bool_signature, false); \
1580   macro(_eetop_offset,         k, "eetop", long_signature, false); \
1581   macro(_stillborn_offset,     k, "stillborn", bool_signature, false); \
1582   macro(_stackSize_offset,     k, "stackSize", long_signature, false); \
1583   macro(_tid_offset,           k, "tid", long_signature, false); \
1584   macro(_thread_status_offset, k, "threadStatus", int_signature, false); \
1585   macro(_park_blocker_offset,  k, "parkBlocker", object_signature, false); \
1586   macro(_park_event_offset,    k, "nativeParkEventPointer", long_signature, false); \
1587   macro(_continuation_offset,  k, "cont", continuation_signature, false)
1588 
1589 void java_lang_Thread::compute_offsets() {
1590   assert(_group_offset == 0, "offsets should be initialized only once");
1591 
1592   InstanceKlass* k = SystemDictionary::Thread_klass();
1593   THREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1594 }
1595 
1596 #if INCLUDE_CDS
1597 void java_lang_Thread::serialize(SerializeClosure* f) {
1598   THREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1599 }
1600 #endif
1601 
1602 JavaThread* java_lang_Thread::thread(oop java_thread) {
1603   return (JavaThread*)java_thread->address_field(_eetop_offset);
1604 }
1605 
1606 
1607 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) {


1703     // use JVMTI values and cast.
1704     JavaThread* thr = java_lang_Thread::thread(java_thread);
1705     if (thr == NULL) {
1706       // the thread hasn't run yet or is in the process of exiting
1707       return NEW;
1708     }
1709     return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
1710   }
1711 }
1712 
1713 
1714 jlong java_lang_Thread::thread_id(oop java_thread) {
1715   // The thread ID field is only present starting in 1.5
1716   if (_tid_offset > 0) {
1717     return java_thread->long_field(_tid_offset);
1718   } else {
1719     return 0;
1720   }
1721 }
1722 
1723 oop java_lang_Thread::continuation(oop java_thread) {
1724   return java_thread->obj_field(_continuation_offset);
1725 }
1726 
1727 void java_lang_Thread::set_continuation(oop java_thread, oop continuation) {
1728   return java_thread->obj_field_put(_continuation_offset, continuation);
1729 }
1730 
1731 oop java_lang_Thread::park_blocker(oop java_thread) {
1732   assert(JDK_Version::current().supports_thread_park_blocker() &&
1733          _park_blocker_offset != 0, "Must support parkBlocker field");
1734 
1735   if (_park_blocker_offset > 0) {
1736     return java_thread->obj_field(_park_blocker_offset);
1737   }
1738 
1739   return NULL;
1740 }
1741 
1742 jlong java_lang_Thread::park_event(oop java_thread) {
1743   if (_park_event_offset > 0) {
1744     return java_thread->long_field(_park_event_offset);
1745   }
1746   return 0;
1747 }
1748 
1749 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) {
1750   if (_park_event_offset > 0) {


4230 int java_lang_reflect_Field::clazz_offset;
4231 int java_lang_reflect_Field::name_offset;
4232 int java_lang_reflect_Field::type_offset;
4233 int java_lang_reflect_Field::slot_offset;
4234 int java_lang_reflect_Field::modifiers_offset;
4235 int java_lang_reflect_Field::signature_offset;
4236 int java_lang_reflect_Field::annotations_offset;
4237 int java_lang_reflect_Field::type_annotations_offset;
4238 int java_lang_reflect_Parameter::name_offset;
4239 int java_lang_reflect_Parameter::modifiers_offset;
4240 int java_lang_reflect_Parameter::index_offset;
4241 int java_lang_reflect_Parameter::executable_offset;
4242 int java_lang_boxing_object::value_offset;
4243 int java_lang_boxing_object::long_value_offset;
4244 int java_lang_ref_Reference::referent_offset;
4245 int java_lang_ref_Reference::queue_offset;
4246 int java_lang_ref_Reference::next_offset;
4247 int java_lang_ref_Reference::discovered_offset;
4248 int java_lang_ref_SoftReference::timestamp_offset;
4249 int java_lang_ref_SoftReference::static_clock_offset;
4250 int java_lang_Continuation::scope_offset;
4251 int java_lang_Continuation::target_offset;
4252 int java_lang_Continuation::stack_offset;
4253 int java_lang_Continuation::refStack_offset;
4254 int java_lang_Continuation::parent_offset;
4255 int java_lang_Continuation::entrySP_offset;
4256 int java_lang_Continuation::entryFP_offset;
4257 int java_lang_Continuation::entryPC_offset;
4258 int java_lang_Continuation::fp_offset;
4259 int java_lang_Continuation::sp_offset;
4260 int java_lang_Continuation::pc_offset;
4261 int java_lang_Continuation::refSP_offset;
4262 Method* java_lang_Continuation::stack_method;
4263 int java_lang_ClassLoader::parent_offset;
4264 int java_lang_System::static_in_offset;
4265 int java_lang_System::static_out_offset;
4266 int java_lang_System::static_err_offset;
4267 int java_lang_System::static_security_offset;
4268 int java_lang_StackTraceElement::methodName_offset;
4269 int java_lang_StackTraceElement::fileName_offset;
4270 int java_lang_StackTraceElement::lineNumber_offset;
4271 int java_lang_StackTraceElement::moduleName_offset;
4272 int java_lang_StackTraceElement::moduleVersion_offset;
4273 int java_lang_StackTraceElement::classLoaderName_offset;
4274 int java_lang_StackTraceElement::declaringClass_offset;
4275 int java_lang_StackTraceElement::declaringClassObject_offset;
4276 int java_lang_StackFrameInfo::_memberName_offset;
4277 int java_lang_StackFrameInfo::_bci_offset;
4278 int java_lang_StackFrameInfo::_version_offset;
4279 int java_lang_LiveStackFrameInfo::_monitors_offset;
4280 int java_lang_LiveStackFrameInfo::_locals_offset;
4281 int java_lang_LiveStackFrameInfo::_operands_offset;
4282 int java_lang_LiveStackFrameInfo::_mode_offset;


4390 void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) {
4391   o->obj_field_put(classes_offset, val);
4392 }
4393 
4394 void java_lang_AssertionStatusDirectives::set_classEnabled(oop o, oop val) {
4395   o->obj_field_put(classEnabled_offset, val);
4396 }
4397 
4398 void java_lang_AssertionStatusDirectives::set_packages(oop o, oop val) {
4399   o->obj_field_put(packages_offset, val);
4400 }
4401 
4402 void java_lang_AssertionStatusDirectives::set_packageEnabled(oop o, oop val) {
4403   o->obj_field_put(packageEnabled_offset, val);
4404 }
4405 
4406 void java_lang_AssertionStatusDirectives::set_deflt(oop o, bool val) {
4407   o->bool_field_put(deflt_offset, val);
4408 }
4409 
4410 // Support for java.lang.Continuation
4411 
4412 void java_lang_Continuation::compute_offsets() {
4413   InstanceKlass* k = SystemDictionary::Continuation_klass();
4414   compute_offset(scope_offset,     k, vmSymbols::scope_name(),     vmSymbols::continuationscope_signature());
4415   compute_offset(target_offset,    k, vmSymbols::target_name(),    vmSymbols::runnable_signature());
4416   compute_offset(parent_offset,    k, vmSymbols::parent_name(),    vmSymbols::continuation_signature());
4417   compute_offset(stack_offset,     k, vmSymbols::stack_name(),     vmSymbols::int_array_signature());
4418   compute_offset(refStack_offset,  k, vmSymbols::refStack_name(),  vmSymbols::object_array_signature());
4419   compute_offset(entrySP_offset,   k, vmSymbols::entrySP_name(),   vmSymbols::long_signature());
4420   compute_offset(entryFP_offset,   k, vmSymbols::entryFP_name(),   vmSymbols::long_signature());
4421   compute_offset(entryPC_offset,   k, vmSymbols::entryPC_name(),   vmSymbols::long_signature());
4422   compute_offset(fp_offset,        k, vmSymbols::fp_name(),        vmSymbols::long_signature());
4423   compute_offset(sp_offset,        k, vmSymbols::sp_name(),        vmSymbols::int_signature());
4424   compute_offset(pc_offset,        k, vmSymbols::pc_name(),        vmSymbols::long_signature());
4425   compute_offset(refSP_offset,     k, vmSymbols::refSP_name(),     vmSymbols::int_signature());
4426 }
4427 
4428 bool java_lang_Continuation::on_local_stack(oop ref, address adr) {
4429   arrayOop s = stack(ref);
4430   void* base = s->base(T_INT);
4431   return adr >= base && (char*)adr < ((char*)base + (s->length() * 4));
4432 }
4433 
4434 
4435 // Support for intrinsification of java.nio.Buffer.checkIndex
4436 int java_nio_Buffer::limit_offset() {
4437   return _limit_offset;
4438 }
4439 
4440 #define BUFFER_FIELDS_DO(macro) \
4441   macro(_limit_offset, k, "limit", int_signature, false)
4442 
4443 void java_nio_Buffer::compute_offsets() {
4444   InstanceKlass* k = SystemDictionary::nio_Buffer_klass();
4445   assert(k != NULL, "must be loaded in 1.4+");
4446   BUFFER_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4447 }
4448 
4449 #if INCLUDE_CDS
4450 void java_nio_Buffer::serialize(SerializeClosure* f) {
4451   BUFFER_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4452 }
4453 #endif


4467 }
4468 
4469 static int member_offset(int hardcoded_offset) {
4470   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
4471 }
4472 
4473 // Compute hard-coded offsets
4474 // Invoked before SystemDictionary::initialize, so pre-loaded classes
4475 // are not available to determine the offset_of_static_fields.
4476 void JavaClasses::compute_hard_coded_offsets() {
4477 
4478   // java_lang_boxing_object
4479   java_lang_boxing_object::value_offset      = member_offset(java_lang_boxing_object::hc_value_offset);
4480   java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong);
4481 
4482   // java_lang_ref_Reference
4483   java_lang_ref_Reference::referent_offset    = member_offset(java_lang_ref_Reference::hc_referent_offset);
4484   java_lang_ref_Reference::queue_offset       = member_offset(java_lang_ref_Reference::hc_queue_offset);
4485   java_lang_ref_Reference::next_offset        = member_offset(java_lang_ref_Reference::hc_next_offset);
4486   java_lang_ref_Reference::discovered_offset  = member_offset(java_lang_ref_Reference::hc_discovered_offset);
4487 
4488   // // java_lang_Continuation Class
4489   // java_lang_Continuation::target_offset       = member_offset(java_lang_Continuation::hc_target_offset);
4490   // java_lang_Continuation::parent_offset       = member_offset(java_lang_Continuation::hc_parent_offset);
4491   // java_lang_Continuation::entrySP_offset      = member_offset(java_lang_Continuation::hc_entrySP_offset);
4492   // java_lang_Continuation::entryFP_offset      = member_offset(java_lang_Continuation::hc_entryFP_offset);
4493   // java_lang_Continuation::entryPC_offset      = member_offset(java_lang_Continuation::hc_entryPC_offset);
4494   // java_lang_Continuation::stack_offset        = member_offset(java_lang_Continuation::hc_stack_offset);
4495   // java_lang_Continuation::lastFP_offset       = member_offset(java_lang_Continuation::hc_lastFP_offset);
4496   // java_lang_Continuation::lastSP_offset       = member_offset(java_lang_Continuation::hc_lastSP_offset);
4497 }
4498 
4499 
4500 // Compute non-hard-coded field offsets of all the classes in this file
4501 void JavaClasses::compute_offsets() {
4502   if (UseSharedSpaces) {
4503     return; // field offsets are loaded from archive
4504   }
4505 
4506   // java_lang_Class::compute_offsets was called earlier in bootstrap
4507   java_lang_System::compute_offsets();
4508   java_lang_ClassLoader::compute_offsets();
4509   java_lang_Throwable::compute_offsets();
4510   java_lang_Thread::compute_offsets();
4511   java_lang_ThreadGroup::compute_offsets();
4512   java_lang_AssertionStatusDirectives::compute_offsets();
4513   java_lang_ref_SoftReference::compute_offsets();
4514   java_lang_invoke_MethodHandle::compute_offsets();
4515   java_lang_invoke_DirectMethodHandle::compute_offsets();
4516   java_lang_invoke_MemberName::compute_offsets();


4519   java_lang_invoke_MethodType::compute_offsets();
4520   java_lang_invoke_CallSite::compute_offsets();
4521   java_lang_invoke_MethodHandleNatives_CallSiteContext::compute_offsets();
4522   java_security_AccessControlContext::compute_offsets();
4523   // Initialize reflection classes. The layouts of these classes
4524   // changed with the new reflection implementation in JDK 1.4, and
4525   // since the Universe doesn't know what JDK version it is until this
4526   // point we defer computation of these offsets until now.
4527   java_lang_reflect_AccessibleObject::compute_offsets();
4528   java_lang_reflect_Method::compute_offsets();
4529   java_lang_reflect_Constructor::compute_offsets();
4530   java_lang_reflect_Field::compute_offsets();
4531   java_nio_Buffer::compute_offsets();
4532   reflect_ConstantPool::compute_offsets();
4533   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
4534   java_lang_reflect_Parameter::compute_offsets();
4535   java_lang_Module::compute_offsets();
4536   java_lang_StackTraceElement::compute_offsets();
4537   java_lang_StackFrameInfo::compute_offsets();
4538   java_lang_LiveStackFrameInfo::compute_offsets();
4539   java_lang_Continuation::compute_offsets();
4540 
4541   // generated interpreter code wants to know about the offsets we just computed:
4542   AbstractAssembler::update_delayed_values();
4543 }
4544 
4545 #ifndef PRODUCT
4546 
4547 // These functions exist to assert the validity of hard-coded field offsets to guard
4548 // against changes in the class files
4549 
4550 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
4551   EXCEPTION_MARK;
4552   fieldDescriptor fd;
4553   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
4554   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
4555   InstanceKlass* ik = InstanceKlass::cast(k);
4556   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
4557   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
4558   if (!ik->find_local_field(f_name, f_sig, &fd)) {
4559     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);


4585 
4586   // Boxed primitive objects (java_lang_boxing_object)
4587 
4588   CHECK_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
4589   CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
4590   CHECK_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
4591   CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
4592   CHECK_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
4593   CHECK_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
4594   CHECK_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
4595   CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
4596 
4597   // java.lang.ref.Reference
4598 
4599   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, referent, "Ljava/lang/Object;");
4600   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, queue, "Ljava/lang/ref/ReferenceQueue;");
4601   CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, next, "Ljava/lang/ref/Reference;");
4602   // Fake field
4603   //CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, discovered, "Ljava/lang/ref/Reference;");
4604 
4605   // java.lang.Continuation
4606 
4607   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, target,   "Ljava/lang/Runnable;");
4608   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, stack,    "[I");
4609   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, parent,   "Ljava/lang/Continuation;");
4610   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, entrySP,  "J");
4611   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, entryFP,  "J");
4612   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, entryPC,  "J");
4613   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, lastFP,   "I");
4614   // CHECK_OFFSET("java/lang/Continuation", java_lang_Continuation, lastSP,   "I");
4615 
4616   if (!valid) vm_exit_during_initialization("Hard-coded field offset verification failed");
4617 }
4618 
4619 #endif // PRODUCT
4620 
4621 int InjectedField::compute_offset() {
4622   InstanceKlass* ik = InstanceKlass::cast(klass());
4623   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
4624     if (!may_be_java && !fs.access_flags().is_internal()) {
4625       // Only look at injected fields
4626       continue;
4627     }
4628     if (fs.name() == name() && fs.signature() == signature()) {
4629       return fs.offset();
4630     }
4631   }
4632   ResourceMark rm;
4633   tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
4634 #ifndef PRODUCT
4635   ik->print();
< prev index next >