< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page




 188   _shared_path_table_size = mapinfo->_shared_path_table_size;
 189   _shared_path_table = mapinfo->_shared_path_table;
 190   _shared_path_entry_size = mapinfo->_shared_path_entry_size;
 191 
 192   // The following fields are for sanity checks for whether this archive
 193   // will function correctly with this JVM and the bootclasspath it's
 194   // invoked with.
 195 
 196   // JVM version string ... changes on each build.
 197   get_header_version(_jvm_ident);
 198 
 199   ClassLoaderExt::finalize_shared_paths_misc_info();
 200   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 201   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 202 
 203   _verify_local = BytecodeVerificationLocal;
 204   _verify_remote = BytecodeVerificationRemote;
 205   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 206 }
 207 
 208 void SharedClassPathEntry::init(const char* name, TRAPS) {

 209   _timestamp = 0;
 210   _filesize  = 0;
 211 
 212   struct stat st;
 213   if (os::stat(name, &st) == 0) {
 214     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 215       _is_dir = true;




 216     } else {
 217       _is_dir = false;
 218       _timestamp = st.st_mtime;

 219       _filesize = st.st_size;
 220     }
 221   } else {
 222     // The file/dir must exist, or it would not have been added
 223     // into ClassLoader::classpath_entry().
 224     //
 225     // If we can't access a jar file in the boot path, then we can't
 226     // make assumptions about where classes get loaded from.
 227     FileMapInfo::fail_stop("Unable to open file %s.", name);
 228   }
 229 
 230   size_t len = strlen(name) + 1;
 231   _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD);
 232   strcpy(_name->data(), name);
 233 }
 234 
 235 bool SharedClassPathEntry::validate(bool is_class_path) {
 236   assert(UseSharedSpaces, "runtime only");
 237 
 238   struct stat st;
 239   const char* name = this->name();











 240   bool ok = true;
 241   log_info(class, path)("checking shared classpath entry: %s", name);
 242   if (os::stat(name, &st) != 0 && is_class_path) {
 243     // If the archived module path entry does not exist at runtime, it is not fatal
 244     // (no need to invalid the shared archive) because the shared runtime visibility check
 245     // filters out any archived module classes that do not have a matching runtime
 246     // module path location.
 247     FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name);
 248     ok = false;
 249   } else if (is_dir()) {
 250     if (!os::dir_is_empty(name)) {
 251       FileMapInfo::fail_continue("directory is not empty: %s", name);
 252       ok = false;
 253     }
 254   } else if (is_jar_or_bootimage()) {
 255     if (_timestamp != st.st_mtime ||
 256         _filesize != st.st_size) {
 257       ok = false;
 258       if (PrintSharedArchiveAndExit) {
 259         FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
 260                                    "Timestamp mismatch" :
 261                                    "File size mismatch");
 262       } else {
 263         FileMapInfo::fail_continue("A jar/jimage file is not the one used while building"
 264                                    " the shared archive file: %s", name);
 265       }
 266     }
 267   }
 268   return ok;
 269 }
 270 
 271 void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 272   it->push(&_name);
 273   it->push(&_manifest);
 274 }
 275 
 276 void FileMapInfo::allocate_shared_path_table() {
 277   assert(DumpSharedSpaces, "Sanity");
 278 
 279   Thread* THREAD = Thread::current();
 280   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 281   ClassPathEntry* jrt = ClassLoader::get_jrt_entry();
 282 
 283   assert(jrt != NULL,
 284          "No modular java runtime image present when allocating the CDS classpath entry table");
 285 
 286   size_t entry_size = sizeof(SharedClassPathEntry); // assert ( should be 8 byte aligned??)
 287   int num_boot_classpath_entries = ClassLoader::num_boot_classpath_entries();
 288   int num_app_classpath_entries = ClassLoader::num_app_classpath_entries();
 289   int num_module_path_entries = ClassLoader::num_module_path_entries();
 290   int num_entries = num_boot_classpath_entries + num_app_classpath_entries + num_module_path_entries;
 291   size_t bytes = entry_size * num_entries;
 292 
 293   _shared_path_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD);
 294   _shared_path_table_size = num_entries;
 295   _shared_path_entry_size = entry_size;
 296 
 297   // 1. boot class path
 298   int i = 0;
 299   ClassPathEntry* cpe = jrt;
 300   while (cpe != NULL) {
 301     const char* type = ((cpe == jrt) ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));

 302     log_info(class, path)("add main shared path (%s) %s", type, cpe->name());
 303     SharedClassPathEntry* ent = shared_path(i);
 304     ent->init(cpe->name(), THREAD);
 305     if (cpe != jrt) { // No need to do jimage.
 306       EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 307       update_shared_classpath(cpe, ent, THREAD);
 308     }
 309     cpe = ClassLoader::get_next_boot_classpath_entry(cpe);
 310     i++;
 311   }
 312   assert(i == num_boot_classpath_entries,
 313          "number of boot class path entry mismatch");
 314 
 315   // 2. app class path
 316   ClassPathEntry *acpe = ClassLoader::app_classpath_entries();
 317   while (acpe != NULL) {
 318     log_info(class, path)("add app shared path %s", acpe->name());
 319     SharedClassPathEntry* ent = shared_path(i);
 320     ent->init(acpe->name(), THREAD);
 321     EXCEPTION_MARK;
 322     update_shared_classpath(acpe, ent, THREAD);
 323     acpe = acpe->next();
 324     i++;
 325   }
 326 
 327   // 3. module path
 328   ClassPathEntry *mpe = ClassLoader::module_path_entries();
 329   while (mpe != NULL) {
 330     log_info(class, path)("add module path %s",mpe->name());
 331     SharedClassPathEntry* ent = shared_path(i);
 332     ent->init(mpe->name(), THREAD);
 333     EXCEPTION_MARK;
 334     update_shared_classpath(mpe, ent, THREAD);
 335     mpe = mpe->next();
 336     i++;
 337   }
 338   assert(i == num_entries, "number of shared path entry mismatch");
 339 }
 340 
 341 void FileMapInfo::check_nonempty_dir_in_shared_path_table() {
 342   assert(DumpSharedSpaces, "dump time only");
 343 
 344   bool has_nonempty_dir = false;
 345 
 346   int end = _shared_path_table_size;
 347   if (!ClassLoaderExt::has_platform_or_app_classes()) {
 348     // only check the boot path if no app class is loaded
 349     end = ClassLoaderExt::app_class_paths_start_index();
 350   }
 351 
 352   for (int i = 0; i < end; i++) {


 403             isSigned = true;
 404             break;
 405           }
 406         }
 407         *_current = '\n'; // restore
 408         attr = _current + 1;
 409       }
 410       _current ++;
 411     }
 412     return isSigned;
 413   }
 414 };
 415 
 416 void FileMapInfo::update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) {
 417   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 418   ResourceMark rm(THREAD);
 419   jint manifest_size;
 420   bool isSigned;
 421 
 422   if (cpe->is_jar_file()) {

 423     char* manifest = ClassLoaderExt::read_manifest(cpe, &manifest_size, CHECK);
 424     if (manifest != NULL) {
 425       ManifestStream* stream = new ManifestStream((u1*)manifest,
 426                                                   manifest_size);
 427       isSigned = stream->check_is_signed();
 428       if (isSigned) {
 429         ent->set_is_signed(true);
 430       } else {
 431         // Copy the manifest into the shared archive
 432         manifest = ClassLoaderExt::read_raw_manifest(cpe, &manifest_size, CHECK);
 433         Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
 434                                                         manifest_size,
 435                                                         THREAD);
 436         char* p = (char*)(buf->data());
 437         memcpy(p, manifest, manifest_size);
 438         ent->set_manifest(buf);
 439         ent->set_is_signed(false);
 440       }
 441     }
 442   }
 443 }
 444 
 445 
 446 bool FileMapInfo::validate_shared_path_table() {
 447   assert(UseSharedSpaces, "runtime only");
 448 
 449   _validating_shared_path_table = true;
 450   _shared_path_table = _header->_shared_path_table;
 451   _shared_path_entry_size = _header->_shared_path_entry_size;
 452   _shared_path_table_size = _header->_shared_path_table_size;
 453 
 454   int module_paths_start_index = _header->_app_module_paths_start_index;
 455 
 456   // If the shared archive contain app or platform classes, validate all entries
 457   // in the shared path table. Otherwise, only validate the boot path entries (with
 458   // entry index < _app_class_paths_start_index).
 459   int count = _header->has_platform_or_app_classes() ?




 188   _shared_path_table_size = mapinfo->_shared_path_table_size;
 189   _shared_path_table = mapinfo->_shared_path_table;
 190   _shared_path_entry_size = mapinfo->_shared_path_entry_size;
 191 
 192   // The following fields are for sanity checks for whether this archive
 193   // will function correctly with this JVM and the bootclasspath it's
 194   // invoked with.
 195 
 196   // JVM version string ... changes on each build.
 197   get_header_version(_jvm_ident);
 198 
 199   ClassLoaderExt::finalize_shared_paths_misc_info();
 200   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 201   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 202 
 203   _verify_local = BytecodeVerificationLocal;
 204   _verify_remote = BytecodeVerificationRemote;
 205   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 206 }
 207 
 208 void SharedClassPathEntry::init(const char* name, bool is_modules_image, TRAPS) {
 209   assert(DumpSharedSpaces, "dump time only");
 210   _timestamp = 0;
 211   _filesize  = 0;
 212 
 213   struct stat st;
 214   if (os::stat(name, &st) == 0) {
 215     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 216       _type = dir_entry;
 217     } else {
 218       // The timestamp of the modules_image is not checked at runtime.
 219       if (is_modules_image) {
 220         _type = modules_image_entry;
 221       } else {
 222         _type = jar_entry;
 223         _timestamp = st.st_mtime;
 224       }
 225       _filesize = st.st_size;
 226     }
 227   } else {
 228     // The file/dir must exist, or it would not have been added
 229     // into ClassLoader::classpath_entry().
 230     //
 231     // If we can't access a jar file in the boot path, then we can't
 232     // make assumptions about where classes get loaded from.
 233     FileMapInfo::fail_stop("Unable to open file %s.", name);
 234   }
 235 
 236   size_t len = strlen(name) + 1;
 237   _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD);
 238   strcpy(_name->data(), name);
 239 }
 240 
 241 bool SharedClassPathEntry::validate(bool is_class_path) {
 242   assert(UseSharedSpaces, "runtime only");
 243 
 244   struct stat st;
 245   const char* name;
 246 
 247   // In order to validate the runtime modules image file size against the archived
 248   // size information, we need to obtain the runtime modules image path. The recorded
 249   // dump time modules image path in the archive may be different from the runtime path
 250   // if the JDK image has beed moved after generating the archive.
 251   if (is_modules_image()) {
 252     name = ClassLoader::get_jrt_entry()->name();
 253   } else {
 254     name = this->name();
 255   }
 256 
 257   bool ok = true;
 258   log_info(class, path)("checking shared classpath entry: %s", name);
 259   if (os::stat(name, &st) != 0 && is_class_path) {
 260     // If the archived module path entry does not exist at runtime, it is not fatal
 261     // (no need to invalid the shared archive) because the shared runtime visibility check
 262     // filters out any archived module classes that do not have a matching runtime
 263     // module path location.
 264     FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name);
 265     ok = false;
 266   } else if (is_dir()) {
 267     if (!os::dir_is_empty(name)) {
 268       FileMapInfo::fail_continue("directory is not empty: %s", name);
 269       ok = false;
 270     }
 271   } else if ((has_timestamp() && _timestamp != st.st_mtime) ||

 272              _filesize != st.st_size) {
 273     ok = false;
 274     if (PrintSharedArchiveAndExit) {
 275       FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
 276                                  "Timestamp mismatch" :
 277                                  "File size mismatch");
 278     } else {
 279       FileMapInfo::fail_continue("A jar file is not the one used while building"
 280                                  " the shared archive file: %s", name);
 281     }
 282   }

 283   return ok;
 284 }
 285 
 286 void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 287   it->push(&_name);
 288   it->push(&_manifest);
 289 }
 290 
 291 void FileMapInfo::allocate_shared_path_table() {
 292   assert(DumpSharedSpaces, "Sanity");
 293 
 294   Thread* THREAD = Thread::current();
 295   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 296   ClassPathEntry* jrt = ClassLoader::get_jrt_entry();
 297 
 298   assert(jrt != NULL,
 299          "No modular java runtime image present when allocating the CDS classpath entry table");
 300 
 301   size_t entry_size = sizeof(SharedClassPathEntry); // assert ( should be 8 byte aligned??)
 302   int num_boot_classpath_entries = ClassLoader::num_boot_classpath_entries();
 303   int num_app_classpath_entries = ClassLoader::num_app_classpath_entries();
 304   int num_module_path_entries = ClassLoader::num_module_path_entries();
 305   int num_entries = num_boot_classpath_entries + num_app_classpath_entries + num_module_path_entries;
 306   size_t bytes = entry_size * num_entries;
 307 
 308   _shared_path_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD);
 309   _shared_path_table_size = num_entries;
 310   _shared_path_entry_size = entry_size;
 311 
 312   // 1. boot class path
 313   int i = 0;
 314   ClassPathEntry* cpe = jrt;
 315   while (cpe != NULL) {
 316     bool is_jrt = (cpe == jrt);
 317     const char* type = (is_jrt ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));
 318     log_info(class, path)("add main shared path (%s) %s", type, cpe->name());
 319     SharedClassPathEntry* ent = shared_path(i);
 320     ent->init(cpe->name(), is_jrt, THREAD);
 321     if (!is_jrt) {    // No need to do the modules image.
 322       EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 323       update_shared_classpath(cpe, ent, THREAD);
 324     }
 325     cpe = ClassLoader::get_next_boot_classpath_entry(cpe);
 326     i++;
 327   }
 328   assert(i == num_boot_classpath_entries,
 329          "number of boot class path entry mismatch");
 330 
 331   // 2. app class path
 332   ClassPathEntry *acpe = ClassLoader::app_classpath_entries();
 333   while (acpe != NULL) {
 334     log_info(class, path)("add app shared path %s", acpe->name());
 335     SharedClassPathEntry* ent = shared_path(i);
 336     ent->init(acpe->name(), false, THREAD);
 337     EXCEPTION_MARK;
 338     update_shared_classpath(acpe, ent, THREAD);
 339     acpe = acpe->next();
 340     i++;
 341   }
 342 
 343   // 3. module path
 344   ClassPathEntry *mpe = ClassLoader::module_path_entries();
 345   while (mpe != NULL) {
 346     log_info(class, path)("add module path %s",mpe->name());
 347     SharedClassPathEntry* ent = shared_path(i);
 348     ent->init(mpe->name(), false, THREAD);
 349     EXCEPTION_MARK;
 350     update_shared_classpath(mpe, ent, THREAD);
 351     mpe = mpe->next();
 352     i++;
 353   }
 354   assert(i == num_entries, "number of shared path entry mismatch");
 355 }
 356 
 357 void FileMapInfo::check_nonempty_dir_in_shared_path_table() {
 358   assert(DumpSharedSpaces, "dump time only");
 359 
 360   bool has_nonempty_dir = false;
 361 
 362   int end = _shared_path_table_size;
 363   if (!ClassLoaderExt::has_platform_or_app_classes()) {
 364     // only check the boot path if no app class is loaded
 365     end = ClassLoaderExt::app_class_paths_start_index();
 366   }
 367 
 368   for (int i = 0; i < end; i++) {


 419             isSigned = true;
 420             break;
 421           }
 422         }
 423         *_current = '\n'; // restore
 424         attr = _current + 1;
 425       }
 426       _current ++;
 427     }
 428     return isSigned;
 429   }
 430 };
 431 
 432 void FileMapInfo::update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) {
 433   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 434   ResourceMark rm(THREAD);
 435   jint manifest_size;
 436   bool isSigned;
 437 
 438   if (cpe->is_jar_file()) {
 439     assert(ent->is_jar(), "the shared class path entry is not a JAR file");
 440     char* manifest = ClassLoaderExt::read_manifest(cpe, &manifest_size, CHECK);
 441     if (manifest != NULL) {
 442       ManifestStream* stream = new ManifestStream((u1*)manifest,
 443                                                   manifest_size);
 444       isSigned = stream->check_is_signed();
 445       if (isSigned) {
 446         ent->set_is_signed();
 447       } else {
 448         // Copy the manifest into the shared archive
 449         manifest = ClassLoaderExt::read_raw_manifest(cpe, &manifest_size, CHECK);
 450         Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
 451                                                         manifest_size,
 452                                                         THREAD);
 453         char* p = (char*)(buf->data());
 454         memcpy(p, manifest, manifest_size);
 455         ent->set_manifest(buf);

 456       }
 457     }
 458   }
 459 }
 460 
 461 
 462 bool FileMapInfo::validate_shared_path_table() {
 463   assert(UseSharedSpaces, "runtime only");
 464 
 465   _validating_shared_path_table = true;
 466   _shared_path_table = _header->_shared_path_table;
 467   _shared_path_entry_size = _header->_shared_path_entry_size;
 468   _shared_path_table_size = _header->_shared_path_table_size;
 469 
 470   int module_paths_start_index = _header->_app_module_paths_start_index;
 471 
 472   // If the shared archive contain app or platform classes, validate all entries
 473   // in the shared path table. Otherwise, only validate the boot path entries (with
 474   // entry index < _app_class_paths_start_index).
 475   int count = _header->has_platform_or_app_classes() ?


< prev index next >