< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page


1034       default:
1035         ShouldNotReachHere();
1036         break;
1037      }
1038   }
1039 };
1040 
1041 void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
1042   assert(HeapShared::is_heap_object_archiving_allowed(),
1043          "HeapShared::is_heap_object_archiving_allowed() must be true");
1044 
1045   for (int t = 0; t <= T_VOID; t++) {
1046     oop m = Universe::_mirrors[t];
1047     if (m != NULL) {
1048       // Update the field at _array_klass_offset to point to the relocated array klass.
1049       oop archived_m = HeapShared::archive_heap_object(m, THREAD);
1050       assert(archived_m != NULL, "sanity");
1051       Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1052       assert(ak != NULL || t == T_VOID, "should not be NULL");
1053       if (ak != NULL) {
1054         Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak);
1055         archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1056       }
1057 
1058       // Clear the fields. Just to be safe
1059       Klass *k = m->klass();
1060       Handle archived_mirror_h(THREAD, archived_m);
1061       ResetMirrorField reset(archived_mirror_h);
1062       InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1063 
1064       log_trace(cds, heap, mirror)(
1065         "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1066         type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1067 
1068       Universe::_mirrors[t] = archived_m;
1069     }
1070   }
1071 
1072   assert(Universe::_mirrors[T_INT] != NULL &&
1073          Universe::_mirrors[T_FLOAT] != NULL &&
1074          Universe::_mirrors[T_DOUBLE] != NULL &&


1179     }
1180     java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1181   } else {
1182     assert(k->is_instance_klass(), "Must be");
1183 
1184     // Reset local static fields in the mirror
1185     InstanceKlass::cast(k)->do_local_static_fields(&reset);
1186 
1187     java_lang_Class:set_init_lock(archived_mirror, NULL);
1188 
1189     set_protection_domain(archived_mirror, NULL);
1190   }
1191 
1192   // clear class loader and mirror_module_field
1193   set_class_loader(archived_mirror, NULL);
1194   set_module(archived_mirror, NULL);
1195 
1196   // The archived mirror's field at _klass_offset is still pointing to the original
1197   // klass. Updated the field in the archived mirror to point to the relocated
1198   // klass in the archive.
1199   Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror));
1200   log_debug(cds, heap, mirror)(
1201     "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1202     p2i(as_Klass(mirror)), p2i(reloc_k));
1203   archived_mirror->metadata_field_put(_klass_offset, reloc_k);
1204 
1205   // The field at _array_klass_offset is pointing to the original one dimension
1206   // higher array klass if exists. Relocate the pointer.
1207   Klass *arr = array_klass_acquire(mirror);
1208   if (arr != NULL) {
1209     Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr);
1210     log_debug(cds, heap, mirror)(
1211       "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1212       p2i(arr), p2i(reloc_arr));
1213     archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1214   }
1215   return archived_mirror;
1216 }
1217 













1218 // Returns true if the mirror is updated, false if no archived mirror
1219 // data is present. After the archived mirror object is restored, the
1220 // shared klass' _has_raw_archived_mirror flag is cleared.
1221 bool java_lang_Class::restore_archived_mirror(Klass *k,
1222                                               Handle class_loader, Handle module,
1223                                               Handle protection_domain, TRAPS) {
1224   // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1225   // see more details in SystemDictionary::resolve_well_known_classes().
1226   if (!SystemDictionary::Class_klass_loaded()) {
1227     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1228     fixup_mirror_list()->push(k);
1229     return true;
1230   }
1231 
1232   oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow());
1233 
1234   if (m == NULL) {
1235     return false;
1236   }
1237 
1238   log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));

1239 
1240   // mirror is archived, restore
1241   assert(HeapShared::is_archived_object(m), "must be archived mirror object");
1242   Handle mirror(THREAD, m);
1243 
1244   if (!k->is_array_klass()) {
1245     // - local static final fields with initial values were initialized at dump time
1246 
1247     // create the init_lock
1248     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1249     set_init_lock(mirror(), r);
1250 
1251     if (protection_domain.not_null()) {
1252       set_protection_domain(mirror(), protection_domain());
1253     }
1254   }
1255 
1256   assert(class_loader() == k->class_loader(), "should be same");
1257   if (class_loader.not_null()) {
1258     set_class_loader(mirror(), class_loader());




1034       default:
1035         ShouldNotReachHere();
1036         break;
1037      }
1038   }
1039 };
1040 
1041 void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
1042   assert(HeapShared::is_heap_object_archiving_allowed(),
1043          "HeapShared::is_heap_object_archiving_allowed() must be true");
1044 
1045   for (int t = 0; t <= T_VOID; t++) {
1046     oop m = Universe::_mirrors[t];
1047     if (m != NULL) {
1048       // Update the field at _array_klass_offset to point to the relocated array klass.
1049       oop archived_m = HeapShared::archive_heap_object(m, THREAD);
1050       assert(archived_m != NULL, "sanity");
1051       Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1052       assert(ak != NULL || t == T_VOID, "should not be NULL");
1053       if (ak != NULL) {
1054         Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak, true);
1055         archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1056       }
1057 
1058       // Clear the fields. Just to be safe
1059       Klass *k = m->klass();
1060       Handle archived_mirror_h(THREAD, archived_m);
1061       ResetMirrorField reset(archived_mirror_h);
1062       InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1063 
1064       log_trace(cds, heap, mirror)(
1065         "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1066         type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1067 
1068       Universe::_mirrors[t] = archived_m;
1069     }
1070   }
1071 
1072   assert(Universe::_mirrors[T_INT] != NULL &&
1073          Universe::_mirrors[T_FLOAT] != NULL &&
1074          Universe::_mirrors[T_DOUBLE] != NULL &&


1179     }
1180     java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1181   } else {
1182     assert(k->is_instance_klass(), "Must be");
1183 
1184     // Reset local static fields in the mirror
1185     InstanceKlass::cast(k)->do_local_static_fields(&reset);
1186 
1187     java_lang_Class:set_init_lock(archived_mirror, NULL);
1188 
1189     set_protection_domain(archived_mirror, NULL);
1190   }
1191 
1192   // clear class loader and mirror_module_field
1193   set_class_loader(archived_mirror, NULL);
1194   set_module(archived_mirror, NULL);
1195 
1196   // The archived mirror's field at _klass_offset is still pointing to the original
1197   // klass. Updated the field in the archived mirror to point to the relocated
1198   // klass in the archive.
1199   Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror), true);
1200   log_debug(cds, heap, mirror)(
1201     "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1202     p2i(as_Klass(mirror)), p2i(reloc_k));
1203   archived_mirror->metadata_field_put(_klass_offset, reloc_k);
1204 
1205   // The field at _array_klass_offset is pointing to the original one dimension
1206   // higher array klass if exists. Relocate the pointer.
1207   Klass *arr = array_klass_acquire(mirror);
1208   if (arr != NULL) {
1209     Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr, true);
1210     log_debug(cds, heap, mirror)(
1211       "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT,
1212       p2i(arr), p2i(reloc_arr));
1213     archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1214   }
1215   return archived_mirror;
1216 }
1217 
1218 void java_lang_Class::update_archived_mirror_native_pointers(oop archived_mirror) {
1219   Klass* k = ((Klass*)archived_mirror->metadata_field(_klass_offset));
1220   if (k != NULL) { // k is NULL for the primitive classes such as java.lang.Byte::TYPE
1221     archived_mirror->metadata_field_put(_klass_offset, (Klass*)(address(k) + MetaspaceShared::mapping_delta()));
1222   }
1223 
1224   Klass* ak = ((Klass*)archived_mirror->metadata_field(_array_klass_offset));
1225   if (ak != NULL) {
1226     archived_mirror->metadata_field_put(_array_klass_offset, (Klass*)(address(ak) + MetaspaceShared::mapping_delta()));
1227   }
1228 }
1229 
1230 
1231 // Returns true if the mirror is updated, false if no archived mirror
1232 // data is present. After the archived mirror object is restored, the
1233 // shared klass' _has_raw_archived_mirror flag is cleared.
1234 bool java_lang_Class::restore_archived_mirror(Klass *k,
1235                                               Handle class_loader, Handle module,
1236                                               Handle protection_domain, TRAPS) {
1237   // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1238   // see more details in SystemDictionary::resolve_well_known_classes().
1239   if (!SystemDictionary::Class_klass_loaded()) {
1240     assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1241     fixup_mirror_list()->push(k);
1242     return true;
1243   }
1244 
1245   oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow());
1246 
1247   if (m == NULL) {
1248     return false;
1249   }
1250 
1251   log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1252   update_archived_mirror_native_pointers(m);
1253 
1254   // mirror is archived, restore
1255   assert(HeapShared::is_archived_object(m), "must be archived mirror object");
1256   Handle mirror(THREAD, m);
1257 
1258   if (!k->is_array_klass()) {
1259     // - local static final fields with initial values were initialized at dump time
1260 
1261     // create the init_lock
1262     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1263     set_init_lock(mirror(), r);
1264 
1265     if (protection_domain.not_null()) {
1266       set_protection_domain(mirror(), protection_domain());
1267     }
1268   }
1269 
1270   assert(class_loader() == k->class_loader(), "should be same");
1271   if (class_loader.not_null()) {
1272     set_class_loader(mirror(), class_loader());


< prev index next >