src/share/vm/classfile/sharedPathsMiscInfo.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/classfile

src/share/vm/classfile/sharedPathsMiscInfo.cpp

Print this page




  69 
  70 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) {
  71   ClassLoader::trace_class_path(msg, name);
  72   MetaspaceShared::set_archive_loading_failed();
  73   return false;
  74 }
  75 
  76 void SharedPathsMiscInfo::print_path(int type, const char* path) {
  77   ResourceMark rm;
  78   outputStream* out = Log(class, path)::info_stream();
  79   switch (type) {
  80   case BOOT:
  81     out->print("Expecting BOOT path=%s", path);
  82     break;
  83   case NON_EXIST:
  84     out->print("Expecting that %s does not exist", path);
  85     break;
  86   case REQUIRED:
  87     out->print("Expecting that file %s must exist and is not altered", path);
  88     break;



  89   default:
  90     ShouldNotReachHere();
  91   }
  92 }
  93 
  94 bool SharedPathsMiscInfo::check() {
  95   // The whole buffer must be 0 terminated so that we can use strlen and strcmp
  96   // without fear.
  97   _end_ptr -= sizeof(jint);
  98   if (_cur_ptr >= _end_ptr) {
  99     return fail("Truncated archive file header");
 100   }
 101   if (*_end_ptr != 0) {
 102     return fail("Corrupted archive file header");
 103   }
 104 
 105   while (_cur_ptr < _end_ptr) {
 106     jint type;
 107     const char* path = _cur_ptr;
 108     _cur_ptr += strlen(path) + 1;


 129     if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
 130       return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath());
 131     }
 132     break;
 133   case NON_EXIST: // fall-through
 134   case REQUIRED:
 135     {
 136       struct stat st;
 137       if (os::stat(path, &st) != 0) {
 138         // The file does not actually exist
 139         if (type == REQUIRED) {
 140           // but we require it to exist -> fail
 141           return fail("Required file doesn't exist");
 142         }
 143       } else {
 144         // The file actually exists
 145         if (type == NON_EXIST) {
 146           // But we want it to not exist -> fail
 147           return fail("File must not exist");
 148         }



 149         time_t    timestamp;
 150         long      filesize;
 151 
 152         if (!read_time(&timestamp) || !read_long(&filesize)) {
 153           return fail("Corrupted archive file header");
 154         }
 155         if (timestamp != st.st_mtime) {
 156           return fail("Timestamp mismatch");
 157         }
 158         if (filesize != st.st_size) {
 159           return fail("File size mismatch");
 160         }
 161       }
 162     }
 163     break;
 164 



















 165   default:
 166     return fail("Corrupted archive file header");
 167   }
 168 
 169   return true;
 170 }


  69 
  70 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) {
  71   ClassLoader::trace_class_path(msg, name);
  72   MetaspaceShared::set_archive_loading_failed();
  73   return false;
  74 }
  75 
  76 void SharedPathsMiscInfo::print_path(int type, const char* path) {
  77   ResourceMark rm;
  78   outputStream* out = Log(class, path)::info_stream();
  79   switch (type) {
  80   case BOOT:
  81     out->print("Expecting BOOT path=%s", path);
  82     break;
  83   case NON_EXIST:
  84     out->print("Expecting that %s does not exist", path);
  85     break;
  86   case REQUIRED:
  87     out->print("Expecting that file %s must exist and is not altered", path);
  88     break;
  89   case PATCH_MOD:
  90     out->print("Expecting --patch-module=%s", path);
  91     break;
  92   default:
  93     ShouldNotReachHere();
  94   }
  95 }
  96 
  97 bool SharedPathsMiscInfo::check() {
  98   // The whole buffer must be 0 terminated so that we can use strlen and strcmp
  99   // without fear.
 100   _end_ptr -= sizeof(jint);
 101   if (_cur_ptr >= _end_ptr) {
 102     return fail("Truncated archive file header");
 103   }
 104   if (*_end_ptr != 0) {
 105     return fail("Corrupted archive file header");
 106   }
 107 
 108   while (_cur_ptr < _end_ptr) {
 109     jint type;
 110     const char* path = _cur_ptr;
 111     _cur_ptr += strlen(path) + 1;


 132     if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
 133       return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath());
 134     }
 135     break;
 136   case NON_EXIST: // fall-through
 137   case REQUIRED:
 138     {
 139       struct stat st;
 140       if (os::stat(path, &st) != 0) {
 141         // The file does not actually exist
 142         if (type == REQUIRED) {
 143           // but we require it to exist -> fail
 144           return fail("Required file doesn't exist");
 145         }
 146       } else {
 147         // The file actually exists
 148         if (type == NON_EXIST) {
 149           // But we want it to not exist -> fail
 150           return fail("File must not exist");
 151         }
 152         if ((st.st_mode & S_IFREG) != S_IFREG) {
 153           return fail("Wanted a file but it has become a directory");
 154         }
 155         time_t    timestamp;
 156         long      filesize;
 157 
 158         if (!read_time(&timestamp) || !read_long(&filesize)) {
 159           return fail("Corrupted archive file header");
 160         }
 161         if (timestamp != st.st_mtime) {
 162           return fail("Timestamp mismatch");
 163         }
 164         if (filesize != st.st_size) {
 165           return fail("File size mismatch");
 166         }
 167       }
 168     }
 169     break;
 170   case PATCH_MOD:
 171     {
 172       GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
 173       if (patch_mod_args != NULL) {
 174         int num_of_entries = patch_mod_args->length();
 175         for (int i = 0; i < num_of_entries; i++) {
 176           const char* module_name = (patch_mod_args->at(i))->module_name();
 177           const char* path_string = (patch_mod_args->at(i))->path_string();
 178           size_t n = strlen(module_name);
 179           // path contains the module name, followed by '=', and one or more entries.
 180           // E.g.: "java.base=foo" or "java.naming=dir1:dir2:dir3"
 181           if ((strncmp(module_name, path, n) != 0 ) ||
 182               (path[n] != '=') ||
 183               (strcmp(path + n + 1, path_string) != 0)) {
 184             return fail("--patch-module mismatch, path not found in run time: ", path);
 185           }
 186         }
 187       }
 188     }
 189     break;
 190   default:
 191     return fail("Corrupted archive file header");
 192   }
 193 
 194   return true;
 195 }
src/share/vm/classfile/sharedPathsMiscInfo.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File