< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.

   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


4256 int java_lang_StackTraceElement::moduleVersion_offset;
4257 int java_lang_StackTraceElement::classLoaderName_offset;
4258 int java_lang_StackTraceElement::declaringClass_offset;
4259 int java_lang_StackTraceElement::declaringClassObject_offset;
4260 int java_lang_StackFrameInfo::_memberName_offset;
4261 int java_lang_StackFrameInfo::_bci_offset;
4262 int java_lang_StackFrameInfo::_version_offset;
4263 int java_lang_LiveStackFrameInfo::_monitors_offset;
4264 int java_lang_LiveStackFrameInfo::_locals_offset;
4265 int java_lang_LiveStackFrameInfo::_operands_offset;
4266 int java_lang_LiveStackFrameInfo::_mode_offset;
4267 int java_lang_AssertionStatusDirectives::classes_offset;
4268 int java_lang_AssertionStatusDirectives::classEnabled_offset;
4269 int java_lang_AssertionStatusDirectives::packages_offset;
4270 int java_lang_AssertionStatusDirectives::packageEnabled_offset;
4271 int java_lang_AssertionStatusDirectives::deflt_offset;
4272 int java_nio_Buffer::_limit_offset;
4273 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset;
4274 int reflect_ConstantPool::_oop_offset;
4275 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;








4276 
4277 #define STACKTRACEELEMENT_FIELDS_DO(macro) \
4278   macro(declaringClassObject_offset,  k, "declaringClassObject", class_signature, false); \
4279   macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \
4280   macro(moduleName_offset,      k, "moduleName",      string_signature, false); \
4281   macro(moduleVersion_offset,   k, "moduleVersion",   string_signature, false); \
4282   macro(declaringClass_offset,  k, "declaringClass",  string_signature, false); \
4283   macro(methodName_offset,      k, "methodName",      string_signature, false); \
4284   macro(fileName_offset,        k, "fileName",        string_signature, false); \
4285   macro(lineNumber_offset,      k, "lineNumber",      int_signature,    false)
4286 
4287 // Support for java_lang_StackTraceElement
4288 void java_lang_StackTraceElement::compute_offsets() {
4289   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
4290   STACKTRACEELEMENT_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4291 }
4292 
4293 #if INCLUDE_CDS
4294 void java_lang_StackTraceElement::serialize(SerializeClosure* f) {
4295   STACKTRACEELEMENT_FIELDS_DO(FIELD_SERIALIZE_OFFSET);


4418 void java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets() {
4419   InstanceKlass* k = SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass();
4420   AOS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4421 }
4422 
4423 oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) {
4424   assert(_owner_offset != 0, "Must be initialized");
4425   return obj->obj_field(_owner_offset);
4426 }
4427 
4428 #if INCLUDE_CDS
4429 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize(SerializeClosure* f) {
4430   AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4431 }
4432 #endif
4433 
4434 static int member_offset(int hardcoded_offset) {
4435   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
4436 }
4437 
















































































4438 // Compute hard-coded offsets
4439 // Invoked before SystemDictionary::initialize, so pre-loaded classes
4440 // are not available to determine the offset_of_static_fields.
4441 void JavaClasses::compute_hard_coded_offsets() {
4442 
4443   // java_lang_boxing_object
4444   java_lang_boxing_object::value_offset      = member_offset(java_lang_boxing_object::hc_value_offset);
4445   java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong);
4446 
4447   // java_lang_ref_Reference
4448   java_lang_ref_Reference::referent_offset    = member_offset(java_lang_ref_Reference::hc_referent_offset);
4449   java_lang_ref_Reference::queue_offset       = member_offset(java_lang_ref_Reference::hc_queue_offset);
4450   java_lang_ref_Reference::next_offset        = member_offset(java_lang_ref_Reference::hc_next_offset);
4451   java_lang_ref_Reference::discovered_offset  = member_offset(java_lang_ref_Reference::hc_discovered_offset);
4452 }
4453 
4454 
4455 // Compute non-hard-coded field offsets of all the classes in this file
4456 void JavaClasses::compute_offsets() {
4457   if (UseSharedSpaces) {


4478   // Initialize reflection classes. The layouts of these classes
4479   // changed with the new reflection implementation in JDK 1.4, and
4480   // since the Universe doesn't know what JDK version it is until this
4481   // point we defer computation of these offsets until now.
4482   java_lang_reflect_AccessibleObject::compute_offsets();
4483   java_lang_reflect_Method::compute_offsets();
4484   java_lang_reflect_Constructor::compute_offsets();
4485   java_lang_reflect_Field::compute_offsets();
4486   java_nio_Buffer::compute_offsets();
4487   reflect_ConstantPool::compute_offsets();
4488   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
4489   java_lang_reflect_Parameter::compute_offsets();
4490   java_lang_Module::compute_offsets();
4491   java_lang_StackTraceElement::compute_offsets();
4492   java_lang_StackFrameInfo::compute_offsets();
4493   java_lang_LiveStackFrameInfo::compute_offsets();
4494   java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets();
4495 
4496   // generated interpreter code wants to know about the offsets we just computed:
4497   AbstractAssembler::update_delayed_values();









4498 }
4499 
4500 #ifndef PRODUCT
4501 
4502 // These functions exist to assert the validity of hard-coded field offsets to guard
4503 // against changes in the class files
4504 
4505 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
4506   EXCEPTION_MARK;
4507   fieldDescriptor fd;
4508   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
4509   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
4510   InstanceKlass* ik = InstanceKlass::cast(k);
4511   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
4512   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
4513   if (!ik->find_local_field(f_name, f_sig, &fd)) {
4514     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
4515     return false;
4516   }
4517   if (fd.is_static()) {


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2015-2018, Azul Systems, Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *


4257 int java_lang_StackTraceElement::moduleVersion_offset;
4258 int java_lang_StackTraceElement::classLoaderName_offset;
4259 int java_lang_StackTraceElement::declaringClass_offset;
4260 int java_lang_StackTraceElement::declaringClassObject_offset;
4261 int java_lang_StackFrameInfo::_memberName_offset;
4262 int java_lang_StackFrameInfo::_bci_offset;
4263 int java_lang_StackFrameInfo::_version_offset;
4264 int java_lang_LiveStackFrameInfo::_monitors_offset;
4265 int java_lang_LiveStackFrameInfo::_locals_offset;
4266 int java_lang_LiveStackFrameInfo::_operands_offset;
4267 int java_lang_LiveStackFrameInfo::_mode_offset;
4268 int java_lang_AssertionStatusDirectives::classes_offset;
4269 int java_lang_AssertionStatusDirectives::classEnabled_offset;
4270 int java_lang_AssertionStatusDirectives::packages_offset;
4271 int java_lang_AssertionStatusDirectives::packageEnabled_offset;
4272 int java_lang_AssertionStatusDirectives::deflt_offset;
4273 int java_nio_Buffer::_limit_offset;
4274 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset;
4275 int reflect_ConstantPool::_oop_offset;
4276 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;
4277 #ifdef AARCH32
4278 int com_sun_crypto_provider_AESCrypt::_K_offset;
4279 int com_sun_crypto_provider_CipherBlockChaining::_r_offset;
4280 int com_sun_crypto_provider_FeedbackCipher::_embeddedCipher_offset;
4281 int sun_security_provider_SHA::_state_offset;
4282 int sun_security_provider_SHA2::_state_offset;
4283 int sun_security_provider_SHA5::_state_offset;
4284 #endif
4285 
4286 #define STACKTRACEELEMENT_FIELDS_DO(macro) \
4287   macro(declaringClassObject_offset,  k, "declaringClassObject", class_signature, false); \
4288   macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \
4289   macro(moduleName_offset,      k, "moduleName",      string_signature, false); \
4290   macro(moduleVersion_offset,   k, "moduleVersion",   string_signature, false); \
4291   macro(declaringClass_offset,  k, "declaringClass",  string_signature, false); \
4292   macro(methodName_offset,      k, "methodName",      string_signature, false); \
4293   macro(fileName_offset,        k, "fileName",        string_signature, false); \
4294   macro(lineNumber_offset,      k, "lineNumber",      int_signature,    false)
4295 
4296 // Support for java_lang_StackTraceElement
4297 void java_lang_StackTraceElement::compute_offsets() {
4298   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
4299   STACKTRACEELEMENT_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4300 }
4301 
4302 #if INCLUDE_CDS
4303 void java_lang_StackTraceElement::serialize(SerializeClosure* f) {
4304   STACKTRACEELEMENT_FIELDS_DO(FIELD_SERIALIZE_OFFSET);


4427 void java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets() {
4428   InstanceKlass* k = SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass();
4429   AOS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4430 }
4431 
4432 oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) {
4433   assert(_owner_offset != 0, "Must be initialized");
4434   return obj->obj_field(_owner_offset);
4435 }
4436 
4437 #if INCLUDE_CDS
4438 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize(SerializeClosure* f) {
4439   AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4440 }
4441 #endif
4442 
4443 static int member_offset(int hardcoded_offset) {
4444   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
4445 }
4446 
4447 #ifdef AARCH32
4448 // Support for intrinsification of com.sun.crypto.provider.AESCrypto.encrypt
4449 #define AESCRYPT_FIELDS_DO(macro)                       \
4450   macro(_K_offset, k, "K", int_array_signature, false)
4451 
4452 void com_sun_crypto_provider_AESCrypt::compute_offsets() {
4453   InstanceKlass* k = SystemDictionary::AESCrypt_klass();
4454   AESCRYPT_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4455 }
4456 
4457 int com_sun_crypto_provider_AESCrypt::K_offset() {
4458   return _K_offset;
4459 }
4460 
4461 // Support for intrinsification of com_sun_crypto_provider_CipherBlockChaining.encrypt
4462 #define CBC_FIELDS_DO(macro) \
4463   macro(_r_offset, k, "r", byte_array_signature, false)
4464 
4465 void com_sun_crypto_provider_CipherBlockChaining::compute_offsets() {
4466   InstanceKlass* k = SystemDictionary::CipherBlockChaining_klass();
4467   CBC_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4468 }
4469 
4470 int com_sun_crypto_provider_CipherBlockChaining::r_offset() {
4471   return _r_offset;
4472 }
4473 
4474 // Support for intrinsification of com_sun_crypto_provider_CipherBlockChaining.encrypt
4475 #define FC_FIELDS_DO(macro) \
4476   macro(_embeddedCipher_offset, k, "embeddedCipher", symmetriccipher_signature, false)
4477 
4478 void com_sun_crypto_provider_FeedbackCipher::compute_offsets() {
4479   InstanceKlass* k = SystemDictionary::FeedbackCipher_klass();
4480   FC_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4481 }
4482 
4483 int com_sun_crypto_provider_FeedbackCipher::embeddedCipher_offset() {
4484   return _embeddedCipher_offset;
4485 }
4486 
4487 // Support for intrinsification of sun_security_provider_SHA.implCompress
4488 #define SHA_FIELDS_DO(macro) \
4489   macro(_state_offset, k, "state", int_array_signature, false)
4490 
4491 void sun_security_provider_SHA::compute_offsets() {
4492   InstanceKlass* k = SystemDictionary::SHA_klass();
4493   SHA_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4494 }
4495 
4496 int sun_security_provider_SHA::state_offset() {
4497   return _state_offset;
4498 }
4499 
4500 // Support for intrinsification of sun_security_provider_SHA2.implCompress
4501 #define SHA2_FIELDS_DO(macro) \
4502   macro(_state_offset, k, "state", int_array_signature, false)
4503 
4504 void sun_security_provider_SHA2::compute_offsets() {
4505   InstanceKlass* k = SystemDictionary::SHA2_klass();
4506   SHA2_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4507 }
4508 
4509 int sun_security_provider_SHA2::state_offset() {
4510   return _state_offset;
4511 }
4512 
4513 // Support for intrinsification of sun_security_provider_SHA5.implCompress
4514 #define SHA5_FIELDS_DO(macro) \
4515   macro(_state_offset, k, "state", long_array_signature, false)
4516 
4517 void sun_security_provider_SHA5::compute_offsets() {
4518   InstanceKlass* k = SystemDictionary::SHA5_klass();
4519   SHA5_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4520 }
4521 
4522 int sun_security_provider_SHA5::state_offset() {
4523   return _state_offset;
4524 }
4525 #endif
4526 
4527 // Compute hard-coded offsets
4528 // Invoked before SystemDictionary::initialize, so pre-loaded classes
4529 // are not available to determine the offset_of_static_fields.
4530 void JavaClasses::compute_hard_coded_offsets() {
4531 
4532   // java_lang_boxing_object
4533   java_lang_boxing_object::value_offset      = member_offset(java_lang_boxing_object::hc_value_offset);
4534   java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong);
4535 
4536   // java_lang_ref_Reference
4537   java_lang_ref_Reference::referent_offset    = member_offset(java_lang_ref_Reference::hc_referent_offset);
4538   java_lang_ref_Reference::queue_offset       = member_offset(java_lang_ref_Reference::hc_queue_offset);
4539   java_lang_ref_Reference::next_offset        = member_offset(java_lang_ref_Reference::hc_next_offset);
4540   java_lang_ref_Reference::discovered_offset  = member_offset(java_lang_ref_Reference::hc_discovered_offset);
4541 }
4542 
4543 
4544 // Compute non-hard-coded field offsets of all the classes in this file
4545 void JavaClasses::compute_offsets() {
4546   if (UseSharedSpaces) {


4567   // Initialize reflection classes. The layouts of these classes
4568   // changed with the new reflection implementation in JDK 1.4, and
4569   // since the Universe doesn't know what JDK version it is until this
4570   // point we defer computation of these offsets until now.
4571   java_lang_reflect_AccessibleObject::compute_offsets();
4572   java_lang_reflect_Method::compute_offsets();
4573   java_lang_reflect_Constructor::compute_offsets();
4574   java_lang_reflect_Field::compute_offsets();
4575   java_nio_Buffer::compute_offsets();
4576   reflect_ConstantPool::compute_offsets();
4577   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
4578   java_lang_reflect_Parameter::compute_offsets();
4579   java_lang_Module::compute_offsets();
4580   java_lang_StackTraceElement::compute_offsets();
4581   java_lang_StackFrameInfo::compute_offsets();
4582   java_lang_LiveStackFrameInfo::compute_offsets();
4583   java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets();
4584 
4585   // generated interpreter code wants to know about the offsets we just computed:
4586   AbstractAssembler::update_delayed_values();
4587 
4588 #ifdef AARCH32
4589   com_sun_crypto_provider_AESCrypt::compute_offsets();
4590   com_sun_crypto_provider_FeedbackCipher::compute_offsets();
4591   com_sun_crypto_provider_CipherBlockChaining::compute_offsets();
4592   sun_security_provider_SHA::compute_offsets();
4593   sun_security_provider_SHA2::compute_offsets();
4594   sun_security_provider_SHA5::compute_offsets();
4595 #endif
4596 }
4597 
4598 #ifndef PRODUCT
4599 
4600 // These functions exist to assert the validity of hard-coded field offsets to guard
4601 // against changes in the class files
4602 
4603 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
4604   EXCEPTION_MARK;
4605   fieldDescriptor fd;
4606   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
4607   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
4608   InstanceKlass* ik = InstanceKlass::cast(k);
4609   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
4610   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
4611   if (!ik->find_local_field(f_name, f_sig, &fd)) {
4612     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
4613     return false;
4614   }
4615   if (fd.is_static()) {


< prev index next >