1034 "MetaspaceShared::is_heap_object_archiving_allowed() must be true");
1035
1036 for (int t = 0; t <= T_VOID; t++) {
1037 oop m = Universe::_mirrors[t];
1038 if (m != NULL) {
1039 // Update the field at _array_klass_offset to point to the relocated array klass.
1040 oop archived_m = MetaspaceShared::archive_heap_object(m, THREAD);
1041 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1042 assert(ak != NULL || t == T_VOID, "should not be NULL");
1043 if (ak != NULL) {
1044 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak);
1045 archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1046 }
1047
1048 // Clear the fields. Just to be safe
1049 Klass *k = m->klass();
1050 Handle archived_mirror_h(THREAD, archived_m);
1051 ResetMirrorField reset(archived_mirror_h);
1052 InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1053
1054 log_trace(cds, mirror)("Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1055 type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1056
1057 Universe::_mirrors[t] = archived_m;
1058 }
1059 }
1060
1061 assert(Universe::_mirrors[T_INT] != NULL &&
1062 Universe::_mirrors[T_FLOAT] != NULL &&
1063 Universe::_mirrors[T_DOUBLE] != NULL &&
1064 Universe::_mirrors[T_BYTE] != NULL &&
1065 Universe::_mirrors[T_BOOLEAN] != NULL &&
1066 Universe::_mirrors[T_CHAR] != NULL &&
1067 Universe::_mirrors[T_LONG] != NULL &&
1068 Universe::_mirrors[T_SHORT] != NULL &&
1069 Universe::_mirrors[T_VOID] != NULL, "sanity");
1070
1071 Universe::set_int_mirror(Universe::_mirrors[T_INT]);
1072 Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]);
1073 Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]);
1074 Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]);
1116 return NULL;
1117 }
1118 }
1119
1120 // Now start archiving the mirror object
1121 oop archived_mirror = MetaspaceShared::archive_heap_object(mirror, THREAD);
1122 if (archived_mirror == NULL) {
1123 return NULL;
1124 }
1125
1126 archived_mirror = process_archived_mirror(k, mirror, archived_mirror, THREAD);
1127 if (archived_mirror == NULL) {
1128 return NULL;
1129 }
1130
1131 k->set_archived_java_mirror_raw(archived_mirror);
1132
1133 k->set_has_raw_archived_mirror();
1134
1135 ResourceMark rm;
1136 log_trace(cds, mirror)("Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1137 k->external_name(), p2i(mirror), p2i(archived_mirror));
1138
1139 return archived_mirror;
1140 }
1141
1142 // The process is based on create_mirror().
1143 oop java_lang_Class::process_archived_mirror(Klass* k, oop mirror,
1144 oop archived_mirror,
1145 Thread *THREAD) {
1146 // Clear nonstatic fields in archived mirror. Some of the fields will be set
1147 // to archived metadata and objects below.
1148 Klass *c = archived_mirror->klass();
1149 Handle archived_mirror_h(THREAD, archived_mirror);
1150 ResetMirrorField reset(archived_mirror_h);
1151 InstanceKlass::cast(c)->do_nonstatic_fields(&reset);
1152
1153 if (k->is_array_klass()) {
1154 oop archived_comp_mirror;
1155 if (k->is_typeArray_klass()) {
1156 // The primitive type mirrors are already archived. Get the archived mirror.
1169 java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1170 } else {
1171 assert(k->is_instance_klass(), "Must be");
1172
1173 // Reset local static fields in the mirror
1174 InstanceKlass::cast(k)->do_local_static_fields(&reset);
1175
1176 java_lang_Class:set_init_lock(archived_mirror, NULL);
1177
1178 set_protection_domain(archived_mirror, NULL);
1179 }
1180
1181 // clear class loader and mirror_module_field
1182 set_class_loader(archived_mirror, NULL);
1183 set_module(archived_mirror, NULL);
1184
1185 // The archived mirror's field at _klass_offset is still pointing to the original
1186 // klass. Updated the field in the archived mirror to point to the relocated
1187 // klass in the archive.
1188 Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror));
1189 log_debug(cds, mirror)("Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1190 p2i(as_Klass(mirror)), p2i(reloc_k));
1191 archived_mirror->metadata_field_put(_klass_offset, reloc_k);
1192
1193 // The field at _array_klass_offset is pointing to the original one dimension
1194 // higher array klass if exists. Relocate the pointer.
1195 Klass *arr = array_klass_acquire(mirror);
1196 if (arr != NULL) {
1197 Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr);
1198 log_debug(cds, mirror)("Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1199 p2i(arr), p2i(reloc_arr));
1200 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1201 }
1202 return archived_mirror;
1203 }
1204
1205 // Returns true if the mirror is updated, false if no archived mirror
1206 // data is present. After the archived mirror object is restored, the
1207 // shared klass' _has_raw_archived_mirror flag is cleared.
1208 bool java_lang_Class::restore_archived_mirror(Klass *k,
1209 Handle class_loader, Handle module,
1210 Handle protection_domain, TRAPS) {
1211 oop m = MetaspaceShared::materialize_archived_object(k->archived_java_mirror_raw());
1212
1213 if (m == NULL) {
1214 return false;
1215 }
1216
1217 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1218
1230 // create the init_lock
1231 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1232 set_init_lock(mirror(), r);
1233
1234 if (protection_domain.not_null()) {
1235 set_protection_domain(mirror(), protection_domain());
1236 }
1237 }
1238
1239 assert(class_loader() == k->class_loader(), "should be same");
1240 if (class_loader.not_null()) {
1241 set_class_loader(mirror(), class_loader());
1242 }
1243
1244 k->set_java_mirror(mirror);
1245 k->clear_has_raw_archived_mirror();
1246
1247 set_mirror_module_field(k, mirror, module, THREAD);
1248
1249 ResourceMark rm;
1250 log_trace(cds, mirror)("Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1251
1252 return true;
1253 }
1254 #endif // INCLUDE_CDS_JAVA_HEAP
1255
1256 void java_lang_Class::fixup_module_field(Klass* k, Handle module) {
1257 assert(_module_offset != 0, "must have been computed already");
1258 java_lang_Class::set_module(k->java_mirror(), module());
1259 }
1260
1261 int java_lang_Class::oop_size(oop java_class) {
1262 assert(_oop_size_offset != 0, "must be set");
1263 int size = java_class->int_field(_oop_size_offset);
1264 assert(size > 0, "Oop size must be greater than zero, not %d", size);
1265 return size;
1266 }
1267
1268 void java_lang_Class::set_oop_size(oop java_class, int size) {
1269 assert(_oop_size_offset != 0, "must be set");
1270 assert(size > 0, "Oop size must be greater than zero, not %d", size);
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) {
4475 java_lang_invoke_CallSite::compute_offsets();
4476 java_lang_invoke_MethodHandleNatives_CallSiteContext::compute_offsets();
4477 java_security_AccessControlContext::compute_offsets();
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);
|
1034 "MetaspaceShared::is_heap_object_archiving_allowed() must be true");
1035
1036 for (int t = 0; t <= T_VOID; t++) {
1037 oop m = Universe::_mirrors[t];
1038 if (m != NULL) {
1039 // Update the field at _array_klass_offset to point to the relocated array klass.
1040 oop archived_m = MetaspaceShared::archive_heap_object(m, THREAD);
1041 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1042 assert(ak != NULL || t == T_VOID, "should not be NULL");
1043 if (ak != NULL) {
1044 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak);
1045 archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1046 }
1047
1048 // Clear the fields. Just to be safe
1049 Klass *k = m->klass();
1050 Handle archived_mirror_h(THREAD, archived_m);
1051 ResetMirrorField reset(archived_mirror_h);
1052 InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1053
1054 log_trace(cds, heap, mirror)(
1055 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1056 type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1057
1058 Universe::_mirrors[t] = archived_m;
1059 }
1060 }
1061
1062 assert(Universe::_mirrors[T_INT] != NULL &&
1063 Universe::_mirrors[T_FLOAT] != NULL &&
1064 Universe::_mirrors[T_DOUBLE] != NULL &&
1065 Universe::_mirrors[T_BYTE] != NULL &&
1066 Universe::_mirrors[T_BOOLEAN] != NULL &&
1067 Universe::_mirrors[T_CHAR] != NULL &&
1068 Universe::_mirrors[T_LONG] != NULL &&
1069 Universe::_mirrors[T_SHORT] != NULL &&
1070 Universe::_mirrors[T_VOID] != NULL, "sanity");
1071
1072 Universe::set_int_mirror(Universe::_mirrors[T_INT]);
1073 Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]);
1074 Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]);
1075 Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]);
1117 return NULL;
1118 }
1119 }
1120
1121 // Now start archiving the mirror object
1122 oop archived_mirror = MetaspaceShared::archive_heap_object(mirror, THREAD);
1123 if (archived_mirror == NULL) {
1124 return NULL;
1125 }
1126
1127 archived_mirror = process_archived_mirror(k, mirror, archived_mirror, THREAD);
1128 if (archived_mirror == NULL) {
1129 return NULL;
1130 }
1131
1132 k->set_archived_java_mirror_raw(archived_mirror);
1133
1134 k->set_has_raw_archived_mirror();
1135
1136 ResourceMark rm;
1137 log_trace(cds, heap, mirror)(
1138 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1139 k->external_name(), p2i(mirror), p2i(archived_mirror));
1140
1141 return archived_mirror;
1142 }
1143
1144 // The process is based on create_mirror().
1145 oop java_lang_Class::process_archived_mirror(Klass* k, oop mirror,
1146 oop archived_mirror,
1147 Thread *THREAD) {
1148 // Clear nonstatic fields in archived mirror. Some of the fields will be set
1149 // to archived metadata and objects below.
1150 Klass *c = archived_mirror->klass();
1151 Handle archived_mirror_h(THREAD, archived_mirror);
1152 ResetMirrorField reset(archived_mirror_h);
1153 InstanceKlass::cast(c)->do_nonstatic_fields(&reset);
1154
1155 if (k->is_array_klass()) {
1156 oop archived_comp_mirror;
1157 if (k->is_typeArray_klass()) {
1158 // The primitive type mirrors are already archived. Get the archived mirror.
1171 java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1172 } else {
1173 assert(k->is_instance_klass(), "Must be");
1174
1175 // Reset local static fields in the mirror
1176 InstanceKlass::cast(k)->do_local_static_fields(&reset);
1177
1178 java_lang_Class:set_init_lock(archived_mirror, NULL);
1179
1180 set_protection_domain(archived_mirror, NULL);
1181 }
1182
1183 // clear class loader and mirror_module_field
1184 set_class_loader(archived_mirror, NULL);
1185 set_module(archived_mirror, NULL);
1186
1187 // The archived mirror's field at _klass_offset is still pointing to the original
1188 // klass. Updated the field in the archived mirror to point to the relocated
1189 // klass in the archive.
1190 Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror));
1191 log_debug(cds, heap, mirror)(
1192 "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1193 p2i(as_Klass(mirror)), p2i(reloc_k));
1194 archived_mirror->metadata_field_put(_klass_offset, reloc_k);
1195
1196 // The field at _array_klass_offset is pointing to the original one dimension
1197 // higher array klass if exists. Relocate the pointer.
1198 Klass *arr = array_klass_acquire(mirror);
1199 if (arr != NULL) {
1200 Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr);
1201 log_debug(cds, heap, mirror)(
1202 "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1203 p2i(arr), p2i(reloc_arr));
1204 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1205 }
1206 return archived_mirror;
1207 }
1208
1209 // Returns true if the mirror is updated, false if no archived mirror
1210 // data is present. After the archived mirror object is restored, the
1211 // shared klass' _has_raw_archived_mirror flag is cleared.
1212 bool java_lang_Class::restore_archived_mirror(Klass *k,
1213 Handle class_loader, Handle module,
1214 Handle protection_domain, TRAPS) {
1215 oop m = MetaspaceShared::materialize_archived_object(k->archived_java_mirror_raw());
1216
1217 if (m == NULL) {
1218 return false;
1219 }
1220
1221 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1222
1234 // create the init_lock
1235 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1236 set_init_lock(mirror(), r);
1237
1238 if (protection_domain.not_null()) {
1239 set_protection_domain(mirror(), protection_domain());
1240 }
1241 }
1242
1243 assert(class_loader() == k->class_loader(), "should be same");
1244 if (class_loader.not_null()) {
1245 set_class_loader(mirror(), class_loader());
1246 }
1247
1248 k->set_java_mirror(mirror);
1249 k->clear_has_raw_archived_mirror();
1250
1251 set_mirror_module_field(k, mirror, module, THREAD);
1252
1253 ResourceMark rm;
1254 log_trace(cds, heap, mirror)(
1255 "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1256
1257 return true;
1258 }
1259 #endif // INCLUDE_CDS_JAVA_HEAP
1260
1261 void java_lang_Class::fixup_module_field(Klass* k, Handle module) {
1262 assert(_module_offset != 0, "must have been computed already");
1263 java_lang_Class::set_module(k->java_mirror(), module());
1264 }
1265
1266 int java_lang_Class::oop_size(oop java_class) {
1267 assert(_oop_size_offset != 0, "must be set");
1268 int size = java_class->int_field(_oop_size_offset);
1269 assert(size > 0, "Oop size must be greater than zero, not %d", size);
1270 return size;
1271 }
1272
1273 void java_lang_Class::set_oop_size(oop java_class, int size) {
1274 assert(_oop_size_offset != 0, "must be set");
1275 assert(size > 0, "Oop size must be greater than zero, not %d", size);
4261 int java_lang_StackTraceElement::moduleVersion_offset;
4262 int java_lang_StackTraceElement::classLoaderName_offset;
4263 int java_lang_StackTraceElement::declaringClass_offset;
4264 int java_lang_StackTraceElement::declaringClassObject_offset;
4265 int java_lang_StackFrameInfo::_memberName_offset;
4266 int java_lang_StackFrameInfo::_bci_offset;
4267 int java_lang_StackFrameInfo::_version_offset;
4268 int java_lang_LiveStackFrameInfo::_monitors_offset;
4269 int java_lang_LiveStackFrameInfo::_locals_offset;
4270 int java_lang_LiveStackFrameInfo::_operands_offset;
4271 int java_lang_LiveStackFrameInfo::_mode_offset;
4272 int java_lang_AssertionStatusDirectives::classes_offset;
4273 int java_lang_AssertionStatusDirectives::classEnabled_offset;
4274 int java_lang_AssertionStatusDirectives::packages_offset;
4275 int java_lang_AssertionStatusDirectives::packageEnabled_offset;
4276 int java_lang_AssertionStatusDirectives::deflt_offset;
4277 int java_nio_Buffer::_limit_offset;
4278 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset;
4279 int reflect_ConstantPool::_oop_offset;
4280 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;
4281 int jdk_internal_module_ArchivedModuleGraph::_archivedSystemModules_offset;
4282 int jdk_internal_module_ArchivedModuleGraph::_archivedModuleFinder_offset;
4283 int jdk_internal_module_ArchivedModuleGraph::_archivedMainModule_offset;
4284
4285 #define STACKTRACEELEMENT_FIELDS_DO(macro) \
4286 macro(declaringClassObject_offset, k, "declaringClassObject", class_signature, false); \
4287 macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \
4288 macro(moduleName_offset, k, "moduleName", string_signature, false); \
4289 macro(moduleVersion_offset, k, "moduleVersion", string_signature, false); \
4290 macro(declaringClass_offset, k, "declaringClass", string_signature, false); \
4291 macro(methodName_offset, k, "methodName", string_signature, false); \
4292 macro(fileName_offset, k, "fileName", string_signature, false); \
4293 macro(lineNumber_offset, k, "lineNumber", int_signature, false)
4294
4295 // Support for java_lang_StackTraceElement
4296 void java_lang_StackTraceElement::compute_offsets() {
4297 InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
4298 STACKTRACEELEMENT_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4299 }
4300
4301 #if INCLUDE_CDS
4302 void java_lang_StackTraceElement::serialize(SerializeClosure* f) {
4303 STACKTRACEELEMENT_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4426 void java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets() {
4427 InstanceKlass* k = SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass();
4428 AOS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4429 }
4430
4431 oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) {
4432 assert(_owner_offset != 0, "Must be initialized");
4433 return obj->obj_field(_owner_offset);
4434 }
4435
4436 #if INCLUDE_CDS
4437 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize(SerializeClosure* f) {
4438 AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4439 }
4440 #endif
4441
4442 static int member_offset(int hardcoded_offset) {
4443 return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
4444 }
4445
4446 #define MODULEBOOTSTRAP_FIELDS_DO(macro) \
4447 macro(_archivedSystemModules_offset, k, "archivedSystemModules", systemModules_signature, true); \
4448 macro(_archivedModuleFinder_offset, k, "archivedModuleFinder", moduleFinder_signature, true); \
4449 macro(_archivedMainModule_offset, k, "archivedMainModule", string_signature, true)
4450
4451 void jdk_internal_module_ArchivedModuleGraph::compute_offsets() {
4452 InstanceKlass* k = SystemDictionary::ArchivedModuleGraph_klass();
4453 assert(k != NULL, "must be loaded");
4454 MODULEBOOTSTRAP_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4455 }
4456
4457 #if INCLUDE_CDS
4458 void jdk_internal_module_ArchivedModuleGraph::serialize(SerializeClosure* f) {
4459 MODULEBOOTSTRAP_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4460 }
4461 #endif
4462
4463 // Compute hard-coded offsets
4464 // Invoked before SystemDictionary::initialize, so pre-loaded classes
4465 // are not available to determine the offset_of_static_fields.
4466 void JavaClasses::compute_hard_coded_offsets() {
4467
4468 // java_lang_boxing_object
4469 java_lang_boxing_object::value_offset = member_offset(java_lang_boxing_object::hc_value_offset);
4470 java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong);
4471
4472 // java_lang_ref_Reference
4473 java_lang_ref_Reference::referent_offset = member_offset(java_lang_ref_Reference::hc_referent_offset);
4474 java_lang_ref_Reference::queue_offset = member_offset(java_lang_ref_Reference::hc_queue_offset);
4475 java_lang_ref_Reference::next_offset = member_offset(java_lang_ref_Reference::hc_next_offset);
4476 java_lang_ref_Reference::discovered_offset = member_offset(java_lang_ref_Reference::hc_discovered_offset);
4477 }
4478
4479
4480 // Compute non-hard-coded field offsets of all the classes in this file
4481 void JavaClasses::compute_offsets() {
4482 if (UseSharedSpaces) {
4500 java_lang_invoke_CallSite::compute_offsets();
4501 java_lang_invoke_MethodHandleNatives_CallSiteContext::compute_offsets();
4502 java_security_AccessControlContext::compute_offsets();
4503 // Initialize reflection classes. The layouts of these classes
4504 // changed with the new reflection implementation in JDK 1.4, and
4505 // since the Universe doesn't know what JDK version it is until this
4506 // point we defer computation of these offsets until now.
4507 java_lang_reflect_AccessibleObject::compute_offsets();
4508 java_lang_reflect_Method::compute_offsets();
4509 java_lang_reflect_Constructor::compute_offsets();
4510 java_lang_reflect_Field::compute_offsets();
4511 java_nio_Buffer::compute_offsets();
4512 reflect_ConstantPool::compute_offsets();
4513 reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
4514 java_lang_reflect_Parameter::compute_offsets();
4515 java_lang_Module::compute_offsets();
4516 java_lang_StackTraceElement::compute_offsets();
4517 java_lang_StackFrameInfo::compute_offsets();
4518 java_lang_LiveStackFrameInfo::compute_offsets();
4519 java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets();
4520
4521 jdk_internal_module_ArchivedModuleGraph::compute_offsets();
4522
4523 // generated interpreter code wants to know about the offsets we just computed:
4524 AbstractAssembler::update_delayed_values();
4525 }
4526
4527 #ifndef PRODUCT
4528
4529 // These functions exist to assert the validity of hard-coded field offsets to guard
4530 // against changes in the class files
4531
4532 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
4533 EXCEPTION_MARK;
4534 fieldDescriptor fd;
4535 TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
4536 Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
4537 InstanceKlass* ik = InstanceKlass::cast(k);
4538 TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
4539 TempNewSymbol f_sig = SymbolTable::new_symbol(field_sig, CATCH);
4540 if (!ik->find_local_field(f_name, f_sig, &fd)) {
4541 tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
|