1 /* 2 * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "cds/aotClassLinker.hpp" 27 #include "cds/archiveBuilder.hpp" 28 #include "cds/archiveHeapWriter.hpp" 29 #include "cds/archiveUtils.inline.hpp" 30 #include "cds/cds_globals.hpp" 31 #include "cds/cdsConfig.hpp" 32 #include "cds/dynamicArchive.hpp" 33 #include "cds/metaspaceShared.hpp" 34 #include "cds/regeneratedClasses.hpp" 35 #include "classfile/classLoader.hpp" 36 #include "classfile/classLoaderData.inline.hpp" 37 #include "classfile/symbolTable.hpp" 38 #include "classfile/systemDictionaryShared.hpp" 39 #include "classfile/vmSymbols.hpp" 40 #include "gc/shared/collectedHeap.hpp" 41 #include "gc/shared/gcVMOperations.hpp" 42 #include "gc/shared/gc_globals.hpp" 43 #include "jvm.h" 44 #include "logging/log.hpp" 45 #include "memory/metaspaceClosure.hpp" 46 #include "memory/resourceArea.hpp" 47 #include "oops/klass.inline.hpp" 48 #include "runtime/arguments.hpp" 49 #include "runtime/os.hpp" 50 #include "runtime/sharedRuntime.hpp" 51 #include "runtime/vmThread.hpp" 52 #include "runtime/vmOperations.hpp" 53 #include "utilities/align.hpp" 54 #include "utilities/bitMap.inline.hpp" 55 56 57 class DynamicArchiveBuilder : public ArchiveBuilder { 58 const char* _archive_name; 59 public: 60 DynamicArchiveBuilder(const char* archive_name) : _archive_name(archive_name) {} 61 void mark_pointer(address* ptr_loc) { 62 ArchivePtrMarker::mark_pointer(ptr_loc); 63 } 64 65 static int dynamic_dump_method_comparator(Method* a, Method* b) { 66 Symbol* a_name = a->name(); 67 Symbol* b_name = b->name(); 68 69 if (a_name == b_name) { 70 return 0; 71 } 72 73 u4 a_offset = ArchiveBuilder::current()->any_to_offset_u4(a_name); 74 u4 b_offset = ArchiveBuilder::current()->any_to_offset_u4(b_name); 75 76 if (a_offset < b_offset) { 77 return -1; 78 } else { 79 assert(a_offset > b_offset, "must be"); 80 return 1; 81 } 82 } 83 84 public: 85 DynamicArchiveHeader *_header; 86 87 void init_header(); 88 void release_header(); 89 void post_dump(); 90 void sort_methods(); 91 void sort_methods(InstanceKlass* ik) const; 92 void remark_pointers_for_instance_klass(InstanceKlass* k, bool should_mark) const; 93 void write_archive(char* serialized_data); 94 void gather_array_klasses(); 95 96 public: 97 DynamicArchiveBuilder() : ArchiveBuilder() { } 98 99 // Do this before and after the archive dump to see if any corruption 100 // is caused by dynamic dumping. 101 void verify_universe(const char* info) { 102 if (VerifyBeforeExit) { 103 log_info(cds)("Verify %s", info); 104 // Among other things, this ensures that Eden top is correct. 105 Universe::heap()->prepare_for_verify(); 106 Universe::verify(info); 107 } 108 } 109 110 void doit() { 111 verify_universe("Before CDS dynamic dump"); 112 DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm); 113 114 // Block concurrent class unloading from changing the _dumptime_table 115 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); 116 SystemDictionaryShared::find_all_archivable_classes(); 117 118 if (SystemDictionaryShared::is_dumptime_table_empty()) { 119 log_warning(cds, dynamic)("There is no class to be included in the dynamic archive."); 120 return; 121 } 122 123 log_info(cds,dynamic)("CDS dynamic dump: clinit = " JLONG_FORMAT "ms)", 124 ClassLoader::class_init_time_ms()); 125 126 init_header(); 127 gather_source_objs(); 128 gather_array_klasses(); 129 reserve_buffer(); 130 131 log_info(cds, dynamic)("Copying %d klasses and %d symbols", 132 klasses()->length(), symbols()->length()); 133 dump_rw_metadata(); 134 dump_ro_metadata(); 135 relocate_metaspaceobj_embedded_pointers(); 136 137 verify_estimate_size(_estimated_metaspaceobj_bytes, "MetaspaceObjs"); 138 139 sort_methods(); 140 141 log_info(cds)("Make classes shareable"); 142 make_klasses_shareable(); 143 144 char* serialized_data; 145 { 146 // Write the symbol table and system dictionaries to the RO space. 147 // Note that these tables still point to the *original* objects, so 148 // they would need to call DynamicArchive::original_to_target() to 149 // get the correct addresses. 150 assert(current_dump_region() == ro_region(), "Must be RO space"); 151 SymbolTable::write_to_archive(symbols()); 152 153 ArchiveBuilder::OtherROAllocMark mark; 154 SystemDictionaryShared::write_to_archive(false); 155 156 DynamicArchive::dump_array_klasses(); 157 AOTClassLinker::write_to_archive(); 158 TrainingData::dump_training_data(); 159 160 serialized_data = ro_region()->top(); 161 WriteClosure wc(ro_region()); 162 ArchiveBuilder::serialize_dynamic_archivable_items(&wc); 163 } 164 165 verify_estimate_size(_estimated_hashtable_bytes, "Hashtables"); 166 167 log_info(cds)("Adjust lambda proxy class dictionary"); 168 SystemDictionaryShared::adjust_lambda_proxy_class_dictionary(); 169 170 log_info(cds)("Adjust method info dictionary"); 171 SystemDictionaryShared::adjust_method_info_dictionary(); 172 173 log_info(cds)("Make training data shareable"); 174 make_training_data_shareable(); 175 176 relocate_to_requested(); 177 178 write_archive(serialized_data); 179 release_header(); 180 DynamicArchive::post_dump(); 181 182 post_dump(); 183 184 assert(_num_dump_regions_used == _total_dump_regions, "must be"); 185 verify_universe("After CDS dynamic dump"); 186 } 187 188 virtual void iterate_roots(MetaspaceClosure* it) { 189 FileMapInfo::metaspace_pointers_do(it); 190 SystemDictionaryShared::dumptime_classes_do(it); 191 TrainingData::iterate_roots(it); 192 iterate_primitive_array_klasses(it); 193 } 194 195 void iterate_primitive_array_klasses(MetaspaceClosure* it) { 196 for (int i = T_BOOLEAN; i <= T_LONG; i++) { 197 assert(is_java_primitive((BasicType)i), "sanity"); 198 Klass* k = Universe::typeArrayKlass((BasicType)i); // this give you "[I", etc 199 assert(MetaspaceShared::is_shared_static((void*)k), 200 "one-dimensional primitive array should be in static archive"); 201 ArrayKlass* ak = ArrayKlass::cast(k); 202 while (ak != nullptr && ak->is_shared()) { 203 Klass* next_k = ak->array_klass_or_null(); 204 if (next_k != nullptr) { 205 ak = ArrayKlass::cast(next_k); 206 } else { 207 ak = nullptr; 208 } 209 } 210 if (ak != nullptr) { 211 assert(ak->dimension() > 1, "sanity"); 212 // this is the lowest dimension that's not in the static archive 213 it->push(&ak); 214 } 215 } 216 } 217 }; 218 219 void DynamicArchiveBuilder::init_header() { 220 FileMapInfo* mapinfo = new FileMapInfo(_archive_name, false); 221 assert(FileMapInfo::dynamic_info() == mapinfo, "must be"); 222 FileMapInfo* base_info = FileMapInfo::current_info(); 223 // header only be available after populate_header 224 mapinfo->populate_header(base_info->core_region_alignment()); 225 _header = mapinfo->dynamic_header(); 226 227 _header->set_base_header_crc(base_info->crc()); 228 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 229 _header->set_base_region_crc(i, base_info->region_crc(i)); 230 } 231 } 232 233 void DynamicArchiveBuilder::release_header() { 234 // We temporarily allocated a dynamic FileMapInfo for dumping, which makes it appear we 235 // have mapped a dynamic archive, but we actually have not. We are in a safepoint now. 236 // Let's free it so that if class loading happens after we leave the safepoint, nothing 237 // bad will happen. 238 assert(SafepointSynchronize::is_at_safepoint(), "must be"); 239 FileMapInfo *mapinfo = FileMapInfo::dynamic_info(); 240 assert(mapinfo != nullptr && _header == mapinfo->dynamic_header(), "must be"); 241 delete mapinfo; 242 assert(!DynamicArchive::is_mapped(), "must be"); 243 _header = nullptr; 244 } 245 246 void DynamicArchiveBuilder::post_dump() { 247 ArchivePtrMarker::reset_map_and_vs(); 248 AOTClassLinker::dispose(); 249 } 250 251 void DynamicArchiveBuilder::sort_methods() { 252 InstanceKlass::disable_method_binary_search(); 253 for (int i = 0; i < klasses()->length(); i++) { 254 Klass* k = get_buffered_addr(klasses()->at(i)); 255 if (k->is_instance_klass()) { 256 sort_methods(InstanceKlass::cast(k)); 257 } 258 } 259 } 260 261 // The address order of the copied Symbols may be different than when the original 262 // klasses were created. Re-sort all the tables. See Method::sort_methods(). 263 void DynamicArchiveBuilder::sort_methods(InstanceKlass* ik) const { 264 assert(ik != nullptr, "DynamicArchiveBuilder currently doesn't support dumping the base archive"); 265 if (MetaspaceShared::is_in_shared_metaspace(ik)) { 266 // We have reached a supertype that's already in the base archive 267 return; 268 } 269 assert(is_in_buffer_space(ik), "method sorting must be done on buffered class, not original class"); 270 if (ik->java_mirror() == nullptr) { 271 // null mirror means this class has already been visited and methods are already sorted 272 return; 273 } 274 ik->remove_java_mirror(); 275 276 if (log_is_enabled(Debug, cds, dynamic)) { 277 ResourceMark rm; 278 log_debug(cds, dynamic)("sorting methods for " PTR_FORMAT " (" PTR_FORMAT ") %s", 279 p2i(ik), p2i(to_requested(ik)), ik->external_name()); 280 } 281 282 // Method sorting may re-layout the [iv]tables, which would change the offset(s) 283 // of the locations in an InstanceKlass that would contain pointers. Let's clear 284 // all the existing pointer marking bits, and re-mark the pointers after sorting. 285 remark_pointers_for_instance_klass(ik, false); 286 287 // Make sure all supertypes have been sorted 288 sort_methods(ik->java_super()); 289 Array<InstanceKlass*>* interfaces = ik->local_interfaces(); 290 int len = interfaces->length(); 291 for (int i = 0; i < len; i++) { 292 sort_methods(interfaces->at(i)); 293 } 294 295 #ifdef ASSERT 296 if (ik->methods() != nullptr) { 297 for (int m = 0; m < ik->methods()->length(); m++) { 298 Symbol* name = ik->methods()->at(m)->name(); 299 assert(MetaspaceShared::is_in_shared_metaspace(name) || is_in_buffer_space(name), "must be"); 300 } 301 } 302 if (ik->default_methods() != nullptr) { 303 for (int m = 0; m < ik->default_methods()->length(); m++) { 304 Symbol* name = ik->default_methods()->at(m)->name(); 305 assert(MetaspaceShared::is_in_shared_metaspace(name) || is_in_buffer_space(name), "must be"); 306 } 307 } 308 #endif 309 310 Method::sort_methods(ik->methods(), /*set_idnums=*/true, dynamic_dump_method_comparator); 311 if (ik->default_methods() != nullptr) { 312 Method::sort_methods(ik->default_methods(), /*set_idnums=*/false, dynamic_dump_method_comparator); 313 } 314 if (ik->is_linked()) { 315 // If the class has already been linked, we must relayout the i/v tables, whose order depends 316 // on the method sorting order. 317 // If the class is unlinked, we cannot layout the i/v tables yet. This is OK, as the 318 // i/v tables will be initialized at runtime after bytecode verification. 319 ik->vtable().initialize_vtable(); 320 ik->itable().initialize_itable(); 321 } 322 323 // Set all the pointer marking bits after sorting. 324 remark_pointers_for_instance_klass(ik, true); 325 } 326 327 template<bool should_mark> 328 class PointerRemarker: public MetaspaceClosure { 329 public: 330 virtual bool do_ref(Ref* ref, bool read_only) { 331 if (should_mark) { 332 ArchivePtrMarker::mark_pointer(ref->addr()); 333 } else { 334 ArchivePtrMarker::clear_pointer(ref->addr()); 335 } 336 return false; // don't recurse 337 } 338 }; 339 340 void DynamicArchiveBuilder::remark_pointers_for_instance_klass(InstanceKlass* k, bool should_mark) const { 341 if (should_mark) { 342 PointerRemarker<true> marker; 343 k->metaspace_pointers_do(&marker); 344 marker.finish(); 345 } else { 346 PointerRemarker<false> marker; 347 k->metaspace_pointers_do(&marker); 348 marker.finish(); 349 } 350 } 351 352 void DynamicArchiveBuilder::write_archive(char* serialized_data) { 353 _header->set_shared_path_table(FileMapInfo::shared_path_table().table()); 354 _header->set_serialized_data(serialized_data); 355 356 FileMapInfo* dynamic_info = FileMapInfo::dynamic_info(); 357 assert(dynamic_info != nullptr, "Sanity"); 358 359 dynamic_info->open_for_write(); 360 ArchiveHeapInfo no_heap_for_dynamic_dump; 361 ArchiveBuilder::write_archive(dynamic_info, &no_heap_for_dynamic_dump); 362 363 address base = _requested_dynamic_archive_bottom; 364 address top = _requested_dynamic_archive_top; 365 size_t file_size = pointer_delta(top, base, sizeof(char)); 366 367 log_info(cds, dynamic)("Written dynamic archive " PTR_FORMAT " - " PTR_FORMAT 368 " [" UINT32_FORMAT " bytes header, " SIZE_FORMAT " bytes total]", 369 p2i(base), p2i(top), _header->header_size(), file_size); 370 371 log_info(cds, dynamic)("%d klasses; %d symbols", klasses()->length(), symbols()->length()); 372 } 373 374 void DynamicArchiveBuilder::gather_array_klasses() { 375 for (int i = 0; i < klasses()->length(); i++) { 376 if (klasses()->at(i)->is_objArray_klass()) { 377 ObjArrayKlass* oak = ObjArrayKlass::cast(klasses()->at(i)); 378 Klass* elem = oak->element_klass(); 379 if (MetaspaceShared::is_shared_static(elem)) { 380 // Only capture the array klass whose element_klass is in the static archive. 381 // During run time, setup (see DynamicArchive::setup_array_klasses()) is needed 382 // so that the element_klass can find its array klasses from the dynamic archive. 383 DynamicArchive::append_array_klass(oak); 384 } else { 385 // The element_klass and its array klasses are in the same archive. 386 assert(!MetaspaceShared::is_shared_static(oak), 387 "we should not gather klasses that are already in the static archive"); 388 } 389 } 390 } 391 log_debug(cds)("Total array klasses gathered for dynamic archive: %d", DynamicArchive::num_array_klasses()); 392 } 393 394 class VM_PopulateDynamicDumpSharedSpace: public VM_GC_Sync_Operation { 395 DynamicArchiveBuilder _builder; 396 public: 397 VM_PopulateDynamicDumpSharedSpace(const char* archive_name) 398 : VM_GC_Sync_Operation(), _builder(archive_name) {} 399 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } 400 void doit() { 401 ResourceMark rm; 402 if (AllowArchivingWithJavaAgent) { 403 log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used " 404 "for testing purposes only and should not be used in a production environment"); 405 } 406 FileMapInfo::check_nonempty_dir_in_shared_path_table(); 407 408 _builder.doit(); 409 } 410 ~VM_PopulateDynamicDumpSharedSpace() { 411 RegeneratedClasses::cleanup(); 412 } 413 }; 414 415 // _array_klasses and _dynamic_archive_array_klasses only hold the array klasses 416 // which have element klass in the static archive. 417 GrowableArray<ObjArrayKlass*>* DynamicArchive::_array_klasses = nullptr; 418 Array<ObjArrayKlass*>* DynamicArchive::_dynamic_archive_array_klasses = nullptr; 419 420 void DynamicArchive::append_array_klass(ObjArrayKlass* ak) { 421 if (_array_klasses == nullptr) { 422 _array_klasses = new (mtClassShared) GrowableArray<ObjArrayKlass*>(50, mtClassShared); 423 } 424 _array_klasses->append(ak); 425 } 426 427 void DynamicArchive::dump_array_klasses() { 428 assert(CDSConfig::is_dumping_dynamic_archive(), "sanity"); 429 if (_array_klasses != nullptr) { 430 ArchiveBuilder* builder = ArchiveBuilder::current(); 431 int num_array_klasses = _array_klasses->length(); 432 _dynamic_archive_array_klasses = 433 ArchiveBuilder::new_ro_array<ObjArrayKlass*>(num_array_klasses); 434 for (int i = 0; i < num_array_klasses; i++) { 435 builder->write_pointer_in_buffer(_dynamic_archive_array_klasses->adr_at(i), _array_klasses->at(i)); 436 } 437 } 438 } 439 440 void DynamicArchive::setup_array_klasses() { 441 if (_dynamic_archive_array_klasses != nullptr) { 442 for (int i = 0; i < _dynamic_archive_array_klasses->length(); i++) { 443 ObjArrayKlass* oak = _dynamic_archive_array_klasses->at(i); 444 assert(!oak->is_typeArray_klass(), "all type array classes must be in static archive"); 445 446 Klass* elm = oak->element_klass(); 447 assert(MetaspaceShared::is_shared_static((void*)elm), "must be"); 448 449 if (elm->is_instance_klass()) { 450 assert(InstanceKlass::cast(elm)->array_klasses() == nullptr, "must be"); 451 InstanceKlass::cast(elm)->set_array_klasses(oak); 452 } else { 453 assert(elm->is_array_klass(), "sanity"); 454 assert(ArrayKlass::cast(elm)->higher_dimension() == nullptr, "must be"); 455 ArrayKlass::cast(elm)->set_higher_dimension(oak); 456 } 457 } 458 log_debug(cds)("Total array klasses read from dynamic archive: %d", _dynamic_archive_array_klasses->length()); 459 } 460 } 461 462 void DynamicArchive::serialize_array_klasses(SerializeClosure* soc) { 463 soc->do_ptr(&_dynamic_archive_array_klasses); 464 } 465 466 void DynamicArchive::make_array_klasses_shareable() { 467 if (_array_klasses != nullptr) { 468 int num_array_klasses = _array_klasses->length(); 469 for (int i = 0; i < num_array_klasses; i++) { 470 ObjArrayKlass* k = ArchiveBuilder::current()->get_buffered_addr(_array_klasses->at(i)); 471 k->remove_unshareable_info(); 472 } 473 } 474 } 475 476 void DynamicArchive::post_dump() { 477 if (_array_klasses != nullptr) { 478 delete _array_klasses; 479 _array_klasses = nullptr; 480 } 481 } 482 483 int DynamicArchive::num_array_klasses() { 484 return _array_klasses != nullptr ? _array_klasses->length() : 0; 485 } 486 487 void DynamicArchive::check_for_dynamic_dump() { 488 if (CDSConfig::is_dumping_dynamic_archive() && !CDSConfig::is_using_archive()) { 489 // This could happen if SharedArchiveFile has failed to load: 490 // - -Xshare:off was specified 491 // - SharedArchiveFile points to an non-existent file. 492 // - SharedArchiveFile points to an archive that has failed CRC check 493 // - SharedArchiveFile is not specified and the VM doesn't have a compatible default archive 494 495 #define __THEMSG " is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info." 496 if (RecordDynamicDumpInfo) { 497 log_error(cds)("-XX:+RecordDynamicDumpInfo%s", __THEMSG); 498 MetaspaceShared::unrecoverable_loading_error(); 499 } else { 500 assert(ArchiveClassesAtExit != nullptr, "sanity"); 501 log_warning(cds)("-XX:ArchiveClassesAtExit" __THEMSG); 502 } 503 #undef __THEMSG 504 CDSConfig::disable_dumping_dynamic_archive(); 505 } 506 } 507 508 void DynamicArchive::dump_at_exit(JavaThread* current, const char* archive_name) { 509 ExceptionMark em(current); 510 ResourceMark rm(current); 511 512 if (!CDSConfig::is_dumping_dynamic_archive() || archive_name == nullptr) { 513 return; 514 } 515 516 log_info(cds, dynamic)("Preparing for dynamic dump at exit in thread %s", current->name()); 517 518 JavaThread* THREAD = current; // For TRAPS processing related to link_shared_classes 519 520 { 521 // FIXME-HACK - make sure we have at least one class in the dynamic archive 522 TempNewSymbol class_name = SymbolTable::new_symbol("sun/nio/cs/IBM850"); // unusual class; shouldn't be used by our tests cases. 523 SystemDictionary::resolve_or_null(class_name, Handle(), Handle(), THREAD); 524 guarantee(!HAS_PENDING_EXCEPTION, "must have this class"); 525 } 526 527 MetaspaceShared::link_shared_classes(false/*not from jcmd*/, THREAD); 528 if (!HAS_PENDING_EXCEPTION) { 529 // copy shared path table to saved. 530 TrainingData::init_dumptime_table(CHECK); // captures TrainingDataSetLocker 531 if (!HAS_PENDING_EXCEPTION) { 532 VM_PopulateDynamicDumpSharedSpace op(archive_name); 533 VMThread::execute(&op); 534 return; 535 } 536 } 537 538 // One of the prepatory steps failed 539 oop ex = current->pending_exception(); 540 log_error(cds)("Dynamic dump has failed"); 541 log_error(cds)("%s: %s", ex->klass()->external_name(), 542 java_lang_String::as_utf8_string(java_lang_Throwable::message(ex))); 543 CLEAR_PENDING_EXCEPTION; 544 CDSConfig::disable_dumping_dynamic_archive(); // Just for good measure 545 } 546 547 // This is called by "jcmd VM.cds dynamic_dump" 548 void DynamicArchive::dump_for_jcmd(const char* archive_name, TRAPS) { 549 assert(CDSConfig::is_using_archive() && RecordDynamicDumpInfo, "already checked in arguments.cpp"); 550 assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp"); 551 assert(CDSConfig::is_dumping_dynamic_archive(), "already checked by check_for_dynamic_dump() during VM startup"); 552 MetaspaceShared::link_shared_classes(true/*from jcmd*/, CHECK); 553 // copy shared path table to saved. 554 TrainingData::init_dumptime_table(CHECK); // captures TrainingDataSetLocker 555 VM_PopulateDynamicDumpSharedSpace op(archive_name); 556 VMThread::execute(&op); 557 } 558 559 bool DynamicArchive::validate(FileMapInfo* dynamic_info) { 560 assert(!dynamic_info->is_static(), "must be"); 561 // Check if the recorded base archive matches with the current one 562 FileMapInfo* base_info = FileMapInfo::current_info(); 563 DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header(); 564 565 // Check the header crc 566 if (dynamic_header->base_header_crc() != base_info->crc()) { 567 log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed."); 568 return false; 569 } 570 571 // Check each space's crc 572 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 573 if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) { 574 log_warning(cds)("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i); 575 return false; 576 } 577 } 578 579 return true; 580 } 581 582 void DynamicArchiveHeader::print(outputStream* st) { 583 ResourceMark rm; 584 585 st->print_cr("- base_header_crc: 0x%08x", base_header_crc()); 586 for (int i = 0; i < NUM_CDS_REGIONS; i++) { 587 st->print_cr("- base_region_crc[%d]: 0x%08x", i, base_region_crc(i)); 588 } 589 }