72 _cur_ptr += size; 73 } 74 75 bool SharedPathsMiscInfo::read(void* ptr, size_t size) { 76 if (_cur_ptr + size <= _end_ptr) { 77 memcpy(ptr, _cur_ptr, size); 78 _cur_ptr += size; 79 return true; 80 } 81 return false; 82 } 83 84 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) { 85 ClassLoader::trace_class_path(msg, name); 86 MetaspaceShared::set_archive_loading_failed(); 87 return false; 88 } 89 90 void SharedPathsMiscInfo::print_path(outputStream* out, int type, const char* path) { 91 switch (type) { 92 case BOOT: 93 out->print("Expecting BOOT path=%s", path); 94 break; 95 case NON_EXIST: 96 out->print("Expecting that %s does not exist", path); 97 break; 98 case APP: 99 ClassLoader::trace_class_path("Expecting -Djava.class.path=", path); 100 break; 101 case MODULE: 102 ClassLoader::trace_class_path("Checking module path: ", path); 103 break; 104 default: 105 ShouldNotReachHere(); 106 } 107 } 108 109 bool SharedPathsMiscInfo::check() { 110 // The whole buffer must be 0 terminated so that we can use strlen and strcmp 111 // without fear. 112 _end_ptr -= sizeof(jint); 113 if (_cur_ptr >= _end_ptr) { 114 return fail("Truncated archive file header"); 115 } 116 if (*_end_ptr != 0) { 117 return fail("Corrupted archive file header"); 118 } 119 120 while (_cur_ptr < _end_ptr) { 121 jint type; 128 if (lt.is_enabled()) { 129 lt.print("type=%s ", type_name(type)); 130 LogStream ls(lt); 131 print_path(&ls, type, path); 132 ls.cr(); 133 } 134 if (!check(type, path)) { 135 if (!PrintSharedArchiveAndExit) { 136 return false; 137 } 138 } else { 139 ClassLoader::trace_class_path("ok"); 140 } 141 } 142 143 return true; 144 } 145 146 bool SharedPathsMiscInfo::check(jint type, const char* path) { 147 switch (type) { 148 case BOOT: 149 // In the future we should perform the check based on the content of the mapped archive. 150 if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) { 151 return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath()); 152 } 153 break; 154 case NON_EXIST: 155 { 156 struct stat st; 157 if (os::stat(path, &st) == 0) { 158 // The file actually exists 159 // But we want it to not exist -> fail 160 return fail("File must not exist"); 161 } 162 } 163 break; 164 case APP: 165 { 166 // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar 167 size_t len = strlen(path); 168 const char *appcp = Arguments::get_appclasspath(); 169 assert(appcp != NULL, "NULL app classpath"); 170 size_t appcp_len = strlen(appcp); 171 if (appcp_len < len) { 172 return fail("Run time APP classpath is shorter than the one at dump time: ", appcp); 173 } 174 ResourceMark rm; 175 char* tmp_path; 176 if (len == appcp_len) { 177 tmp_path = (char*)appcp; 178 } else { 179 tmp_path = NEW_RESOURCE_ARRAY(char, len + 1); 180 strncpy(tmp_path, appcp, len); 181 tmp_path[len] = 0; 182 } 183 if (os::file_name_strcmp(path, tmp_path) != 0) { 184 return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp); 185 } 186 if (appcp[len] != '\0' && appcp[len] != os::path_separator()[0]) { 187 return fail("Dump time APP classpath is not a proper prefix of run time APP classpath: ", appcp); 188 } 189 } 190 break; 191 // FIXME: why is there no MODULE check? 192 default: 193 return fail("Corrupted archive file header"); 194 } 195 196 return true; 197 } | 72 _cur_ptr += size; 73 } 74 75 bool SharedPathsMiscInfo::read(void* ptr, size_t size) { 76 if (_cur_ptr + size <= _end_ptr) { 77 memcpy(ptr, _cur_ptr, size); 78 _cur_ptr += size; 79 return true; 80 } 81 return false; 82 } 83 84 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) { 85 ClassLoader::trace_class_path(msg, name); 86 MetaspaceShared::set_archive_loading_failed(); 87 return false; 88 } 89 90 void SharedPathsMiscInfo::print_path(outputStream* out, int type, const char* path) { 91 switch (type) { 92 case BOOT_PATH: 93 out->print("Expecting BOOT path=%s", path); 94 break; 95 case NON_EXIST: 96 out->print("Expecting that %s does not exist", path); 97 break; 98 case APP_PATH: 99 ClassLoader::trace_class_path("Expecting -Djava.class.path=", path); 100 break; 101 case MODULE_PATH: 102 ClassLoader::trace_class_path("Checking module path: ", path); 103 break; 104 default: 105 ShouldNotReachHere(); 106 } 107 } 108 109 bool SharedPathsMiscInfo::check() { 110 // The whole buffer must be 0 terminated so that we can use strlen and strcmp 111 // without fear. 112 _end_ptr -= sizeof(jint); 113 if (_cur_ptr >= _end_ptr) { 114 return fail("Truncated archive file header"); 115 } 116 if (*_end_ptr != 0) { 117 return fail("Corrupted archive file header"); 118 } 119 120 while (_cur_ptr < _end_ptr) { 121 jint type; 128 if (lt.is_enabled()) { 129 lt.print("type=%s ", type_name(type)); 130 LogStream ls(lt); 131 print_path(&ls, type, path); 132 ls.cr(); 133 } 134 if (!check(type, path)) { 135 if (!PrintSharedArchiveAndExit) { 136 return false; 137 } 138 } else { 139 ClassLoader::trace_class_path("ok"); 140 } 141 } 142 143 return true; 144 } 145 146 bool SharedPathsMiscInfo::check(jint type, const char* path) { 147 switch (type) { 148 case BOOT_PATH: 149 // In the future we should perform the check based on the content of the mapped archive. 150 if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) { 151 return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath()); 152 } 153 break; 154 case NON_EXIST: 155 { 156 struct stat st; 157 if (os::stat(path, &st) == 0) { 158 // The file actually exists 159 // But we want it to not exist -> fail 160 return fail("File must not exist"); 161 } 162 } 163 break; 164 case APP_PATH: 165 { 166 // Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar 167 size_t len = strlen(path); 168 const char *appcp = Arguments::get_appclasspath(); 169 assert(appcp != NULL, "NULL app classpath"); 170 size_t appcp_len = strlen(appcp); 171 if (appcp_len < len) { 172 return fail("Run time APP classpath is shorter than the one at dump time: ", appcp); 173 } 174 ResourceMark rm; 175 char* tmp_path; 176 if (len == appcp_len) { 177 tmp_path = (char*)appcp; 178 } else { 179 tmp_path = NEW_RESOURCE_ARRAY(char, len + 1); 180 strncpy(tmp_path, appcp, len); 181 tmp_path[len] = 0; 182 } 183 if (os::file_name_strcmp(path, tmp_path) != 0) { 184 return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp); 185 } 186 if (appcp[len] != '\0' && appcp[len] != os::path_separator()[0]) { 187 return fail("Dump time APP classpath is not a proper prefix of run time APP classpath: ", appcp); 188 } 189 } 190 break; 191 case MODULE_PATH: 192 // The path check for archived module classes is handled differently than the classes 193 // from the -cp or -Xbootclasspath/a because we can quickly determine if an archived 194 // module class's origin matches with the runtime module source path (see 195 // SystemDictionaryShared::is_shared_class_visible_for_classloader()). No need to 196 // do strict string matching here. 197 ShouldNotReachHere(); 198 default: 199 return fail("Corrupted archive file header"); 200 } 201 202 return true; 203 } |