190 _narrow_klass_shift = Universe::narrow_klass_shift(); 191 _shared_path_table_size = mapinfo->_shared_path_table_size; 192 _shared_path_table = mapinfo->_shared_path_table; 193 _shared_path_entry_size = mapinfo->_shared_path_entry_size; 194 195 // The following fields are for sanity checks for whether this archive 196 // will function correctly with this JVM and the bootclasspath it's 197 // invoked with. 198 199 // JVM version string ... changes on each build. 200 get_header_version(_jvm_ident); 201 } 202 203 void SharedClassPathEntry::init(const char* name, TRAPS) { 204 _timestamp = 0; 205 _filesize = 0; 206 207 struct stat st; 208 if (os::stat(name, &st) == 0) { 209 if ((st.st_mode & S_IFMT) == S_IFDIR) { 210 if (!os::dir_is_empty(name)) { 211 ClassLoader::exit_with_path_failure( 212 "Cannot have non-empty directory in archived classpaths", name); 213 } 214 _is_dir = true; 215 } else { 216 _is_dir = false; 217 _timestamp = st.st_mtime; 218 _filesize = st.st_size; 219 } 220 } else { 221 // The file/dir must exist, or it would not have been added 222 // into ClassLoader::classpath_entry(). 223 // 224 // If we can't access a jar file in the boot path, then we can't 225 // make assumptions about where classes get loaded from. 226 FileMapInfo::fail_stop("Unable to open file %s.", name); 227 } 228 229 size_t len = strlen(name) + 1; 230 _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD); 231 strcpy(_name->data(), name); 232 } 233 234 bool SharedClassPathEntry::validate(bool is_class_path) { 235 struct stat st; 236 const char* name = this->name(); 237 bool ok = true; 238 log_info(class, path)("checking shared classpath entry: %s", name); 239 if (os::stat(name, &st) != 0 && is_class_path) { 240 // If the archived module path entry does not exist at runtime, it is not fatal 241 // (no need to invalid the shared archive) because the shared runtime visibility check 242 // filters out any archived module classes that do not have a matching runtime 243 // module path location. 244 FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name); 245 ok = false; 246 } else if (is_dir()) { 247 if (!os::dir_is_empty(name)) { 248 FileMapInfo::fail_continue("directory is not empty: %s", name); 249 ok = false; 250 } 251 } else if (is_jar_or_bootimage()) { 252 if (_timestamp != st.st_mtime || 253 _filesize != st.st_size) { 254 ok = false; 318 EXCEPTION_MARK; 319 SharedClassUtil::update_shared_classpath(acpe, ent, THREAD); 320 acpe = acpe->next(); 321 i++; 322 } 323 324 // 3. module path 325 ClassPathEntry *mpe = ClassLoader::module_path_entries(); 326 while (mpe != NULL) { 327 log_info(class, path)("add module path %s",mpe->name()); 328 SharedClassPathEntry* ent = shared_path(i); 329 ent->init(mpe->name(), THREAD); 330 EXCEPTION_MARK; 331 SharedClassUtil::update_shared_classpath(mpe, ent, THREAD); 332 mpe = mpe->next(); 333 i++; 334 } 335 assert(i == num_entries, "number of shared path entry mismatch"); 336 } 337 338 // This function should only be called during run time with UseSharedSpaces enabled. 339 bool FileMapInfo::validate_shared_path_table() { 340 _validating_shared_path_table = true; 341 342 _shared_path_table = _header->_shared_path_table; 343 _shared_path_entry_size = _header->_shared_path_entry_size; 344 _shared_path_table_size = _header->_shared_path_table_size; 345 346 // Note: _app_module_paths_start_index may not have a valid value if the UseAppCDS flag 347 // wasn't enabled during dump time. Therefore, we need to use the smaller of 348 // _shared_path_table_size and _app_module_paths_start_index for the _app_module_paths_start_index. 349 FileMapHeaderExt* header = (FileMapHeaderExt*)FileMapInfo::current_info()->header(); 350 int module_paths_start_index = (header->_app_module_paths_start_index >= _shared_path_table_size) ? 351 _shared_path_table_size : header->_app_module_paths_start_index; 352 353 int count = _shared_path_table_size; 354 355 for (int i=0; i<count; i++) { 356 if (i < module_paths_start_index) { 357 if (shared_path(i)->validate()) { 358 log_info(class, path)("ok"); 359 } 360 } else if (i >= module_paths_start_index) { 361 if (shared_path(i)->validate(false /* not a class path entry */)) { 362 log_info(class, path)("ok"); 363 } 364 } else if (!PrintSharedArchiveAndExit) { 365 _validating_shared_path_table = false; 366 _shared_path_table = NULL; 367 _shared_path_table_size = 0; 368 return false; 369 } 370 } 371 372 _validating_shared_path_table = false; 373 return true; | 190 _narrow_klass_shift = Universe::narrow_klass_shift(); 191 _shared_path_table_size = mapinfo->_shared_path_table_size; 192 _shared_path_table = mapinfo->_shared_path_table; 193 _shared_path_entry_size = mapinfo->_shared_path_entry_size; 194 195 // The following fields are for sanity checks for whether this archive 196 // will function correctly with this JVM and the bootclasspath it's 197 // invoked with. 198 199 // JVM version string ... changes on each build. 200 get_header_version(_jvm_ident); 201 } 202 203 void SharedClassPathEntry::init(const char* name, TRAPS) { 204 _timestamp = 0; 205 _filesize = 0; 206 207 struct stat st; 208 if (os::stat(name, &st) == 0) { 209 if ((st.st_mode & S_IFMT) == S_IFDIR) { 210 _is_dir = true; 211 } else { 212 _is_dir = false; 213 _timestamp = st.st_mtime; 214 _filesize = st.st_size; 215 } 216 } else { 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 file %s.", name); 223 } 224 225 size_t len = strlen(name) + 1; 226 _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD); 227 strcpy(_name->data(), name); 228 } 229 230 bool SharedClassPathEntry::validate(bool is_class_path) { 231 assert(UseSharedSpaces, "runtime only"); 232 233 struct stat st; 234 const char* name = this->name(); 235 bool ok = true; 236 log_info(class, path)("checking shared classpath entry: %s", name); 237 if (os::stat(name, &st) != 0 && is_class_path) { 238 // If the archived module path entry does not exist at runtime, it is not fatal 239 // (no need to invalid the shared archive) because the shared runtime visibility check 240 // filters out any archived module classes that do not have a matching runtime 241 // module path location. 242 FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name); 243 ok = false; 244 } else if (is_dir()) { 245 if (!os::dir_is_empty(name)) { 246 FileMapInfo::fail_continue("directory is not empty: %s", name); 247 ok = false; 248 } 249 } else if (is_jar_or_bootimage()) { 250 if (_timestamp != st.st_mtime || 251 _filesize != st.st_size) { 252 ok = false; 316 EXCEPTION_MARK; 317 SharedClassUtil::update_shared_classpath(acpe, ent, THREAD); 318 acpe = acpe->next(); 319 i++; 320 } 321 322 // 3. module path 323 ClassPathEntry *mpe = ClassLoader::module_path_entries(); 324 while (mpe != NULL) { 325 log_info(class, path)("add module path %s",mpe->name()); 326 SharedClassPathEntry* ent = shared_path(i); 327 ent->init(mpe->name(), THREAD); 328 EXCEPTION_MARK; 329 SharedClassUtil::update_shared_classpath(mpe, ent, THREAD); 330 mpe = mpe->next(); 331 i++; 332 } 333 assert(i == num_entries, "number of shared path entry mismatch"); 334 } 335 336 void FileMapInfo::check_nonempty_dir_in_shared_path_table() { 337 assert(DumpSharedSpaces, "dump time only"); 338 int end = _shared_path_table_size; 339 if (!ClassLoaderExt::has_platform_or_app_classes()) { 340 // only check the boot path if no app class is loaded 341 end = ClassLoaderExt::app_class_paths_start_index(); 342 } 343 for (int i = 0; i < end; i++) { 344 SharedClassPathEntry *e = shared_path(i); 345 if (e->is_dir()) { 346 const char* path = e->name(); 347 if (!os::dir_is_empty(path)) { 348 tty->print_cr("Error: non-empty directory '%s'", path); 349 ClassLoader::exit_with_path_failure("Cannot have non-empty directory in paths", NULL); 350 } 351 } 352 } 353 } 354 355 bool FileMapInfo::validate_shared_path_table() { 356 assert(UseSharedSpaces, "runtime only"); 357 358 _validating_shared_path_table = true; 359 _shared_path_table = _header->_shared_path_table; 360 _shared_path_entry_size = _header->_shared_path_entry_size; 361 _shared_path_table_size = _header->_shared_path_table_size; 362 363 FileMapHeaderExt* header = (FileMapHeaderExt*)FileMapInfo::current_info()->header(); 364 int module_paths_start_index = header->_app_module_paths_start_index; 365 366 // If the shared archive contain app or platform classes, validate all entries 367 // in the shared path table. Otherwise, only validate the boot path entries (with 368 // entry index < _app_class_paths_start_index). 369 int count = header->has_platform_or_app_classes() ? 370 _shared_path_table_size : header->_app_class_paths_start_index; 371 372 for (int i=0; i<count; i++) { 373 if (i < module_paths_start_index) { 374 if (shared_path(i)->validate()) { 375 log_info(class, path)("ok"); 376 } 377 } else if (i >= module_paths_start_index) { 378 if (shared_path(i)->validate(false /* not a class path entry */)) { 379 log_info(class, path)("ok"); 380 } 381 } else if (!PrintSharedArchiveAndExit) { 382 _validating_shared_path_table = false; 383 _shared_path_table = NULL; 384 _shared_path_table_size = 0; 385 return false; 386 } 387 } 388 389 _validating_shared_path_table = false; 390 return true; |