< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

 113     // do not validate, we can still continue "limping" to validate the remaining
 114     // entries. No need to quit.
 115     tty->print("[");
 116     tty->vprint(msg, ap);
 117     tty->print_cr("]");
 118   } else {
 119     if (RequireSharedSpaces) {
 120       fail_exit(msg, ap);
 121     } else {
 122       if (log_is_enabled(Info, cds)) {
 123         ResourceMark rm;
 124         LogStream ls(Log(cds)::info());
 125         ls.print("UseSharedSpaces: ");
 126         ls.vprint_cr(msg, ap);
 127       }
 128     }
 129   }
 130   va_end(ap);
 131 }
 132 

































































 133 // Fill in the fileMapInfo structure with data about this VM instance.
 134 
 135 // This method copies the vm version info into header_version.  If the version is too
 136 // long then a truncated version, which has a hash code appended to it, is copied.
 137 //
 138 // Using a template enables this method to verify that header_version is an array of
 139 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
 140 // the code that reads the CDS file will both use the same size buffer.  Hence, will
 141 // use identical truncation.  This is necessary for matching of truncated versions.
 142 template <int N> static void get_header_version(char (&header_version) [N]) {
 143   assert(N == JVM_IDENT_MAX, "Bad header_version size");
 144 
 145   const char *vm_version = VM_Version::internal_vm_info_string();
 146   const int version_len = (int)strlen(vm_version);
 147 
 148   memset(header_version, 0, JVM_IDENT_MAX);
 149 
 150   if (version_len < (JVM_IDENT_MAX-1)) {
 151     strcpy(header_version, vm_version);
 152 

 231   // invoked with.
 232 
 233   // JVM version string ... changes on each build.
 234   get_header_version(_jvm_ident);
 235 
 236   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 237   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 238   _num_module_paths = ClassLoader::num_module_path_entries();
 239   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 240 
 241   _verify_local = BytecodeVerificationLocal;
 242   _verify_remote = BytecodeVerificationRemote;
 243   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 244   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 245   _requested_base_address = (char*)SharedBaseAddress;
 246   _mapped_base_address = (char*)SharedBaseAddress;
 247   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 248   // the following 2 fields will be set in write_header for dynamic archive header
 249   _base_archive_name_size = 0;
 250   _base_archive_is_default = false;

 251 
 252   if (!DynamicDumpSharedSpaces) {
 253     set_shared_path_table(mapinfo->_shared_path_table);
 254     CDS_JAVA_HEAP_ONLY(_heap_obj_roots = CompressedOops::encode(HeapShared::roots());)
 255   }
 256 }
 257 
 258 void FileMapHeader::print(outputStream* st) {
 259   ResourceMark rm;
 260 
 261   st->print_cr("- magic:                          0x%08x", _magic);
 262   st->print_cr("- crc:                            0x%08x", _crc);
 263   st->print_cr("- version:                        %d", _version);
 264 
 265   for (int i = 0; i < NUM_CDS_REGIONS; i++) {
 266     FileMapRegion* si = space_at(i);
 267     si->print(st, i);
 268   }
 269   st->print_cr("============ end regions ======== ");
 270 

 285   st->print_cr("- heap_end:                       " INTPTR_FORMAT, p2i(_heap_end));
 286   st->print_cr("- base_archive_is_default:        %d", _base_archive_is_default);
 287   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 288   st->print_cr("- base_archive_name_size:         " SIZE_FORMAT, _base_archive_name_size);
 289   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_HEX, _shared_path_table_offset);
 290   st->print_cr("- shared_path_table_size:         %d", _shared_path_table_size);
 291   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 292   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 293   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 294   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 295   st->print_cr("- verify_local:                   %d", _verify_local);
 296   st->print_cr("- verify_remote:                  %d", _verify_remote);
 297   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 298   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 299   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 300   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 301   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 302   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 303   st->print_cr("- use_full_module_graph           %d", _use_full_module_graph);
 304   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);

 305 }
 306 
 307 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 308   _type = non_existent_entry;
 309   set_name(path, CHECK);
 310 }
 311 
 312 void SharedClassPathEntry::init(bool is_modules_image,
 313                                 bool is_module_path,
 314                                 ClassPathEntry* cpe, TRAPS) {
 315   Arguments::assert_is_dumping_archive();
 316   _timestamp = 0;
 317   _filesize  = 0;
 318   _from_class_path_attr = false;
 319 
 320   struct stat st;
 321   if (os::stat(cpe->name(), &st) == 0) {
 322     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 323       _type = dir_entry;
 324     } else {

1166       log_info(cds)("       actual: %d", header()->crc());
1167       FileMapInfo::fail_continue("Header checksum verification failed.");
1168       return false;
1169     }
1170   }
1171 
1172   _file_offset = n + header()->base_archive_name_size(); // accounts for the size of _base_archive_name
1173 
1174   if (is_static()) {
1175     // just checking the last region is sufficient since the archive is written
1176     // in sequential order
1177     size_t len = lseek(fd, 0, SEEK_END);
1178     FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
1179     // The last space might be empty
1180     if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1181       fail_continue("The shared archive file has been truncated.");
1182       return false;
1183     }
1184   }
1185 




1186   return true;
1187 }
1188 
1189 void FileMapInfo::seek_to_position(size_t pos) {
1190   if (lseek(_fd, (long)pos, SEEK_SET) < 0) {
1191     fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1192   }
1193 }
1194 
1195 // Read the FileMapInfo information from the file.
1196 bool FileMapInfo::open_for_read() {
1197   if (_file_open) {
1198     return true;
1199   }
1200   if (is_static()) {
1201     _full_path = Arguments::GetSharedArchivePath();
1202   } else {
1203     _full_path = Arguments::GetSharedDynamicArchivePath();
1204   }
1205   log_info(cds)("trying to map %s", _full_path);

 113     // do not validate, we can still continue "limping" to validate the remaining
 114     // entries. No need to quit.
 115     tty->print("[");
 116     tty->vprint(msg, ap);
 117     tty->print_cr("]");
 118   } else {
 119     if (RequireSharedSpaces) {
 120       fail_exit(msg, ap);
 121     } else {
 122       if (log_is_enabled(Info, cds)) {
 123         ResourceMark rm;
 124         LogStream ls(Log(cds)::info());
 125         ls.print("UseSharedSpaces: ");
 126         ls.vprint_cr(msg, ap);
 127       }
 128     }
 129   }
 130   va_end(ap);
 131 }
 132 
 133 inline void CDSMustMatchFlags::do_print(outputStream* st, bool v) {
 134   st->print("%s", v ? "true" : "false");
 135 }
 136 
 137 inline void CDSMustMatchFlags::do_print(outputStream* st, intx v) {
 138   st->print(INTX_FORMAT, v);
 139 }
 140 
 141 inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) {
 142   st->print(UINTX_FORMAT, v);
 143 }
 144 
 145 inline void CDSMustMatchFlags::do_print(outputStream* st, double v) {
 146   st->print("%f", v);
 147 }
 148 
 149 void CDSMustMatchFlags::init() {
 150   Arguments::assert_is_dumping_archive();
 151   _max_name_width = 0;
 152 
 153 #define INIT_CDS_MUST_MATCH_FLAG(n) \
 154   _v_##n = n; \
 155   _max_name_width = MAX2(_max_name_width,strlen(#n));
 156   CDS_MUST_MATCH_FLAGS_DO(INIT_CDS_MUST_MATCH_FLAG);
 157 #undef INIT_CDS_MUST_MATCH_FLAG
 158 }
 159 
 160 bool CDSMustMatchFlags::runtime_check() const {
 161 #define CHECK_CDS_MUST_MATCH_FLAG(n) \
 162   if (_v_##n != n) { \
 163     ResourceMark rm; \
 164     stringStream ss; \
 165     ss.print("VM option %s is different between dumptime (", #n);  \
 166     do_print(&ss, _v_ ## n); \
 167     ss.print(") and runtime ("); \
 168     do_print(&ss, n); \
 169     ss.print(")"); \
 170     FileMapInfo::fail_continue("%s", ss.as_string()); \
 171     return false; \
 172   }
 173   CDS_MUST_MATCH_FLAGS_DO(CHECK_CDS_MUST_MATCH_FLAG);
 174 #undef CHECK_CDS_MUST_MATCH_FLAG
 175 
 176   return true;
 177 }
 178 
 179 void CDSMustMatchFlags::print_info() const {
 180   LogTarget(Info, cds) lt;
 181   if (lt.is_enabled()) {
 182     LogStream ls(lt);
 183     ls.print_cr("Recorded VM flags during dumptime:");
 184     print(&ls);
 185   }
 186 }
 187 
 188 void CDSMustMatchFlags::print(outputStream* st) const {
 189 #define PRINT_CDS_MUST_MATCH_FLAG(n) \
 190   st->print("- %-s ", #n);                   \
 191   st->sp(int(_max_name_width - strlen(#n))); \
 192   do_print(st, _v_##n);                      \
 193   st->cr();
 194   CDS_MUST_MATCH_FLAGS_DO(PRINT_CDS_MUST_MATCH_FLAG);
 195 #undef PRINT_CDS_MUST_MATCH_FLAG
 196 }
 197 
 198 // Fill in the fileMapInfo structure with data about this VM instance.
 199 
 200 // This method copies the vm version info into header_version.  If the version is too
 201 // long then a truncated version, which has a hash code appended to it, is copied.
 202 //
 203 // Using a template enables this method to verify that header_version is an array of
 204 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
 205 // the code that reads the CDS file will both use the same size buffer.  Hence, will
 206 // use identical truncation.  This is necessary for matching of truncated versions.
 207 template <int N> static void get_header_version(char (&header_version) [N]) {
 208   assert(N == JVM_IDENT_MAX, "Bad header_version size");
 209 
 210   const char *vm_version = VM_Version::internal_vm_info_string();
 211   const int version_len = (int)strlen(vm_version);
 212 
 213   memset(header_version, 0, JVM_IDENT_MAX);
 214 
 215   if (version_len < (JVM_IDENT_MAX-1)) {
 216     strcpy(header_version, vm_version);
 217 

 296   // invoked with.
 297 
 298   // JVM version string ... changes on each build.
 299   get_header_version(_jvm_ident);
 300 
 301   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 302   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 303   _num_module_paths = ClassLoader::num_module_path_entries();
 304   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 305 
 306   _verify_local = BytecodeVerificationLocal;
 307   _verify_remote = BytecodeVerificationRemote;
 308   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 309   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 310   _requested_base_address = (char*)SharedBaseAddress;
 311   _mapped_base_address = (char*)SharedBaseAddress;
 312   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 313   // the following 2 fields will be set in write_header for dynamic archive header
 314   _base_archive_name_size = 0;
 315   _base_archive_is_default = false;
 316   _must_match.init();
 317 
 318   if (!DynamicDumpSharedSpaces) {
 319     set_shared_path_table(mapinfo->_shared_path_table);
 320     CDS_JAVA_HEAP_ONLY(_heap_obj_roots = CompressedOops::encode(HeapShared::roots());)
 321   }
 322 }
 323 
 324 void FileMapHeader::print(outputStream* st) {
 325   ResourceMark rm;
 326 
 327   st->print_cr("- magic:                          0x%08x", _magic);
 328   st->print_cr("- crc:                            0x%08x", _crc);
 329   st->print_cr("- version:                        %d", _version);
 330 
 331   for (int i = 0; i < NUM_CDS_REGIONS; i++) {
 332     FileMapRegion* si = space_at(i);
 333     si->print(st, i);
 334   }
 335   st->print_cr("============ end regions ======== ");
 336 

 351   st->print_cr("- heap_end:                       " INTPTR_FORMAT, p2i(_heap_end));
 352   st->print_cr("- base_archive_is_default:        %d", _base_archive_is_default);
 353   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 354   st->print_cr("- base_archive_name_size:         " SIZE_FORMAT, _base_archive_name_size);
 355   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_HEX, _shared_path_table_offset);
 356   st->print_cr("- shared_path_table_size:         %d", _shared_path_table_size);
 357   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 358   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 359   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 360   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 361   st->print_cr("- verify_local:                   %d", _verify_local);
 362   st->print_cr("- verify_remote:                  %d", _verify_remote);
 363   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 364   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 365   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 366   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 367   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 368   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 369   st->print_cr("- use_full_module_graph           %d", _use_full_module_graph);
 370   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
 371   _must_match.print(st);
 372 }
 373 
 374 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 375   _type = non_existent_entry;
 376   set_name(path, CHECK);
 377 }
 378 
 379 void SharedClassPathEntry::init(bool is_modules_image,
 380                                 bool is_module_path,
 381                                 ClassPathEntry* cpe, TRAPS) {
 382   Arguments::assert_is_dumping_archive();
 383   _timestamp = 0;
 384   _filesize  = 0;
 385   _from_class_path_attr = false;
 386 
 387   struct stat st;
 388   if (os::stat(cpe->name(), &st) == 0) {
 389     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 390       _type = dir_entry;
 391     } else {

1233       log_info(cds)("       actual: %d", header()->crc());
1234       FileMapInfo::fail_continue("Header checksum verification failed.");
1235       return false;
1236     }
1237   }
1238 
1239   _file_offset = n + header()->base_archive_name_size(); // accounts for the size of _base_archive_name
1240 
1241   if (is_static()) {
1242     // just checking the last region is sufficient since the archive is written
1243     // in sequential order
1244     size_t len = lseek(fd, 0, SEEK_END);
1245     FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
1246     // The last space might be empty
1247     if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1248       fail_continue("The shared archive file has been truncated.");
1249       return false;
1250     }
1251   }
1252 
1253   if (!header()->check_must_match_flags()) {
1254     return false;
1255   }
1256 
1257   return true;
1258 }
1259 
1260 void FileMapInfo::seek_to_position(size_t pos) {
1261   if (lseek(_fd, (long)pos, SEEK_SET) < 0) {
1262     fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1263   }
1264 }
1265 
1266 // Read the FileMapInfo information from the file.
1267 bool FileMapInfo::open_for_read() {
1268   if (_file_open) {
1269     return true;
1270   }
1271   if (is_static()) {
1272     _full_path = Arguments::GetSharedArchivePath();
1273   } else {
1274     _full_path = Arguments::GetSharedDynamicArchivePath();
1275   }
1276   log_info(cds)("trying to map %s", _full_path);
< prev index next >