66 VirtualSpace MetaspaceShared::_shared_vs; |
71 VirtualSpace MetaspaceShared::_shared_vs; |
67 MetaspaceSharedStats MetaspaceShared::_stats; |
72 MetaspaceSharedStats MetaspaceShared::_stats; |
68 bool MetaspaceShared::_has_error_classes; |
73 bool MetaspaceShared::_has_error_classes; |
69 bool MetaspaceShared::_archive_loading_failed = false; |
74 bool MetaspaceShared::_archive_loading_failed = false; |
70 bool MetaspaceShared::_remapped_readwrite = false; |
75 bool MetaspaceShared::_remapped_readwrite = false; |
|
76 bool MetaspaceShared::_open_archive_heap_region_mapped = false; |
71 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL; |
77 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL; |
72 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0; |
78 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0; |
73 size_t MetaspaceShared::_core_spaces_size = 0; |
79 size_t MetaspaceShared::_core_spaces_size = 0; |
74 |
80 |
75 // The CDS archive is divided into the following regions: |
81 // The CDS archive is divided into the following regions: |
76 // mc - misc code (the method entry trampolines) |
82 // mc - misc code (the method entry trampolines) |
77 // rw - read-write metadata |
83 // rw - read-write metadata |
78 // ro - read-only metadata and read-only tables |
84 // ro - read-only metadata and read-only tables |
79 // md - misc data (the c++ vtables) |
85 // md - misc data (the c++ vtables) |
80 // od - optional data (original class files) |
86 // od - optional data (original class files) |
81 // |
87 // |
82 // s0 - shared strings #0 |
88 // s0 - shared strings(closed archive heap space) #0 |
83 // s1 - shared strings #1 (may be empty) |
89 // s1 - shared strings(closed archive heap space) #1 (may be empty) |
|
90 // oa0 - open archive heap space #0 |
|
91 // oa1 - open archive heap space #1 (may be empty) |
84 // |
92 // |
85 // Except for the s0/s1 regions, the other 5 regions are linearly allocated, starting from |
93 // The mc, rw, ro, md and od regions are linearly allocated, starting from |
86 // SharedBaseAddress, in the order of mc->rw->ro->md->od. The size of these 5 regions |
94 // SharedBaseAddress, in the order of mc->rw->ro->md->od. The size of these 5 regions |
87 // are page-aligned, and there's no gap between any consecutive regions. |
95 // are page-aligned, and there's no gap between any consecutive regions. |
88 // |
96 // |
89 // These 5 regions are populated in the following steps: |
97 // These 5 regions are populated in the following steps: |
90 // [1] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are |
98 // [1] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are |
854 // Populate the shared space. |
863 // Populate the shared space. |
855 |
864 |
856 class VM_PopulateDumpSharedSpace: public VM_Operation { |
865 class VM_PopulateDumpSharedSpace: public VM_Operation { |
857 private: |
866 private: |
858 GrowableArray<MemRegion> *_string_regions; |
867 GrowableArray<MemRegion> *_string_regions; |
859 |
868 GrowableArray<MemRegion> *_open_archive_heap_regions; |
860 void dump_string_and_symbols(); |
869 |
|
870 void dump_java_heap_objects() NOT_CDS_JAVA_HEAP_RETURN; |
|
871 void dump_symbols(); |
861 char* dump_read_only_tables(); |
872 char* dump_read_only_tables(); |
862 void print_region_stats(); |
873 void print_region_stats(); |
|
874 void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem, |
|
875 const char *name, const size_t total_size); |
863 public: |
876 public: |
864 |
877 |
865 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } |
878 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } |
866 void doit(); // outline because gdb sucks |
879 void doit(); // outline because gdb sucks |
867 static void write_region(FileMapInfo* mapinfo, int region, DumpRegion* space, bool read_only, bool allow_exec); |
880 static void write_region(FileMapInfo* mapinfo, int region, DumpRegion* space, bool read_only, bool allow_exec); |
1125 void VM_PopulateDumpSharedSpace::write_region(FileMapInfo* mapinfo, int region_idx, |
1137 void VM_PopulateDumpSharedSpace::write_region(FileMapInfo* mapinfo, int region_idx, |
1126 DumpRegion* dump_region, bool read_only, bool allow_exec) { |
1138 DumpRegion* dump_region, bool read_only, bool allow_exec) { |
1127 mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec); |
1139 mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec); |
1128 } |
1140 } |
1129 |
1141 |
1130 void VM_PopulateDumpSharedSpace::dump_string_and_symbols() { |
1142 void VM_PopulateDumpSharedSpace::dump_symbols() { |
1131 tty->print_cr("Dumping string and symbol tables ..."); |
1143 tty->print_cr("Dumping symbol table ..."); |
1132 |
1144 |
1133 NOT_PRODUCT(SymbolTable::verify()); |
1145 NOT_PRODUCT(SymbolTable::verify()); |
1134 NOT_PRODUCT(StringTable::verify()); |
|
1135 SymbolTable::write_to_archive(); |
1146 SymbolTable::write_to_archive(); |
1136 |
|
1137 // The string space has maximum two regions. See FileMapInfo::write_string_regions() for details. |
|
1138 _string_regions = new GrowableArray<MemRegion>(2); |
|
1139 StringTable::write_to_archive(_string_regions); |
|
1140 } |
1147 } |
1141 |
1148 |
1142 char* VM_PopulateDumpSharedSpace::dump_read_only_tables() { |
1149 char* VM_PopulateDumpSharedSpace::dump_read_only_tables() { |
1143 char* oldtop = _ro_region.top(); |
1150 char* oldtop = _ro_region.top(); |
1144 // Reorder the system dictionary. Moving the symbols affects |
1151 // Reorder the system dictionary. Moving the symbols affects |
1280 write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false); |
1289 write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false); |
1281 write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false); |
1290 write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false); |
1282 write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false); |
1291 write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false); |
1283 write_region(mapinfo, MetaspaceShared::od, &_od_region, /*read_only=*/true, /*allow_exec=*/false); |
1292 write_region(mapinfo, MetaspaceShared::od, &_od_region, /*read_only=*/true, /*allow_exec=*/false); |
1284 |
1293 |
1285 mapinfo->write_string_regions(_string_regions, |
1294 _total_string_region_size = mapinfo->write_archive_heap_regions( |
1286 &s0_start, &s0_top, &s0_end, |
1295 _string_regions, |
1287 &s1_start, &s1_top, &s1_end); |
1296 MetaspaceShared::first_string, |
|
1297 MetaspaceShared::max_strings); |
|
1298 _total_open_archive_region_size = mapinfo->write_archive_heap_regions( |
|
1299 _open_archive_heap_regions, |
|
1300 MetaspaceShared::first_open_archive_heap_region, |
|
1301 MetaspaceShared::max_open_archive_heap_region); |
1288 } |
1302 } |
1289 |
1303 |
1290 mapinfo->close(); |
1304 mapinfo->close(); |
1291 |
1305 |
1292 // Restore the vtable in case we invoke any virtual methods. |
1306 // Restore the vtable in case we invoke any virtual methods. |
1293 MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list); |
1307 MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list); |
1294 |
1308 |
1295 _s0_region.init(s0_start, s0_top, s0_end); |
|
1296 _s1_region.init(s1_start, s1_top, s1_end); |
|
1297 print_region_stats(); |
1309 print_region_stats(); |
1298 |
1310 |
1299 if (log_is_enabled(Info, cds)) { |
1311 if (log_is_enabled(Info, cds)) { |
1300 ArchiveCompactor::alloc_stats()->print_stats(int(_ro_region.used()), int(_rw_region.used()), |
1312 ArchiveCompactor::alloc_stats()->print_stats(int(_ro_region.used()), int(_rw_region.used()), |
1301 int(_mc_region.used()), int(_md_region.used())); |
1313 int(_mc_region.used()), int(_md_region.used())); |
1302 } |
1314 } |
1303 } |
1315 } |
1304 |
1316 |
1305 void VM_PopulateDumpSharedSpace::print_region_stats() { |
1317 void VM_PopulateDumpSharedSpace::print_region_stats() { |
1306 // Print statistics of all the regions |
1318 // Print statistics of all the regions |
1307 const size_t total_reserved = _ro_region.reserved() + _rw_region.reserved() + |
1319 const size_t total_reserved = _ro_region.reserved() + _rw_region.reserved() + |
1308 _mc_region.reserved() + _md_region.reserved() + |
1320 _mc_region.reserved() + _md_region.reserved() + |
1309 _od_region.reserved() + |
1321 _od_region.reserved() + |
1310 _s0_region.reserved() + _s1_region.reserved(); |
1322 _total_string_region_size + |
1311 const size_t total_bytes = _ro_region.used() + _rw_region.used() + |
1323 _total_open_archive_region_size; |
1312 _mc_region.used() + _md_region.used() + |
1324 const size_t total_bytes = _ro_region.used() + _rw_region.used() + |
1313 _od_region.used() + |
1325 _mc_region.used() + _md_region.used() + |
1314 _s0_region.used() + _s1_region.used(); |
1326 _od_region.used() + |
|
1327 _total_string_region_size + |
|
1328 _total_open_archive_region_size; |
1315 const double total_u_perc = total_bytes / double(total_reserved) * 100.0; |
1329 const double total_u_perc = total_bytes / double(total_reserved) * 100.0; |
1316 |
1330 |
1317 _mc_region.print(total_reserved); |
1331 _mc_region.print(total_reserved); |
1318 _rw_region.print(total_reserved); |
1332 _rw_region.print(total_reserved); |
1319 _ro_region.print(total_reserved); |
1333 _ro_region.print(total_reserved); |
1320 _md_region.print(total_reserved); |
1334 _md_region.print(total_reserved); |
1321 _od_region.print(total_reserved); |
1335 _od_region.print(total_reserved); |
1322 _s0_region.print(total_reserved); |
1336 print_heap_region_stats(_string_regions, "st", total_reserved); |
1323 _s1_region.print(total_reserved); |
1337 print_heap_region_stats(_open_archive_heap_regions, "oa", total_reserved); |
1324 |
1338 |
1325 tty->print_cr("total : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]", |
1339 tty->print_cr("total : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]", |
1326 total_bytes, total_reserved, total_u_perc); |
1340 total_bytes, total_reserved, total_u_perc); |
1327 } |
1341 } |
1328 |
1342 |
|
1343 void VM_PopulateDumpSharedSpace::print_heap_region_stats(GrowableArray<MemRegion> *heap_mem, |
|
1344 const char *name, const size_t total_size) { |
|
1345 int arr_len = heap_mem == NULL ? 0 : heap_mem->length(); |
|
1346 for (int i = 0; i < arr_len; i++) { |
|
1347 char* start = (char*)heap_mem->at(i).start(); |
|
1348 size_t size = heap_mem->at(i).byte_size(); |
|
1349 char* top = start + size; |
|
1350 tty->print_cr("%s%d space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [100%% used] at " INTPTR_FORMAT, |
|
1351 name, i, size, size/double(total_size)*100.0, size, p2i(start)); |
|
1352 |
|
1353 } |
|
1354 } |
1329 |
1355 |
1330 // Update a Java object to point its Klass* to the new location after |
1356 // Update a Java object to point its Klass* to the new location after |
1331 // shared archive has been compacted. |
1357 // shared archive has been compacted. |
1332 void MetaspaceShared::relocate_klass_ptr(oop o) { |
1358 void MetaspaceShared::relocate_klass_ptr(oop o) { |
1333 assert(DumpSharedSpaces, "sanity"); |
1359 assert(DumpSharedSpaces, "sanity"); |
1554 } else { |
1582 } else { |
1555 return false; |
1583 return false; |
1556 } |
1584 } |
1557 } |
1585 } |
1558 |
1586 |
|
1587 #if INCLUDE_CDS_JAVA_HEAP |
|
1588 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() { |
|
1589 if (!MetaspaceShared::is_heap_object_archiving_allowed()) { |
|
1590 if (log_is_enabled(Info, cds)) { |
|
1591 log_info(cds)( |
|
1592 "Archived java heap is not supported as UseG1GC, " |
|
1593 "UseCompressedOops and UseCompressedClassPointers are required." |
|
1594 "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.", |
|
1595 BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops), |
|
1596 BOOL_TO_STR(UseCompressedClassPointers)); |
|
1597 } |
|
1598 return; |
|
1599 } |
|
1600 |
|
1601 { |
|
1602 NoSafepointVerifier nsv; |
|
1603 |
|
1604 // Cache for recording where the archived objects are copied to |
|
1605 MetaspaceShared::create_archive_object_cache(); |
|
1606 |
|
1607 tty->print_cr("Dumping String objects to closed archive heap region ..."); |
|
1608 NOT_PRODUCT(StringTable::verify()); |
|
1609 // The string space has maximum two regions. See FileMapInfo::write_archive_heap_regions() for details. |
|
1610 _string_regions = new GrowableArray<MemRegion>(2); |
|
1611 StringTable::write_to_archive(_string_regions); |
|
1612 |
|
1613 tty->print_cr("Dumping objects to open archive heap region ..."); |
|
1614 _open_archive_heap_regions = new GrowableArray<MemRegion>(2); |
|
1615 MetaspaceShared::dump_open_archive_heap_objects(_open_archive_heap_regions); |
|
1616 } |
|
1617 |
|
1618 G1HeapVerifier::verify_archive_regions(); |
|
1619 } |
|
1620 |
|
1621 void MetaspaceShared::dump_open_archive_heap_objects( |
|
1622 GrowableArray<MemRegion> * open_archive) { |
|
1623 assert(UseG1GC, "Only support G1 GC"); |
|
1624 assert(UseCompressedOops && UseCompressedClassPointers, |
|
1625 "Only support UseCompressedOops and UseCompressedClassPointers enabled"); |
|
1626 |
|
1627 Thread* THREAD = Thread::current(); |
|
1628 G1CollectedHeap::heap()->begin_archive_alloc_range(true /* open */); |
|
1629 |
|
1630 MetaspaceShared::archive_resolved_constants(THREAD); |
|
1631 |
|
1632 G1CollectedHeap::heap()->end_archive_alloc_range(open_archive, |
|
1633 os::vm_allocation_granularity()); |
|
1634 } |
|
1635 |
|
1636 MetaspaceShared::ArchivedObjectCache* MetaspaceShared::_archive_object_cache = NULL; |
|
1637 oop MetaspaceShared::archive_heap_object(oop obj, Thread* THREAD) { |
|
1638 assert(DumpSharedSpaces, "dump-time only"); |
|
1639 |
|
1640 ArchivedObjectCache* cache = MetaspaceShared::archive_object_cache(); |
|
1641 oop* p = cache->get(obj); |
|
1642 if (p != NULL) { |
|
1643 // already archived |
|
1644 return *p; |
|
1645 } |
|
1646 |
|
1647 int len = obj->size(); |
|
1648 if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) { |
|
1649 return NULL; |
|
1650 } |
|
1651 |
|
1652 int hash = obj->identity_hash(); |
|
1653 oop archived_oop = (oop)G1CollectedHeap::heap()->archive_mem_allocate(len); |
|
1654 if (archived_oop != NULL) { |
|
1655 Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)archived_oop, len); |
|
1656 relocate_klass_ptr(archived_oop); |
|
1657 cache->put(obj, archived_oop); |
|
1658 } |
|
1659 return archived_oop; |
|
1660 } |
|
1661 |
|
1662 void MetaspaceShared::archive_resolved_constants(Thread* THREAD) { |
|
1663 int i; |
|
1664 for (i = 0; i < _global_klass_objects->length(); i++) { |
|
1665 Klass* k = _global_klass_objects->at(i); |
|
1666 if (k->is_instance_klass()) { |
|
1667 InstanceKlass* ik = InstanceKlass::cast(k); |
|
1668 ik->constants()->archive_resolved_references(THREAD); |
|
1669 } |
|
1670 } |
|
1671 } |
|
1672 |
|
1673 void MetaspaceShared::fixup_mapped_heap_regions() { |
|
1674 FileMapInfo *mapinfo = FileMapInfo::current_info(); |
|
1675 mapinfo->fixup_mapped_heap_regions(); |
|
1676 } |
|
1677 #endif // INCLUDE_CDS_JAVA_HEAP |
|
1678 |
1559 // Closure for serializing initialization data in from a data area |
1679 // Closure for serializing initialization data in from a data area |
1560 // (ptr_array) read from the shared file. |
1680 // (ptr_array) read from the shared file. |
1561 |
1681 |
1562 class ReadClosure : public SerializeClosure { |
1682 class ReadClosure : public SerializeClosure { |
1563 private: |
1683 private: |