696 } 697 return true; 698 } 699 700 bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { 701 const char *appcp = Arguments::get_appclasspath(); 702 assert(appcp != NULL, "NULL app classpath"); 703 int rp_len = num_paths(appcp); 704 bool mismatch = false; 705 if (rp_len < shared_app_paths_len) { 706 return fail("Run time APP classpath is shorter than the one at dump time: ", appcp); 707 } 708 if (shared_app_paths_len != 0 && rp_len != 0) { 709 // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar. 710 ResourceMark rm; 711 GrowableArray<const char*>* rp_array = create_path_array(appcp); 712 if (rp_array->length() == 0) { 713 // None of the jar file specified in the runtime -cp exists. 714 return fail("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp); 715 } 716 int j = _header->_app_class_paths_start_index; 717 mismatch = check_paths(j, shared_app_paths_len, rp_array); 718 if (mismatch) { 719 return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp); 720 } 721 } 722 return true; 723 } 724 725 void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) { 726 LogTarget(Info, class, path) lt; 727 if (lt.is_enabled()) { 728 LogStream ls(lt); 729 ls.print("%s", msg); 730 const char* prefix = ""; 731 for (int i = start_idx; i < end_idx; i++) { 732 ls.print("%s%s", prefix, shared_path(i)->name()); 733 prefix = os::path_separator(); 734 } 735 ls.cr(); 790 log_info(class, path)("ok"); 791 } else { 792 if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) { 793 assert(!UseSharedSpaces, "UseSharedSpaces should be disabled"); 794 } 795 return false; 796 } 797 } 798 } 799 800 if (_header->_max_used_path_index == 0) { 801 // default archive only contains the module image in the bootclasspath 802 assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); 803 } else { 804 if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) { 805 fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)"); 806 return false; 807 } 808 } 809 810 if (!validate_non_existent_class_paths()) { 811 return false; 812 } 813 814 _validating_shared_path_table = false; 815 816 #if INCLUDE_JVMTI 817 if (_classpath_entries_for_jvmti != NULL) { 818 os::free(_classpath_entries_for_jvmti); 819 } 820 size_t sz = sizeof(ClassPathEntry*) * get_number_of_shared_paths(); 821 _classpath_entries_for_jvmti = (ClassPathEntry**)os::malloc(sz, mtClass); 822 memset((void*)_classpath_entries_for_jvmti, 0, sz); 823 #endif 824 825 return true; 826 } 827 828 bool FileMapInfo::validate_non_existent_class_paths() const { 829 assert(UseSharedSpaces, "runtime only"); 830 for (int i = _header->_app_module_paths_start_index + _header->_num_module_paths; 831 i < get_number_of_shared_paths(); 832 i++) { 833 SharedClassPathEntry* ent = shared_path(i); 834 if (!ent->check_non_existent()) { 835 fail_continue("file must not exist: %s", ent->name()); 836 return false; 837 } 838 } 839 return true; 840 } 841 842 843 844 bool FileMapInfo::check_archive(const char* archive_name, bool is_static) { 845 int fd = os::open(archive_name, O_RDONLY | O_BINARY, 0); 846 if (fd < 0) { 847 // do not vm_exit_during_initialization here because Arguments::init_shared_archive_paths() 848 // requires a shared archive name. The open_for_read() function will log a message regarding 849 // failure in opening a shared archive. 850 return false; 851 } 852 853 size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader); 854 void* header = os::malloc(sz, mtInternal); 855 memset(header, 0, sz); 856 size_t n = os::read(fd, header, (unsigned int)sz); 857 if (n != sz) { 858 os::free(header); 859 os::close(fd); 860 vm_exit_during_initialization("Unable to read header from shared archive", archive_name); 861 return false; 862 } | 696 } 697 return true; 698 } 699 700 bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { 701 const char *appcp = Arguments::get_appclasspath(); 702 assert(appcp != NULL, "NULL app classpath"); 703 int rp_len = num_paths(appcp); 704 bool mismatch = false; 705 if (rp_len < shared_app_paths_len) { 706 return fail("Run time APP classpath is shorter than the one at dump time: ", appcp); 707 } 708 if (shared_app_paths_len != 0 && rp_len != 0) { 709 // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar. 710 ResourceMark rm; 711 GrowableArray<const char*>* rp_array = create_path_array(appcp); 712 if (rp_array->length() == 0) { 713 // None of the jar file specified in the runtime -cp exists. 714 return fail("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp); 715 } 716 717 // Handling of non-existent entries in the classpath: we eliminate all the non-existent 718 // entries from both the dump time classpath (ClassLoader::update_class_path_entry_list) 719 // and the runtime classpath (FileMapInfo::create_path_array), and check the remaining 720 // entries. E.g.: 721 // 722 // dump : -cp a.jar:NE1:NE2:b.jar -> a.jar:b.jar -> recorded in archive. 723 // run 1: -cp NE3:a.jar:NE4:b.jar -> a.jar:b.jar -> matched 724 // run 2: -cp x.jar:NE4:b.jar -> x.jar:b.jar -> mismatched 725 726 int j = _header->_app_class_paths_start_index; 727 mismatch = check_paths(j, shared_app_paths_len, rp_array); 728 if (mismatch) { 729 return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp); 730 } 731 } 732 return true; 733 } 734 735 void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) { 736 LogTarget(Info, class, path) lt; 737 if (lt.is_enabled()) { 738 LogStream ls(lt); 739 ls.print("%s", msg); 740 const char* prefix = ""; 741 for (int i = start_idx; i < end_idx; i++) { 742 ls.print("%s%s", prefix, shared_path(i)->name()); 743 prefix = os::path_separator(); 744 } 745 ls.cr(); 800 log_info(class, path)("ok"); 801 } else { 802 if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) { 803 assert(!UseSharedSpaces, "UseSharedSpaces should be disabled"); 804 } 805 return false; 806 } 807 } 808 } 809 810 if (_header->_max_used_path_index == 0) { 811 // default archive only contains the module image in the bootclasspath 812 assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); 813 } else { 814 if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) { 815 fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)"); 816 return false; 817 } 818 } 819 820 validate_non_existent_class_paths(); 821 822 _validating_shared_path_table = false; 823 824 #if INCLUDE_JVMTI 825 if (_classpath_entries_for_jvmti != NULL) { 826 os::free(_classpath_entries_for_jvmti); 827 } 828 size_t sz = sizeof(ClassPathEntry*) * get_number_of_shared_paths(); 829 _classpath_entries_for_jvmti = (ClassPathEntry**)os::malloc(sz, mtClass); 830 memset((void*)_classpath_entries_for_jvmti, 0, sz); 831 #endif 832 833 return true; 834 } 835 836 void FileMapInfo::validate_non_existent_class_paths() { 837 // All of the recorded non-existent paths came from the Class-Path: attribute from the JAR 838 // files on the app classpath. If any of these are found to exist during runtime, 839 // it will change how classes are loading for the app loader. For safety, disable 840 // loading of archived platform/app classes (currently there's no way to disable just the 841 // app classes). 842 843 assert(UseSharedSpaces, "runtime only"); 844 for (int i = _header->_app_module_paths_start_index + _header->_num_module_paths; 845 i < get_number_of_shared_paths(); 846 i++) { 847 SharedClassPathEntry* ent = shared_path(i); 848 if (!ent->check_non_existent()) { 849 warning("Archived non-system classes are disabled because the " 850 "file %s exists", ent->name()); 851 _header->_has_platform_or_app_classes = false; 852 } 853 } 854 } 855 856 bool FileMapInfo::check_archive(const char* archive_name, bool is_static) { 857 int fd = os::open(archive_name, O_RDONLY | O_BINARY, 0); 858 if (fd < 0) { 859 // do not vm_exit_during_initialization here because Arguments::init_shared_archive_paths() 860 // requires a shared archive name. The open_for_read() function will log a message regarding 861 // failure in opening a shared archive. 862 return false; 863 } 864 865 size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader); 866 void* header = os::malloc(sz, mtInternal); 867 memset(header, 0, sz); 868 size_t n = os::read(fd, header, (unsigned int)sz); 869 if (n != sz) { 870 os::free(header); 871 os::close(fd); 872 vm_exit_during_initialization("Unable to read header from shared archive", archive_name); 873 return false; 874 } |