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 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 1445 // Relocate the archived class file data into the od region 1699 int class_count = preload_classes(class_list_path, THREAD); 1700 if (ExtraSharedClassListFile) { 1701 class_count += preload_classes(ExtraSharedClassListFile, THREAD); 1702 } 1703 tty->print_cr("Loading classes to share: done."); 1704 1705 log_info(cds)("Shared spaces: preloaded %d classes", class_count); 1706 1707 // Rewrite and link classes 1708 tty->print_cr("Rewriting and linking classes ..."); 1709 1710 // Link any classes which got missed. This would happen if we have loaded classes that 1711 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K 1712 // fails verification, all other interfaces that were not specified in the classlist but 1713 // are implemented by K are not verified. 1714 link_and_cleanup_shared_classes(CATCH); 1715 tty->print_cr("Rewriting and linking classes: done"); 1716 1717 SystemDictionary::clear_invoke_method_table(); 1718 HeapShared::init_archivable_static_fields(THREAD); 1719 1720 VM_PopulateDumpSharedSpace op; 1721 VMThread::execute(&op); 1722 } 1723 } 1724 1725 1726 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) { 1727 ClassListParser parser(class_list_path); 1728 int class_count = 0; 1729 1730 while (parser.parse_one_line()) { 1731 Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD); 1732 if (HAS_PENDING_EXCEPTION) { 1733 if (klass == NULL && 1734 (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) { 1735 // print a warning only when the pending exception is class not found 1736 tty->print_cr("Preload Warning: Cannot find %s", parser.current_class_name()); 1737 } 1738 CLEAR_PENDING_EXCEPTION; | 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 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 1447 // Relocate the archived class file data into the od region 1701 int class_count = preload_classes(class_list_path, THREAD); 1702 if (ExtraSharedClassListFile) { 1703 class_count += preload_classes(ExtraSharedClassListFile, THREAD); 1704 } 1705 tty->print_cr("Loading classes to share: done."); 1706 1707 log_info(cds)("Shared spaces: preloaded %d classes", class_count); 1708 1709 // Rewrite and link classes 1710 tty->print_cr("Rewriting and linking classes ..."); 1711 1712 // Link any classes which got missed. This would happen if we have loaded classes that 1713 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K 1714 // fails verification, all other interfaces that were not specified in the classlist but 1715 // are implemented by K are not verified. 1716 link_and_cleanup_shared_classes(CATCH); 1717 tty->print_cr("Rewriting and linking classes: done"); 1718 1719 SystemDictionary::clear_invoke_method_table(); 1720 HeapShared::init_archivable_static_fields(THREAD); 1721 1722 SystemDictionaryShared::finalize_verification_constraints(); 1723 1724 VM_PopulateDumpSharedSpace op; 1725 VMThread::execute(&op); 1726 } 1727 } 1728 1729 1730 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) { 1731 ClassListParser parser(class_list_path); 1732 int class_count = 0; 1733 1734 while (parser.parse_one_line()) { 1735 Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD); 1736 if (HAS_PENDING_EXCEPTION) { 1737 if (klass == NULL && 1738 (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) { 1739 // print a warning only when the pending exception is class not found 1740 tty->print_cr("Preload Warning: Cannot find %s", parser.current_class_name()); 1741 } 1742 CLEAR_PENDING_EXCEPTION; |