src/hotspot/share/memory/filemap.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/share/memory

src/hotspot/share/memory/filemap.cpp

Print this page
rev 49528 : [mq]: module_path


  79 }
  80 
  81 
  82 void FileMapInfo::fail_stop(const char *msg, ...) {
  83         va_list ap;
  84   va_start(ap, msg);
  85   fail(msg, ap);        // Never returns.
  86   va_end(ap);           // for completeness.
  87 }
  88 
  89 
  90 // Complain and continue.  Recoverable errors during the reading of the
  91 // archive file may continue (with sharing disabled).
  92 //
  93 // If we continue, then disable shared spaces and close the file.
  94 
  95 void FileMapInfo::fail_continue(const char *msg, ...) {
  96   va_list ap;
  97   va_start(ap, msg);
  98   MetaspaceShared::set_archive_loading_failed();
  99   if (PrintSharedArchiveAndExit && _validating_classpath_entry_table) {
 100     // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
 101     // do not validate, we can still continue "limping" to validate the remaining
 102     // entries. No need to quit.
 103     tty->print("[");
 104     tty->vprint(msg, ap);
 105     tty->print_cr("]");
 106   } else {
 107     if (RequireSharedSpaces) {
 108       fail(msg, ap);
 109     } else {
 110       if (log_is_enabled(Info, cds)) {
 111         ResourceMark rm;
 112         LogStream ls(Log(cds)::info());
 113         ls.print("UseSharedSpaces: ");
 114         ls.vprint_cr(msg, ap);
 115       }
 116     }
 117     UseSharedSpaces = false;
 118     assert(current_info() != NULL, "singleton must be registered");
 119     current_info()->close();


 171 void FileMapInfo::populate_header(size_t alignment) {
 172   _header->populate(this, alignment);
 173 }
 174 
 175 size_t FileMapInfo::FileMapHeader::data_size() {
 176   return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase);
 177 }
 178 
 179 void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
 180   _magic = 0xf00baba2;
 181   _version = _current_version;
 182   _alignment = alignment;
 183   _obj_alignment = ObjectAlignmentInBytes;
 184   _compact_strings = CompactStrings;
 185   _narrow_oop_mode = Universe::narrow_oop_mode();
 186   _narrow_oop_base = Universe::narrow_oop_base();
 187   _narrow_oop_shift = Universe::narrow_oop_shift();
 188   _max_heap_size = MaxHeapSize;
 189   _narrow_klass_base = Universe::narrow_klass_base();
 190   _narrow_klass_shift = Universe::narrow_klass_shift();
 191   _classpath_entry_table_size = mapinfo->_classpath_entry_table_size;
 192   _classpath_entry_table = mapinfo->_classpath_entry_table;
 193   _classpath_entry_size = mapinfo->_classpath_entry_size;
 194 
 195   // The following fields are for sanity checks for whether this archive
 196   // will function correctly with this JVM and the bootclasspath it's
 197   // invoked with.
 198 
 199   // JVM version string ... changes on each build.
 200   get_header_version(_jvm_ident);
 201 }
 202 
 203 void SharedClassPathEntry::init(const char* name, TRAPS) {
 204   _timestamp = 0;
 205   _filesize  = 0;
 206 
 207   struct stat st;
 208   if (os::stat(name, &st) == 0) {
 209     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 210       if (!os::dir_is_empty(name)) {
 211         ClassLoader::exit_with_path_failure(
 212                   "Cannot have non-empty directory in archived classpaths", name);
 213       }
 214       _is_dir = true;
 215     } else {
 216       _is_dir = false;
 217       _timestamp = st.st_mtime;
 218       _filesize = st.st_size;
 219     }
 220   } else {
 221     // The file/dir must exist, or it would not have been added
 222     // into ClassLoader::classpath_entry().
 223     //
 224     // If we can't access a jar file in the boot path, then we can't
 225     // make assumptions about where classes get loaded from.
 226     FileMapInfo::fail_stop("Unable to open file %s.", name);
 227   }
 228 
 229   size_t len = strlen(name) + 1;
 230   _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD);
 231   strcpy(_name->data(), name);
 232 }
 233 
 234 bool SharedClassPathEntry::validate() {
 235   struct stat st;
 236   const char* name = this->name();
 237   bool ok = true;
 238   log_info(class, path)("checking shared classpath entry: %s", name);
 239   if (os::stat(name, &st) != 0) {




 240     FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name);
 241     ok = false;
 242   } else if (is_dir()) {
 243     if (!os::dir_is_empty(name)) {
 244       FileMapInfo::fail_continue("directory is not empty: %s", name);
 245       ok = false;
 246     }
 247   } else if (is_jar_or_bootimage()) {
 248     if (_timestamp != st.st_mtime ||
 249         _filesize != st.st_size) {
 250       ok = false;
 251       if (PrintSharedArchiveAndExit) {
 252         FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
 253                                    "Timestamp mismatch" :
 254                                    "File size mismatch");
 255       } else {
 256         FileMapInfo::fail_continue("A jar/jimage file is not the one used while building"
 257                                    " the shared archive file: %s", name);
 258       }
 259     }
 260   }
 261   return ok;
 262 }
 263 
 264 void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 265   it->push(&_name);
 266   it->push(&_manifest);
 267 }
 268 
 269 void FileMapInfo::allocate_classpath_entry_table() {
 270   assert(DumpSharedSpaces, "Sanity");
 271 
 272   Thread* THREAD = Thread::current();
 273   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 274   ClassPathEntry* jrt = ClassLoader::get_jrt_entry();
 275 
 276   assert(jrt != NULL,
 277          "No modular java runtime image present when allocating the CDS classpath entry table");
 278 
 279   size_t entry_size = SharedClassUtil::shared_class_path_entry_size(); // assert ( should be 8 byte aligned??)
 280   int num_boot_classpath_entries = ClassLoader::num_boot_classpath_entries();
 281   int num_app_classpath_entries = ClassLoader::num_app_classpath_entries();
 282   int num_entries = num_boot_classpath_entries + num_app_classpath_entries;

 283   size_t bytes = entry_size * num_entries;
 284 
 285   _classpath_entry_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD);
 286   _classpath_entry_table_size = num_entries;
 287   _classpath_entry_size = entry_size;
 288 
 289   // 1. boot class path
 290   int i = 0;
 291   ClassPathEntry* cpe = jrt;
 292   while (cpe != NULL) {
 293     const char* type = ((cpe == jrt) ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));
 294     log_info(class, path)("add main shared path (%s) %s", type, cpe->name());
 295     SharedClassPathEntry* ent = shared_classpath(i);
 296     ent->init(cpe->name(), THREAD);
 297     if (cpe != jrt) { // No need to do jimage.
 298       EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 299       SharedClassUtil::update_shared_classpath(cpe, ent, THREAD);
 300     }
 301     cpe = ClassLoader::get_next_boot_classpath_entry(cpe);
 302     i++;
 303   }
 304   assert(i == num_boot_classpath_entries,
 305          "number of boot class path entry mismatch");
 306 
 307   // 2. app class path
 308   ClassPathEntry *acpe = ClassLoader::app_classpath_entries();
 309   while (acpe != NULL) {
 310     log_info(class, path)("add app shared path %s", acpe->name());
 311     SharedClassPathEntry* ent = shared_classpath(i);
 312     ent->init(acpe->name(), THREAD);
 313     EXCEPTION_MARK;
 314     SharedClassUtil::update_shared_classpath(acpe, ent, THREAD);
 315     acpe = acpe->next();
 316     i ++;












 317   }
 318   assert(i == num_entries, "number of app class path entry mismatch");
 319 }
 320 
 321 bool FileMapInfo::validate_classpath_entry_table() {
 322   _validating_classpath_entry_table = true;

 323 
 324   int count = _header->_classpath_entry_table_size;


 325 
 326   _classpath_entry_table = _header->_classpath_entry_table;
 327   _classpath_entry_size = _header->_classpath_entry_size;
 328   _classpath_entry_table_size = _header->_classpath_entry_table_size;





 329 
 330   for (int i=0; i<count; i++) {
 331     if (shared_classpath(i)->validate()) {





 332       log_info(class, path)("ok");

 333     } else if (!PrintSharedArchiveAndExit) {
 334       _validating_classpath_entry_table = false;
 335       _classpath_entry_table = NULL;
 336       _classpath_entry_table_size = 0;
 337       return false;
 338     }
 339   }
 340 
 341   _validating_classpath_entry_table = false;
 342   return true;
 343 }
 344 
 345 
 346 // Read the FileMapInfo information from the file.
 347 
 348 bool FileMapInfo::init_from_file(int fd) {
 349   size_t sz = _header->data_size();
 350   char* addr = _header->data();
 351   size_t n = os::read(fd, addr, (unsigned int)sz);
 352   if (n != sz) {
 353     fail_continue("Unable to read the file header.");
 354     return false;
 355   }
 356   if (_header->_version != current_version()) {
 357     fail_continue("The shared archive file has the wrong version.");
 358     return false;
 359   }
 360   _file_offset = (long)n;
 361 
 362   size_t info_size = _header->_paths_misc_info_size;
 363   _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);
 364   if (_paths_misc_info == NULL) {
 365     fail_continue("Unable to read the file header.");


 908   size_t used = si->_used;
 909   size_t size = align_up(used, os::vm_allocation_granularity());
 910 
 911   if (used == 0) {
 912     return;
 913   }
 914 
 915   char* addr = _header->region_addr(i);
 916   if (!os::unmap_memory(addr, size)) {
 917     fail_stop("Unable to unmap shared space.");
 918   }
 919 }
 920 
 921 void FileMapInfo::assert_mark(bool check) {
 922   if (!check) {
 923     fail_stop("Mark mismatch while restoring from shared file.");
 924   }
 925 }
 926 
 927 void FileMapInfo::metaspace_pointers_do(MetaspaceClosure* it) {
 928   it->push(&_classpath_entry_table);
 929   for (int i=0; i<_classpath_entry_table_size; i++) {
 930     shared_classpath(i)->metaspace_pointers_do(it);
 931   }
 932 }
 933 
 934 
 935 FileMapInfo* FileMapInfo::_current_info = NULL;
 936 Array<u8>* FileMapInfo::_classpath_entry_table = NULL;
 937 int FileMapInfo::_classpath_entry_table_size = 0;
 938 size_t FileMapInfo::_classpath_entry_size = 0x1234baad;
 939 bool FileMapInfo::_validating_classpath_entry_table = false;
 940 
 941 // Open the shared archive file, read and validate the header
 942 // information (version, boot classpath, etc.).  If initialization
 943 // fails, shared spaces are disabled and the file is closed. [See
 944 // fail_continue.]
 945 //
 946 // Validation of the archive is done in two steps:
 947 //
 948 // [1] validate_header() - done here. This checks the header, including _paths_misc_info.
 949 // [2] validate_classpath_entry_table - this is done later, because the table is in the RW
 950 //     region of the archive, which is not mapped yet.
 951 bool FileMapInfo::initialize() {
 952   assert(UseSharedSpaces, "UseSharedSpaces expected.");
 953 
 954   if (!open_for_read()) {
 955     return false;
 956   }
 957 
 958   init_from_file(_fd);
 959   if (!validate_header()) {
 960     return false;
 961   }
 962   return true;
 963 }
 964 
 965 char* FileMapInfo::FileMapHeader::region_addr(int idx) {
 966   if (MetaspaceShared::is_heap_region(idx)) {
 967     return _space[idx]._used > 0 ?
 968              (char*)((void*)CompressedOops::decode_not_null((narrowOop)_space[idx]._addr._offset)) : NULL;
 969   } else {
 970     return _space[idx]._addr._base;
 971   }
 972 }
 973 
 974 int FileMapInfo::FileMapHeader::compute_crc() {
 975   char* header = data();
 976   // start computing from the field after _crc
 977   char* buf = (char*)&_crc + sizeof(int);
 978   size_t sz = data_size() - (buf - header);
 979   int crc = ClassLoader::crc32(0, buf, (jint)sz);
 980   return crc;
 981 }
 982 

 983 bool FileMapInfo::FileMapHeader::validate() {
 984   if (VerifySharedSpaces && compute_crc() != _crc) {
 985     fail_continue("Header checksum verification failed.");
 986     return false;
 987   }
 988 
 989   if (!Arguments::has_jimage()) {
 990     FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
 991     return false;
 992   }
 993 
 994   if (_version != current_version()) {
 995     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
 996     return false;
 997   }
 998   if (_magic != (int)0xf00baba2) {
 999     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1000     return false;
1001   }
1002   char header_version[JVM_IDENT_MAX];




  79 }
  80 
  81 
  82 void FileMapInfo::fail_stop(const char *msg, ...) {
  83         va_list ap;
  84   va_start(ap, msg);
  85   fail(msg, ap);        // Never returns.
  86   va_end(ap);           // for completeness.
  87 }
  88 
  89 
  90 // Complain and continue.  Recoverable errors during the reading of the
  91 // archive file may continue (with sharing disabled).
  92 //
  93 // If we continue, then disable shared spaces and close the file.
  94 
  95 void FileMapInfo::fail_continue(const char *msg, ...) {
  96   va_list ap;
  97   va_start(ap, msg);
  98   MetaspaceShared::set_archive_loading_failed();
  99   if (PrintSharedArchiveAndExit && _validating_shared_path_table) {
 100     // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
 101     // do not validate, we can still continue "limping" to validate the remaining
 102     // entries. No need to quit.
 103     tty->print("[");
 104     tty->vprint(msg, ap);
 105     tty->print_cr("]");
 106   } else {
 107     if (RequireSharedSpaces) {
 108       fail(msg, ap);
 109     } else {
 110       if (log_is_enabled(Info, cds)) {
 111         ResourceMark rm;
 112         LogStream ls(Log(cds)::info());
 113         ls.print("UseSharedSpaces: ");
 114         ls.vprint_cr(msg, ap);
 115       }
 116     }
 117     UseSharedSpaces = false;
 118     assert(current_info() != NULL, "singleton must be registered");
 119     current_info()->close();


 171 void FileMapInfo::populate_header(size_t alignment) {
 172   _header->populate(this, alignment);
 173 }
 174 
 175 size_t FileMapInfo::FileMapHeader::data_size() {
 176   return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase);
 177 }
 178 
 179 void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
 180   _magic = 0xf00baba2;
 181   _version = _current_version;
 182   _alignment = alignment;
 183   _obj_alignment = ObjectAlignmentInBytes;
 184   _compact_strings = CompactStrings;
 185   _narrow_oop_mode = Universe::narrow_oop_mode();
 186   _narrow_oop_base = Universe::narrow_oop_base();
 187   _narrow_oop_shift = Universe::narrow_oop_shift();
 188   _max_heap_size = MaxHeapSize;
 189   _narrow_klass_base = Universe::narrow_klass_base();
 190   _narrow_klass_shift = Universe::narrow_klass_shift();
 191   _shared_path_table_size = mapinfo->_shared_path_table_size;
 192   _shared_path_table = mapinfo->_shared_path_table;
 193   _shared_path_entry_size = mapinfo->_shared_path_entry_size;
 194 
 195   // The following fields are for sanity checks for whether this archive
 196   // will function correctly with this JVM and the bootclasspath it's
 197   // invoked with.
 198 
 199   // JVM version string ... changes on each build.
 200   get_header_version(_jvm_ident);
 201 }
 202 
 203 void SharedClassPathEntry::init(const char* name, TRAPS) {
 204   _timestamp = 0;
 205   _filesize  = 0;
 206 
 207   struct stat st;
 208   if (os::stat(name, &st) == 0) {
 209     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 210       if (!os::dir_is_empty(name)) {
 211         ClassLoader::exit_with_path_failure(
 212                   "Cannot have non-empty directory in archived classpaths", name);
 213       }
 214       _is_dir = true;
 215     } else {
 216       _is_dir = false;
 217       _timestamp = st.st_mtime;
 218       _filesize = st.st_size;
 219     }
 220   } else {
 221     // The file/dir must exist, or it would not have been added
 222     // into ClassLoader::classpath_entry().
 223     //
 224     // If we can't access a jar file in the boot path, then we can't
 225     // make assumptions about where classes get loaded from.
 226     FileMapInfo::fail_stop("Unable to open file %s.", name);
 227   }
 228 
 229   size_t len = strlen(name) + 1;
 230   _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD);
 231   strcpy(_name->data(), name);
 232 }
 233 
 234 bool SharedClassPathEntry::validate(bool is_class_path) {
 235   struct stat st;
 236   const char* name = this->name();
 237   bool ok = true;
 238   log_info(class, path)("checking shared classpath entry: %s", name);
 239   if (os::stat(name, &st) != 0 && is_class_path) {
 240     // If the archived module path entry does not exist at runtime, it is not fatal
 241     // (no need to invalid the shared archive) because the shared runtime visibility check
 242     // filters out any archived module classes that do not have a matching runtime
 243     // module path location.
 244     FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name);
 245     ok = false;
 246   } else if (is_dir()) {
 247     if (!os::dir_is_empty(name)) {
 248       FileMapInfo::fail_continue("directory is not empty: %s", name);
 249       ok = false;
 250     }
 251   } else if (is_jar_or_bootimage()) {
 252     if (_timestamp != st.st_mtime ||
 253         _filesize != st.st_size) {
 254       ok = false;
 255       if (PrintSharedArchiveAndExit) {
 256         FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
 257                                    "Timestamp mismatch" :
 258                                    "File size mismatch");
 259       } else {
 260         FileMapInfo::fail_continue("A jar/jimage file is not the one used while building"
 261                                    " the shared archive file: %s", name);
 262       }
 263     }
 264   }
 265   return ok;
 266 }
 267 
 268 void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 269   it->push(&_name);
 270   it->push(&_manifest);
 271 }
 272 
 273 void FileMapInfo::allocate_shared_path_table() {
 274   assert(DumpSharedSpaces, "Sanity");
 275 
 276   Thread* THREAD = Thread::current();
 277   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 278   ClassPathEntry* jrt = ClassLoader::get_jrt_entry();
 279 
 280   assert(jrt != NULL,
 281          "No modular java runtime image present when allocating the CDS classpath entry table");
 282 
 283   size_t entry_size = SharedClassUtil::shared_class_path_entry_size(); // assert ( should be 8 byte aligned??)
 284   int num_boot_classpath_entries = ClassLoader::num_boot_classpath_entries();
 285   int num_app_classpath_entries = ClassLoader::num_app_classpath_entries();
 286   int num_module_path_entries = ClassLoader::num_module_path_entries();
 287   int num_entries = num_boot_classpath_entries + num_app_classpath_entries + num_module_path_entries;
 288   size_t bytes = entry_size * num_entries;
 289 
 290   _shared_path_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD);
 291   _shared_path_table_size = num_entries;
 292   _shared_path_entry_size = entry_size;
 293 
 294   // 1. boot class path
 295   int i = 0;
 296   ClassPathEntry* cpe = jrt;
 297   while (cpe != NULL) {
 298     const char* type = ((cpe == jrt) ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));
 299     log_info(class, path)("add main shared path (%s) %s", type, cpe->name());
 300     SharedClassPathEntry* ent = shared_path(i);
 301     ent->init(cpe->name(), THREAD);
 302     if (cpe != jrt) { // No need to do jimage.
 303       EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 304       SharedClassUtil::update_shared_classpath(cpe, ent, THREAD);
 305     }
 306     cpe = ClassLoader::get_next_boot_classpath_entry(cpe);
 307     i++;
 308   }
 309   assert(i == num_boot_classpath_entries,
 310          "number of boot class path entry mismatch");
 311 
 312   // 2. app class path
 313   ClassPathEntry *acpe = ClassLoader::app_classpath_entries();
 314   while (acpe != NULL) {
 315     log_info(class, path)("add app shared path %s", acpe->name());
 316     SharedClassPathEntry* ent = shared_path(i);
 317     ent->init(acpe->name(), THREAD);
 318     EXCEPTION_MARK;
 319     SharedClassUtil::update_shared_classpath(acpe, ent, THREAD);
 320     acpe = acpe->next();
 321     i++;
 322   }
 323 
 324   // 3. module path
 325   ClassPathEntry *mpe = ClassLoader::module_path_entries();
 326   while (mpe != NULL) {
 327     log_info(class, path)("add module path %s",mpe->name());
 328     SharedClassPathEntry* ent = shared_path(i);
 329     ent->init(mpe->name(), THREAD);
 330     EXCEPTION_MARK;
 331     SharedClassUtil::update_shared_classpath(mpe, ent, THREAD);
 332     mpe = mpe->next();
 333     i++;
 334   }
 335   assert(i == num_entries, "number of shared path entry mismatch");
 336 }
 337 
 338 // This function should only be called during run time with UseSharedSpaces enabled.
 339 bool FileMapInfo::validate_shared_path_table() {
 340   _validating_shared_path_table = true;
 341 
 342   _shared_path_table = _header->_shared_path_table;
 343   _shared_path_entry_size = _header->_shared_path_entry_size;
 344   _shared_path_table_size = _header->_shared_path_table_size;
 345 
 346   // Note: _app_module_paths_start_index may not have a valid value if the UseAppCDS flag
 347   // wasn't enabled during dump time. Therefore, we need to use the smaller of
 348   // _shared_path_table_size and _app_module_paths_start_index for the _app_module_paths_start_index.
 349   FileMapHeaderExt* header = (FileMapHeaderExt*)FileMapInfo::current_info()->header();
 350   int module_paths_start_index = (header->_app_module_paths_start_index >= _shared_path_table_size) ?
 351                                   _shared_path_table_size : header->_app_module_paths_start_index;
 352 
 353   int count = _shared_path_table_size;
 354 
 355   for (int i=0; i<count; i++) {
 356     if (i < module_paths_start_index) {
 357       if (shared_path(i)->validate()) {
 358         log_info(class, path)("ok");
 359       }
 360     } else if (i >= module_paths_start_index) {
 361       if (shared_path(i)->validate(false /* not a class path entry */)) {
 362         log_info(class, path)("ok");
 363       }
 364     } else if (!PrintSharedArchiveAndExit) {
 365       _validating_shared_path_table = false;
 366       _shared_path_table = NULL;
 367       _shared_path_table_size = 0;
 368       return false;
 369     }
 370   }
 371 
 372   _validating_shared_path_table = false;
 373   return true;
 374 }
 375 

 376 // Read the FileMapInfo information from the file.
 377 
 378 bool FileMapInfo::init_from_file(int fd) {
 379   size_t sz = _header->data_size();
 380   char* addr = _header->data();
 381   size_t n = os::read(fd, addr, (unsigned int)sz);
 382   if (n != sz) {
 383     fail_continue("Unable to read the file header.");
 384     return false;
 385   }
 386   if (_header->_version != current_version()) {
 387     fail_continue("The shared archive file has the wrong version.");
 388     return false;
 389   }
 390   _file_offset = (long)n;
 391 
 392   size_t info_size = _header->_paths_misc_info_size;
 393   _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);
 394   if (_paths_misc_info == NULL) {
 395     fail_continue("Unable to read the file header.");


 938   size_t used = si->_used;
 939   size_t size = align_up(used, os::vm_allocation_granularity());
 940 
 941   if (used == 0) {
 942     return;
 943   }
 944 
 945   char* addr = _header->region_addr(i);
 946   if (!os::unmap_memory(addr, size)) {
 947     fail_stop("Unable to unmap shared space.");
 948   }
 949 }
 950 
 951 void FileMapInfo::assert_mark(bool check) {
 952   if (!check) {
 953     fail_stop("Mark mismatch while restoring from shared file.");
 954   }
 955 }
 956 
 957 void FileMapInfo::metaspace_pointers_do(MetaspaceClosure* it) {
 958   it->push(&_shared_path_table);
 959   for (int i=0; i<_shared_path_table_size; i++) {
 960     shared_path(i)->metaspace_pointers_do(it);
 961   }
 962 }
 963 
 964 
 965 FileMapInfo* FileMapInfo::_current_info = NULL;
 966 Array<u8>* FileMapInfo::_shared_path_table = NULL;
 967 int FileMapInfo::_shared_path_table_size = 0;
 968 size_t FileMapInfo::_shared_path_entry_size = 0x1234baad;
 969 bool FileMapInfo::_validating_shared_path_table = false;
 970 
 971 // Open the shared archive file, read and validate the header
 972 // information (version, boot classpath, etc.).  If initialization
 973 // fails, shared spaces are disabled and the file is closed. [See
 974 // fail_continue.]
 975 //
 976 // Validation of the archive is done in two steps:
 977 //
 978 // [1] validate_header() - done here. This checks the header, including _paths_misc_info.
 979 // [2] validate_shared_path_table - this is done later, because the table is in the RW
 980 //     region of the archive, which is not mapped yet.
 981 bool FileMapInfo::initialize() {
 982   assert(UseSharedSpaces, "UseSharedSpaces expected.");
 983 
 984   if (!open_for_read()) {
 985     return false;
 986   }
 987 
 988   init_from_file(_fd);
 989   if (!validate_header()) {
 990     return false;
 991   }
 992   return true;
 993 }
 994 
 995 char* FileMapInfo::FileMapHeader::region_addr(int idx) {
 996   if (MetaspaceShared::is_heap_region(idx)) {
 997     return _space[idx]._used > 0 ?
 998              (char*)((void*)CompressedOops::decode_not_null((narrowOop)_space[idx]._addr._offset)) : NULL;
 999   } else {
1000     return _space[idx]._addr._base;
1001   }
1002 }
1003 
1004 int FileMapInfo::FileMapHeader::compute_crc() {
1005   char* header = data();
1006   // start computing from the field after _crc
1007   char* buf = (char*)&_crc + sizeof(int);
1008   size_t sz = data_size() - (buf - header);
1009   int crc = ClassLoader::crc32(0, buf, (jint)sz);
1010   return crc;
1011 }
1012 
1013 // This function should only be called during run time with UseSharedSpaces enabled.
1014 bool FileMapInfo::FileMapHeader::validate() {
1015   if (VerifySharedSpaces && compute_crc() != _crc) {
1016     fail_continue("Header checksum verification failed.");
1017     return false;
1018   }
1019 
1020   if (!Arguments::has_jimage()) {
1021     FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
1022     return false;
1023   }
1024 
1025   if (_version != current_version()) {
1026     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
1027     return false;
1028   }
1029   if (_magic != (int)0xf00baba2) {
1030     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1031     return false;
1032   }
1033   char header_version[JVM_IDENT_MAX];


src/hotspot/share/memory/filemap.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File