63 #include "runtime/os.hpp"
64 #include "runtime/vm_version.hpp"
65 #include "services/memTracker.hpp"
66 #include "utilities/align.hpp"
67 #include "utilities/bitMap.inline.hpp"
68 #include "utilities/classpathStream.hpp"
69 #include "utilities/defaultStream.hpp"
70 #include "utilities/ostream.hpp"
71 #if INCLUDE_G1GC
72 #include "gc/g1/g1CollectedHeap.hpp"
73 #include "gc/g1/heapRegion.hpp"
74 #endif
75
76 # include <sys/stat.h>
77 # include <errno.h>
78
79 #ifndef O_BINARY // if defined (Win32) use binary files.
80 #define O_BINARY 0 // otherwise do nothing.
81 #endif
82
83 // Fill in the fileMapInfo structure with data about this VM instance.
84
85 // This method copies the vm version info into header_version. If the version is too
86 // long then a truncated version, which has a hash code appended to it, is copied.
87 //
88 // Using a template enables this method to verify that header_version is an array of
89 // length JVM_IDENT_MAX. This ensures that the code that writes to the CDS file and
90 // the code that reads the CDS file will both use the same size buffer. Hence, will
91 // use identical truncation. This is necessary for matching of truncated versions.
92 template <int N> static void get_header_version(char (&header_version) [N]) {
93 assert(N == JVM_IDENT_MAX, "Bad header_version size");
94
95 const char *vm_version = VM_Version::internal_vm_info_string();
96 const int version_len = (int)strlen(vm_version);
97
98 memset(header_version, 0, JVM_IDENT_MAX);
99
100 if (version_len < (JVM_IDENT_MAX-1)) {
101 strcpy(header_version, vm_version);
102
228
229 // The following fields are for sanity checks for whether this archive
230 // will function correctly with this JVM and the bootclasspath it's
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
249 if (!DynamicDumpSharedSpaces) {
250 set_shared_path_table(info->_shared_path_table);
251 }
252 }
253
254 void FileMapHeader::copy_base_archive_name(const char* archive) {
255 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
256 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
257 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
258 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
259 }
260
261 void FileMapHeader::print(outputStream* st) {
262 ResourceMark rm;
263
264 st->print_cr("- magic: 0x%08x", magic());
265 st->print_cr("- crc: 0x%08x", crc());
266 st->print_cr("- version: 0x%x", version());
267 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
289 st->print_cr("- cloned_vtables_offset: " SIZE_FORMAT_X, _cloned_vtables_offset);
290 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_X, _serialized_data_offset);
291 st->print_cr("- heap_begin: " INTPTR_FORMAT, p2i(_heap_begin));
292 st->print_cr("- heap_end: " INTPTR_FORMAT, p2i(_heap_end));
293 st->print_cr("- jvm_ident: %s", _jvm_ident);
294 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_X, _shared_path_table_offset);
295 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
296 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
297 st->print_cr("- num_module_paths: %d", _num_module_paths);
298 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
299 st->print_cr("- verify_local: %d", _verify_local);
300 st->print_cr("- verify_remote: %d", _verify_remote);
301 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
302 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
303 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
304 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
305 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
306 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
307 st->print_cr("- use_full_module_graph %d", _use_full_module_graph);
308 st->print_cr("- ptrmap_size_in_bits: " SIZE_FORMAT, _ptrmap_size_in_bits);
309 }
310
311 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
312 _type = non_existent_entry;
313 set_name(path, CHECK);
314 }
315
316 void SharedClassPathEntry::init(bool is_modules_image,
317 bool is_module_path,
318 ClassPathEntry* cpe, TRAPS) {
319 Arguments::assert_is_dumping_archive();
320 _timestamp = 0;
321 _filesize = 0;
322 _from_class_path_attr = false;
323
324 struct stat st;
325 if (os::stat(cpe->name(), &st) == 0) {
326 if ((st.st_mode & S_IFMT) == S_IFDIR) {
327 _type = dir_entry;
328 } else {
1366 if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1367 log_info(cds)("_jvm_ident expected: %s", expected_ident);
1368 log_info(cds)(" actual: %s", actual_ident);
1369 log_warning(cds)("The shared archive file was created by a different"
1370 " version or build of HotSpot");
1371 return false;
1372 }
1373
1374 _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1375
1376 size_t len = os::lseek(fd, 0, SEEK_END);
1377
1378 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1379 FileMapRegion* r = region_at(i);
1380 if (r->file_offset() > len || len - r->file_offset() < r->used()) {
1381 log_warning(cds)("The shared archive file has been truncated.");
1382 return false;
1383 }
1384 }
1385
1386 return true;
1387 }
1388
1389 void FileMapInfo::seek_to_position(size_t pos) {
1390 if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1391 log_error(cds)("Unable to seek to position " SIZE_FORMAT, pos);
1392 MetaspaceShared::unrecoverable_loading_error();
1393 }
1394 }
1395
1396 // Read the FileMapInfo information from the file.
1397 bool FileMapInfo::open_for_read() {
1398 if (_file_open) {
1399 return true;
1400 }
1401 log_info(cds)("trying to map %s", _full_path);
1402 int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1403 if (fd < 0) {
1404 if (errno == ENOENT) {
1405 log_info(cds)("Specified shared archive not found (%s)", _full_path);
|
63 #include "runtime/os.hpp"
64 #include "runtime/vm_version.hpp"
65 #include "services/memTracker.hpp"
66 #include "utilities/align.hpp"
67 #include "utilities/bitMap.inline.hpp"
68 #include "utilities/classpathStream.hpp"
69 #include "utilities/defaultStream.hpp"
70 #include "utilities/ostream.hpp"
71 #if INCLUDE_G1GC
72 #include "gc/g1/g1CollectedHeap.hpp"
73 #include "gc/g1/heapRegion.hpp"
74 #endif
75
76 # include <sys/stat.h>
77 # include <errno.h>
78
79 #ifndef O_BINARY // if defined (Win32) use binary files.
80 #define O_BINARY 0 // otherwise do nothing.
81 #endif
82
83 inline void CDSMustMatchFlags::do_print(outputStream* st, bool v) {
84 st->print("%s", v ? "true" : "false");
85 }
86
87 inline void CDSMustMatchFlags::do_print(outputStream* st, intx v) {
88 st->print(INTX_FORMAT, v);
89 }
90
91 inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) {
92 st->print(UINTX_FORMAT, v);
93 }
94
95 inline void CDSMustMatchFlags::do_print(outputStream* st, double v) {
96 st->print("%f", v);
97 }
98
99 void CDSMustMatchFlags::init() {
100 Arguments::assert_is_dumping_archive();
101 _max_name_width = 0;
102
103 #define INIT_CDS_MUST_MATCH_FLAG(n) \
104 _v_##n = n; \
105 _max_name_width = MAX2(_max_name_width,strlen(#n));
106 CDS_MUST_MATCH_FLAGS_DO(INIT_CDS_MUST_MATCH_FLAG);
107 #undef INIT_CDS_MUST_MATCH_FLAG
108 }
109
110 bool CDSMustMatchFlags::runtime_check() const {
111 #define CHECK_CDS_MUST_MATCH_FLAG(n) \
112 if (_v_##n != n) { \
113 ResourceMark rm; \
114 stringStream ss; \
115 ss.print("VM option %s is different between dumptime (", #n); \
116 do_print(&ss, _v_ ## n); \
117 ss.print(") and runtime ("); \
118 do_print(&ss, n); \
119 ss.print(")"); \
120 log_info(cds)("%s", ss.as_string()); \
121 return false; \
122 }
123 CDS_MUST_MATCH_FLAGS_DO(CHECK_CDS_MUST_MATCH_FLAG);
124 #undef CHECK_CDS_MUST_MATCH_FLAG
125
126 return true;
127 }
128
129 void CDSMustMatchFlags::print_info() const {
130 LogTarget(Info, cds) lt;
131 if (lt.is_enabled()) {
132 LogStream ls(lt);
133 ls.print_cr("Recorded VM flags during dumptime:");
134 print(&ls);
135 }
136 }
137
138 void CDSMustMatchFlags::print(outputStream* st) const {
139 #define PRINT_CDS_MUST_MATCH_FLAG(n) \
140 st->print("- %-s ", #n); \
141 st->sp(int(_max_name_width - strlen(#n))); \
142 do_print(st, _v_##n); \
143 st->cr();
144 CDS_MUST_MATCH_FLAGS_DO(PRINT_CDS_MUST_MATCH_FLAG);
145 #undef PRINT_CDS_MUST_MATCH_FLAG
146 }
147
148 // Fill in the fileMapInfo structure with data about this VM instance.
149
150 // This method copies the vm version info into header_version. If the version is too
151 // long then a truncated version, which has a hash code appended to it, is copied.
152 //
153 // Using a template enables this method to verify that header_version is an array of
154 // length JVM_IDENT_MAX. This ensures that the code that writes to the CDS file and
155 // the code that reads the CDS file will both use the same size buffer. Hence, will
156 // use identical truncation. This is necessary for matching of truncated versions.
157 template <int N> static void get_header_version(char (&header_version) [N]) {
158 assert(N == JVM_IDENT_MAX, "Bad header_version size");
159
160 const char *vm_version = VM_Version::internal_vm_info_string();
161 const int version_len = (int)strlen(vm_version);
162
163 memset(header_version, 0, JVM_IDENT_MAX);
164
165 if (version_len < (JVM_IDENT_MAX-1)) {
166 strcpy(header_version, vm_version);
167
293
294 // The following fields are for sanity checks for whether this archive
295 // will function correctly with this JVM and the bootclasspath it's
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 _must_match.init();
314
315 if (!DynamicDumpSharedSpaces) {
316 set_shared_path_table(info->_shared_path_table);
317 }
318 }
319
320 void FileMapHeader::copy_base_archive_name(const char* archive) {
321 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
322 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
323 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
324 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
325 }
326
327 void FileMapHeader::print(outputStream* st) {
328 ResourceMark rm;
329
330 st->print_cr("- magic: 0x%08x", magic());
331 st->print_cr("- crc: 0x%08x", crc());
332 st->print_cr("- version: 0x%x", version());
333 st->print_cr("- header_size: " UINT32_FORMAT, header_size());
355 st->print_cr("- cloned_vtables_offset: " SIZE_FORMAT_X, _cloned_vtables_offset);
356 st->print_cr("- serialized_data_offset: " SIZE_FORMAT_X, _serialized_data_offset);
357 st->print_cr("- heap_begin: " INTPTR_FORMAT, p2i(_heap_begin));
358 st->print_cr("- heap_end: " INTPTR_FORMAT, p2i(_heap_end));
359 st->print_cr("- jvm_ident: %s", _jvm_ident);
360 st->print_cr("- shared_path_table_offset: " SIZE_FORMAT_X, _shared_path_table_offset);
361 st->print_cr("- app_class_paths_start_index: %d", _app_class_paths_start_index);
362 st->print_cr("- app_module_paths_start_index: %d", _app_module_paths_start_index);
363 st->print_cr("- num_module_paths: %d", _num_module_paths);
364 st->print_cr("- max_used_path_index: %d", _max_used_path_index);
365 st->print_cr("- verify_local: %d", _verify_local);
366 st->print_cr("- verify_remote: %d", _verify_remote);
367 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
368 st->print_cr("- has_non_jar_in_classpath: %d", _has_non_jar_in_classpath);
369 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
370 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
371 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
372 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
373 st->print_cr("- use_full_module_graph %d", _use_full_module_graph);
374 st->print_cr("- ptrmap_size_in_bits: " SIZE_FORMAT, _ptrmap_size_in_bits);
375 _must_match.print(st);
376 }
377
378 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
379 _type = non_existent_entry;
380 set_name(path, CHECK);
381 }
382
383 void SharedClassPathEntry::init(bool is_modules_image,
384 bool is_module_path,
385 ClassPathEntry* cpe, TRAPS) {
386 Arguments::assert_is_dumping_archive();
387 _timestamp = 0;
388 _filesize = 0;
389 _from_class_path_attr = false;
390
391 struct stat st;
392 if (os::stat(cpe->name(), &st) == 0) {
393 if ((st.st_mode & S_IFMT) == S_IFDIR) {
394 _type = dir_entry;
395 } else {
1433 if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1434 log_info(cds)("_jvm_ident expected: %s", expected_ident);
1435 log_info(cds)(" actual: %s", actual_ident);
1436 log_warning(cds)("The shared archive file was created by a different"
1437 " version or build of HotSpot");
1438 return false;
1439 }
1440
1441 _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1442
1443 size_t len = os::lseek(fd, 0, SEEK_END);
1444
1445 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1446 FileMapRegion* r = region_at(i);
1447 if (r->file_offset() > len || len - r->file_offset() < r->used()) {
1448 log_warning(cds)("The shared archive file has been truncated.");
1449 return false;
1450 }
1451 }
1452
1453 if (!header()->check_must_match_flags()) {
1454 return false;
1455 }
1456
1457 return true;
1458 }
1459
1460 void FileMapInfo::seek_to_position(size_t pos) {
1461 if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1462 log_error(cds)("Unable to seek to position " SIZE_FORMAT, pos);
1463 MetaspaceShared::unrecoverable_loading_error();
1464 }
1465 }
1466
1467 // Read the FileMapInfo information from the file.
1468 bool FileMapInfo::open_for_read() {
1469 if (_file_open) {
1470 return true;
1471 }
1472 log_info(cds)("trying to map %s", _full_path);
1473 int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1474 if (fd < 0) {
1475 if (errno == ENOENT) {
1476 log_info(cds)("Specified shared archive not found (%s)", _full_path);
|