< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page


 585     }
 586   }
 587   return npaths;
 588 }
 589 
 590 GrowableArray<const char*>* FileMapInfo::create_path_array(const char* paths) {
 591   GrowableArray<const char*>* path_array =  new(ResourceObj::RESOURCE_AREA, mtInternal)
 592       GrowableArray<const char*>(10);
 593 
 594   ClasspathStream cp_stream(paths);
 595   while (cp_stream.has_next()) {
 596     const char* path = cp_stream.get_next();
 597     struct stat st;
 598     if (os::stat(path, &st) == 0) {
 599       path_array->append(path);
 600     }
 601   }
 602   return path_array;
 603 }
 604 
 605 bool FileMapInfo::fail(const char* msg, const char* name) {
 606   ClassLoader::trace_class_path(msg, name);



 607   return false;
 608 }
 609 
 610 bool FileMapInfo::check_paths(int shared_path_start_idx, int num_paths, GrowableArray<const char*>* rp_array) {
 611   int i = 0;
 612   int j = shared_path_start_idx;
 613   bool mismatch = false;
 614   while (i < num_paths && !mismatch) {
 615     while (shared_path(j)->from_class_path_attr()) {
 616       // shared_path(j) was expanded from the JAR file attribute "Class-Path:"
 617       // during dump time. It's not included in the -classpath VM argument.
 618       j++;
 619     }
 620     if (!os::same_files(shared_path(j)->name(), rp_array->at(i))) {
 621       mismatch = true;
 622     }
 623     i++;
 624     j++;
 625   }
 626   return mismatch;


 661   } else if (dp_len > 0 && rp != NULL) {
 662     int num;
 663     ResourceMark rm;
 664     GrowableArray<const char*>* rp_array = create_path_array(rp);
 665     int rp_len = rp_array->length();
 666     if (rp_len >= dp_len) {
 667       if (relaxed_check) {
 668         // only check the leading entries in the runtime boot path, up to
 669         // the length of the dump time boot path
 670         num = dp_len;
 671       } else {
 672         // check the full runtime boot path, must match with dump time
 673         num = rp_len;
 674       }
 675       mismatch = check_paths(1, num, rp_array);
 676     }
 677   }
 678 
 679   if (mismatch) {
 680     // The paths are different
 681     return fail("[BOOT classpath mismatch, actual =", runtime_boot_path);
 682   }
 683   return true;
 684 }
 685 
 686 bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) {
 687   const char *appcp = Arguments::get_appclasspath();
 688   assert(appcp != NULL, "NULL app classpath");
 689   int rp_len = num_paths(appcp);
 690   bool mismatch = false;
 691   if (rp_len < shared_app_paths_len) {
 692     return fail("Run time APP classpath is shorter than the one at dump time: ", appcp);
 693   }
 694   if (shared_app_paths_len != 0 && rp_len != 0) {
 695     // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar.
 696     ResourceMark rm;
 697     GrowableArray<const char*>* rp_array = create_path_array(appcp);
 698     if (rp_array->length() == 0) {
 699       // None of the jar file specified in the runtime -cp exists.
 700       return fail("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp);
 701     }
 702 
 703     // Handling of non-existent entries in the classpath: we eliminate all the non-existent
 704     // entries from both the dump time classpath (ClassLoader::update_class_path_entry_list)
 705     // and the runtime classpath (FileMapInfo::create_path_array), and check the remaining
 706     // entries. E.g.:
 707     //
 708     // dump : -cp a.jar:NE1:NE2:b.jar  -> a.jar:b.jar -> recorded in archive.
 709     // run 1: -cp NE3:a.jar:NE4:b.jar  -> a.jar:b.jar -> matched
 710     // run 2: -cp x.jar:NE4:b.jar      -> x.jar:b.jar -> mismatched
 711 
 712     int j = header()->app_class_paths_start_index();
 713     mismatch = check_paths(j, shared_app_paths_len, rp_array);
 714     if (mismatch) {
 715       return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
 716     }
 717   }
 718   return true;
 719 }
 720 
 721 void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) {
 722   LogTarget(Info, class, path) lt;
 723   if (lt.is_enabled()) {
 724     LogStream ls(lt);
 725     ls.print("%s", msg);
 726     const char* prefix = "";
 727     for (int i = start_idx; i < end_idx; i++) {
 728       ls.print("%s%s", prefix, shared_path(i)->name());
 729       prefix = os::path_separator();
 730     }
 731     ls.cr();
 732   }
 733 }
 734 
 735 bool FileMapInfo::validate_shared_path_table() {




 585     }
 586   }
 587   return npaths;
 588 }
 589 
 590 GrowableArray<const char*>* FileMapInfo::create_path_array(const char* paths) {
 591   GrowableArray<const char*>* path_array =  new(ResourceObj::RESOURCE_AREA, mtInternal)
 592       GrowableArray<const char*>(10);
 593 
 594   ClasspathStream cp_stream(paths);
 595   while (cp_stream.has_next()) {
 596     const char* path = cp_stream.get_next();
 597     struct stat st;
 598     if (os::stat(path, &st) == 0) {
 599       path_array->append(path);
 600     }
 601   }
 602   return path_array;
 603 }
 604 
 605 bool FileMapInfo::classpath_failure(const char* msg, const char* name) {
 606   ClassLoader::trace_class_path(msg, name);
 607   if (PrintSharedArchiveAndExit) {
 608     MetaspaceShared::set_archive_loading_failed();
 609   }
 610   return false;
 611 }
 612 
 613 bool FileMapInfo::check_paths(int shared_path_start_idx, int num_paths, GrowableArray<const char*>* rp_array) {
 614   int i = 0;
 615   int j = shared_path_start_idx;
 616   bool mismatch = false;
 617   while (i < num_paths && !mismatch) {
 618     while (shared_path(j)->from_class_path_attr()) {
 619       // shared_path(j) was expanded from the JAR file attribute "Class-Path:"
 620       // during dump time. It's not included in the -classpath VM argument.
 621       j++;
 622     }
 623     if (!os::same_files(shared_path(j)->name(), rp_array->at(i))) {
 624       mismatch = true;
 625     }
 626     i++;
 627     j++;
 628   }
 629   return mismatch;


 664   } else if (dp_len > 0 && rp != NULL) {
 665     int num;
 666     ResourceMark rm;
 667     GrowableArray<const char*>* rp_array = create_path_array(rp);
 668     int rp_len = rp_array->length();
 669     if (rp_len >= dp_len) {
 670       if (relaxed_check) {
 671         // only check the leading entries in the runtime boot path, up to
 672         // the length of the dump time boot path
 673         num = dp_len;
 674       } else {
 675         // check the full runtime boot path, must match with dump time
 676         num = rp_len;
 677       }
 678       mismatch = check_paths(1, num, rp_array);
 679     }
 680   }
 681 
 682   if (mismatch) {
 683     // The paths are different
 684     return classpath_failure("[BOOT classpath mismatch, actual =", runtime_boot_path);
 685   }
 686   return true;
 687 }
 688 
 689 bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) {
 690   const char *appcp = Arguments::get_appclasspath();
 691   assert(appcp != NULL, "NULL app classpath");
 692   int rp_len = num_paths(appcp);
 693   bool mismatch = false;
 694   if (rp_len < shared_app_paths_len) {
 695     return classpath_failure("Run time APP classpath is shorter than the one at dump time: ", appcp);
 696   }
 697   if (shared_app_paths_len != 0 && rp_len != 0) {
 698     // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar.
 699     ResourceMark rm;
 700     GrowableArray<const char*>* rp_array = create_path_array(appcp);
 701     if (rp_array->length() == 0) {
 702       // None of the jar file specified in the runtime -cp exists.
 703       return classpath_failure("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp);
 704     }
 705 
 706     // Handling of non-existent entries in the classpath: we eliminate all the non-existent
 707     // entries from both the dump time classpath (ClassLoader::update_class_path_entry_list)
 708     // and the runtime classpath (FileMapInfo::create_path_array), and check the remaining
 709     // entries. E.g.:
 710     //
 711     // dump : -cp a.jar:NE1:NE2:b.jar  -> a.jar:b.jar -> recorded in archive.
 712     // run 1: -cp NE3:a.jar:NE4:b.jar  -> a.jar:b.jar -> matched
 713     // run 2: -cp x.jar:NE4:b.jar      -> x.jar:b.jar -> mismatched
 714 
 715     int j = header()->app_class_paths_start_index();
 716     mismatch = check_paths(j, shared_app_paths_len, rp_array);
 717     if (mismatch) {
 718       return classpath_failure("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
 719     }
 720   }
 721   return true;
 722 }
 723 
 724 void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) {
 725   LogTarget(Info, class, path) lt;
 726   if (lt.is_enabled()) {
 727     LogStream ls(lt);
 728     ls.print("%s", msg);
 729     const char* prefix = "";
 730     for (int i = start_idx; i < end_idx; i++) {
 731       ls.print("%s%s", prefix, shared_path(i)->name());
 732       prefix = os::path_separator();
 733     }
 734     ls.cr();
 735   }
 736 }
 737 
 738 bool FileMapInfo::validate_shared_path_table() {


< prev index next >