113 // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
114 // do not validate, we can still continue "limping" to validate the remaining
115 // entries. No need to quit.
116 tty->print("[");
117 tty->vprint(msg, ap);
118 tty->print_cr("]");
119 } else {
120 if (RequireSharedSpaces) {
121 fail_exit(msg, ap);
122 } else {
123 if (log_is_enabled(Info, cds)) {
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
262
263 // The following fields are for sanity checks for whether this archive
264 // will function correctly with this JVM and the bootclasspath it's
265 // invoked with.
266
267 // JVM version string ... changes on each build.
268 get_header_version(_jvm_ident);
269
270 _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
271 _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
272 _num_module_paths = ClassLoader::num_module_path_entries();
273 _max_used_path_index = ClassLoaderExt::max_used_path_index();
274
275 _verify_local = BytecodeVerificationLocal;
276 _verify_remote = BytecodeVerificationRemote;
277 _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
278 _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
279 _requested_base_address = (char*)SharedBaseAddress;
280 _mapped_base_address = (char*)SharedBaseAddress;
281 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
282
283 if (!DynamicDumpSharedSpaces) {
284 set_shared_path_table(info->_shared_path_table);
285 }
286 }
287
288 void FileMapHeader::copy_base_archive_name(const char* archive) {
289 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
290 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
291 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
292 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
293 }
294
295 void FileMapHeader::print(outputStream* st) {
296 ResourceMark rm;
297
298 st->print_cr("- magic: 0x%08x", magic());
299 st->print_cr("- crc: 0x%08x", crc());
300 st->print_cr("- version: %d", version());
301 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
323 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_HEX, _serialized_data_offset);
324 st->print_cr("- heap_begin: " INTPTR_FORMAT, p2i(_heap_begin));
325 st->print_cr("- heap_end: " INTPTR_FORMAT, p2i(_heap_end));
326 st->print_cr("- jvm_ident: %s", _jvm_ident);
327 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_HEX, _shared_path_table_offset);
328 st->print_cr("- shared_path_table_size: %d", _shared_path_table_size);
329 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
330 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
331 st->print_cr("- num_module_paths: %d", _num_module_paths);
332 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
333 st->print_cr("- verify_local: %d", _verify_local);
334 st->print_cr("- verify_remote: %d", _verify_remote);
335 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
336 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
337 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
338 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
339 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
340 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
341 st->print_cr("- use_full_module_graph %d", _use_full_module_graph);
342 st->print_cr("- ptrmap_size_in_bits: " SIZE_FORMAT, _ptrmap_size_in_bits);
343 }
344
345 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
346 _type = non_existent_entry;
347 set_name(path, CHECK);
348 }
349
350 void SharedClassPathEntry::init(bool is_modules_image,
351 bool is_module_path,
352 ClassPathEntry* cpe, TRAPS) {
353 Arguments::assert_is_dumping_archive();
354 _timestamp = 0;
355 _filesize = 0;
356 _from_class_path_attr = false;
357
358 struct stat st;
359 if (os::stat(cpe->name(), &st) == 0) {
360 if ((st.st_mode & S_IFMT) == S_IFDIR) {
361 _type = dir_entry;
362 } else {
1361 log_info(cds)(" actual: %s", actual_ident);
1362 FileMapInfo::fail_continue("The shared archive file was created by a different"
1363 " version or build of HotSpot");
1364 return false;
1365 }
1366
1367 _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1368
1369 if (is_static()) {
1370 // just checking the last region is sufficient since the archive is written
1371 // in sequential order
1372 size_t len = os::lseek(fd, 0, SEEK_END);
1373 FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
1374 // The last space might be empty
1375 if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1376 fail_continue("The shared archive file has been truncated.");
1377 return false;
1378 }
1379 }
1380
1381 return true;
1382 }
1383
1384 void FileMapInfo::seek_to_position(size_t pos) {
1385 if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1386 fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1387 }
1388 }
1389
1390 // Read the FileMapInfo information from the file.
1391 bool FileMapInfo::open_for_read() {
1392 if (_file_open) {
1393 return true;
1394 }
1395 log_info(cds)("trying to map %s", _full_path);
1396 int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1397 if (fd < 0) {
1398 if (errno == ENOENT) {
1399 fail_continue("Specified shared archive not found (%s)", _full_path);
1400 } else {
|
113 // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
114 // do not validate, we can still continue "limping" to validate the remaining
115 // entries. No need to quit.
116 tty->print("[");
117 tty->vprint(msg, ap);
118 tty->print_cr("]");
119 } else {
120 if (RequireSharedSpaces) {
121 fail_exit(msg, ap);
122 } else {
123 if (log_is_enabled(Info, cds)) {
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
327
328 // The following fields are for sanity checks for whether this archive
329 // will function correctly with this JVM and the bootclasspath it's
330 // invoked with.
331
332 // JVM version string ... changes on each build.
333 get_header_version(_jvm_ident);
334
335 _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
336 _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
337 _num_module_paths = ClassLoader::num_module_path_entries();
338 _max_used_path_index = ClassLoaderExt::max_used_path_index();
339
340 _verify_local = BytecodeVerificationLocal;
341 _verify_remote = BytecodeVerificationRemote;
342 _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
343 _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
344 _requested_base_address = (char*)SharedBaseAddress;
345 _mapped_base_address = (char*)SharedBaseAddress;
346 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
347 _must_match.init();
348
349 if (!DynamicDumpSharedSpaces) {
350 set_shared_path_table(info->_shared_path_table);
351 }
352 }
353
354 void FileMapHeader::copy_base_archive_name(const char* archive) {
355 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
356 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
357 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
358 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
359 }
360
361 void FileMapHeader::print(outputStream* st) {
362 ResourceMark rm;
363
364 st->print_cr("- magic: 0x%08x", magic());
365 st->print_cr("- crc: 0x%08x", crc());
366 st->print_cr("- version: %d", version());
367 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
389 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_HEX, _serialized_data_offset);
390 st->print_cr("- heap_begin: " INTPTR_FORMAT, p2i(_heap_begin));
391 st->print_cr("- heap_end: " INTPTR_FORMAT, p2i(_heap_end));
392 st->print_cr("- jvm_ident: %s", _jvm_ident);
393 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_HEX, _shared_path_table_offset);
394 st->print_cr("- shared_path_table_size: %d", _shared_path_table_size);
395 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
396 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
397 st->print_cr("- num_module_paths: %d", _num_module_paths);
398 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
399 st->print_cr("- verify_local: %d", _verify_local);
400 st->print_cr("- verify_remote: %d", _verify_remote);
401 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
402 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
403 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
404 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
405 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
406 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
407 st->print_cr("- use_full_module_graph %d", _use_full_module_graph);
408 st->print_cr("- ptrmap_size_in_bits: " SIZE_FORMAT, _ptrmap_size_in_bits);
409 _must_match.print(st);
410 }
411
412 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
413 _type = non_existent_entry;
414 set_name(path, CHECK);
415 }
416
417 void SharedClassPathEntry::init(bool is_modules_image,
418 bool is_module_path,
419 ClassPathEntry* cpe, TRAPS) {
420 Arguments::assert_is_dumping_archive();
421 _timestamp = 0;
422 _filesize = 0;
423 _from_class_path_attr = false;
424
425 struct stat st;
426 if (os::stat(cpe->name(), &st) == 0) {
427 if ((st.st_mode & S_IFMT) == S_IFDIR) {
428 _type = dir_entry;
429 } else {
1428 log_info(cds)(" actual: %s", actual_ident);
1429 FileMapInfo::fail_continue("The shared archive file was created by a different"
1430 " version or build of HotSpot");
1431 return false;
1432 }
1433
1434 _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1435
1436 if (is_static()) {
1437 // just checking the last region is sufficient since the archive is written
1438 // in sequential order
1439 size_t len = os::lseek(fd, 0, SEEK_END);
1440 FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
1441 // The last space might be empty
1442 if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1443 fail_continue("The shared archive file has been truncated.");
1444 return false;
1445 }
1446 }
1447
1448 if (!header()->check_must_match_flags()) {
1449 return false;
1450 }
1451
1452 return true;
1453 }
1454
1455 void FileMapInfo::seek_to_position(size_t pos) {
1456 if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1457 fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1458 }
1459 }
1460
1461 // Read the FileMapInfo information from the file.
1462 bool FileMapInfo::open_for_read() {
1463 if (_file_open) {
1464 return true;
1465 }
1466 log_info(cds)("trying to map %s", _full_path);
1467 int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1468 if (fd < 0) {
1469 if (errno == ENOENT) {
1470 fail_continue("Specified shared archive not found (%s)", _full_path);
1471 } else {
|