1075 oop archived_m = HeapShared::archive_heap_object(m, THREAD); |
1075 oop archived_m = HeapShared::archive_heap_object(m, THREAD); |
1076 assert(archived_m != NULL, "sanity"); |
1076 assert(archived_m != NULL, "sanity"); |
1077 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset)); |
1077 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset)); |
1078 assert(ak != NULL || t == T_VOID, "should not be NULL"); |
1078 assert(ak != NULL || t == T_VOID, "should not be NULL"); |
1079 if (ak != NULL) { |
1079 if (ak != NULL) { |
1080 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak); |
1080 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak, true); |
1081 archived_m->metadata_field_put(_array_klass_offset, reloc_ak); |
1081 archived_m->metadata_field_put(_array_klass_offset, reloc_ak); |
1082 } |
1082 } |
1083 |
1083 |
1084 // Clear the fields. Just to be safe |
1084 // Clear the fields. Just to be safe |
1085 Klass *k = m->klass(); |
1085 Klass *k = m->klass(); |
1220 set_module(archived_mirror, NULL); |
1220 set_module(archived_mirror, NULL); |
1221 |
1221 |
1222 // The archived mirror's field at _klass_offset is still pointing to the original |
1222 // The archived mirror's field at _klass_offset is still pointing to the original |
1223 // klass. Updated the field in the archived mirror to point to the relocated |
1223 // klass. Updated the field in the archived mirror to point to the relocated |
1224 // klass in the archive. |
1224 // klass in the archive. |
1225 Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror)); |
1225 Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror), true); |
1226 log_debug(cds, heap, mirror)( |
1226 log_debug(cds, heap, mirror)( |
1227 "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, |
1227 "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, |
1228 p2i(as_Klass(mirror)), p2i(reloc_k)); |
1228 p2i(as_Klass(mirror)), p2i(reloc_k)); |
1229 archived_mirror->metadata_field_put(_klass_offset, reloc_k); |
1229 archived_mirror->metadata_field_put(_klass_offset, reloc_k); |
1230 |
1230 |
1231 // The field at _array_klass_offset is pointing to the original one dimension |
1231 // The field at _array_klass_offset is pointing to the original one dimension |
1232 // higher array klass if exists. Relocate the pointer. |
1232 // higher array klass if exists. Relocate the pointer. |
1233 Klass *arr = array_klass_acquire(mirror); |
1233 Klass *arr = array_klass_acquire(mirror); |
1234 if (arr != NULL) { |
1234 if (arr != NULL) { |
1235 Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr); |
1235 Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr, true); |
1236 log_debug(cds, heap, mirror)( |
1236 log_debug(cds, heap, mirror)( |
1237 "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, |
1237 "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, |
1238 p2i(arr), p2i(reloc_arr)); |
1238 p2i(arr), p2i(reloc_arr)); |
1239 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr); |
1239 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr); |
1240 } |
1240 } |
1241 return archived_mirror; |
1241 return archived_mirror; |
1242 } |
1242 } |
|
1243 |
|
1244 void java_lang_Class::update_archived_primitive_mirror_native_pointers(oop archived_mirror) { |
|
1245 if (MetaspaceShared::relocation_delta() != 0) { |
|
1246 assert(archived_mirror->metadata_field(_klass_offset) == NULL, "must be for primitive class"); |
|
1247 |
|
1248 Klass* ak = ((Klass*)archived_mirror->metadata_field(_array_klass_offset)); |
|
1249 if (ak != NULL) { |
|
1250 archived_mirror->metadata_field_put(_array_klass_offset, |
|
1251 (Klass*)(address(ak) + MetaspaceShared::relocation_delta())); |
|
1252 } |
|
1253 } |
|
1254 } |
|
1255 |
|
1256 void java_lang_Class::update_archived_mirror_native_pointers(oop archived_mirror) { |
|
1257 if (MetaspaceShared::relocation_delta() != 0) { |
|
1258 Klass* k = ((Klass*)archived_mirror->metadata_field(_klass_offset)); |
|
1259 archived_mirror->metadata_field_put(_klass_offset, |
|
1260 (Klass*)(address(k) + MetaspaceShared::relocation_delta())); |
|
1261 |
|
1262 Klass* ak = ((Klass*)archived_mirror->metadata_field(_array_klass_offset)); |
|
1263 if (ak != NULL) { |
|
1264 archived_mirror->metadata_field_put(_array_klass_offset, |
|
1265 (Klass*)(address(ak) + MetaspaceShared::relocation_delta())); |
|
1266 } |
|
1267 } |
|
1268 } |
|
1269 |
1243 |
1270 |
1244 // Returns true if the mirror is updated, false if no archived mirror |
1271 // Returns true if the mirror is updated, false if no archived mirror |
1245 // data is present. After the archived mirror object is restored, the |
1272 // data is present. After the archived mirror object is restored, the |
1246 // shared klass' _has_raw_archived_mirror flag is cleared. |
1273 // shared klass' _has_raw_archived_mirror flag is cleared. |
1247 bool java_lang_Class::restore_archived_mirror(Klass *k, |
1274 bool java_lang_Class::restore_archived_mirror(Klass *k, |
1254 fixup_mirror_list()->push(k); |
1281 fixup_mirror_list()->push(k); |
1255 return true; |
1282 return true; |
1256 } |
1283 } |
1257 |
1284 |
1258 oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow()); |
1285 oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow()); |
1259 |
|
1260 if (m == NULL) { |
1286 if (m == NULL) { |
1261 return false; |
1287 return false; |
1262 } |
1288 } |
1263 |
1289 |
|
1290 // mirror is archived, restore |
1264 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m)); |
1291 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m)); |
1265 |
|
1266 // mirror is archived, restore |
|
1267 assert(HeapShared::is_archived_object(m), "must be archived mirror object"); |
1292 assert(HeapShared::is_archived_object(m), "must be archived mirror object"); |
|
1293 update_archived_mirror_native_pointers(m); |
|
1294 assert(as_Klass(m) == k, "must be"); |
1268 Handle mirror(THREAD, m); |
1295 Handle mirror(THREAD, m); |
1269 |
1296 |
1270 if (!k->is_array_klass()) { |
1297 if (!k->is_array_klass()) { |
1271 // - local static final fields with initial values were initialized at dump time |
1298 // - local static final fields with initial values were initialized at dump time |
1272 |
1299 |
4647 void JavaClasses::serialize_offsets(SerializeClosure* soc) { |
4674 void JavaClasses::serialize_offsets(SerializeClosure* soc) { |
4648 BASIC_JAVA_CLASSES_DO(DO_SERIALIZE_OFFSETS); |
4675 BASIC_JAVA_CLASSES_DO(DO_SERIALIZE_OFFSETS); |
4649 } |
4676 } |
4650 #endif |
4677 #endif |
4651 |
4678 |
|
4679 #if INCLUDE_CDS_JAVA_HEAP |
|
4680 bool JavaClasses::is_supported_for_archiving(oop obj) { |
|
4681 Klass* klass = obj->klass(); |
|
4682 |
|
4683 if (klass == SystemDictionary::ClassLoader_klass() || // ClassLoader::loader_data is malloc'ed. |
|
4684 klass == SystemDictionary::Module_klass() || // Module::module_entry is malloc'ed |
|
4685 // The next 3 classes are used to implement java.lang.invoke, and are not used directly in |
|
4686 // regular Java code. The implementation of java.lang.invoke uses generated anonymoys classes |
|
4687 // (e.g., as referenced by ResolvedMethodName::vmholder) that are not yet supported by CDS. |
|
4688 // So for now we cannot not support these classes for archiving. |
|
4689 // |
|
4690 // These objects typically are not referenced by static fields, but rather by resolved |
|
4691 // constant pool entries, so excluding them shouldn't affect the archiving of static fields. |
|
4692 klass == SystemDictionary::ResolvedMethodName_klass() || |
|
4693 klass == SystemDictionary::MemberName_klass() || |
|
4694 klass == SystemDictionary::Context_klass()) { |
|
4695 return false; |
|
4696 } |
|
4697 |
|
4698 return true; |
|
4699 } |
|
4700 #endif |
4652 |
4701 |
4653 #ifndef PRODUCT |
4702 #ifndef PRODUCT |
4654 |
4703 |
4655 // These functions exist to assert the validity of hard-coded field offsets to guard |
4704 // These functions exist to assert the validity of hard-coded field offsets to guard |
4656 // against changes in the class files |
4705 // against changes in the class files |