src/share/vm/memory/filemap.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File classpath.03 Sdiff src/share/vm/memory

src/share/vm/memory/filemap.cpp

Print this page




 191   int bytes = 0;
 192   int count = 0;
 193   char* strptr = NULL;
 194   char* strptr_max = NULL;
 195   Thread* THREAD = Thread::current();
 196 
 197   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 198   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 199 
 200   for (int pass=0; pass<2; pass++) {
 201     ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 202 
 203     for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
 204       const char *name = cpe->name();
 205       int name_bytes = (int)(strlen(name) + 1);
 206 
 207       if (pass == 0) {
 208         count ++;
 209         bytes += (int)entry_size;
 210         bytes += name_bytes;
 211         if (TraceClassPaths) {
 212           tty->print_cr("[Add main shared path (%s) %s]", (cpe->is_jar_file() ? "jar" : "dir"), name);
 213         }
 214       } else {
 215         SharedClassPathEntry* ent = shared_classpath(cur_entry);
 216         if (cpe->is_jar_file()) {
 217           struct stat st;
 218           if (os::stat(name, &st) != 0) {
 219             // The file/dir must exist, or it would not have been added
 220             // into ClassLoader::classpath_entry().
 221             //
 222             // If we can't access a jar file in the boot path, then we can't
 223             // make assumptions about where classes get loaded from.
 224             FileMapInfo::fail_stop("Unable to open jar file %s.", name);
 225           }
 226 
 227           EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 228           SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
 229         } else {
 230           struct stat st;
 231           if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) {
 232             if (!os::dir_is_empty(name)) {
 233               ClassLoader::exit_with_path_failure("Cannot have non-empty directory in archived classpaths", name);


 258       _classpath_entry_table_size = count;
 259       _classpath_entry_table = table;
 260       _classpath_entry_size = entry_size;
 261     }
 262   }
 263 }
 264 
 265 bool FileMapInfo::validate_classpath_entry_table() {
 266   _validating_classpath_entry_table = true;
 267 
 268   int count = _header->_classpath_entry_table_size;
 269 
 270   _classpath_entry_table = _header->_classpath_entry_table;
 271   _classpath_entry_size = _header->_classpath_entry_size;
 272 
 273   for (int i=0; i<count; i++) {
 274     SharedClassPathEntry* ent = shared_classpath(i);
 275     struct stat st;
 276     const char* name = ent->_name;
 277     bool ok = true;
 278     if (TraceClassPaths) {
 279       tty->print_cr("[Checking shared classpath entry: %s]", name);
 280     }
 281     if (os::stat(name, &st) != 0) {
 282       fail_continue("Required classpath entry does not exist: %s", name);
 283       ok = false;
 284     } else if (ent->is_dir()) {
 285       if (!os::dir_is_empty(name)) {
 286         fail_continue("directory is not empty: %s", name);
 287         ok = false;
 288       }
 289     } else if (ent->is_jar()) {
 290       if (ent->_timestamp != st.st_mtime ||
 291           ent->_filesize != st.st_size) {
 292         ok = false;
 293         if (PrintSharedArchiveAndExit) {
 294           fail_continue(ent->_timestamp != st.st_mtime ?
 295                         "Timestamp mismatch" :
 296                         "File size mismatch");
 297         } else {
 298           fail_continue("A jar file is not the one used while building"
 299                         " the shared archive file: %s", name);
 300         }
 301       }
 302     }
 303     if (ok) {
 304       if (TraceClassPaths) {
 305         tty->print_cr("[ok]");
 306       }
 307     } else if (!PrintSharedArchiveAndExit) {
 308       _validating_classpath_entry_table = false;
 309       return false;
 310     }
 311   }
 312 
 313   _classpath_entry_table_size = _header->_classpath_entry_table_size;
 314   _validating_classpath_entry_table = false;
 315   return true;
 316 }
 317 
 318 
 319 // Read the FileMapInfo information from the file.
 320 
 321 bool FileMapInfo::init_from_file(int fd) {
 322   size_t sz = _header->data_size();
 323   char* addr = _header->data();
 324   size_t n = os::read(fd, addr, (unsigned int)sz);
 325   if (n != sz) {
 326     fail_continue("Unable to read the file header.");


 871   return crc;
 872 }
 873 
 874 bool FileMapInfo::FileMapHeader::validate() {
 875   if (VerifySharedSpaces && compute_crc() != _crc) {
 876     fail_continue("Header checksum verification failed.");
 877     return false;
 878   }
 879 
 880   if (_version != current_version()) {
 881     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
 882     return false;
 883   }
 884   if (_magic != (int)0xf00baba2) {
 885     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
 886     return false;
 887   }
 888   char header_version[JVM_IDENT_MAX];
 889   get_header_version(header_version);
 890   if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
 891     if (TraceClassPaths) {
 892       tty->print_cr("Expected: %s", header_version);
 893       tty->print_cr("Actual:   %s", _jvm_ident);
 894     }
 895     FileMapInfo::fail_continue("The shared archive file was created by a different"
 896                   " version or build of HotSpot");
 897     return false;
 898   }
 899   if (_obj_alignment != ObjectAlignmentInBytes) {
 900     FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
 901                   " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
 902                   _obj_alignment, ObjectAlignmentInBytes);
 903     return false;
 904   }
 905   if (_compact_strings != CompactStrings) {
 906     FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
 907                   " does not equal the current CompactStrings setting (%s).",
 908                   _compact_strings ? "enabled" : "disabled",
 909                   CompactStrings   ? "enabled" : "disabled");
 910     return false;
 911   }
 912 
 913   return true;
 914 }
 915 
 916 bool FileMapInfo::validate_header() {
 917   bool status = _header->validate();
 918 
 919   if (status) {
 920     if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
 921       if (!PrintSharedArchiveAndExit) {
 922         fail_continue("shared class paths mismatch (hint: enable -XX:+TraceClassPaths to diagnose the failure)");
 923         status = false;
 924       }
 925     }
 926   }
 927 
 928   if (_paths_misc_info != NULL) {
 929     FREE_C_HEAP_ARRAY(char, _paths_misc_info);
 930     _paths_misc_info = NULL;
 931   }
 932   return status;
 933 }
 934 
 935 // The following method is provided to see whether a given pointer
 936 // falls in the mapped shared space.
 937 // Param:
 938 // p, The given pointer
 939 // Return:
 940 // True if the p is within the mapped shared space, otherwise, false.
 941 bool FileMapInfo::is_in_shared_space(const void* p) {
 942   for (int i = 0; i < MetaspaceShared::n_regions; i++) {




 191   int bytes = 0;
 192   int count = 0;
 193   char* strptr = NULL;
 194   char* strptr_max = NULL;
 195   Thread* THREAD = Thread::current();
 196 
 197   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 198   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 199 
 200   for (int pass=0; pass<2; pass++) {
 201     ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 202 
 203     for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
 204       const char *name = cpe->name();
 205       int name_bytes = (int)(strlen(name) + 1);
 206 
 207       if (pass == 0) {
 208         count ++;
 209         bytes += (int)entry_size;
 210         bytes += name_bytes;
 211         log_info(classpath)("add main shared path (%s) %s", (cpe->is_jar_file() ? "jar" : "dir"), name);


 212       } else {
 213         SharedClassPathEntry* ent = shared_classpath(cur_entry);
 214         if (cpe->is_jar_file()) {
 215           struct stat st;
 216           if (os::stat(name, &st) != 0) {
 217             // The file/dir must exist, or it would not have been added
 218             // into ClassLoader::classpath_entry().
 219             //
 220             // If we can't access a jar file in the boot path, then we can't
 221             // make assumptions about where classes get loaded from.
 222             FileMapInfo::fail_stop("Unable to open jar file %s.", name);
 223           }
 224 
 225           EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 226           SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
 227         } else {
 228           struct stat st;
 229           if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) {
 230             if (!os::dir_is_empty(name)) {
 231               ClassLoader::exit_with_path_failure("Cannot have non-empty directory in archived classpaths", name);


 256       _classpath_entry_table_size = count;
 257       _classpath_entry_table = table;
 258       _classpath_entry_size = entry_size;
 259     }
 260   }
 261 }
 262 
 263 bool FileMapInfo::validate_classpath_entry_table() {
 264   _validating_classpath_entry_table = true;
 265 
 266   int count = _header->_classpath_entry_table_size;
 267 
 268   _classpath_entry_table = _header->_classpath_entry_table;
 269   _classpath_entry_size = _header->_classpath_entry_size;
 270 
 271   for (int i=0; i<count; i++) {
 272     SharedClassPathEntry* ent = shared_classpath(i);
 273     struct stat st;
 274     const char* name = ent->_name;
 275     bool ok = true;
 276     log_info(classpath)("checking shared classpath entry: %s", name);


 277     if (os::stat(name, &st) != 0) {
 278       fail_continue("Required classpath entry does not exist: %s", name);
 279       ok = false;
 280     } else if (ent->is_dir()) {
 281       if (!os::dir_is_empty(name)) {
 282         fail_continue("directory is not empty: %s", name);
 283         ok = false;
 284       }
 285     } else if (ent->is_jar()) {
 286       if (ent->_timestamp != st.st_mtime ||
 287           ent->_filesize != st.st_size) {
 288         ok = false;
 289         if (PrintSharedArchiveAndExit) {
 290           fail_continue(ent->_timestamp != st.st_mtime ?
 291                         "Timestamp mismatch" :
 292                         "File size mismatch");
 293         } else {
 294           fail_continue("A jar file is not the one used while building"
 295                         " the shared archive file: %s", name);
 296         }
 297       }
 298     }
 299     if (ok) {
 300       log_info(classpath)("ok");


 301     } else if (!PrintSharedArchiveAndExit) {
 302       _validating_classpath_entry_table = false;
 303       return false;
 304     }
 305   }
 306 
 307   _classpath_entry_table_size = _header->_classpath_entry_table_size;
 308   _validating_classpath_entry_table = false;
 309   return true;
 310 }
 311 
 312 
 313 // Read the FileMapInfo information from the file.
 314 
 315 bool FileMapInfo::init_from_file(int fd) {
 316   size_t sz = _header->data_size();
 317   char* addr = _header->data();
 318   size_t n = os::read(fd, addr, (unsigned int)sz);
 319   if (n != sz) {
 320     fail_continue("Unable to read the file header.");


 865   return crc;
 866 }
 867 
 868 bool FileMapInfo::FileMapHeader::validate() {
 869   if (VerifySharedSpaces && compute_crc() != _crc) {
 870     fail_continue("Header checksum verification failed.");
 871     return false;
 872   }
 873 
 874   if (_version != current_version()) {
 875     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
 876     return false;
 877   }
 878   if (_magic != (int)0xf00baba2) {
 879     FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
 880     return false;
 881   }
 882   char header_version[JVM_IDENT_MAX];
 883   get_header_version(header_version);
 884   if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
 885     log_info(classpath)("expected: %s", header_version);
 886     log_info(classpath)("actual:   %s", _jvm_ident);


 887     FileMapInfo::fail_continue("The shared archive file was created by a different"
 888                   " version or build of HotSpot");
 889     return false;
 890   }
 891   if (_obj_alignment != ObjectAlignmentInBytes) {
 892     FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
 893                   " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
 894                   _obj_alignment, ObjectAlignmentInBytes);
 895     return false;
 896   }
 897   if (_compact_strings != CompactStrings) {
 898     FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
 899                   " does not equal the current CompactStrings setting (%s).",
 900                   _compact_strings ? "enabled" : "disabled",
 901                   CompactStrings   ? "enabled" : "disabled");
 902     return false;
 903   }
 904 
 905   return true;
 906 }
 907 
 908 bool FileMapInfo::validate_header() {
 909   bool status = _header->validate();
 910 
 911   if (status) {
 912     if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
 913       if (!PrintSharedArchiveAndExit) {
 914         fail_continue("shared class paths mismatch (hint: enable -Xlog:classpath=info to diagnose the failure)");
 915         status = false;
 916       }
 917     }
 918   }
 919 
 920   if (_paths_misc_info != NULL) {
 921     FREE_C_HEAP_ARRAY(char, _paths_misc_info);
 922     _paths_misc_info = NULL;
 923   }
 924   return status;
 925 }
 926 
 927 // The following method is provided to see whether a given pointer
 928 // falls in the mapped shared space.
 929 // Param:
 930 // p, The given pointer
 931 // Return:
 932 // True if the p is within the mapped shared space, otherwise, false.
 933 bool FileMapInfo::is_in_shared_space(const void* p) {
 934   for (int i = 0; i < MetaspaceShared::n_regions; i++) {


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