src/hotspot/share/memory/metaspaceShared.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54927 1512d88b24c6
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    78 VirtualSpace MetaspaceShared::_shared_vs;
    78 VirtualSpace MetaspaceShared::_shared_vs;
    79 MetaspaceSharedStats MetaspaceShared::_stats;
    79 MetaspaceSharedStats MetaspaceShared::_stats;
    80 bool MetaspaceShared::_has_error_classes;
    80 bool MetaspaceShared::_has_error_classes;
    81 bool MetaspaceShared::_archive_loading_failed = false;
    81 bool MetaspaceShared::_archive_loading_failed = false;
    82 bool MetaspaceShared::_remapped_readwrite = false;
    82 bool MetaspaceShared::_remapped_readwrite = false;
    83 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
    83 address MetaspaceShared::_i2i_entry_code_buffers = NULL;
    84 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
    84 size_t MetaspaceShared::_i2i_entry_code_buffers_size = 0;
    85 size_t MetaspaceShared::_core_spaces_size = 0;
    85 size_t MetaspaceShared::_core_spaces_size = 0;
    86 void* MetaspaceShared::_shared_metaspace_static_top = NULL;
    86 void* MetaspaceShared::_shared_metaspace_static_top = NULL;
    87 
    87 
    88 // The CDS archive is divided into the following regions:
    88 // The CDS archive is divided into the following regions:
    89 //     mc  - misc code (the method entry trampolines)
    89 //     mc  - misc code (the method entry trampolines)
    90 //     rw  - read-write metadata
    90 //     rw  - read-write metadata
    91 //     ro  - read-only metadata and read-only tables
    91 //     ro  - read-only metadata and read-only tables
    92 //     md  - misc data (the c++ vtables)
    92 //     md  - misc data (the c++ vtables)
    93 //     od  - optional data (original class files)
       
    94 //
    93 //
    95 //     ca0 - closed archive heap space #0
    94 //     ca0 - closed archive heap space #0
    96 //     ca1 - closed archive heap space #1 (may be empty)
    95 //     ca1 - closed archive heap space #1 (may be empty)
    97 //     oa0 - open archive heap space #0
    96 //     oa0 - open archive heap space #0
    98 //     oa1 - open archive heap space #1 (may be empty)
    97 //     oa1 - open archive heap space #1 (may be empty)
    99 //
    98 //
   100 // The mc, rw, ro, md and od regions are linearly allocated, starting from
    99 // The mc, rw, ro, and md regions are linearly allocated, starting from
   101 // SharedBaseAddress, in the order of mc->rw->ro->md->od. The size of these 5 regions
   100 // SharedBaseAddress, in the order of mc->rw->ro->md. The size of these 4 regions
   102 // are page-aligned, and there's no gap between any consecutive regions.
   101 // are page-aligned, and there's no gap between any consecutive regions.
   103 //
   102 //
   104 // These 5 regions are populated in the following steps:
   103 // These 4 regions are populated in the following steps:
   105 // [1] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are
   104 // [1] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are
   106 //     temporarily allocated outside of the shared regions. Only the method entry
   105 //     temporarily allocated outside of the shared regions. Only the method entry
   107 //     trampolines are written into the mc region.
   106 //     trampolines are written into the mc region.
   108 // [2] ArchiveCompactor copies RW metadata into the rw region.
   107 // [2] ArchiveCompactor copies RW metadata into the rw region.
   109 // [3] ArchiveCompactor copies RO metadata into the ro region.
   108 // [3] ArchiveCompactor copies RO metadata into the ro region.
   110 // [4] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
   109 // [4] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
   111 //     are copied into the ro region as read-only tables.
   110 //     are copied into the ro region as read-only tables.
   112 // [5] C++ vtables are copied into the md region.
   111 // [5] C++ vtables are copied into the md region.
   113 // [6] Original class files are copied into the od region.
       
   114 //
   112 //
   115 // The s0/s1 and oa0/oa1 regions are populated inside HeapShared::archive_java_heap_objects.
   113 // The s0/s1 and oa0/oa1 regions are populated inside HeapShared::archive_java_heap_objects.
   116 // Their layout is independent of the other 5 regions.
   114 // Their layout is independent of the other 4 regions.
   117 
   115 
   118 char* DumpRegion::expand_top_to(char* newtop) {
   116 char* DumpRegion::expand_top_to(char* newtop) {
   119   assert(is_allocatable(), "must be initialized and not packed");
   117   assert(is_allocatable(), "must be initialized and not packed");
   120   assert(newtop >= _top, "must not grow backwards");
   118   assert(newtop >= _top, "must not grow backwards");
   121   if (newtop > _end) {
   119   if (newtop > _end) {
   172     next->_base = next->_top = this->_end;
   170     next->_base = next->_top = this->_end;
   173     next->_end = MetaspaceShared::shared_rs()->end();
   171     next->_end = MetaspaceShared::shared_rs()->end();
   174   }
   172   }
   175 }
   173 }
   176 
   174 
   177 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"), _od_region("od");
   175 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md");
   178 size_t _total_closed_archive_region_size = 0, _total_open_archive_region_size = 0;
   176 size_t _total_closed_archive_region_size = 0, _total_open_archive_region_size = 0;
   179 
   177 
   180 void MetaspaceShared::init_shared_dump_space(DumpRegion* first_space, address first_space_bottom) {
   178 void MetaspaceShared::init_shared_dump_space(DumpRegion* first_space, address first_space_bottom) {
   181   // Start with 0 committed bytes. The memory will be committed as needed by
   179   // Start with 0 committed bytes. The memory will be committed as needed by
   182   // MetaspaceShared::commit_shared_space_to().
   180   // MetaspaceShared::commit_shared_space_to().
   194   return &_rw_region;
   192   return &_rw_region;
   195 }
   193 }
   196 
   194 
   197 DumpRegion* MetaspaceShared::read_only_dump_space() {
   195 DumpRegion* MetaspaceShared::read_only_dump_space() {
   198   return &_ro_region;
   196   return &_ro_region;
   199 }
       
   200 
       
   201 DumpRegion* MetaspaceShared::optional_data_dump_space() {
       
   202   return &_od_region;
       
   203 }
   197 }
   204 
   198 
   205 void MetaspaceShared::pack_dump_space(DumpRegion* current, DumpRegion* next,
   199 void MetaspaceShared::pack_dump_space(DumpRegion* current, DumpRegion* next,
   206                                       ReservedSpace* rs) {
   200                                       ReservedSpace* rs) {
   207   current->pack(next);
   201   current->pack(next);
   288   // On 64-bit VM, the heap and class space layout will be the same as if
   282   // On 64-bit VM, the heap and class space layout will be the same as if
   289   // you're running in -Xshare:on mode:
   283   // you're running in -Xshare:on mode:
   290   //
   284   //
   291   //                              +-- SharedBaseAddress (default = 0x800000000)
   285   //                              +-- SharedBaseAddress (default = 0x800000000)
   292   //                              v
   286   //                              v
   293   // +-..---------+---------+ ... +----+----+----+----+----+---------------+
   287   // +-..---------+---------+ ... +----+----+----+----+---------------+
   294   // |    Heap    | Archive |     | MC | RW | RO | MD | OD | class space   |
   288   // |    Heap    | Archive |     | MC | RW | RO | MD | class space   |
   295   // +-..---------+---------+ ... +----+----+----+----+----+---------------+
   289   // +-..---------+---------+ ... +----+----+----+----+---------------+
   296   // |<--   MaxHeapSize  -->|     |<-- UnscaledClassSpaceMax = 4GB ------->|
   290   // |<--   MaxHeapSize  -->|     |<-- UnscaledClassSpaceMax = 4GB -->|
   297   //
   291   //
   298   const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
   292   const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
   299   const size_t cds_total = align_down(UnscaledClassSpaceMax, reserve_alignment);
   293   const size_t cds_total = align_down(UnscaledClassSpaceMax, reserve_alignment);
   300 #else
   294 #else
   301   // We don't support archives larger than 256MB on 32-bit due to limited virtual address space.
   295   // We don't support archives larger than 256MB on 32-bit due to limited virtual address space.
   360   if (UseSharedSpaces) {
   354   if (UseSharedSpaces) {
   361     int size = FileMapInfo::get_number_of_shared_paths();
   355     int size = FileMapInfo::get_number_of_shared_paths();
   362     if (size > 0) {
   356     if (size > 0) {
   363       SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);
   357       SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);
   364       if (!DynamicDumpSharedSpaces) {
   358       if (!DynamicDumpSharedSpaces) {
   365         FileMapHeader* header;
   359         FileMapInfo* info;
   366         if (FileMapInfo::dynamic_info() == NULL) {
   360         if (FileMapInfo::dynamic_info() == NULL) {
   367           header = FileMapInfo::current_info()->header();
   361           info = FileMapInfo::current_info();
   368         } else {
   362         } else {
   369           header = FileMapInfo::dynamic_info()->header();
   363           info = FileMapInfo::dynamic_info();
   370         }
   364         }
   371         ClassLoaderExt::init_paths_start_index(header->_app_class_paths_start_index);
   365         ClassLoaderExt::init_paths_start_index(info->app_class_paths_start_index());
   372         ClassLoaderExt::init_app_module_paths_start_index(header->_app_module_paths_start_index);
   366         ClassLoaderExt::init_app_module_paths_start_index(info->app_module_paths_start_index());
   373       }
   367       }
   374     }
   368     }
   375   }
   369   }
   376 }
   370 }
   377 
   371 
   429     }
   423     }
   430   }
   424   }
   431 }
   425 }
   432 
   426 
   433 void MetaspaceShared::commit_shared_space_to(char* newtop) {
   427 void MetaspaceShared::commit_shared_space_to(char* newtop) {
   434   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump-time only");
   428   Arguments::assert_is_dumping_archive();
   435   char* base = _shared_rs.base();
   429   char* base = _shared_rs.base();
   436   size_t need_committed_size = newtop - base;
   430   size_t need_committed_size = newtop - base;
   437   size_t has_committed_size = _shared_vs.committed_size();
   431   size_t has_committed_size = _shared_vs.committed_size();
   438   if (need_committed_size < has_committed_size) {
   432   if (need_committed_size < has_committed_size) {
   439     return;
   433     return;
   496   soc->do_tag(--tag);
   490   soc->do_tag(--tag);
   497 
   491 
   498   soc->do_tag(666);
   492   soc->do_tag(666);
   499 }
   493 }
   500 
   494 
   501 address MetaspaceShared::cds_i2i_entry_code_buffers(size_t total_size) {
   495 address MetaspaceShared::i2i_entry_code_buffers(size_t total_size) {
   502   if (DumpSharedSpaces) {
   496   if (DumpSharedSpaces) {
   503     if (_cds_i2i_entry_code_buffers == NULL) {
   497     if (_i2i_entry_code_buffers == NULL) {
   504       _cds_i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
   498       _i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
   505       _cds_i2i_entry_code_buffers_size = total_size;
   499       _i2i_entry_code_buffers_size = total_size;
   506     }
   500     }
   507   } else if (UseSharedSpaces) {
   501   } else if (UseSharedSpaces) {
   508     assert(_cds_i2i_entry_code_buffers != NULL, "must already been initialized");
   502     assert(_i2i_entry_code_buffers != NULL, "must already been initialized");
   509   } else {
   503   } else {
   510     return NULL;
   504     return NULL;
   511   }
   505   }
   512 
   506 
   513   assert(_cds_i2i_entry_code_buffers_size == total_size, "must not change");
   507   assert(_i2i_entry_code_buffers_size == total_size, "must not change");
   514   return _cds_i2i_entry_code_buffers;
   508   return _i2i_entry_code_buffers;
   515 }
   509 }
   516 
   510 
   517 uintx MetaspaceShared::object_delta_uintx(void* obj) {
   511 uintx MetaspaceShared::object_delta_uintx(void* obj) {
   518   assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
   512   Arguments::assert_is_dumping_archive();
   519          "supported only for dumping");
       
   520   if (DumpSharedSpaces) {
   513   if (DumpSharedSpaces) {
   521     assert(shared_rs()->contains(obj), "must be");
   514     assert(shared_rs()->contains(obj), "must be");
   522   } else {
   515   } else {
   523     assert(is_in_shared_metaspace(obj) || DynamicArchive::is_in_target_space(obj), "must be");
   516     assert(is_in_shared_metaspace(obj) || DynamicArchive::is_in_target_space(obj), "must be");
   524   }
   517   }
  1072   const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
  1065   const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
  1073   const char *hdr = "                        ro_cnt   ro_bytes     % |   rw_cnt   rw_bytes     % |  all_cnt  all_bytes     %";
  1066   const char *hdr = "                        ro_cnt   ro_bytes     % |   rw_cnt   rw_bytes     % |  all_cnt  all_bytes     %";
  1074 
  1067 
  1075   LogMessage(cds) msg;
  1068   LogMessage(cds) msg;
  1076 
  1069 
  1077   msg.info("Detailed metadata info (excluding od/st regions; rw stats include md/mc regions):");
  1070   msg.info("Detailed metadata info (excluding st regions; rw stats include md/mc regions):");
  1078   msg.info("%s", hdr);
  1071   msg.info("%s", hdr);
  1079   msg.info("%s", sep);
  1072   msg.info("%s", sep);
  1080   for (int type = 0; type < int(_number_of_types); type ++) {
  1073   for (int type = 0; type < int(_number_of_types); type ++) {
  1081     const char *name = type_name((Type)type);
  1074     const char *name = type_name((Type)type);
  1082     int ro_count = _counts[RO][type];
  1075     int ro_count = _counts[RO][type];
  1141                                const char *name, const size_t total_size);
  1134                                const char *name, const size_t total_size);
  1142 public:
  1135 public:
  1143 
  1136 
  1144   VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
  1137   VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
  1145   void doit();   // outline because gdb sucks
  1138   void doit();   // outline because gdb sucks
  1146   static void write_region(FileMapInfo* mapinfo, int region, DumpRegion* space, bool read_only,  bool allow_exec);
  1139   static void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region, bool read_only,  bool allow_exec) {
       
  1140     mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
       
  1141   }
  1147   bool allow_nested_vm_operations() const { return true; }
  1142   bool allow_nested_vm_operations() const { return true; }
  1148 }; // class VM_PopulateDumpSharedSpace
  1143 }; // class VM_PopulateDumpSharedSpace
  1149 
  1144 
  1150 class SortedSymbolClosure: public SymbolClosure {
  1145 class SortedSymbolClosure: public SymbolClosure {
  1151   GrowableArray<Symbol*> _symbols;
  1146   GrowableArray<Symbol*> _symbols;
  1410 
  1405 
  1411 DumpAllocStats* ArchiveCompactor::_alloc_stats;
  1406 DumpAllocStats* ArchiveCompactor::_alloc_stats;
  1412 SortedSymbolClosure* ArchiveCompactor::_ssc;
  1407 SortedSymbolClosure* ArchiveCompactor::_ssc;
  1413 ArchiveCompactor::RelocationTable* ArchiveCompactor::_new_loc_table;
  1408 ArchiveCompactor::RelocationTable* ArchiveCompactor::_new_loc_table;
  1414 
  1409 
  1415 void VM_PopulateDumpSharedSpace::write_region(FileMapInfo* mapinfo, int region_idx,
       
  1416                                               DumpRegion* dump_region, bool read_only,  bool allow_exec) {
       
  1417   mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
       
  1418 }
       
  1419 
       
  1420 void VM_PopulateDumpSharedSpace::dump_symbols() {
  1410 void VM_PopulateDumpSharedSpace::dump_symbols() {
  1421   tty->print_cr("Dumping symbol table ...");
  1411   tty->print_cr("Dumping symbol table ...");
  1422 
  1412 
  1423   NOT_PRODUCT(SymbolTable::verify());
  1413   NOT_PRODUCT(SymbolTable::verify());
  1424   SymbolTable::write_to_archive();
  1414   SymbolTable::write_to_archive();
  1434   remove_java_mirror_in_classes();
  1424   remove_java_mirror_in_classes();
  1435   tty->print_cr("done. ");
  1425   tty->print_cr("done. ");
  1436 
  1426 
  1437   SystemDictionaryShared::write_to_archive();
  1427   SystemDictionaryShared::write_to_archive();
  1438 
  1428 
  1439   char* start = _ro_region.top();
       
  1440 
       
  1441   size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(intptr_t*);
  1429   size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(intptr_t*);
  1442   _cloned_cpp_vtptrs = (intptr_t**)_ro_region.allocate(vtptrs_bytes, sizeof(intptr_t*));
  1430   _cloned_cpp_vtptrs = (intptr_t**)_ro_region.allocate(vtptrs_bytes, sizeof(intptr_t*));
  1443 
  1431 
  1444   // Write the other data to the output array.
  1432   // Write the other data to the output array.
       
  1433   char* start = _ro_region.top();
  1445   WriteClosure wc(&_ro_region);
  1434   WriteClosure wc(&_ro_region);
  1446   MetaspaceShared::serialize(&wc);
  1435   MetaspaceShared::serialize(&wc);
  1447 
  1436 
  1448   // Write the bitmaps for patching the archive heap regions
  1437   // Write the bitmaps for patching the archive heap regions
  1449   dump_archive_heap_oopmaps();
  1438   dump_archive_heap_oopmaps();
  1522   _open_archive_heap_regions = NULL;
  1511   _open_archive_heap_regions = NULL;
  1523   dump_java_heap_objects();
  1512   dump_java_heap_objects();
  1524 
  1513 
  1525   ArchiveCompactor::relocate_well_known_klasses();
  1514   ArchiveCompactor::relocate_well_known_klasses();
  1526 
  1515 
  1527   char* read_only_tables_start = dump_read_only_tables();
  1516   char* serialized_data_start = dump_read_only_tables();
  1528   _ro_region.pack(&_md_region);
  1517   _ro_region.pack(&_md_region);
  1529 
  1518 
  1530   char* vtbl_list = _md_region.top();
  1519   char* vtbl_list = _md_region.top();
  1531   MetaspaceShared::allocate_cpp_vtable_clones();
  1520   MetaspaceShared::allocate_cpp_vtable_clones();
  1532   _md_region.pack();
  1521   _md_region.pack();
  1547 
  1536 
  1548   // Create and write the archive file that maps the shared spaces.
  1537   // Create and write the archive file that maps the shared spaces.
  1549 
  1538 
  1550   FileMapInfo* mapinfo = new FileMapInfo(true);
  1539   FileMapInfo* mapinfo = new FileMapInfo(true);
  1551   mapinfo->populate_header(os::vm_allocation_granularity());
  1540   mapinfo->populate_header(os::vm_allocation_granularity());
  1552   mapinfo->set_read_only_tables_start(read_only_tables_start);
  1541   mapinfo->set_serialized_data_start(serialized_data_start);
  1553   mapinfo->set_misc_data_patching_start(vtbl_list);
  1542   mapinfo->set_misc_data_patching_start(vtbl_list);
  1554   mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
  1543   mapinfo->set_i2i_entry_code_buffers(MetaspaceShared::i2i_entry_code_buffers(),
  1555   mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
  1544                                       MetaspaceShared::i2i_entry_code_buffers_size());
  1556   mapinfo->set_core_spaces_size(core_spaces_size);
  1545   mapinfo->set_core_spaces_size(core_spaces_size);
  1557 
  1546   mapinfo->open_for_write();
  1558   for (int pass=1; pass<=2; pass++) {
  1547 
  1559     bool print_archive_log = (pass==1);
  1548   // NOTE: md contains the trampoline code for method entries, which are patched at run time,
  1560     if (pass == 1) {
  1549   // so it needs to be read/write.
  1561       // The first pass doesn't actually write the data to disk. All it
  1550   write_region(mapinfo, MetaspaceShared::mc, &_mc_region, /*read_only=*/false,/*allow_exec=*/true);
  1562       // does is to update the fields in the mapinfo->_header.
  1551   write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
  1563     } else {
  1552   write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
  1564       // After the first pass, the contents of mapinfo->_header are finalized,
  1553   write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
  1565       // so we can compute the header's CRC, and write the contents of the header
  1554 
  1566       // and the regions into disk.
  1555   _total_closed_archive_region_size = mapinfo->write_archive_heap_regions(
  1567       mapinfo->open_for_write();
       
  1568       mapinfo->set_header_crc(mapinfo->compute_header_crc());
       
  1569     }
       
  1570     mapinfo->write_header();
       
  1571 
       
  1572     // NOTE: md contains the trampoline code for method entries, which are patched at run time,
       
  1573     // so it needs to be read/write.
       
  1574     write_region(mapinfo, MetaspaceShared::mc, &_mc_region, /*read_only=*/false,/*allow_exec=*/true);
       
  1575     write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
       
  1576     write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
       
  1577     write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
       
  1578 
       
  1579     _total_closed_archive_region_size = mapinfo->write_archive_heap_regions(
       
  1580                                         _closed_archive_heap_regions,
  1556                                         _closed_archive_heap_regions,
  1581                                         _closed_archive_heap_oopmaps,
  1557                                         _closed_archive_heap_oopmaps,
  1582                                         MetaspaceShared::first_closed_archive_heap_region,
  1558                                         MetaspaceShared::first_closed_archive_heap_region,
  1583                                         MetaspaceShared::max_closed_archive_heap_region,
  1559                                         MetaspaceShared::max_closed_archive_heap_region);
  1584                                         print_archive_log);
  1560   _total_open_archive_region_size = mapinfo->write_archive_heap_regions(
  1585     _total_open_archive_region_size = mapinfo->write_archive_heap_regions(
       
  1586                                         _open_archive_heap_regions,
  1561                                         _open_archive_heap_regions,
  1587                                         _open_archive_heap_oopmaps,
  1562                                         _open_archive_heap_oopmaps,
  1588                                         MetaspaceShared::first_open_archive_heap_region,
  1563                                         MetaspaceShared::first_open_archive_heap_region,
  1589                                         MetaspaceShared::max_open_archive_heap_region,
  1564                                         MetaspaceShared::max_open_archive_heap_region);
  1590                                         print_archive_log);
  1565 
  1591   }
  1566   mapinfo->set_header_crc(mapinfo->compute_header_crc());
  1592 
  1567   mapinfo->write_header();
  1593   mapinfo->close();
  1568   mapinfo->close();
  1594 
  1569 
  1595   // Restore the vtable in case we invoke any virtual methods.
  1570   // Restore the vtable in case we invoke any virtual methods.
  1596   MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
  1571   MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
  1597 
  1572 
  1818     Klass* klass = parser.load_current_class(THREAD);
  1793     Klass* klass = parser.load_current_class(THREAD);
  1819     if (HAS_PENDING_EXCEPTION) {
  1794     if (HAS_PENDING_EXCEPTION) {
  1820       if (klass == NULL &&
  1795       if (klass == NULL &&
  1821           (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
  1796           (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
  1822         // print a warning only when the pending exception is class not found
  1797         // print a warning only when the pending exception is class not found
  1823         tty->print_cr("Preload Warning: Cannot find %s", parser.current_class_name());
  1798         log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
  1824       }
  1799       }
  1825       CLEAR_PENDING_EXCEPTION;
  1800       CLEAR_PENDING_EXCEPTION;
  1826     }
  1801     }
  1827     if (klass != NULL) {
  1802     if (klass != NULL) {
  1828       if (log_is_enabled(Trace, cds)) {
  1803       if (log_is_enabled(Trace, cds)) {
  1864       BytecodeVerificationLocal = BytecodeVerificationRemote;
  1839       BytecodeVerificationLocal = BytecodeVerificationRemote;
  1865     }
  1840     }
  1866     ik->link_class(THREAD);
  1841     ik->link_class(THREAD);
  1867     if (HAS_PENDING_EXCEPTION) {
  1842     if (HAS_PENDING_EXCEPTION) {
  1868       ResourceMark rm;
  1843       ResourceMark rm;
  1869       tty->print_cr("Preload Warning: Verification failed for %s",
  1844       log_warning(cds)("Preload Warning: Verification failed for %s",
  1870                     ik->external_name());
  1845                     ik->external_name());
  1871       CLEAR_PENDING_EXCEPTION;
  1846       CLEAR_PENDING_EXCEPTION;
  1872       ik->set_in_error_state();
  1847       ik->set_in_error_state();
  1873       _has_error_classes = true;
  1848       _has_error_classes = true;
  1874     }
  1849     }
  1931 }
  1906 }
  1932 
  1907 
  1933 void ReadClosure::do_u4(u4* p) {
  1908 void ReadClosure::do_u4(u4* p) {
  1934   intptr_t obj = nextPtr();
  1909   intptr_t obj = nextPtr();
  1935   *p = (u4)(uintx(obj));
  1910   *p = (u4)(uintx(obj));
       
  1911 }
       
  1912 
       
  1913 void ReadClosure::do_bool(bool* p) {
       
  1914   intptr_t obj = nextPtr();
       
  1915   *p = (bool)(uintx(obj));
  1936 }
  1916 }
  1937 
  1917 
  1938 void ReadClosure::do_tag(int tag) {
  1918 void ReadClosure::do_tag(int tag) {
  1939   int old_tag;
  1919   int old_tag;
  1940   old_tag = (int)(intptr_t)nextPtr();
  1920   old_tag = (int)(intptr_t)nextPtr();
  2042 // Read the miscellaneous data from the shared file, and
  2022 // Read the miscellaneous data from the shared file, and
  2043 // serialize it out to its various destinations.
  2023 // serialize it out to its various destinations.
  2044 
  2024 
  2045 void MetaspaceShared::initialize_shared_spaces() {
  2025 void MetaspaceShared::initialize_shared_spaces() {
  2046   FileMapInfo *mapinfo = FileMapInfo::current_info();
  2026   FileMapInfo *mapinfo = FileMapInfo::current_info();
  2047   _cds_i2i_entry_code_buffers = mapinfo->cds_i2i_entry_code_buffers();
  2027   _i2i_entry_code_buffers = mapinfo->i2i_entry_code_buffers();
  2048   _cds_i2i_entry_code_buffers_size = mapinfo->cds_i2i_entry_code_buffers_size();
  2028   _i2i_entry_code_buffers_size = mapinfo->i2i_entry_code_buffers_size();
  2049   // _core_spaces_size is loaded from the shared archive immediatelly after mapping
  2029   // _core_spaces_size is loaded from the shared archive immediatelly after mapping
  2050   assert(_core_spaces_size == mapinfo->core_spaces_size(), "sanity");
  2030   assert(_core_spaces_size == mapinfo->core_spaces_size(), "sanity");
  2051   char* buffer = mapinfo->misc_data_patching_start();
  2031   char* buffer = mapinfo->misc_data_patching_start();
  2052   clone_cpp_vtables((intptr_t*)buffer);
  2032   clone_cpp_vtables((intptr_t*)buffer);
  2053 
  2033 
  2054   // The rest of the data is now stored in the RW region
       
  2055   buffer = mapinfo->read_only_tables_start();
       
  2056 
       
  2057   // Skip over _cloned_cpp_vtptrs;
       
  2058   buffer += _num_cloned_vtable_kinds * sizeof(intptr_t*);
       
  2059 
       
  2060   // Verify various attributes of the archive, plus initialize the
  2034   // Verify various attributes of the archive, plus initialize the
  2061   // shared string/symbol tables
  2035   // shared string/symbol tables
       
  2036   buffer = mapinfo->serialized_data_start();
  2062   intptr_t* array = (intptr_t*)buffer;
  2037   intptr_t* array = (intptr_t*)buffer;
  2063   ReadClosure rc(&array);
  2038   ReadClosure rc(&array);
  2064   serialize(&rc);
  2039   serialize(&rc);
  2065 
  2040 
  2066   // Initialize the run-time symbol table.
  2041   // Initialize the run-time symbol table.