hotspot/src/share/vm/memory/metaspaceShared.cpp
changeset 41182 dbd59c1da636
parent 39714 976b97b59d87
child 43410 8c70a25642c4
equal deleted inserted replaced
41181:2ce2f1c582ca 41182:dbd59c1da636
    63 bool MetaspaceShared::_remapped_readwrite = false;
    63 bool MetaspaceShared::_remapped_readwrite = false;
    64 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
    64 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
    65 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
    65 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
    66 SharedMiscRegion MetaspaceShared::_mc;
    66 SharedMiscRegion MetaspaceShared::_mc;
    67 SharedMiscRegion MetaspaceShared::_md;
    67 SharedMiscRegion MetaspaceShared::_md;
       
    68 SharedMiscRegion MetaspaceShared::_od;
    68 
    69 
    69 void SharedMiscRegion::initialize(ReservedSpace rs, size_t committed_byte_size,  SharedSpaceType space_type) {
    70 void SharedMiscRegion::initialize(ReservedSpace rs, size_t committed_byte_size,  SharedSpaceType space_type) {
    70   _vs.initialize(rs, committed_byte_size);
    71   _vs.initialize(rs, committed_byte_size);
    71   _alloc_top = _vs.low();
    72   _alloc_top = _vs.low();
    72   _space_type = space_type;
    73   _space_type = space_type;
    91 
    92 
    92 void MetaspaceShared::initialize_shared_rs(ReservedSpace* rs) {
    93 void MetaspaceShared::initialize_shared_rs(ReservedSpace* rs) {
    93   assert(DumpSharedSpaces, "dump time only");
    94   assert(DumpSharedSpaces, "dump time only");
    94   _shared_rs = rs;
    95   _shared_rs = rs;
    95 
    96 
    96   // Split up and initialize the misc code and data spaces
    97   size_t core_spaces_size = FileMapInfo::core_spaces_size();
    97   size_t metadata_size = SharedReadOnlySize + SharedReadWriteSize;
    98   size_t metadata_size = SharedReadOnlySize + SharedReadWriteSize;
    98   ReservedSpace shared_ro_rw = _shared_rs->first_part(metadata_size);
    99 
    99   ReservedSpace misc_section = _shared_rs->last_part(metadata_size);
   100   // Split into the core and optional sections
   100 
   101   ReservedSpace core_data = _shared_rs->first_part(core_spaces_size);
   101   // Now split into misc sections.
   102   ReservedSpace optional_data = _shared_rs->last_part(core_spaces_size);
       
   103 
       
   104   // The RO/RW and the misc sections
       
   105   ReservedSpace shared_ro_rw = core_data.first_part(metadata_size);
       
   106   ReservedSpace misc_section = core_data.last_part(metadata_size);
       
   107 
       
   108   // Now split the misc code and misc data sections.
   102   ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
   109   ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
   103   ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
   110   ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
       
   111 
   104   _md.initialize(md_rs, SharedMiscDataSize, SharedMiscData);
   112   _md.initialize(md_rs, SharedMiscDataSize, SharedMiscData);
   105   _mc.initialize(mc_rs, SharedMiscCodeSize, SharedMiscData);
   113   _mc.initialize(mc_rs, SharedMiscCodeSize, SharedMiscCode);
       
   114   _od.initialize(optional_data, metadata_size, SharedOptional);
   106 }
   115 }
   107 
   116 
   108 // Read/write a data stream for restoring/preserving metadata pointers and
   117 // Read/write a data stream for restoring/preserving metadata pointers and
   109 // miscellaneous data from/to the shared archive file.
   118 // miscellaneous data from/to the shared archive file.
   110 
   119 
   519 private:
   528 private:
   520   ClassLoaderData* _loader_data;
   529   ClassLoaderData* _loader_data;
   521   GrowableArray<Klass*> *_class_promote_order;
   530   GrowableArray<Klass*> *_class_promote_order;
   522   VirtualSpace _md_vs;
   531   VirtualSpace _md_vs;
   523   VirtualSpace _mc_vs;
   532   VirtualSpace _mc_vs;
       
   533   VirtualSpace _od_vs;
   524   GrowableArray<MemRegion> *_string_regions;
   534   GrowableArray<MemRegion> *_string_regions;
   525 
   535 
   526 public:
   536 public:
   527   VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
   537   VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
   528                              GrowableArray<Klass*> *class_promote_order) :
   538                              GrowableArray<Klass*> *class_promote_order) :
   596   // Remove all references outside the metadata
   606   // Remove all references outside the metadata
   597   tty->print("Removing unshareable information ... ");
   607   tty->print("Removing unshareable information ... ");
   598   remove_unshareable_in_classes();
   608   remove_unshareable_in_classes();
   599   tty->print_cr("done. ");
   609   tty->print_cr("done. ");
   600 
   610 
   601   // Set up the share data and shared code segments.
   611   // Set up the misc data, misc code and optional data segments.
   602   _md_vs = *MetaspaceShared::misc_data_region()->virtual_space();
   612   _md_vs = *MetaspaceShared::misc_data_region()->virtual_space();
   603   _mc_vs = *MetaspaceShared::misc_code_region()->virtual_space();
   613   _mc_vs = *MetaspaceShared::misc_code_region()->virtual_space();
       
   614   _od_vs = *MetaspaceShared::optional_data_region()->virtual_space();
   604   char* md_low = _md_vs.low();
   615   char* md_low = _md_vs.low();
   605   char* md_top = MetaspaceShared::misc_data_region()->alloc_top();
   616   char* md_top = MetaspaceShared::misc_data_region()->alloc_top();
   606   char* md_end = _md_vs.high();
   617   char* md_end = _md_vs.high();
   607   char* mc_low = _mc_vs.low();
   618   char* mc_low = _mc_vs.low();
   608   char* mc_top = MetaspaceShared::misc_code_region()->alloc_top();
   619   char* mc_top = MetaspaceShared::misc_code_region()->alloc_top();
   609   char* mc_end = _mc_vs.high();
   620   char* mc_end = _mc_vs.high();
       
   621   char* od_low = _od_vs.low();
       
   622   char* od_top = MetaspaceShared::optional_data_region()->alloc_top();
       
   623   char* od_end = _od_vs.high();
   610 
   624 
   611   // Reserve space for the list of Klass*s whose vtables are used
   625   // Reserve space for the list of Klass*s whose vtables are used
   612   // for patching others as needed.
   626   // for patching others as needed.
   613 
   627 
   614   void** vtbl_list = (void**)md_top;
   628   void** vtbl_list = (void**)md_top;
   659   // Allocated size of each space (may not be all occupied)
   673   // Allocated size of each space (may not be all occupied)
   660   const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
   674   const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
   661   const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
   675   const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
   662   const size_t md_alloced = md_end-md_low;
   676   const size_t md_alloced = md_end-md_low;
   663   const size_t mc_alloced = mc_end-mc_low;
   677   const size_t mc_alloced = mc_end-mc_low;
       
   678   const size_t od_alloced = od_end-od_low;
   664   const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
   679   const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
   665                              + ss_bytes;
   680                              + ss_bytes + od_alloced;
   666 
   681 
   667   // Occupied size of each space.
   682   // Occupied size of each space.
   668   const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
   683   const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
   669   const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
   684   const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
   670   const size_t md_bytes = size_t(md_top - md_low);
   685   const size_t md_bytes = size_t(md_top - md_low);
   671   const size_t mc_bytes = size_t(mc_top - mc_low);
   686   const size_t mc_bytes = size_t(mc_top - mc_low);
       
   687   const size_t od_bytes = size_t(od_top - od_low);
   672 
   688 
   673   // Percent of total size
   689   // Percent of total size
   674   const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes;
   690   const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes + od_bytes;
   675   const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
   691   const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
   676   const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
   692   const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
   677   const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
   693   const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
   678   const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
   694   const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
   679   const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
   695   const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
       
   696   const double od_t_perc = od_bytes / double(total_bytes) * 100.0;
   680 
   697 
   681   // Percent of fullness of each space
   698   // Percent of fullness of each space
   682   const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
   699   const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
   683   const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
   700   const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
   684   const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
   701   const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
   685   const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
   702   const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
       
   703   const double od_u_perc = od_bytes / double(od_alloced) * 100.0;
   686   const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
   704   const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
   687 
   705 
   688 #define fmt_space "%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT
   706 #define fmt_space "%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT
   689   tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, p2i(ro_space->bottom()));
   707   tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, p2i(ro_space->bottom()));
   690   tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, p2i(rw_space->bottom()));
   708   tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, p2i(rw_space->bottom()));
   691   tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, p2i(md_low));
   709   tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, p2i(md_low));
   692   tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, p2i(mc_low));
   710   tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, p2i(mc_low));
   693   tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes,   100.0,     p2i(ss_low));
   711   tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes,   100.0,     p2i(ss_low));
       
   712   tty->print_cr(fmt_space, "od", od_bytes, od_t_perc, od_alloced, od_u_perc, p2i(od_low));
   694   tty->print_cr("total   : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]",
   713   tty->print_cr("total   : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]",
   695                  total_bytes, total_alloced, total_u_perc);
   714                  total_bytes, total_alloced, total_u_perc);
   696 
   715 
   697   // Update the vtable pointers in all of the Klass objects in the
   716   // Update the vtable pointers in all of the Klass objects in the
   698   // heap. They should point to newly generated vtable.
   717   // heap. They should point to newly generated vtable.
   732     mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
   751     mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
   733                           pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
   752                           pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
   734                           SharedMiscCodeSize,
   753                           SharedMiscCodeSize,
   735                           true, true);
   754                           true, true);
   736     mapinfo->write_string_regions(_string_regions);
   755     mapinfo->write_string_regions(_string_regions);
       
   756     mapinfo->write_region(MetaspaceShared::od, _od_vs.low(),
       
   757                           pointer_delta(od_top, _od_vs.low(), sizeof(char)),
       
   758                           pointer_delta(od_end, _od_vs.low(), sizeof(char)),
       
   759                           true, false);
   737   }
   760   }
   738 
   761 
   739   mapinfo->close();
   762   mapinfo->close();
   740 
   763 
   741   memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
   764   memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
  1047   }
  1070   }
  1048 }
  1071 }
  1049 
  1072 
  1050 
  1073 
  1051 // Map shared spaces at requested addresses and return if succeeded.
  1074 // Map shared spaces at requested addresses and return if succeeded.
  1052 // Need to keep the bounds of the ro and rw space for the Metaspace::contains
       
  1053 // call, or is_in_shared_space.
       
  1054 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
  1075 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
  1055   size_t image_alignment = mapinfo->alignment();
  1076   size_t image_alignment = mapinfo->alignment();
  1056 
  1077 
  1057 #ifndef _WINDOWS
  1078 #ifndef _WINDOWS
  1058   // Map in the shared memory and then map the regions on top of it.
  1079   // Map in the shared memory and then map the regions on top of it.
  1066 
  1087 
  1067   char* _ro_base = NULL;
  1088   char* _ro_base = NULL;
  1068   char* _rw_base = NULL;
  1089   char* _rw_base = NULL;
  1069   char* _md_base = NULL;
  1090   char* _md_base = NULL;
  1070   char* _mc_base = NULL;
  1091   char* _mc_base = NULL;
       
  1092   char* _od_base = NULL;
  1071 
  1093 
  1072   // Map each shared region
  1094   // Map each shared region
  1073   if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
  1095   if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
  1074       mapinfo->verify_region_checksum(ro) &&
  1096       mapinfo->verify_region_checksum(ro) &&
  1075       (_rw_base = mapinfo->map_region(rw)) != NULL &&
  1097       (_rw_base = mapinfo->map_region(rw)) != NULL &&
  1076       mapinfo->verify_region_checksum(rw) &&
  1098       mapinfo->verify_region_checksum(rw) &&
  1077       (_md_base = mapinfo->map_region(md)) != NULL &&
  1099       (_md_base = mapinfo->map_region(md)) != NULL &&
  1078       mapinfo->verify_region_checksum(md) &&
  1100       mapinfo->verify_region_checksum(md) &&
  1079       (_mc_base = mapinfo->map_region(mc)) != NULL &&
  1101       (_mc_base = mapinfo->map_region(mc)) != NULL &&
  1080       mapinfo->verify_region_checksum(mc) &&
  1102       mapinfo->verify_region_checksum(mc) &&
       
  1103       (_od_base = mapinfo->map_region(od)) != NULL &&
       
  1104       mapinfo->verify_region_checksum(od) &&
  1081       (image_alignment == (size_t)max_alignment()) &&
  1105       (image_alignment == (size_t)max_alignment()) &&
  1082       mapinfo->validate_classpath_entry_table()) {
  1106       mapinfo->validate_classpath_entry_table()) {
  1083     // Success (no need to do anything)
  1107     // Success (no need to do anything)
  1084     return true;
  1108     return true;
  1085   } else {
  1109   } else {
  1087     // that succeeded
  1111     // that succeeded
  1088     if (_ro_base != NULL) mapinfo->unmap_region(ro);
  1112     if (_ro_base != NULL) mapinfo->unmap_region(ro);
  1089     if (_rw_base != NULL) mapinfo->unmap_region(rw);
  1113     if (_rw_base != NULL) mapinfo->unmap_region(rw);
  1090     if (_md_base != NULL) mapinfo->unmap_region(md);
  1114     if (_md_base != NULL) mapinfo->unmap_region(md);
  1091     if (_mc_base != NULL) mapinfo->unmap_region(mc);
  1115     if (_mc_base != NULL) mapinfo->unmap_region(mc);
       
  1116     if (_od_base != NULL) mapinfo->unmap_region(od);
  1092 #ifndef _WINDOWS
  1117 #ifndef _WINDOWS
  1093     // Release the entire mapped region
  1118     // Release the entire mapped region
  1094     shared_rs.release();
  1119     shared_rs.release();
  1095 #endif
  1120 #endif
  1096     // If -Xshare:on is specified, print out the error message and exit VM,
  1121     // If -Xshare:on is specified, print out the error message and exit VM,