src/hotspot/share/memory/filemap.cpp
branchstuefe-new-metaspace-branch
changeset 58107 69c38b90014c
parent 58063 bdf136b8ae0e
parent 58096 0d97bf7cf8a4
child 58199 595fcbebaa77
equal deleted inserted replaced
58099:5aeb07390c74 58107:69c38b90014c
    36 #include "logging/logMessage.hpp"
    36 #include "logging/logMessage.hpp"
    37 #include "memory/dynamicArchive.hpp"
    37 #include "memory/dynamicArchive.hpp"
    38 #include "memory/filemap.hpp"
    38 #include "memory/filemap.hpp"
    39 #include "memory/heapShared.inline.hpp"
    39 #include "memory/heapShared.inline.hpp"
    40 #include "memory/iterator.inline.hpp"
    40 #include "memory/iterator.inline.hpp"
       
    41 #include "memory/metadataFactory.hpp"
    41 #include "memory/metaspace.hpp"
    42 #include "memory/metaspace.hpp"
    42 #include "memory/metadataFactory.hpp"
       
    43 #include "memory/metaspaceClosure.hpp"
    43 #include "memory/metaspaceClosure.hpp"
    44 #include "memory/metaspaceShared.hpp"
    44 #include "memory/metaspaceShared.hpp"
    45 #include "memory/oopFactory.hpp"
    45 #include "memory/oopFactory.hpp"
    46 #include "memory/universe.hpp"
    46 #include "memory/universe.hpp"
    47 #include "oops/compressedOops.hpp"
    47 #include "oops/compressedOops.hpp"
   191     _dynamic_archive_info = this;
   191     _dynamic_archive_info = this;
   192     header_size = sizeof(DynamicArchiveHeader);
   192     header_size = sizeof(DynamicArchiveHeader);
   193   }
   193   }
   194   _header = (FileMapHeader*)os::malloc(header_size, mtInternal);
   194   _header = (FileMapHeader*)os::malloc(header_size, mtInternal);
   195   memset((void*)_header, 0, header_size);
   195   memset((void*)_header, 0, header_size);
   196   _header->_header_size = header_size;
   196   _header->set_header_size(header_size);
   197   _header->_version = INVALID_CDS_ARCHIVE_VERSION;
   197   _header->set_version(INVALID_CDS_ARCHIVE_VERSION);
   198   _header->_has_platform_or_app_classes = true;
   198   _header->set_has_platform_or_app_classes(true);
   199   _file_offset = 0;
   199   _file_offset = 0;
   200   _file_open = false;
   200   _file_open = false;
   201 }
   201 }
   202 
   202 
   203 FileMapInfo::~FileMapInfo() {
   203 FileMapInfo::~FileMapInfo() {
   209     _dynamic_archive_info = NULL;
   209     _dynamic_archive_info = NULL;
   210   }
   210   }
   211 }
   211 }
   212 
   212 
   213 void FileMapInfo::populate_header(size_t alignment) {
   213 void FileMapInfo::populate_header(size_t alignment) {
   214   _header->populate(this, alignment);
   214   header()->populate(this, alignment);
   215 }
   215 }
   216 
   216 
   217 void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
   217 void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
   218   if (DynamicDumpSharedSpaces) {
   218   if (DynamicDumpSharedSpaces) {
   219     _magic = CDS_DYNAMIC_ARCHIVE_MAGIC;
   219     _magic = CDS_DYNAMIC_ARCHIVE_MAGIC;
   659   // after generating the shared archive), which is acceptable. For most
   659   // after generating the shared archive), which is acceptable. For most
   660   // common cases, the dump time boot path might contain modules_image only.
   660   // common cases, the dump time boot path might contain modules_image only.
   661   char* runtime_boot_path = Arguments::get_sysclasspath();
   661   char* runtime_boot_path = Arguments::get_sysclasspath();
   662   char* rp = skip_first_path_entry(runtime_boot_path);
   662   char* rp = skip_first_path_entry(runtime_boot_path);
   663   assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   663   assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   664   int dp_len = _header->_app_class_paths_start_index - 1; // ignore the first path to the module image
   664   int dp_len = header()->app_class_paths_start_index() - 1; // ignore the first path to the module image
   665   bool mismatch = false;
   665   bool mismatch = false;
   666 
   666 
   667   bool relaxed_check = !header()->has_platform_or_app_classes();
   667   bool relaxed_check = !header()->has_platform_or_app_classes();
   668   if (dp_len == 0 && rp == NULL) {
   668   if (dp_len == 0 && rp == NULL) {
   669     return true;   // ok, both runtime and dump time boot paths have modules_images only
   669     return true;   // ok, both runtime and dump time boot paths have modules_images only
   722     //
   722     //
   723     // dump : -cp a.jar:NE1:NE2:b.jar  -> a.jar:b.jar -> recorded in archive.
   723     // dump : -cp a.jar:NE1:NE2:b.jar  -> a.jar:b.jar -> recorded in archive.
   724     // run 1: -cp NE3:a.jar:NE4:b.jar  -> a.jar:b.jar -> matched
   724     // run 1: -cp NE3:a.jar:NE4:b.jar  -> a.jar:b.jar -> matched
   725     // run 2: -cp x.jar:NE4:b.jar      -> x.jar:b.jar -> mismatched
   725     // run 2: -cp x.jar:NE4:b.jar      -> x.jar:b.jar -> mismatched
   726 
   726 
   727     int j = _header->_app_class_paths_start_index;
   727     int j = header()->app_class_paths_start_index();
   728     mismatch = check_paths(j, shared_app_paths_len, rp_array);
   728     mismatch = check_paths(j, shared_app_paths_len, rp_array);
   729     if (mismatch) {
   729     if (mismatch) {
   730       return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
   730       return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
   731     }
   731     }
   732   }
   732   }
   751   assert(UseSharedSpaces, "runtime only");
   751   assert(UseSharedSpaces, "runtime only");
   752 
   752 
   753   _validating_shared_path_table = true;
   753   _validating_shared_path_table = true;
   754 
   754 
   755   // Load the shared path table info from the archive header
   755   // Load the shared path table info from the archive header
   756   _shared_path_table = _header->_shared_path_table;
   756   _shared_path_table = header()->shared_path_table();
   757   if (DynamicDumpSharedSpaces) {
   757   if (DynamicDumpSharedSpaces) {
   758     // Only support dynamic dumping with the usage of the default CDS archive
   758     // Only support dynamic dumping with the usage of the default CDS archive
   759     // or a simple base archive.
   759     // or a simple base archive.
   760     // If the base layer archive contains additional path component besides
   760     // If the base layer archive contains additional path component besides
   761     // the runtime image and the -cp, dynamic dumping is disabled.
   761     // the runtime image and the -cp, dynamic dumping is disabled.
   762     //
   762     //
   763     // When dynamic archiving is enabled, the _shared_path_table is overwritten
   763     // When dynamic archiving is enabled, the _shared_path_table is overwritten
   764     // to include the application path and stored in the top layer archive.
   764     // to include the application path and stored in the top layer archive.
   765     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   765     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   766     if (_header->_app_class_paths_start_index > 1) {
   766     if (header()->app_class_paths_start_index() > 1) {
   767       DynamicDumpSharedSpaces = false;
   767       DynamicDumpSharedSpaces = false;
   768       warning(
   768       warning(
   769         "Dynamic archiving is disabled because base layer archive has appended boot classpath");
   769         "Dynamic archiving is disabled because base layer archive has appended boot classpath");
   770     }
   770     }
   771     if (_header->_num_module_paths > 0) {
   771     if (header()->num_module_paths() > 0) {
   772       DynamicDumpSharedSpaces = false;
   772       DynamicDumpSharedSpaces = false;
   773       warning(
   773       warning(
   774         "Dynamic archiving is disabled because base layer archive has module path");
   774         "Dynamic archiving is disabled because base layer archive has module path");
   775     }
   775     }
   776   }
   776   }
   777 
   777 
   778   log_paths("Expecting BOOT path=", 0, _header->_app_class_paths_start_index);
   778   log_paths("Expecting BOOT path=", 0, header()->app_class_paths_start_index());
   779   log_paths("Expecting -Djava.class.path=", _header->_app_class_paths_start_index, _header->_app_module_paths_start_index);
   779   log_paths("Expecting -Djava.class.path=", header()->app_class_paths_start_index(), header()->app_module_paths_start_index());
   780 
   780 
   781   int module_paths_start_index = _header->_app_module_paths_start_index;
   781   int module_paths_start_index = header()->app_module_paths_start_index();
   782   int shared_app_paths_len = 0;
   782   int shared_app_paths_len = 0;
   783 
   783 
   784   // validate the path entries up to the _max_used_path_index
   784   // validate the path entries up to the _max_used_path_index
   785   for (int i=0; i < _header->_max_used_path_index + 1; i++) {
   785   for (int i=0; i < header()->max_used_path_index() + 1; i++) {
   786     if (i < module_paths_start_index) {
   786     if (i < module_paths_start_index) {
   787       if (shared_path(i)->validate()) {
   787       if (shared_path(i)->validate()) {
   788         // Only count the app class paths not from the "Class-path" attribute of a jar manifest.
   788         // Only count the app class paths not from the "Class-path" attribute of a jar manifest.
   789         if (!shared_path(i)->from_class_path_attr() && i >= _header->_app_class_paths_start_index) {
   789         if (!shared_path(i)->from_class_path_attr() && i >= header()->app_class_paths_start_index()) {
   790           shared_app_paths_len++;
   790           shared_app_paths_len++;
   791         }
   791         }
   792         log_info(class, path)("ok");
   792         log_info(class, path)("ok");
   793       } else {
   793       } else {
   794         if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) {
   794         if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) {
   806         return false;
   806         return false;
   807       }
   807       }
   808     }
   808     }
   809   }
   809   }
   810 
   810 
   811   if (_header->_max_used_path_index == 0) {
   811   if (header()->max_used_path_index() == 0) {
   812     // default archive only contains the module image in the bootclasspath
   812     // default archive only contains the module image in the bootclasspath
   813     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   813     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
   814   } else {
   814   } else {
   815     if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) {
   815     if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) {
   816       fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
   816       fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
   840   // it will change how classes are loading for the app loader. For safety, disable
   840   // it will change how classes are loading for the app loader. For safety, disable
   841   // loading of archived platform/app classes (currently there's no way to disable just the
   841   // loading of archived platform/app classes (currently there's no way to disable just the
   842   // app classes).
   842   // app classes).
   843 
   843 
   844   assert(UseSharedSpaces, "runtime only");
   844   assert(UseSharedSpaces, "runtime only");
   845   for (int i = _header->_app_module_paths_start_index + _header->_num_module_paths;
   845   for (int i = header()->app_module_paths_start_index() + header()->num_module_paths();
   846        i < get_number_of_shared_paths();
   846        i < get_number_of_shared_paths();
   847        i++) {
   847        i++) {
   848     SharedClassPathEntry* ent = shared_path(i);
   848     SharedClassPathEntry* ent = shared_path(i);
   849     if (!ent->check_non_existent()) {
   849     if (!ent->check_non_existent()) {
   850       warning("Archived non-system classes are disabled because the "
   850       warning("Archived non-system classes are disabled because the "
   851               "file %s exists", ent->name());
   851               "file %s exists", ent->name());
   852       _header->_has_platform_or_app_classes = false;
   852       header()->set_has_platform_or_app_classes(false);
   853     }
   853     }
   854   }
   854   }
   855 }
   855 }
   856 
   856 
   857 bool FileMapInfo::check_archive(const char* archive_name, bool is_static) {
   857 bool FileMapInfo::check_archive(const char* archive_name, bool is_static) {
   873     vm_exit_during_initialization("Unable to read header from shared archive", archive_name);
   873     vm_exit_during_initialization("Unable to read header from shared archive", archive_name);
   874     return false;
   874     return false;
   875   }
   875   }
   876   if (is_static) {
   876   if (is_static) {
   877     FileMapHeader* static_header = (FileMapHeader*)header;
   877     FileMapHeader* static_header = (FileMapHeader*)header;
   878     if (static_header->_magic != CDS_ARCHIVE_MAGIC) {
   878     if (static_header->magic() != CDS_ARCHIVE_MAGIC) {
   879       os::free(header);
   879       os::free(header);
   880       os::close(fd);
   880       os::close(fd);
   881       vm_exit_during_initialization("Not a base shared archive", archive_name);
   881       vm_exit_during_initialization("Not a base shared archive", archive_name);
   882       return false;
   882       return false;
   883     }
   883     }
   884   } else {
   884   } else {
   885     DynamicArchiveHeader* dynamic_header = (DynamicArchiveHeader*)header;
   885     DynamicArchiveHeader* dynamic_header = (DynamicArchiveHeader*)header;
   886     if (dynamic_header->_magic != CDS_DYNAMIC_ARCHIVE_MAGIC) {
   886     if (dynamic_header->magic() != CDS_DYNAMIC_ARCHIVE_MAGIC) {
   887       os::free(header);
   887       os::free(header);
   888       os::close(fd);
   888       os::close(fd);
   889       vm_exit_during_initialization("Not a top shared archive", archive_name);
   889       vm_exit_during_initialization("Not a top shared archive", archive_name);
   890       return false;
   890       return false;
   891     }
   891     }
   911     fail_continue("Unable to read the file header.");
   911     fail_continue("Unable to read the file header.");
   912     os::free(dynamic_header);
   912     os::free(dynamic_header);
   913     os::close(fd);
   913     os::close(fd);
   914     return false;
   914     return false;
   915   }
   915   }
   916   if (dynamic_header->_magic != CDS_DYNAMIC_ARCHIVE_MAGIC) {
   916   if (dynamic_header->magic() != CDS_DYNAMIC_ARCHIVE_MAGIC) {
   917     // Not a dynamic header, no need to proceed further.
   917     // Not a dynamic header, no need to proceed further.
   918     *size = 0;
   918     *size = 0;
   919     os::free(dynamic_header);
   919     os::free(dynamic_header);
   920     os::close(fd);
   920     os::close(fd);
   921     return false;
   921     return false;
   922   }
   922   }
   923   if (dynamic_header->_base_archive_is_default) {
   923   if (dynamic_header->base_archive_is_default()) {
   924     *base_archive_name = Arguments::get_default_shared_archive_path();
   924     *base_archive_name = Arguments::get_default_shared_archive_path();
   925   } else {
   925   } else {
   926     // read the base archive name
   926     // read the base archive name
   927     size_t name_size = dynamic_header->_base_archive_name_size;
   927     size_t name_size = dynamic_header->base_archive_name_size();
   928     if (name_size == 0) {
   928     if (name_size == 0) {
   929       os::free(dynamic_header);
   929       os::free(dynamic_header);
   930       os::close(fd);
   930       os::close(fd);
   931       return false;
   931       return false;
   932     }
   932     }
   946   os::close(fd);
   946   os::close(fd);
   947   return true;
   947   return true;
   948 }
   948 }
   949 
   949 
   950 void FileMapInfo::restore_shared_path_table() {
   950 void FileMapInfo::restore_shared_path_table() {
   951   _shared_path_table = _current_info->_header->_shared_path_table;
   951   _shared_path_table = _current_info->header()->shared_path_table();
   952 }
   952 }
   953 
   953 
   954 // Read the FileMapInfo information from the file.
   954 // Read the FileMapInfo information from the file.
   955 
   955 
   956 bool FileMapInfo::init_from_file(int fd, bool is_static) {
   956 bool FileMapInfo::init_from_file(int fd, bool is_static) {
   957   size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader);
   957   size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader);
   958   size_t n = os::read(fd, _header, (unsigned int)sz);
   958   size_t n = os::read(fd, header(), (unsigned int)sz);
   959   if (n != sz) {
   959   if (n != sz) {
   960     fail_continue("Unable to read the file header.");
   960     fail_continue("Unable to read the file header.");
   961     return false;
   961     return false;
   962   }
   962   }
   963 
   963 
   965     FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
   965     FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
   966     return false;
   966     return false;
   967   }
   967   }
   968 
   968 
   969   unsigned int expected_magic = is_static ? CDS_ARCHIVE_MAGIC : CDS_DYNAMIC_ARCHIVE_MAGIC;
   969   unsigned int expected_magic = is_static ? CDS_ARCHIVE_MAGIC : CDS_DYNAMIC_ARCHIVE_MAGIC;
   970   if (_header->_magic != expected_magic) {
   970   if (header()->magic() != expected_magic) {
   971     log_info(cds)("_magic expected: 0x%08x", expected_magic);
   971     log_info(cds)("_magic expected: 0x%08x", expected_magic);
   972     log_info(cds)("         actual: 0x%08x", _header->_magic);
   972     log_info(cds)("         actual: 0x%08x", header()->magic());
   973     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
   973     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
   974     return false;
   974     return false;
   975   }
   975   }
   976 
   976 
   977   if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
   977   if (header()->version() != CURRENT_CDS_ARCHIVE_VERSION) {
   978     log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION);
   978     log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION);
   979     log_info(cds)("           actual: %d", _header->_version);
   979     log_info(cds)("           actual: %d", header()->version());
   980     fail_continue("The shared archive file has the wrong version.");
   980     fail_continue("The shared archive file has the wrong version.");
   981     return false;
   981     return false;
   982   }
   982   }
   983 
   983 
   984   if (_header->_header_size != sz) {
   984   if (header()->header_size() != sz) {
   985     log_info(cds)("_header_size expected: " SIZE_FORMAT, sz);
   985     log_info(cds)("_header_size expected: " SIZE_FORMAT, sz);
   986     log_info(cds)("               actual: " SIZE_FORMAT, _header->_header_size);
   986     log_info(cds)("               actual: " SIZE_FORMAT, header()->header_size());
   987     FileMapInfo::fail_continue("The shared archive file has an incorrect header size.");
   987     FileMapInfo::fail_continue("The shared archive file has an incorrect header size.");
   988     return false;
   988     return false;
   989   }
   989   }
   990 
   990 
   991   if (_header->_jvm_ident[JVM_IDENT_MAX-1] != 0) {
   991   const char* actual_ident = header()->jvm_ident();
       
   992 
       
   993   if (actual_ident[JVM_IDENT_MAX-1] != 0) {
   992     FileMapInfo::fail_continue("JVM version identifier is corrupted.");
   994     FileMapInfo::fail_continue("JVM version identifier is corrupted.");
   993     return false;
   995     return false;
   994   }
   996   }
   995 
   997 
   996   char header_version[JVM_IDENT_MAX];
   998   char expected_ident[JVM_IDENT_MAX];
   997   get_header_version(header_version);
   999   get_header_version(expected_ident);
   998   if (strncmp(_header->_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
  1000   if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
   999     log_info(cds)("_jvm_ident expected: %s", header_version);
  1001     log_info(cds)("_jvm_ident expected: %s", expected_ident);
  1000     log_info(cds)("             actual: %s", _header->_jvm_ident);
  1002     log_info(cds)("             actual: %s", actual_ident);
  1001     FileMapInfo::fail_continue("The shared archive file was created by a different"
  1003     FileMapInfo::fail_continue("The shared archive file was created by a different"
  1002                   " version or build of HotSpot");
  1004                   " version or build of HotSpot");
  1003     return false;
  1005     return false;
  1004   }
  1006   }
  1005 
  1007 
  1006   if (VerifySharedSpaces) {
  1008   if (VerifySharedSpaces) {
  1007     int expected_crc = _header->compute_crc();
  1009     int expected_crc = header()->compute_crc();
  1008     if (expected_crc != _header->_crc) {
  1010     if (expected_crc != header()->crc()) {
  1009       log_info(cds)("_crc expected: %d", expected_crc);
  1011       log_info(cds)("_crc expected: %d", expected_crc);
  1010       log_info(cds)("       actual: %d", _header->_crc);
  1012       log_info(cds)("       actual: %d", header()->crc());
  1011       FileMapInfo::fail_continue("Header checksum verification failed.");
  1013       FileMapInfo::fail_continue("Header checksum verification failed.");
  1012       return false;
  1014       return false;
  1013     }
  1015     }
  1014   }
  1016   }
  1015 
  1017 
  1016   _file_offset = n + _header->_base_archive_name_size; // accounts for the size of _base_archive_name
  1018   _file_offset = n + header()->base_archive_name_size(); // accounts for the size of _base_archive_name
  1017 
  1019 
  1018   if (is_static) {
  1020   if (is_static) {
  1019     // just checking the last region is sufficient since the archive is written
  1021     // just checking the last region is sufficient since the archive is written
  1020     // in sequential order
  1022     // in sequential order
  1021     size_t len = lseek(fd, 0, SEEK_END);
  1023     size_t len = lseek(fd, 0, SEEK_END);
  1022     CDSFileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
  1024     FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
  1023     // The last space might be empty
  1025     // The last space might be empty
  1024     if (si->_file_offset > len || len - si->_file_offset < si->_used) {
  1026     if (si->file_offset() > len || len - si->file_offset() < si->used()) {
  1025       fail_continue("The shared archive file has been truncated.");
  1027       fail_continue("The shared archive file has been truncated.");
  1026       return false;
  1028       return false;
  1027     }
  1029     }
  1028 
  1030 
  1029     SharedBaseAddress = _header->_shared_base_address;
  1031     SharedBaseAddress = header()->shared_base_address();
  1030   }
  1032   }
  1031 
  1033 
  1032   return true;
  1034   return true;
  1033 }
  1035 }
  1034 
  1036 
  1094 
  1096 
  1095 // Write the header to the file, seek to the next allocation boundary.
  1097 // Write the header to the file, seek to the next allocation boundary.
  1096 
  1098 
  1097 void FileMapInfo::write_header() {
  1099 void FileMapInfo::write_header() {
  1098   char* base_archive_name = NULL;
  1100   char* base_archive_name = NULL;
  1099   if (_header->_magic == CDS_DYNAMIC_ARCHIVE_MAGIC) {
  1101   if (header()->magic() == CDS_DYNAMIC_ARCHIVE_MAGIC) {
  1100     base_archive_name = (char*)Arguments::GetSharedArchivePath();
  1102     base_archive_name = (char*)Arguments::GetSharedArchivePath();
  1101     _header->_base_archive_name_size = (int)strlen(base_archive_name) + 1;
  1103     header()->set_base_archive_name_size(strlen(base_archive_name) + 1);
  1102     _header->_base_archive_is_default = FLAG_IS_DEFAULT(SharedArchiveFile);
  1104     header()->set_base_archive_is_default(FLAG_IS_DEFAULT(SharedArchiveFile));
  1103   }
  1105   }
  1104 
  1106 
  1105   assert(is_file_position_aligned(), "must be");
  1107   assert(is_file_position_aligned(), "must be");
  1106   write_bytes(_header, _header->_header_size);
  1108   write_bytes(header(), header()->header_size());
  1107   if (base_archive_name != NULL) {
  1109   if (base_archive_name != NULL) {
  1108     write_bytes(base_archive_name, (size_t)_header->_base_archive_name_size);
  1110     write_bytes(base_archive_name, header()->base_archive_name_size());
  1109   }
  1111   }
  1110   align_file_position();
  1112   align_file_position();
       
  1113 }
       
  1114 
       
  1115 void FileMapRegion::init(bool is_heap_region, char* base, size_t size, bool read_only,
       
  1116                          bool allow_exec, int crc) {
       
  1117   _is_heap_region = is_heap_region;
       
  1118 
       
  1119   if (is_heap_region) {
       
  1120     assert(!DynamicDumpSharedSpaces, "must be");
       
  1121     assert((base - (char*)CompressedKlassPointers::base()) % HeapWordSize == 0, "Sanity");
       
  1122     if (base != NULL) {
       
  1123       _addr._offset = (intx)CompressedOops::encode_not_null((oop)base);
       
  1124     } else {
       
  1125       _addr._offset = 0;
       
  1126     }
       
  1127   } else {
       
  1128     _addr._base = base;
       
  1129   }
       
  1130   _used = size;
       
  1131   _read_only = read_only;
       
  1132   _allow_exec = allow_exec;
       
  1133   _crc = crc;
  1111 }
  1134 }
  1112 
  1135 
  1113 // Dump region to file.
  1136 // Dump region to file.
  1114 // This is called twice for each region during archiving, once before
  1137 // This is called twice for each region during archiving, once before
  1115 // the archive file is open (_file_open is false) and once after.
  1138 // the archive file is open (_file_open is false) and once after.
  1116 void FileMapInfo::write_region(int region, char* base, size_t size,
  1139 void FileMapInfo::write_region(int region, char* base, size_t size,
  1117                                bool read_only, bool allow_exec) {
  1140                                bool read_only, bool allow_exec) {
  1118   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Dump time only");
  1141   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Dump time only");
  1119 
  1142 
  1120   CDSFileMapRegion* si = space_at(region);
  1143   FileMapRegion* si = space_at(region);
  1121   char* target_base = base;
  1144   char* target_base = base;
  1122   if (DynamicDumpSharedSpaces) {
  1145   if (DynamicDumpSharedSpaces) {
       
  1146     assert(!HeapShared::is_heap_region(region), "dynamic archive doesn't support heap regions");
  1123     target_base = DynamicArchive::buffer_to_target(base);
  1147     target_base = DynamicArchive::buffer_to_target(base);
  1124   }
  1148   }
  1125 
  1149 
  1126   if (_file_open) {
  1150   if (_file_open) {
  1127     guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
  1151     guarantee(si->file_offset() == _file_offset, "file offset mismatch.");
  1128     log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08)
  1152     log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08)
  1129                   " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
  1153                   " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
  1130                   region, size, p2i(target_base), _file_offset);
  1154                   region, size, p2i(target_base), _file_offset);
  1131   } else {
  1155   } else {
  1132     si->_file_offset = _file_offset;
  1156     si->set_file_offset(_file_offset);
  1133   }
  1157   }
  1134 
  1158 
  1135   if (HeapShared::is_heap_region(region)) {
  1159   int crc = ClassLoader::crc32(0, base, (jint)size);
  1136     assert((target_base - (char*)CompressedKlassPointers::base()) % HeapWordSize == 0, "Sanity");
  1160   si->init(HeapShared::is_heap_region(region), target_base, size, read_only, allow_exec, crc);
  1137     if (target_base != NULL) {
  1161 
  1138       si->_addr._offset = (intx)CompressedOops::encode_not_null((oop)target_base);
       
  1139     } else {
       
  1140       si->_addr._offset = 0;
       
  1141     }
       
  1142   } else {
       
  1143     si->_addr._base = target_base;
       
  1144   }
       
  1145   si->_used = size;
       
  1146   si->_read_only = read_only;
       
  1147   si->_allow_exec = allow_exec;
       
  1148 
       
  1149   // Use the current 'base' when computing the CRC value and writing out data
       
  1150   si->_crc = ClassLoader::crc32(0, base, (jint)size);
       
  1151   if (base != NULL) {
  1162   if (base != NULL) {
  1152     write_bytes_aligned(base, size);
  1163     write_bytes_aligned(base, size);
  1153   }
  1164   }
  1154 }
  1165 }
  1155 
  1166 
  1215       log_info(cds)("Archive heap region %d " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes",
  1226       log_info(cds)("Archive heap region %d " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes",
  1216                     i, p2i(start), p2i(start + size), size);
  1227                     i, p2i(start), p2i(start + size), size);
  1217     }
  1228     }
  1218     write_region(i, start, size, false, false);
  1229     write_region(i, start, size, false, false);
  1219     if (size > 0) {
  1230     if (size > 0) {
  1220       space_at(i)->_oopmap = oopmaps->at(arr_idx)._oopmap;
  1231       space_at(i)->init_oopmap(oopmaps->at(arr_idx)._oopmap,
  1221       space_at(i)->_oopmap_size_in_bits = oopmaps->at(arr_idx)._oopmap_size_in_bits;
  1232                                oopmaps->at(arr_idx)._oopmap_size_in_bits);
  1222     }
  1233     }
  1223   }
  1234   }
  1224   return total_size;
  1235   return total_size;
  1225 }
  1236 }
  1226 
  1237 
  1289 
  1300 
  1290 // JVM/TI RedefineClasses() support:
  1301 // JVM/TI RedefineClasses() support:
  1291 // Remap the shared readonly space to shared readwrite, private.
  1302 // Remap the shared readonly space to shared readwrite, private.
  1292 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
  1303 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
  1293   int idx = MetaspaceShared::ro;
  1304   int idx = MetaspaceShared::ro;
  1294   CDSFileMapRegion* si = space_at(idx);
  1305   FileMapRegion* si = space_at(idx);
  1295   if (!si->_read_only) {
  1306   if (!si->read_only()) {
  1296     // the space is already readwrite so we are done
  1307     // the space is already readwrite so we are done
  1297     return true;
  1308     return true;
  1298   }
  1309   }
  1299   size_t used = si->_used;
  1310   size_t used = si->used();
  1300   size_t size = align_up(used, os::vm_allocation_granularity());
  1311   size_t size = align_up(used, os::vm_allocation_granularity());
  1301   if (!open_for_read()) {
  1312   if (!open_for_read()) {
  1302     return false;
  1313     return false;
  1303   }
  1314   }
  1304   char *addr = region_addr(idx);
  1315   char *addr = region_addr(idx);
  1305   char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
  1316   char *base = os::remap_memory(_fd, _full_path, si->file_offset(),
  1306                                 addr, size, false /* !read_only */,
  1317                                 addr, size, false /* !read_only */,
  1307                                 si->_allow_exec);
  1318                                 si->allow_exec());
  1308   close();
  1319   close();
  1309   // These have to be errors because the shared region is now unmapped.
  1320   // These have to be errors because the shared region is now unmapped.
  1310   if (base == NULL) {
  1321   if (base == NULL) {
  1311     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
  1322     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
  1312     vm_exit(1);
  1323     vm_exit(1);
  1313   }
  1324   }
  1314   if (base != addr) {
  1325   if (base != addr) {
  1315     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
  1326     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
  1316     vm_exit(1);
  1327     vm_exit(1);
  1317   }
  1328   }
  1318   si->_read_only = false;
  1329   si->set_read_only(false);
  1319   return true;
  1330   return true;
  1320 }
  1331 }
  1321 
  1332 
  1322 // Map the whole region at once, assumed to be allocated contiguously.
  1333 // Map the whole region at once, assumed to be allocated contiguously.
  1323 ReservedSpace FileMapInfo::reserve_shared_memory() {
  1334 ReservedSpace FileMapInfo::reserve_shared_memory() {
  1366   return curr_top;
  1377   return curr_top;
  1367 }
  1378 }
  1368 
  1379 
  1369 char* FileMapInfo::map_region(int i, char** top_ret) {
  1380 char* FileMapInfo::map_region(int i, char** top_ret) {
  1370   assert(!HeapShared::is_heap_region(i), "sanity");
  1381   assert(!HeapShared::is_heap_region(i), "sanity");
  1371   CDSFileMapRegion* si = space_at(i);
  1382   FileMapRegion* si = space_at(i);
  1372   size_t used = si->_used;
  1383   size_t used = si->used();
  1373   size_t alignment = Metaspace::reserve_alignment();
  1384   size_t alignment = Metaspace::reserve_alignment();
  1374   size_t size = align_up(used, alignment);
  1385   size_t size = align_up(used, alignment);
  1375   char *requested_addr = region_addr(i);
  1386   char *requested_addr = region_addr(i);
  1376 
  1387 
  1377 #ifdef _WINDOWS
  1388 #ifdef _WINDOWS
  1378   // Windows cannot remap read-only shared memory to read-write when required for
  1389   // Windows cannot remap read-only shared memory to read-write when required for
  1379   // RedefineClasses, which is also used by JFR.  Always map windows regions as RW.
  1390   // RedefineClasses, which is also used by JFR.  Always map windows regions as RW.
  1380   si->_read_only = false;
  1391   si->set_read_only(false);
  1381 #else
  1392 #else
  1382   // If a tool agent is in use (debugging enabled), or JFR, we must map the address space RW
  1393   // If a tool agent is in use (debugging enabled), or JFR, we must map the address space RW
  1383   if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space() ||
  1394   if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space() ||
  1384       Arguments::has_jfr_option()) {
  1395       Arguments::has_jfr_option()) {
  1385     si->_read_only = false;
  1396     si->set_read_only(false);
  1386   }
  1397   }
  1387 #endif // _WINDOWS
  1398 #endif // _WINDOWS
  1388 
  1399 
  1389   // map the contents of the CDS archive in this memory
  1400   // map the contents of the CDS archive in this memory
  1390   char *base = os::map_memory(_fd, _full_path, si->_file_offset,
  1401   char *base = os::map_memory(_fd, _full_path, si->file_offset(),
  1391                               requested_addr, size, si->_read_only,
  1402                               requested_addr, size, si->read_only(),
  1392                               si->_allow_exec);
  1403                               si->allow_exec());
  1393   if (base == NULL || base != requested_addr) {
  1404   if (base == NULL || base != requested_addr) {
  1394     fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
  1405     fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
  1395     _memory_mapping_failed = true;
  1406     _memory_mapping_failed = true;
  1396     return NULL;
  1407     return NULL;
  1397   }
  1408   }
  1419   }
  1430   }
  1420   _file_offset += count;
  1431   _file_offset += count;
  1421   return count;
  1432   return count;
  1422 }
  1433 }
  1423 
  1434 
  1424 address FileMapInfo::decode_start_address(CDSFileMapRegion* spc, bool with_current_oop_encoding_mode) {
  1435 address FileMapInfo::decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode) {
  1425   if (with_current_oop_encoding_mode) {
  1436   if (with_current_oop_encoding_mode) {
  1426     return (address)CompressedOops::decode_not_null(offset_of_space(spc));
  1437     return (address)CompressedOops::decode_not_null(spc->offset());
  1427   } else {
  1438   } else {
  1428     return (address)HeapShared::decode_from_archive(offset_of_space(spc));
  1439     return (address)HeapShared::decode_from_archive(spc->offset());
  1429   }
  1440   }
  1430 }
  1441 }
  1431 
  1442 
  1432 static MemRegion *closed_archive_heap_ranges = NULL;
  1443 static MemRegion *closed_archive_heap_ranges = NULL;
  1433 static MemRegion *open_archive_heap_ranges = NULL;
  1444 static MemRegion *open_archive_heap_ranges = NULL;
  1434 static int num_closed_archive_heap_ranges = 0;
  1445 static int num_closed_archive_heap_ranges = 0;
  1435 static int num_open_archive_heap_ranges = 0;
  1446 static int num_open_archive_heap_ranges = 0;
  1436 
  1447 
  1437 #if INCLUDE_CDS_JAVA_HEAP
  1448 #if INCLUDE_CDS_JAVA_HEAP
  1438 bool FileMapInfo::has_heap_regions() {
  1449 bool FileMapInfo::has_heap_regions() {
  1439   return (_header->_space[MetaspaceShared::first_closed_archive_heap_region]._used > 0);
  1450   return (space_at(MetaspaceShared::first_closed_archive_heap_region)->used() > 0);
  1440 }
  1451 }
  1441 
  1452 
  1442 // Returns the address range of the archived heap regions computed using the
  1453 // Returns the address range of the archived heap regions computed using the
  1443 // current oop encoding mode. This range may be different than the one seen at
  1454 // current oop encoding mode. This range may be different than the one seen at
  1444 // dump time due to encoding mode differences. The result is used in determining
  1455 // dump time due to encoding mode differences. The result is used in determining
  1448   address end   = NULL;
  1459   address end   = NULL;
  1449 
  1460 
  1450   for (int i = MetaspaceShared::first_closed_archive_heap_region;
  1461   for (int i = MetaspaceShared::first_closed_archive_heap_region;
  1451            i <= MetaspaceShared::last_valid_region;
  1462            i <= MetaspaceShared::last_valid_region;
  1452            i++) {
  1463            i++) {
  1453     CDSFileMapRegion* si = space_at(i);
  1464     FileMapRegion* si = space_at(i);
  1454     size_t size = si->_used;
  1465     size_t size = si->used();
  1455     if (size > 0) {
  1466     if (size > 0) {
  1456       address s = start_address_as_decoded_with_current_oop_encoding_mode(si);
  1467       address s = start_address_as_decoded_with_current_oop_encoding_mode(si);
  1457       address e = s + size;
  1468       address e = s + size;
  1458       if (start > s) {
  1469       if (start > s) {
  1459         start = s;
  1470         start = s;
  1545     //
  1556     //
  1546     // At dump time, the archived heap regions were near the top of the heap.
  1557     // At dump time, the archived heap regions were near the top of the heap.
  1547     // At run time, they may not be inside the heap, so we move them so
  1558     // At run time, they may not be inside the heap, so we move them so
  1548     // that they are now near the top of the runtime time. This can be done by
  1559     // that they are now near the top of the runtime time. This can be done by
  1549     // the simple math of adding the delta as shown above.
  1560     // the simple math of adding the delta as shown above.
  1550     address dumptime_heap_end = (address)_header->_heap_end;
  1561     address dumptime_heap_end = header()->heap_end();
  1551     address runtime_heap_end = (address)CompressedOops::end();
  1562     address runtime_heap_end = (address)CompressedOops::end();
  1552     delta = runtime_heap_end - dumptime_heap_end;
  1563     delta = runtime_heap_end - dumptime_heap_end;
  1553   }
  1564   }
  1554 
  1565 
  1555   log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta);
  1566   log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta);
  1556   HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
  1567   HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
  1557 
  1568 
  1558   CDSFileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region);
  1569   FileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region);
  1559   address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
  1570   address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
  1560   if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) {
  1571   if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) {
  1561     // Align the bottom of the closed archive heap regions at G1 region boundary.
  1572     // Align the bottom of the closed archive heap regions at G1 region boundary.
  1562     // This will avoid the situation where the highest open region and the lowest
  1573     // This will avoid the situation where the highest open region and the lowest
  1563     // closed region sharing the same G1 region. Otherwise we will fail to map the
  1574     // closed region sharing the same G1 region. Otherwise we will fail to map the
  1608 }
  1619 }
  1609 
  1620 
  1610 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
  1621 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
  1611                                 int max, int* num, bool is_open_archive) {
  1622                                 int max, int* num, bool is_open_archive) {
  1612   MemRegion * regions = new MemRegion[max];
  1623   MemRegion * regions = new MemRegion[max];
  1613   CDSFileMapRegion* si;
  1624   FileMapRegion* si;
  1614   int region_num = 0;
  1625   int region_num = 0;
  1615 
  1626 
  1616   for (int i = first;
  1627   for (int i = first;
  1617            i < first + max; i++) {
  1628            i < first + max; i++) {
  1618     si = space_at(i);
  1629     si = space_at(i);
  1619     size_t size = si->_used;
  1630     size_t size = si->used();
  1620     if (size > 0) {
  1631     if (size > 0) {
  1621       HeapWord* start = (HeapWord*)start_address_as_decoded_from_archive(si);
  1632       HeapWord* start = (HeapWord*)start_address_as_decoded_from_archive(si);
  1622       regions[region_num] = MemRegion(start, size / HeapWordSize);
  1633       regions[region_num] = MemRegion(start, size / HeapWordSize);
  1623       region_num ++;
  1634       region_num ++;
  1624       log_info(cds)("Trying to map heap data: region[%d] at " INTPTR_FORMAT ", size = " SIZE_FORMAT_W(8) " bytes",
  1635       log_info(cds)("Trying to map heap data: region[%d] at " INTPTR_FORMAT ", size = " SIZE_FORMAT_W(8) " bytes",
  1647   // for mapped regions as they are part of the reserved java heap, which is
  1658   // for mapped regions as they are part of the reserved java heap, which is
  1648   // already recorded.
  1659   // already recorded.
  1649   for (int i = 0; i < region_num; i++) {
  1660   for (int i = 0; i < region_num; i++) {
  1650     si = space_at(first + i);
  1661     si = space_at(first + i);
  1651     char* addr = (char*)regions[i].start();
  1662     char* addr = (char*)regions[i].start();
  1652     char* base = os::map_memory(_fd, _full_path, si->_file_offset,
  1663     char* base = os::map_memory(_fd, _full_path, si->file_offset(),
  1653                                 addr, regions[i].byte_size(), si->_read_only,
  1664                                 addr, regions[i].byte_size(), si->read_only(),
  1654                                 si->_allow_exec);
  1665                                 si->allow_exec());
  1655     if (base == NULL || base != addr) {
  1666     if (base == NULL || base != addr) {
  1656       // dealloc the regions from java heap
  1667       // dealloc the regions from java heap
  1657       dealloc_archive_heap_regions(regions, region_num, is_open_archive);
  1668       dealloc_archive_heap_regions(regions, region_num, is_open_archive);
  1658       log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
  1669       log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
  1659                     INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
  1670                     INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
  1660                     p2i(addr), regions[i].byte_size());
  1671                     p2i(addr), regions[i].byte_size());
  1661       return false;
  1672       return false;
  1662     }
  1673     }
  1663 
  1674 
  1664     if (VerifySharedSpaces && !region_crc_check(addr, regions[i].byte_size(), si->_crc)) {
  1675     if (VerifySharedSpaces && !region_crc_check(addr, regions[i].byte_size(), si->crc())) {
  1665       // dealloc the regions from java heap
  1676       // dealloc the regions from java heap
  1666       dealloc_archive_heap_regions(regions, region_num, is_open_archive);
  1677       dealloc_archive_heap_regions(regions, region_num, is_open_archive);
  1667       log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
  1678       log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
  1668       return false;
  1679       return false;
  1669     }
  1680     }
  1690 }
  1701 }
  1691 
  1702 
  1692 void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges,
  1703 void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges,
  1693                                                         int first_region_idx) {
  1704                                                         int first_region_idx) {
  1694   for (int i=0; i<num_ranges; i++) {
  1705   for (int i=0; i<num_ranges; i++) {
  1695     CDSFileMapRegion* si = space_at(i + first_region_idx);
  1706     FileMapRegion* si = space_at(i + first_region_idx);
  1696     HeapShared::patch_archived_heap_embedded_pointers(ranges[i], (address)si->_oopmap,
  1707     HeapShared::patch_archived_heap_embedded_pointers(ranges[i], (address)si->oopmap(),
  1697                                                       si->_oopmap_size_in_bits);
  1708                                                       si->oopmap_size_in_bits());
  1698   }
  1709   }
  1699 }
  1710 }
  1700 
  1711 
  1701 // This internally allocates objects using SystemDictionary::Object_klass(), so it
  1712 // This internally allocates objects using SystemDictionary::Object_klass(), so it
  1702 // must be called after the well-known classes are resolved.
  1713 // must be called after the well-known classes are resolved.
  1736   return true;
  1747   return true;
  1737 }
  1748 }
  1738 
  1749 
  1739 bool FileMapInfo::verify_region_checksum(int i) {
  1750 bool FileMapInfo::verify_region_checksum(int i) {
  1740   assert(VerifySharedSpaces, "sanity");
  1751   assert(VerifySharedSpaces, "sanity");
  1741 
  1752   size_t sz = space_at(i)->used();
  1742   size_t sz = space_at(i)->_used;
       
  1743 
  1753 
  1744   if (sz == 0) {
  1754   if (sz == 0) {
  1745     return true; // no data
  1755     return true; // no data
  1746   }
  1756   } else {
  1747 
  1757     return region_crc_check(region_addr(i), sz, space_at(i)->crc());
  1748   return region_crc_check(region_addr(i), sz, space_at(i)->_crc);
  1758   }
  1749 }
  1759 }
  1750 
  1760 
  1751 void FileMapInfo::unmap_regions(int regions[], char* saved_base[], size_t len) {
  1761 void FileMapInfo::unmap_regions(int regions[], char* saved_base[], size_t len) {
  1752   for (int i = 0; i < (int)len; i++) {
  1762   for (int i = 0; i < (int)len; i++) {
  1753     if (saved_base[i] != NULL) {
  1763     if (saved_base[i] != NULL) {
  1758 
  1768 
  1759 // Unmap a memory region in the address space.
  1769 // Unmap a memory region in the address space.
  1760 
  1770 
  1761 void FileMapInfo::unmap_region(int i) {
  1771 void FileMapInfo::unmap_region(int i) {
  1762   assert(!HeapShared::is_heap_region(i), "sanity");
  1772   assert(!HeapShared::is_heap_region(i), "sanity");
  1763   CDSFileMapRegion* si = space_at(i);
  1773   FileMapRegion* si = space_at(i);
  1764   size_t used = si->_used;
  1774   size_t used = si->used();
  1765   size_t size = align_up(used, os::vm_allocation_granularity());
  1775   size_t size = align_up(used, os::vm_allocation_granularity());
  1766 
  1776 
  1767   if (used == 0) {
  1777   if (used == 0) {
  1768     return;
  1778     return;
  1769   }
  1779   }
  1826   }
  1836   }
  1827   return true;
  1837   return true;
  1828 }
  1838 }
  1829 
  1839 
  1830 char* FileMapInfo::region_addr(int idx) {
  1840 char* FileMapInfo::region_addr(int idx) {
  1831   CDSFileMapRegion* si = space_at(idx);
  1841   FileMapRegion* si = space_at(idx);
  1832   if (HeapShared::is_heap_region(idx)) {
  1842   if (HeapShared::is_heap_region(idx)) {
  1833     assert(DumpSharedSpaces, "The following doesn't work at runtime");
  1843     assert(DumpSharedSpaces, "The following doesn't work at runtime");
  1834     return si->_used > 0 ?
  1844     return si->used() > 0 ?
  1835           (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
  1845           (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
  1836   } else {
  1846   } else {
  1837     return si->_addr._base;
  1847     return si->base();
  1838   }
  1848   }
  1839 }
  1849 }
  1840 
  1850 
  1841 int FileMapHeader::compute_crc() {
  1851 int FileMapHeader::compute_crc() {
  1842   char* start = (char*)this;
  1852   char* start = (char*)this;
  1901 
  1911 
  1902   return true;
  1912   return true;
  1903 }
  1913 }
  1904 
  1914 
  1905 bool FileMapInfo::validate_header(bool is_static) {
  1915 bool FileMapInfo::validate_header(bool is_static) {
  1906   return _header->validate();
  1916   return header()->validate();
  1907 }
  1917 }
  1908 
  1918 
  1909 // Check if a given address is within one of the shared regions
  1919 // Check if a given address is within one of the shared regions
  1910 bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
  1920 bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
  1911   assert(idx == MetaspaceShared::ro ||
  1921   assert(idx == MetaspaceShared::ro ||
  1912          idx == MetaspaceShared::rw ||
  1922          idx == MetaspaceShared::rw ||
  1913          idx == MetaspaceShared::mc ||
  1923          idx == MetaspaceShared::mc ||
  1914          idx == MetaspaceShared::md, "invalid region index");
  1924          idx == MetaspaceShared::md, "invalid region index");
  1915   char* base = region_addr(idx);
  1925   char* base = region_addr(idx);
  1916   if (p >= base && p < base + space_at(idx)->_used) {
  1926   if (p >= base && p < base + space_at(idx)->used()) {
  1917     return true;
  1927     return true;
  1918   }
  1928   }
  1919   return false;
  1929   return false;
  1920 }
  1930 }
  1921 
  1931 
  1929     for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
  1939     for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
  1930       if (!HeapShared::is_heap_region(i)) {
  1940       if (!HeapShared::is_heap_region(i)) {
  1931         char *addr = map_info->region_addr(i);
  1941         char *addr = map_info->region_addr(i);
  1932         if (addr != NULL) {
  1942         if (addr != NULL) {
  1933           map_info->unmap_region(i);
  1943           map_info->unmap_region(i);
  1934           map_info->space_at(i)->_addr._base = NULL;
  1944           map_info->space_at(i)->mark_invalid();
  1935         }
  1945         }
  1936       }
  1946       }
  1937     }
  1947     }
  1938     // Dealloc the archive heap regions only without unmapping. The regions are part
  1948     // Dealloc the archive heap regions only without unmapping. The regions are part
  1939     // of the java heap. Unmapping of the heap regions are managed by GC.
  1949     // of the java heap. Unmapping of the heap regions are managed by GC.