< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page


1190       return false; // Do not recurse.
1191     }
1192   };
1193 
1194 #ifdef ASSERT
1195   class IsRefInArchiveChecker: public MetaspaceClosure {
1196   public:
1197     virtual bool do_ref(Ref* ref, bool read_only) {
1198       if (ref->not_null()) {
1199         char* obj = (char*)ref->obj();
1200         assert(_ro_region.contains(obj) || _rw_region.contains(obj),
1201                "must be relocated to point to CDS archive");
1202       }
1203       return false; // Do not recurse.
1204     }
1205   };
1206 #endif
1207 
1208 public:
1209   static void copy_and_compact() {
1210     // We should no longer allocate anything from the metaspace, so that
1211     // we can have a stable set of MetaspaceObjs to work with.
1212     Metaspace::freeze();
1213 
1214     ResourceMark rm;
1215     SortedSymbolClosure the_ssc; // StackObj
1216     _ssc = &the_ssc;
1217 
1218     tty->print_cr("Scanning all metaspace objects ... ");
1219     {
1220       // allocate and shallow-copy RW objects, immediately following the MC region
1221       tty->print_cr("Allocating RW objects ... ");
1222       _mc_region.pack(&_rw_region);
1223 
1224       ResourceMark rm;
1225       ShallowCopier rw_copier(false);
1226       iterate_roots(&rw_copier);
1227     }
1228     {
1229       // allocate and shallow-copy of RO object, immediately following the RW region
1230       tty->print_cr("Allocating RO objects ... ");
1231       _rw_region.pack(&_ro_region);
1232 
1233       ResourceMark rm;


1340 
1341   size_t buckets_bytes = SystemDictionary::count_bytes_for_buckets();
1342   char* buckets_top = _ro_region.allocate(buckets_bytes, sizeof(intptr_t));
1343   SystemDictionary::copy_buckets(buckets_top, _ro_region.top());
1344 
1345   size_t table_bytes = SystemDictionary::count_bytes_for_table();
1346   char* table_top = _ro_region.allocate(table_bytes, sizeof(intptr_t));
1347   SystemDictionary::copy_table(table_top, _ro_region.top());
1348 
1349   // Write the other data to the output array.
1350   WriteClosure wc(&_ro_region);
1351   MetaspaceShared::serialize(&wc);
1352 
1353   // Write the bitmaps for patching the archive heap regions
1354   dump_archive_heap_oopmaps();
1355 
1356   return buckets_top;
1357 }
1358 
1359 void VM_PopulateDumpSharedSpace::doit() {








1360   Thread* THREAD = VMThread::vm_thread();
1361 
1362   FileMapInfo::check_nonempty_dir_in_shared_path_table();
1363 
1364   NOT_PRODUCT(SystemDictionary::verify();)
1365   // The following guarantee is meant to ensure that no loader constraints
1366   // exist yet, since the constraints table is not shared.  This becomes
1367   // more important now that we don't re-initialize vtables/itables for
1368   // shared classes at runtime, where constraints were previously created.
1369   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1370             "loader constraints are not saved");
1371   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1372           "placeholders are not saved");
1373   // Revisit and implement this if we prelink method handle call sites:
1374   guarantee(SystemDictionary::invoke_method_table() == NULL ||
1375             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
1376             "invoke method table is not saved");
1377 
1378   // At this point, many classes have been loaded.
1379   // Gather systemDictionary classes in a global array and do everything to


1403 
1404   // Ensure the ConstMethods won't be modified at run-time
1405   tty->print("Updating ConstMethods ... ");
1406   rewrite_nofast_bytecodes_and_calculate_fingerprints();
1407   tty->print_cr("done. ");
1408 
1409   // Move classes from platform/system dictionaries into the boot dictionary
1410   SystemDictionary::combine_shared_dictionaries();
1411 
1412   // Make sure all classes have a correct loader type.
1413   ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
1414 
1415   // Remove all references outside the metadata
1416   tty->print("Removing unshareable information ... ");
1417   remove_unshareable_in_classes();
1418   tty->print_cr("done. ");
1419 
1420   // We don't support archiving unsafe anonymous classes. Verify that they are not stored in
1421   // any dictionaries.
1422   NOT_PRODUCT(assert_no_unsafe_anonymous_classes_in_dictionaries());
1423 
1424   SystemDictionaryShared::finalize_verification_constraints();
1425 
1426   ArchiveCompactor::initialize();
1427   ArchiveCompactor::copy_and_compact();
1428 
1429   dump_symbols();
1430 
1431   // Dump supported java heap objects
1432   _closed_archive_heap_regions = NULL;
1433   _open_archive_heap_regions = NULL;
1434   dump_java_heap_objects();
1435 
1436   ArchiveCompactor::relocate_well_known_klasses();
1437 
1438   char* read_only_tables_start = dump_read_only_tables();
1439   _ro_region.pack(&_md_region);
1440 
1441   char* vtbl_list = _md_region.top();
1442   MetaspaceShared::allocate_cpp_vtable_clones();
1443   _md_region.pack(&_od_region);
1444 




1190       return false; // Do not recurse.
1191     }
1192   };
1193 
1194 #ifdef ASSERT
1195   class IsRefInArchiveChecker: public MetaspaceClosure {
1196   public:
1197     virtual bool do_ref(Ref* ref, bool read_only) {
1198       if (ref->not_null()) {
1199         char* obj = (char*)ref->obj();
1200         assert(_ro_region.contains(obj) || _rw_region.contains(obj),
1201                "must be relocated to point to CDS archive");
1202       }
1203       return false; // Do not recurse.
1204     }
1205   };
1206 #endif
1207 
1208 public:
1209   static void copy_and_compact() {




1210     ResourceMark rm;
1211     SortedSymbolClosure the_ssc; // StackObj
1212     _ssc = &the_ssc;
1213 
1214     tty->print_cr("Scanning all metaspace objects ... ");
1215     {
1216       // allocate and shallow-copy RW objects, immediately following the MC region
1217       tty->print_cr("Allocating RW objects ... ");
1218       _mc_region.pack(&_rw_region);
1219 
1220       ResourceMark rm;
1221       ShallowCopier rw_copier(false);
1222       iterate_roots(&rw_copier);
1223     }
1224     {
1225       // allocate and shallow-copy of RO object, immediately following the RW region
1226       tty->print_cr("Allocating RO objects ... ");
1227       _rw_region.pack(&_ro_region);
1228 
1229       ResourceMark rm;


1336 
1337   size_t buckets_bytes = SystemDictionary::count_bytes_for_buckets();
1338   char* buckets_top = _ro_region.allocate(buckets_bytes, sizeof(intptr_t));
1339   SystemDictionary::copy_buckets(buckets_top, _ro_region.top());
1340 
1341   size_t table_bytes = SystemDictionary::count_bytes_for_table();
1342   char* table_top = _ro_region.allocate(table_bytes, sizeof(intptr_t));
1343   SystemDictionary::copy_table(table_top, _ro_region.top());
1344 
1345   // Write the other data to the output array.
1346   WriteClosure wc(&_ro_region);
1347   MetaspaceShared::serialize(&wc);
1348 
1349   // Write the bitmaps for patching the archive heap regions
1350   dump_archive_heap_oopmaps();
1351 
1352   return buckets_top;
1353 }
1354 
1355 void VM_PopulateDumpSharedSpace::doit() {
1356   // We should no longer allocate anything from the metaspace, so that:
1357   //
1358   // (1) Metaspace::allocate might trigger GC if we have run out of
1359   //     committed metaspace, but we can't GC because we're running
1360   //     in the VM thread.
1361   // (2) ArchiveCompactor needs to work with a stable set of MetaspaceObjs.
1362   Metaspace::freeze();
1363 
1364   Thread* THREAD = VMThread::vm_thread();
1365 
1366   FileMapInfo::check_nonempty_dir_in_shared_path_table();
1367 
1368   NOT_PRODUCT(SystemDictionary::verify();)
1369   // The following guarantee is meant to ensure that no loader constraints
1370   // exist yet, since the constraints table is not shared.  This becomes
1371   // more important now that we don't re-initialize vtables/itables for
1372   // shared classes at runtime, where constraints were previously created.
1373   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1374             "loader constraints are not saved");
1375   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1376           "placeholders are not saved");
1377   // Revisit and implement this if we prelink method handle call sites:
1378   guarantee(SystemDictionary::invoke_method_table() == NULL ||
1379             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
1380             "invoke method table is not saved");
1381 
1382   // At this point, many classes have been loaded.
1383   // Gather systemDictionary classes in a global array and do everything to


1407 
1408   // Ensure the ConstMethods won't be modified at run-time
1409   tty->print("Updating ConstMethods ... ");
1410   rewrite_nofast_bytecodes_and_calculate_fingerprints();
1411   tty->print_cr("done. ");
1412 
1413   // Move classes from platform/system dictionaries into the boot dictionary
1414   SystemDictionary::combine_shared_dictionaries();
1415 
1416   // Make sure all classes have a correct loader type.
1417   ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
1418 
1419   // Remove all references outside the metadata
1420   tty->print("Removing unshareable information ... ");
1421   remove_unshareable_in_classes();
1422   tty->print_cr("done. ");
1423 
1424   // We don't support archiving unsafe anonymous classes. Verify that they are not stored in
1425   // any dictionaries.
1426   NOT_PRODUCT(assert_no_unsafe_anonymous_classes_in_dictionaries());


1427 
1428   ArchiveCompactor::initialize();
1429   ArchiveCompactor::copy_and_compact();
1430 
1431   dump_symbols();
1432 
1433   // Dump supported java heap objects
1434   _closed_archive_heap_regions = NULL;
1435   _open_archive_heap_regions = NULL;
1436   dump_java_heap_objects();
1437 
1438   ArchiveCompactor::relocate_well_known_klasses();
1439 
1440   char* read_only_tables_start = dump_read_only_tables();
1441   _ro_region.pack(&_md_region);
1442 
1443   char* vtbl_list = _md_region.top();
1444   MetaspaceShared::allocate_cpp_vtable_clones();
1445   _md_region.pack(&_od_region);
1446 


< prev index next >