hotspot/src/share/vm/memory/metaspaceShared.cpp
changeset 46810 7dad333205cd
parent 46746 ea379ebb9447
child 46989 119e1e88cf15
equal deleted inserted replaced
46809:057f21a10f5f 46810:7dad333205cd
    32 #include "classfile/symbolTable.hpp"
    32 #include "classfile/symbolTable.hpp"
    33 #include "classfile/stringTable.hpp"
    33 #include "classfile/stringTable.hpp"
    34 #include "classfile/systemDictionary.hpp"
    34 #include "classfile/systemDictionary.hpp"
    35 #include "classfile/systemDictionaryShared.hpp"
    35 #include "classfile/systemDictionaryShared.hpp"
    36 #include "code/codeCache.hpp"
    36 #include "code/codeCache.hpp"
       
    37 #if INCLUDE_ALL_GCS
       
    38 #include "gc/g1/g1Allocator.inline.hpp"
       
    39 #include "gc/g1/g1CollectedHeap.hpp"
       
    40 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
       
    41 #endif
    37 #include "gc/shared/gcLocker.hpp"
    42 #include "gc/shared/gcLocker.hpp"
    38 #include "interpreter/bytecodeStream.hpp"
    43 #include "interpreter/bytecodeStream.hpp"
    39 #include "interpreter/bytecodes.hpp"
    44 #include "interpreter/bytecodes.hpp"
    40 #include "logging/log.hpp"
    45 #include "logging/log.hpp"
    41 #include "logging/logMessage.hpp"
    46 #include "logging/logMessage.hpp"
    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
    95 // [4] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
   103 // [4] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
    96 //     are copied into the ro region as read-only tables.
   104 //     are copied into the ro region as read-only tables.
    97 // [5] C++ vtables are copied into the md region.
   105 // [5] C++ vtables are copied into the md region.
    98 // [6] Original class files are copied into the od region.
   106 // [6] Original class files are copied into the od region.
    99 //
   107 //
   100 // The s0/s1 regions are populated inside MetaspaceShared::dump_string_and_symbols. Their
   108 // The s0/s1 and oa0/oa1 regions are populated inside MetaspaceShared::dump_java_heap_objects.
   101 // layout is independent of the other 5 regions.
   109 // Their layout is independent of the other 5 regions.
   102 
   110 
   103 class DumpRegion {
   111 class DumpRegion {
   104 private:
   112 private:
   105   const char* _name;
   113   const char* _name;
   106   char* _base;
   114   char* _base;
   192   bool contains(char* p) {
   200   bool contains(char* p) {
   193     return base() <= p && p < top();
   201     return base() <= p && p < top();
   194   }
   202   }
   195 };
   203 };
   196 
   204 
       
   205 
   197 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"), _od_region("od");
   206 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"), _od_region("od");
   198 DumpRegion _s0_region("s0"), _s1_region("s1");
   207 size_t _total_string_region_size = 0, _total_open_archive_region_size = 0;
   199 
   208 
   200 char* MetaspaceShared::misc_code_space_alloc(size_t num_bytes) {
   209 char* MetaspaceShared::misc_code_space_alloc(size_t num_bytes) {
   201   return _mc_region.allocate(num_bytes);
   210   return _mc_region.allocate(num_bytes);
   202 }
   211 }
   203 
   212 
   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);
  1070     // cleanup
  1083     // cleanup
  1071     _ssc = NULL;
  1084     _ssc = NULL;
  1072   }
  1085   }
  1073 
  1086 
  1074   // We must relocate the System::_well_known_klasses only after we have copied the
  1087   // We must relocate the System::_well_known_klasses only after we have copied the
  1075   // strings in during dump_string_and_symbols(): during the string copy, we operate on old
  1088   // java objects in during dump_java_heap_objects(): during the object copy, we operate on
  1076   // String objects which assert that their klass is the old
  1089   // old objects which assert that their klass is the original klass.
  1077   // SystemDictionary::String_klass().
       
  1078   static void relocate_well_known_klasses() {
  1090   static void relocate_well_known_klasses() {
  1079     {
  1091     {
  1080       tty->print_cr("Relocating SystemDictionary::_well_known_klasses[] ... ");
  1092       tty->print_cr("Relocating SystemDictionary::_well_known_klasses[] ... ");
  1081       ResourceMark rm;
  1093       ResourceMark rm;
  1082       RefRelocator ext_reloc;
  1094       RefRelocator ext_reloc;
  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
  1204     tty->print_cr("    instance classes   = %5d", num_inst);
  1211     tty->print_cr("    instance classes   = %5d", num_inst);
  1205     tty->print_cr("    obj array classes  = %5d", num_obj_array);
  1212     tty->print_cr("    obj array classes  = %5d", num_obj_array);
  1206     tty->print_cr("    type array classes = %5d", num_type_array);
  1213     tty->print_cr("    type array classes = %5d", num_type_array);
  1207   }
  1214   }
  1208 
  1215 
  1209 
       
  1210   // Ensure the ConstMethods won't be modified at run-time
  1216   // Ensure the ConstMethods won't be modified at run-time
  1211   tty->print("Updating ConstMethods ... ");
  1217   tty->print("Updating ConstMethods ... ");
  1212   rewrite_nofast_bytecodes_and_calculate_fingerprints();
  1218   rewrite_nofast_bytecodes_and_calculate_fingerprints();
  1213   tty->print_cr("done. ");
  1219   tty->print_cr("done. ");
  1214 
  1220 
  1218   tty->print_cr("done. ");
  1224   tty->print_cr("done. ");
  1219 
  1225 
  1220   ArchiveCompactor::initialize();
  1226   ArchiveCompactor::initialize();
  1221   ArchiveCompactor::copy_and_compact();
  1227   ArchiveCompactor::copy_and_compact();
  1222 
  1228 
  1223   dump_string_and_symbols();
  1229   dump_symbols();
       
  1230 
       
  1231   // Dump supported java heap objects
       
  1232   _string_regions = NULL;
       
  1233   _open_archive_heap_regions = NULL;
       
  1234   dump_java_heap_objects();
       
  1235 
  1224   ArchiveCompactor::relocate_well_known_klasses();
  1236   ArchiveCompactor::relocate_well_known_klasses();
  1225 
  1237 
  1226   char* read_only_tables_start = dump_read_only_tables();
  1238   char* read_only_tables_start = dump_read_only_tables();
  1227   _ro_region.pack(&_md_region);
  1239   _ro_region.pack(&_md_region);
  1228 
  1240 
  1255   mapinfo->set_read_only_tables_start(read_only_tables_start);
  1267   mapinfo->set_read_only_tables_start(read_only_tables_start);
  1256   mapinfo->set_misc_data_patching_start(vtbl_list);
  1268   mapinfo->set_misc_data_patching_start(vtbl_list);
  1257   mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
  1269   mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
  1258   mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
  1270   mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
  1259   mapinfo->set_core_spaces_size(core_spaces_size);
  1271   mapinfo->set_core_spaces_size(core_spaces_size);
  1260 
       
  1261   char* s0_start, *s0_top, *s0_end;
       
  1262   char* s1_start, *s1_top, *s1_end;
       
  1263 
  1272 
  1264   for (int pass=1; pass<=2; pass++) {
  1273   for (int pass=1; pass<=2; pass++) {
  1265     if (pass == 1) {
  1274     if (pass == 1) {
  1266       // The first pass doesn't actually write the data to disk. All it
  1275       // The first pass doesn't actually write the data to disk. All it
  1267       // does is to update the fields in the mapinfo->_header.
  1276       // does is to update the fields in the mapinfo->_header.
  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");
  1350       // Link the class to cause the bytecodes to be rewritten and the
  1376       // Link the class to cause the bytecodes to be rewritten and the
  1351       // cpcache to be created. Class verification is done according
  1377       // cpcache to be created. Class verification is done according
  1352       // to -Xverify setting.
  1378       // to -Xverify setting.
  1353       _made_progress |= MetaspaceShared::try_link_class(ik, THREAD);
  1379       _made_progress |= MetaspaceShared::try_link_class(ik, THREAD);
  1354       guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
  1380       guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
       
  1381 
       
  1382       ik->constants()->resolve_class_constants(THREAD);
  1355     }
  1383     }
  1356   }
  1384   }
  1357 };
  1385 };
  1358 
  1386 
  1359 class CheckSharedClassesClosure : public KlassClosure {
  1387 class CheckSharedClassesClosure : public KlassClosure {
  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:
  1741       vm_exit(0);
  1861       vm_exit(0);
  1742     }
  1862     }
  1743   }
  1863   }
  1744 }
  1864 }
  1745 
  1865 
  1746 void MetaspaceShared::fixup_shared_string_regions() {
       
  1747   FileMapInfo *mapinfo = FileMapInfo::current_info();
       
  1748   mapinfo->fixup_string_regions();
       
  1749 }
       
  1750 
       
  1751 // JVM/TI RedefineClasses() support:
  1866 // JVM/TI RedefineClasses() support:
  1752 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
  1867 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
  1753   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
  1868   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
  1754 
  1869 
  1755   if (UseSharedSpaces) {
  1870   if (UseSharedSpaces) {