1 /* 2 * Copyright (c) 2012, 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/archiveBuilder.hpp" 27 #include "cds/archiveHeapLoader.hpp" 28 #include "cds/archiveHeapWriter.hpp" 29 #include "cds/cds_globals.hpp" 30 #include "cds/cdsConfig.hpp" 31 #include "cds/cdsProtectionDomain.hpp" 32 #include "cds/cds_globals.hpp" 33 #include "cds/classListParser.hpp" 34 #include "cds/classListWriter.hpp" 35 #include "cds/classPrelinker.hpp" 36 #include "cds/cppVtables.hpp" 37 #include "cds/dumpAllocStats.hpp" 38 #include "cds/dynamicArchive.hpp" 39 #include "cds/filemap.hpp" 40 #include "cds/heapShared.hpp" 41 #include "cds/lambdaFormInvokers.hpp" 42 #include "cds/metaspaceShared.hpp" 43 #include "classfile/classLoaderDataGraph.hpp" 44 #include "classfile/classLoaderDataShared.hpp" 45 #include "classfile/classLoaderExt.hpp" 46 #include "classfile/javaClasses.inline.hpp" 47 #include "classfile/loaderConstraints.hpp" 48 #include "classfile/modules.hpp" 49 #include "classfile/placeholders.hpp" 50 #include "classfile/stringTable.hpp" 51 #include "classfile/symbolTable.hpp" 52 #include "classfile/systemDictionary.hpp" 53 #include "classfile/systemDictionaryShared.hpp" 54 #include "classfile/vmClasses.hpp" 55 #include "classfile/vmSymbols.hpp" 56 #include "code/codeCache.hpp" 57 #include "gc/shared/gcVMOperations.hpp" 58 #include "interpreter/bytecodeStream.hpp" 59 #include "interpreter/bytecodes.hpp" 60 #include "jvm_io.h" 61 #include "logging/log.hpp" 62 #include "logging/logMessage.hpp" 63 #include "logging/logStream.hpp" 64 #include "memory/metaspace.hpp" 65 #include "memory/metaspaceClosure.hpp" 66 #include "memory/resourceArea.hpp" 67 #include "memory/universe.hpp" 68 #include "nmt/memTracker.hpp" 69 #include "oops/compressedKlass.hpp" 70 #include "oops/flatArrayKlass.hpp" 71 #include "oops/inlineKlass.hpp" 72 #include "oops/instanceMirrorKlass.hpp" 73 #include "oops/klass.inline.hpp" 74 #include "oops/objArrayOop.hpp" 75 #include "oops/oop.inline.hpp" 76 #include "oops/oopHandle.hpp" 77 #include "prims/jvmtiExport.hpp" 78 #include "runtime/arguments.hpp" 79 #include "runtime/globals.hpp" 80 #include "runtime/globals_extension.hpp" 81 #include "runtime/handles.inline.hpp" 82 #include "runtime/os.inline.hpp" 83 #include "runtime/safepointVerifiers.hpp" 84 #include "runtime/sharedRuntime.hpp" 85 #include "runtime/vmOperations.hpp" 86 #include "runtime/vmThread.hpp" 87 #include "sanitizers/leak.hpp" 88 #include "utilities/align.hpp" 89 #include "utilities/bitMap.inline.hpp" 90 #include "utilities/defaultStream.hpp" 91 #include "utilities/ostream.hpp" 92 #include "utilities/resourceHash.hpp" 93 94 ReservedSpace MetaspaceShared::_symbol_rs; 95 VirtualSpace MetaspaceShared::_symbol_vs; 96 bool MetaspaceShared::_archive_loading_failed = false; 97 bool MetaspaceShared::_remapped_readwrite = false; 98 void* MetaspaceShared::_shared_metaspace_static_top = nullptr; 99 intx MetaspaceShared::_relocation_delta; 100 char* MetaspaceShared::_requested_base_address; 101 bool MetaspaceShared::_use_optimized_module_handling = true; 102 103 // The CDS archive is divided into the following regions: 104 // rw - read-write metadata 105 // ro - read-only metadata and read-only tables 106 // hp - heap region 107 // bm - bitmap for relocating the above 7 regions. 108 // 109 // The rw and ro regions are linearly allocated, in the order of rw->ro. 110 // These regions are aligned with MetaspaceShared::core_region_alignment(). 111 // 112 // These 2 regions are populated in the following steps: 113 // [0] All classes are loaded in MetaspaceShared::loadable_descriptors(). All metadata are 114 // temporarily allocated outside of the shared regions. 115 // [1] We enter a safepoint and allocate a buffer for the rw/ro regions. 116 // [2] C++ vtables are copied into the rw region. 117 // [3] ArchiveBuilder copies RW metadata into the rw region. 118 // [4] ArchiveBuilder copies RO metadata into the ro region. 119 // [5] SymbolTable, StringTable, SystemDictionary, and a few other read-only data 120 // are copied into the ro region as read-only tables. 121 // 122 // The heap region is populated by HeapShared::archive_objects. 123 // 124 // The bitmap region is used to relocate the ro/rw/hp regions. 125 126 static DumpRegion _symbol_region("symbols"); 127 128 char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) { 129 return _symbol_region.allocate(num_bytes); 130 } 131 132 // os::vm_allocation_granularity() is usually 4K for most OSes. However, some platforms 133 // such as linux-aarch64 and macos-x64 ... 134 // it can be either 4K or 64K and on macos-aarch64 it is 16K. To generate archives that are 135 // compatible for both settings, an alternative cds core region alignment can be enabled 136 // at building time: 137 // --enable-compactible-cds-alignment 138 // Upon successful configuration, the compactible alignment then can be defined in: 139 // os_linux_aarch64.cpp 140 // os_bsd_x86.cpp 141 size_t MetaspaceShared::core_region_alignment() { 142 return os::cds_core_region_alignment(); 143 } 144 145 static bool shared_base_valid(char* shared_base) { 146 // We check user input for SharedBaseAddress at dump time. We must weed out values 147 // we already know to be invalid later. 148 149 // At CDS runtime, "shared_base" will be the (attempted) mapping start. It will also 150 // be the encoding base, since the the headers of archived base objects (and with Lilliput, 151 // the prototype mark words) carry pre-computed narrow Klass IDs that refer to the mapping 152 // start as base. 153 // 154 // Therefore, "shared_base" must be later usable as encoding base. 155 return AARCH64_ONLY(is_aligned(shared_base, 4 * G)) NOT_AARCH64(true); 156 } 157 158 class DumpClassListCLDClosure : public CLDClosure { 159 static const int INITIAL_TABLE_SIZE = 1987; 160 static const int MAX_TABLE_SIZE = 61333; 161 162 fileStream *_stream; 163 ResizeableResourceHashtable<InstanceKlass*, bool, 164 AnyObj::C_HEAP, mtClassShared> _dumped_classes; 165 166 void dump(InstanceKlass* ik) { 167 bool created; 168 _dumped_classes.put_if_absent(ik, &created); 169 if (!created) { 170 return; 171 } 172 if (_dumped_classes.maybe_grow()) { 173 log_info(cds, hashtables)("Expanded _dumped_classes table to %d", _dumped_classes.table_size()); 174 } 175 if (ik->java_super()) { 176 dump(ik->java_super()); 177 } 178 Array<InstanceKlass*>* interfaces = ik->local_interfaces(); 179 int len = interfaces->length(); 180 for (int i = 0; i < len; i++) { 181 dump(interfaces->at(i)); 182 } 183 ClassListWriter::write_to_stream(ik, _stream); 184 } 185 186 public: 187 DumpClassListCLDClosure(fileStream* f) 188 : CLDClosure(), _dumped_classes(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE) { 189 _stream = f; 190 } 191 192 void do_cld(ClassLoaderData* cld) { 193 for (Klass* klass = cld->klasses(); klass != nullptr; klass = klass->next_link()) { 194 if (klass->is_instance_klass()) { 195 dump(InstanceKlass::cast(klass)); 196 } 197 } 198 } 199 }; 200 201 void MetaspaceShared::dump_loaded_classes(const char* file_name, TRAPS) { 202 fileStream stream(file_name, "w"); 203 if (stream.is_open()) { 204 MutexLocker lock(ClassLoaderDataGraph_lock); 205 MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag); 206 DumpClassListCLDClosure collect_classes(&stream); 207 ClassLoaderDataGraph::loaded_cld_do(&collect_classes); 208 } else { 209 THROW_MSG(vmSymbols::java_io_IOException(), "Failed to open file"); 210 } 211 } 212 213 static bool shared_base_too_high(char* specified_base, char* aligned_base, size_t cds_max) { 214 if (specified_base != nullptr && aligned_base < specified_base) { 215 // SharedBaseAddress is very high (e.g., 0xffffffffffffff00) so 216 // align_up(SharedBaseAddress, MetaspaceShared::core_region_alignment()) has wrapped around. 217 return true; 218 } 219 if (max_uintx - uintx(aligned_base) < uintx(cds_max)) { 220 // The end of the archive will wrap around 221 return true; 222 } 223 224 return false; 225 } 226 227 static char* compute_shared_base(size_t cds_max) { 228 char* specified_base = (char*)SharedBaseAddress; 229 char* aligned_base = align_up(specified_base, MetaspaceShared::core_region_alignment()); 230 if (UseCompressedClassPointers) { 231 aligned_base = align_up(specified_base, Metaspace::reserve_alignment()); 232 } 233 234 if (aligned_base != specified_base) { 235 log_info(cds)("SharedBaseAddress (" INTPTR_FORMAT ") aligned up to " INTPTR_FORMAT, 236 p2i(specified_base), p2i(aligned_base)); 237 } 238 239 const char* err = nullptr; 240 if (shared_base_too_high(specified_base, aligned_base, cds_max)) { 241 err = "too high"; 242 } else if (!shared_base_valid(aligned_base)) { 243 err = "invalid for this platform"; 244 } else { 245 return aligned_base; 246 } 247 248 log_warning(cds)("SharedBaseAddress (" INTPTR_FORMAT ") is %s. Reverted to " INTPTR_FORMAT, 249 p2i((void*)SharedBaseAddress), err, 250 p2i((void*)Arguments::default_SharedBaseAddress())); 251 252 specified_base = (char*)Arguments::default_SharedBaseAddress(); 253 aligned_base = align_up(specified_base, MetaspaceShared::core_region_alignment()); 254 255 // Make sure the default value of SharedBaseAddress specified in globals.hpp is sane. 256 assert(!shared_base_too_high(specified_base, aligned_base, cds_max), "Sanity"); 257 assert(shared_base_valid(aligned_base), "Sanity"); 258 return aligned_base; 259 } 260 261 void MetaspaceShared::initialize_for_static_dump() { 262 assert(CDSConfig::is_dumping_static_archive(), "sanity"); 263 log_info(cds)("Core region alignment: " SIZE_FORMAT, core_region_alignment()); 264 // The max allowed size for CDS archive. We use this to limit SharedBaseAddress 265 // to avoid address space wrap around. 266 size_t cds_max; 267 const size_t reserve_alignment = core_region_alignment(); 268 269 #ifdef _LP64 270 const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1); 271 cds_max = align_down(UnscaledClassSpaceMax, reserve_alignment); 272 #else 273 // We don't support archives larger than 256MB on 32-bit due to limited 274 // virtual address space. 275 cds_max = align_down(256*M, reserve_alignment); 276 #endif 277 278 _requested_base_address = compute_shared_base(cds_max); 279 SharedBaseAddress = (size_t)_requested_base_address; 280 281 size_t symbol_rs_size = LP64_ONLY(3 * G) NOT_LP64(128 * M); 282 _symbol_rs = ReservedSpace(symbol_rs_size); 283 if (!_symbol_rs.is_reserved()) { 284 log_error(cds)("Unable to reserve memory for symbols: " SIZE_FORMAT " bytes.", symbol_rs_size); 285 MetaspaceShared::unrecoverable_writing_error(); 286 } 287 _symbol_region.init(&_symbol_rs, &_symbol_vs); 288 } 289 290 // Called by universe_post_init() 291 void MetaspaceShared::post_initialize(TRAPS) { 292 if (CDSConfig::is_using_archive()) { 293 int size = FileMapInfo::get_number_of_shared_paths(); 294 if (size > 0) { 295 CDSProtectionDomain::allocate_shared_data_arrays(size, CHECK); 296 if (!CDSConfig::is_dumping_dynamic_archive()) { 297 FileMapInfo* info; 298 if (FileMapInfo::dynamic_info() == nullptr) { 299 info = FileMapInfo::current_info(); 300 } else { 301 info = FileMapInfo::dynamic_info(); 302 } 303 ClassLoaderExt::init_paths_start_index(info->app_class_paths_start_index()); 304 ClassLoaderExt::init_app_module_paths_start_index(info->app_module_paths_start_index()); 305 } 306 } 307 } 308 } 309 310 static GrowableArrayCHeap<OopHandle, mtClassShared>* _extra_interned_strings = nullptr; 311 static GrowableArrayCHeap<Symbol*, mtClassShared>* _extra_symbols = nullptr; 312 313 void MetaspaceShared::read_extra_data(JavaThread* current, const char* filename) { 314 _extra_interned_strings = new GrowableArrayCHeap<OopHandle, mtClassShared>(10000); 315 _extra_symbols = new GrowableArrayCHeap<Symbol*, mtClassShared>(1000); 316 317 HashtableTextDump reader(filename); 318 reader.check_version("VERSION: 1.0"); 319 320 while (reader.remain() > 0) { 321 int utf8_length; 322 int prefix_type = reader.scan_prefix(&utf8_length); 323 ResourceMark rm(current); 324 if (utf8_length == 0x7fffffff) { 325 // buf_len will overflown 32-bit value. 326 log_error(cds)("string length too large: %d", utf8_length); 327 MetaspaceShared::unrecoverable_loading_error(); 328 } 329 int buf_len = utf8_length+1; 330 char* utf8_buffer = NEW_RESOURCE_ARRAY(char, buf_len); 331 reader.get_utf8(utf8_buffer, utf8_length); 332 utf8_buffer[utf8_length] = '\0'; 333 334 if (prefix_type == HashtableTextDump::SymbolPrefix) { 335 _extra_symbols->append(SymbolTable::new_permanent_symbol(utf8_buffer)); 336 } else{ 337 assert(prefix_type == HashtableTextDump::StringPrefix, "Sanity"); 338 ExceptionMark em(current); 339 JavaThread* THREAD = current; // For exception macros. 340 oop str = StringTable::intern(utf8_buffer, THREAD); 341 342 if (HAS_PENDING_EXCEPTION) { 343 log_warning(cds, heap)("[line %d] extra interned string allocation failed; size too large: %d", 344 reader.last_line_no(), utf8_length); 345 CLEAR_PENDING_EXCEPTION; 346 } else { 347 #if INCLUDE_CDS_JAVA_HEAP 348 if (ArchiveHeapWriter::is_string_too_large_to_archive(str)) { 349 log_warning(cds, heap)("[line %d] extra interned string ignored; size too large: %d", 350 reader.last_line_no(), utf8_length); 351 continue; 352 } 353 // Make sure this string is included in the dumped interned string table. 354 assert(str != nullptr, "must succeed"); 355 _extra_interned_strings->append(OopHandle(Universe::vm_global(), str)); 356 #endif 357 } 358 } 359 } 360 } 361 362 // Read/write a data stream for restoring/preserving metadata pointers and 363 // miscellaneous data from/to the shared archive file. 364 365 void MetaspaceShared::serialize(SerializeClosure* soc) { 366 int tag = 0; 367 soc->do_tag(--tag); 368 369 // Verify the sizes of various metadata in the system. 370 soc->do_tag(sizeof(Method)); 371 soc->do_tag(sizeof(ConstMethod)); 372 soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE)); 373 soc->do_tag(sizeof(ConstantPool)); 374 soc->do_tag(sizeof(ConstantPoolCache)); 375 soc->do_tag(objArrayOopDesc::base_offset_in_bytes()); 376 soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE)); 377 soc->do_tag(sizeof(Symbol)); 378 379 // Need to do this first, as subsequent steps may call virtual functions 380 // in archived Metadata objects. 381 CppVtables::serialize(soc); 382 soc->do_tag(--tag); 383 384 // Dump/restore miscellaneous metadata. 385 JavaClasses::serialize_offsets(soc); 386 Universe::serialize(soc); 387 soc->do_tag(--tag); 388 389 // Dump/restore references to commonly used names and signatures. 390 vmSymbols::serialize(soc); 391 soc->do_tag(--tag); 392 393 // Dump/restore the symbol/string/subgraph_info tables 394 SymbolTable::serialize_shared_table_header(soc); 395 StringTable::serialize_shared_table_header(soc); 396 HeapShared::serialize_tables(soc); 397 SystemDictionaryShared::serialize_dictionary_headers(soc); 398 399 InstanceMirrorKlass::serialize_offsets(soc); 400 401 // Dump/restore well known classes (pointers) 402 SystemDictionaryShared::serialize_vm_classes(soc); 403 soc->do_tag(--tag); 404 405 CDS_JAVA_HEAP_ONLY(Modules::serialize(soc);) 406 CDS_JAVA_HEAP_ONLY(ClassLoaderDataShared::serialize(soc);) 407 408 LambdaFormInvokers::serialize(soc); 409 soc->do_tag(666); 410 } 411 412 static void rewrite_nofast_bytecode(const methodHandle& method) { 413 BytecodeStream bcs(method); 414 while (!bcs.is_last_bytecode()) { 415 Bytecodes::Code opcode = bcs.next(); 416 switch (opcode) { 417 case Bytecodes::_getfield: *bcs.bcp() = Bytecodes::_nofast_getfield; break; 418 case Bytecodes::_putfield: *bcs.bcp() = Bytecodes::_nofast_putfield; break; 419 case Bytecodes::_aload_0: *bcs.bcp() = Bytecodes::_nofast_aload_0; break; 420 case Bytecodes::_iload: { 421 if (!bcs.is_wide()) { 422 *bcs.bcp() = Bytecodes::_nofast_iload; 423 } 424 break; 425 } 426 default: break; 427 } 428 } 429 } 430 431 // [1] Rewrite all bytecodes as needed, so that the ConstMethod* will not be modified 432 // at run time by RewriteBytecodes/RewriteFrequentPairs 433 // [2] Assign a fingerprint, so one doesn't need to be assigned at run-time. 434 void MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik) { 435 for (int i = 0; i < ik->methods()->length(); i++) { 436 methodHandle m(thread, ik->methods()->at(i)); 437 if (ik->can_be_verified_at_dumptime() && ik->is_linked()) { 438 rewrite_nofast_bytecode(m); 439 } 440 Fingerprinter fp(m); 441 // The side effect of this call sets method's fingerprint field. 442 fp.fingerprint(); 443 } 444 } 445 446 class VM_PopulateDumpSharedSpace : public VM_Operation { 447 private: 448 ArchiveHeapInfo _heap_info; 449 FileMapInfo* _map_info; 450 StaticArchiveBuilder& _builder; 451 452 void dump_java_heap_objects(GrowableArray<Klass*>* klasses) NOT_CDS_JAVA_HEAP_RETURN; 453 void dump_shared_symbol_table(GrowableArray<Symbol*>* symbols) { 454 log_info(cds)("Dumping symbol table ..."); 455 SymbolTable::write_to_archive(symbols); 456 } 457 char* dump_read_only_tables(); 458 459 public: 460 461 VM_PopulateDumpSharedSpace(StaticArchiveBuilder& b) : 462 VM_Operation(), _heap_info(), _map_info(nullptr), _builder(b) {} 463 464 bool skip_operation() const { return false; } 465 466 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } 467 ArchiveHeapInfo* heap_info() { return &_heap_info; } 468 FileMapInfo* map_info() const { return _map_info; } 469 void doit(); // outline because gdb sucks 470 bool allow_nested_vm_operations() const { return true; } 471 }; // class VM_PopulateDumpSharedSpace 472 473 class StaticArchiveBuilder : public ArchiveBuilder { 474 public: 475 StaticArchiveBuilder() : ArchiveBuilder() {} 476 477 virtual void iterate_roots(MetaspaceClosure* it) { 478 FileMapInfo::metaspace_pointers_do(it); 479 SystemDictionaryShared::dumptime_classes_do(it); 480 Universe::metaspace_pointers_do(it); 481 vmSymbols::metaspace_pointers_do(it); 482 483 // The above code should find all the symbols that are referenced by the 484 // archived classes. We just need to add the extra symbols which 485 // may not be used by any of the archived classes -- these are usually 486 // symbols that we anticipate to be used at run time, so we can store 487 // them in the RO region, to be shared across multiple processes. 488 if (_extra_symbols != nullptr) { 489 for (int i = 0; i < _extra_symbols->length(); i++) { 490 it->push(_extra_symbols->adr_at(i)); 491 } 492 } 493 } 494 }; 495 496 char* VM_PopulateDumpSharedSpace::dump_read_only_tables() { 497 ArchiveBuilder::OtherROAllocMark mark; 498 499 SystemDictionaryShared::write_to_archive(); 500 501 // Write lambform lines into archive 502 LambdaFormInvokers::dump_static_archive_invokers(); 503 // Write module name into archive 504 CDS_JAVA_HEAP_ONLY(Modules::dump_main_module_name();) 505 // Write the other data to the output array. 506 DumpRegion* ro_region = ArchiveBuilder::current()->ro_region(); 507 char* start = ro_region->top(); 508 WriteClosure wc(ro_region); 509 MetaspaceShared::serialize(&wc); 510 511 return start; 512 } 513 514 void VM_PopulateDumpSharedSpace::doit() { 515 guarantee(!CDSConfig::is_using_archive(), "We should not be using an archive when we dump"); 516 517 DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm); 518 519 FileMapInfo::check_nonempty_dir_in_shared_path_table(); 520 521 NOT_PRODUCT(SystemDictionary::verify();) 522 523 // Block concurrent class unloading from changing the _dumptime_table 524 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); 525 SystemDictionaryShared::check_excluded_classes(); 526 527 _builder.gather_source_objs(); 528 _builder.reserve_buffer(); 529 530 CppVtables::dumptime_init(&_builder); 531 532 _builder.sort_metadata_objs(); 533 _builder.dump_rw_metadata(); 534 _builder.dump_ro_metadata(); 535 _builder.relocate_metaspaceobj_embedded_pointers(); 536 537 dump_java_heap_objects(_builder.klasses()); 538 dump_shared_symbol_table(_builder.symbols()); 539 540 log_info(cds)("Make classes shareable"); 541 _builder.make_klasses_shareable(); 542 543 char* serialized_data = dump_read_only_tables(); 544 545 SystemDictionaryShared::adjust_lambda_proxy_class_dictionary(); 546 547 // The vtable clones contain addresses of the current process. 548 // We don't want to write these addresses into the archive. 549 CppVtables::zero_archived_vtables(); 550 551 // Write the archive file 552 const char* static_archive = CDSConfig::static_archive_path(); 553 assert(static_archive != nullptr, "SharedArchiveFile not set?"); 554 _map_info = new FileMapInfo(static_archive, true); 555 _map_info->populate_header(MetaspaceShared::core_region_alignment()); 556 _map_info->set_serialized_data(serialized_data); 557 _map_info->set_cloned_vtables(CppVtables::vtables_serialized_base()); 558 } 559 560 class CollectCLDClosure : public CLDClosure { 561 GrowableArray<ClassLoaderData*> _loaded_cld; 562 GrowableArray<OopHandle> _loaded_cld_handles; // keep the CLDs alive 563 Thread* _current_thread; 564 public: 565 CollectCLDClosure(Thread* thread) : _current_thread(thread) {} 566 ~CollectCLDClosure() { 567 for (int i = 0; i < _loaded_cld_handles.length(); i++) { 568 _loaded_cld_handles.at(i).release(Universe::vm_global()); 569 } 570 } 571 void do_cld(ClassLoaderData* cld) { 572 assert(cld->is_alive(), "must be"); 573 _loaded_cld.append(cld); 574 _loaded_cld_handles.append(OopHandle(Universe::vm_global(), cld->holder())); 575 } 576 577 int nof_cld() const { return _loaded_cld.length(); } 578 ClassLoaderData* cld_at(int index) { return _loaded_cld.at(index); } 579 }; 580 581 // Check if we can eagerly link this class at dump time, so we can avoid the 582 // runtime linking overhead (especially verification) 583 bool MetaspaceShared::may_be_eagerly_linked(InstanceKlass* ik) { 584 if (!ik->can_be_verified_at_dumptime()) { 585 // For old classes, try to leave them in the unlinked state, so 586 // we can still store them in the archive. They must be 587 // linked/verified at runtime. 588 return false; 589 } 590 if (CDSConfig::is_dumping_dynamic_archive() && ik->is_shared_unregistered_class()) { 591 // Linking of unregistered classes at this stage may cause more 592 // classes to be resolved, resulting in calls to ClassLoader.loadClass() 593 // that may not be expected by custom class loaders. 594 // 595 // It's OK to do this for the built-in loaders as we know they can 596 // tolerate this. 597 return false; 598 } 599 return true; 600 } 601 602 bool MetaspaceShared::link_class_for_cds(InstanceKlass* ik, TRAPS) { 603 // Link the class to cause the bytecodes to be rewritten and the 604 // cpcache to be created. Class verification is done according 605 // to -Xverify setting. 606 bool res = MetaspaceShared::try_link_class(THREAD, ik); 607 ClassPrelinker::dumptime_resolve_constants(ik, CHECK_(false)); 608 return res; 609 } 610 611 void MetaspaceShared::link_shared_classes(bool jcmd_request, TRAPS) { 612 ClassPrelinker::initialize(); 613 614 if (!jcmd_request) { 615 LambdaFormInvokers::regenerate_holder_classes(CHECK); 616 } 617 618 // Collect all loaded ClassLoaderData. 619 CollectCLDClosure collect_cld(THREAD); 620 { 621 // ClassLoaderDataGraph::loaded_cld_do requires ClassLoaderDataGraph_lock. 622 // We cannot link the classes while holding this lock (or else we may run into deadlock). 623 // Therefore, we need to first collect all the CLDs, and then link their classes after 624 // releasing the lock. 625 MutexLocker lock(ClassLoaderDataGraph_lock); 626 ClassLoaderDataGraph::loaded_cld_do(&collect_cld); 627 } 628 629 while (true) { 630 bool has_linked = false; 631 for (int i = 0; i < collect_cld.nof_cld(); i++) { 632 ClassLoaderData* cld = collect_cld.cld_at(i); 633 for (Klass* klass = cld->klasses(); klass != nullptr; klass = klass->next_link()) { 634 if (klass->is_instance_klass()) { 635 InstanceKlass* ik = InstanceKlass::cast(klass); 636 if (may_be_eagerly_linked(ik)) { 637 has_linked |= link_class_for_cds(ik, CHECK); 638 } 639 } 640 } 641 } 642 643 if (!has_linked) { 644 break; 645 } 646 // Class linking includes verification which may load more classes. 647 // Keep scanning until we have linked no more classes. 648 } 649 } 650 651 void MetaspaceShared::prepare_for_dumping() { 652 assert(CDSConfig::is_dumping_archive(), "sanity"); 653 CDSConfig::check_unsupported_dumping_module_options(); 654 ClassLoader::initialize_shared_path(JavaThread::current()); 655 } 656 657 // Preload classes from a list, populate the shared spaces and dump to a 658 // file. 659 void MetaspaceShared::preload_and_dump(TRAPS) { 660 ResourceMark rm(THREAD); 661 StaticArchiveBuilder builder; 662 preload_and_dump_impl(builder, THREAD); 663 if (HAS_PENDING_EXCEPTION) { 664 if (PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) { 665 log_error(cds)("Out of memory. Please run with a larger Java heap, current MaxHeapSize = " 666 SIZE_FORMAT "M", MaxHeapSize/M); 667 MetaspaceShared::writing_error(); 668 } else { 669 log_error(cds)("%s: %s", PENDING_EXCEPTION->klass()->external_name(), 670 java_lang_String::as_utf8_string(java_lang_Throwable::message(PENDING_EXCEPTION))); 671 MetaspaceShared::writing_error("Unexpected exception, use -Xlog:cds,exceptions=trace for detail"); 672 } 673 } 674 } 675 676 #if INCLUDE_CDS_JAVA_HEAP && defined(_LP64) 677 void MetaspaceShared::adjust_heap_sizes_for_dumping() { 678 if (!CDSConfig::is_dumping_heap() || UseCompressedOops) { 679 return; 680 } 681 // CDS heap dumping requires all string oops to have an offset 682 // from the heap bottom that can be encoded in 32-bit. 683 julong max_heap_size = (julong)(4 * G); 684 685 if (MinHeapSize > max_heap_size) { 686 log_debug(cds)("Setting MinHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", MinHeapSize/M); 687 FLAG_SET_ERGO(MinHeapSize, max_heap_size); 688 } 689 if (InitialHeapSize > max_heap_size) { 690 log_debug(cds)("Setting InitialHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", InitialHeapSize/M); 691 FLAG_SET_ERGO(InitialHeapSize, max_heap_size); 692 } 693 if (MaxHeapSize > max_heap_size) { 694 log_debug(cds)("Setting MaxHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", MaxHeapSize/M); 695 FLAG_SET_ERGO(MaxHeapSize, max_heap_size); 696 } 697 } 698 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64 699 700 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) { 701 // Construct the path to the class list (in jre/lib) 702 // Walk up two directories from the location of the VM and 703 // optionally tack on "lib" (depending on platform) 704 os::jvm_path(default_classlist, (jint)(buf_size)); 705 for (int i = 0; i < 3; i++) { 706 char *end = strrchr(default_classlist, *os::file_separator()); 707 if (end != nullptr) *end = '\0'; 708 } 709 size_t classlist_path_len = strlen(default_classlist); 710 if (classlist_path_len >= 3) { 711 if (strcmp(default_classlist + classlist_path_len - 3, "lib") != 0) { 712 if (classlist_path_len < buf_size - 4) { 713 jio_snprintf(default_classlist + classlist_path_len, 714 buf_size - classlist_path_len, 715 "%slib", os::file_separator()); 716 classlist_path_len += 4; 717 } 718 } 719 } 720 if (classlist_path_len < buf_size - 10) { 721 jio_snprintf(default_classlist + classlist_path_len, 722 buf_size - classlist_path_len, 723 "%sclasslist", os::file_separator()); 724 } 725 } 726 727 void MetaspaceShared::loadable_descriptors(TRAPS) { 728 char default_classlist[JVM_MAXPATHLEN]; 729 const char* classlist_path; 730 731 get_default_classlist(default_classlist, sizeof(default_classlist)); 732 if (SharedClassListFile == nullptr) { 733 classlist_path = default_classlist; 734 } else { 735 classlist_path = SharedClassListFile; 736 } 737 738 log_info(cds)("Loading classes to share ..."); 739 ClassListParser::parse_classlist(classlist_path, 740 ClassListParser::_parse_all, CHECK); 741 if (ExtraSharedClassListFile) { 742 ClassListParser::parse_classlist(ExtraSharedClassListFile, 743 ClassListParser::_parse_all, CHECK); 744 } 745 if (classlist_path != default_classlist) { 746 struct stat statbuf; 747 if (os::stat(default_classlist, &statbuf) == 0) { 748 // File exists, let's use it. 749 ClassListParser::parse_classlist(default_classlist, 750 ClassListParser::_parse_lambda_forms_invokers_only, CHECK); 751 } 752 } 753 754 // Exercise the manifest processing code to ensure classes used by CDS at runtime 755 // are always archived 756 const char* dummy = "Manifest-Version: 1.0\n"; 757 CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK); 758 759 log_info(cds)("Loading classes to share: done."); 760 } 761 762 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) { 763 loadable_descriptors(CHECK); 764 765 if (SharedArchiveConfigFile) { 766 log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile); 767 read_extra_data(THREAD, SharedArchiveConfigFile); 768 log_info(cds)("Reading extra data: done."); 769 } 770 771 // Rewrite and link classes 772 log_info(cds)("Rewriting and linking classes ..."); 773 774 // Link any classes which got missed. This would happen if we have loaded classes that 775 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K 776 // fails verification, all other interfaces that were not specified in the classlist but 777 // are implemented by K are not verified. 778 link_shared_classes(false/*not from jcmd*/, CHECK); 779 log_info(cds)("Rewriting and linking classes: done"); 780 781 #if INCLUDE_CDS_JAVA_HEAP 782 if (CDSConfig::is_dumping_heap()) { 783 if (!HeapShared::is_archived_boot_layer_available(THREAD)) { 784 log_info(cds)("archivedBootLayer not available, disabling full module graph"); 785 CDSConfig::stop_dumping_full_module_graph(); 786 } 787 HeapShared::init_for_dumping(CHECK); 788 ArchiveHeapWriter::init(); 789 if (CDSConfig::is_dumping_full_module_graph()) { 790 HeapShared::reset_archived_object_states(CHECK); 791 } 792 793 // Do this at the very end, when no Java code will be executed. Otherwise 794 // some new strings may be added to the intern table. 795 StringTable::allocate_shared_strings_array(CHECK); 796 } 797 #endif 798 799 VM_PopulateDumpSharedSpace op(builder); 800 VMThread::execute(&op); 801 802 if (!write_static_archive(&builder, op.map_info(), op.heap_info())) { 803 THROW_MSG(vmSymbols::java_io_IOException(), "Encountered error while dumping"); 804 } 805 } 806 807 bool MetaspaceShared::write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info) { 808 // relocate the data so that it can be mapped to MetaspaceShared::requested_base_address() 809 // without runtime relocation. 810 builder->relocate_to_requested(); 811 812 map_info->open_for_write(); 813 if (!map_info->is_open()) { 814 return false; 815 } 816 builder->write_archive(map_info, heap_info); 817 818 if (AllowArchivingWithJavaAgent) { 819 log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used " 820 "for testing purposes only and should not be used in a production environment"); 821 } 822 return true; 823 } 824 825 // Returns true if the class's status has changed. 826 bool MetaspaceShared::try_link_class(JavaThread* current, InstanceKlass* ik) { 827 ExceptionMark em(current); 828 JavaThread* THREAD = current; // For exception macros. 829 assert(CDSConfig::is_dumping_archive(), "sanity"); 830 if (!ik->is_shared() && ik->is_loaded() && !ik->is_linked() && ik->can_be_verified_at_dumptime() && 831 !SystemDictionaryShared::has_class_failed_verification(ik)) { 832 bool saved = BytecodeVerificationLocal; 833 if (ik->is_shared_unregistered_class() && ik->class_loader() == nullptr) { 834 // The verification decision is based on BytecodeVerificationRemote 835 // for non-system classes. Since we are using the null classloader 836 // to load non-system classes for customized class loaders during dumping, 837 // we need to temporarily change BytecodeVerificationLocal to be the same as 838 // BytecodeVerificationRemote. Note this can cause the parent system 839 // classes also being verified. The extra overhead is acceptable during 840 // dumping. 841 BytecodeVerificationLocal = BytecodeVerificationRemote; 842 } 843 ik->link_class(THREAD); 844 if (HAS_PENDING_EXCEPTION) { 845 ResourceMark rm(THREAD); 846 log_warning(cds)("Preload Warning: Verification failed for %s", 847 ik->external_name()); 848 CLEAR_PENDING_EXCEPTION; 849 SystemDictionaryShared::set_class_has_failed_verification(ik); 850 } 851 ik->compute_has_loops_flag_for_methods(); 852 BytecodeVerificationLocal = saved; 853 return true; 854 } else { 855 return false; 856 } 857 } 858 859 #if INCLUDE_CDS_JAVA_HEAP 860 void VM_PopulateDumpSharedSpace::dump_java_heap_objects(GrowableArray<Klass*>* klasses) { 861 if (CDSConfig::is_valhalla_preview()) { 862 log_info(cds)("Archived java heap is not yet supported with Valhalla preview"); 863 return; 864 } 865 if(!HeapShared::can_write()) { 866 log_info(cds)( 867 "Archived java heap is not supported as UseG1GC " 868 "and UseCompressedClassPointers are required." 869 "Current settings: UseG1GC=%s, UseCompressedClassPointers=%s.", 870 BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedClassPointers)); 871 return; 872 } 873 // Find all the interned strings that should be dumped. 874 int i; 875 for (i = 0; i < klasses->length(); i++) { 876 Klass* k = klasses->at(i); 877 if (k->is_instance_klass()) { 878 InstanceKlass* ik = InstanceKlass::cast(k); 879 if (ik->is_linked()) { 880 ik->constants()->add_dumped_interned_strings(); 881 } 882 } 883 } 884 if (_extra_interned_strings != nullptr) { 885 for (i = 0; i < _extra_interned_strings->length(); i ++) { 886 OopHandle string = _extra_interned_strings->at(i); 887 HeapShared::add_to_dumped_interned_strings(string.resolve()); 888 } 889 } 890 891 HeapShared::archive_objects(&_heap_info); 892 ArchiveBuilder::OtherROAllocMark mark; 893 HeapShared::write_subgraph_info_table(); 894 } 895 #endif // INCLUDE_CDS_JAVA_HEAP 896 897 void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) { 898 assert(base <= static_top && static_top <= top, "must be"); 899 _shared_metaspace_static_top = static_top; 900 MetaspaceObj::set_shared_metaspace_range(base, top); 901 } 902 903 bool MetaspaceShared::is_shared_dynamic(void* p) { 904 if ((p < MetaspaceObj::shared_metaspace_top()) && 905 (p >= _shared_metaspace_static_top)) { 906 return true; 907 } else { 908 return false; 909 } 910 } 911 912 bool MetaspaceShared::is_shared_static(void* p) { 913 if (is_in_shared_metaspace(p) && !is_shared_dynamic(p)) { 914 return true; 915 } else { 916 return false; 917 } 918 } 919 920 // This function is called when the JVM is unable to load the specified archive(s) due to one 921 // of the following conditions. 922 // - There's an error that indicates that the archive(s) files were corrupt or otherwise damaged. 923 // - When -XX:+RequireSharedSpaces is specified, AND the JVM cannot load the archive(s) due 924 // to version or classpath mismatch. 925 void MetaspaceShared::unrecoverable_loading_error(const char* message) { 926 log_error(cds)("An error has occurred while processing the shared archive file."); 927 if (message != nullptr) { 928 log_error(cds)("%s", message); 929 } 930 vm_exit_during_initialization("Unable to use shared archive.", nullptr); 931 } 932 933 // This function is called when the JVM is unable to write the specified CDS archive due to an 934 // unrecoverable error. 935 void MetaspaceShared::unrecoverable_writing_error(const char* message) { 936 writing_error(message); 937 vm_direct_exit(1); 938 } 939 940 // This function is called when the JVM is unable to write the specified CDS archive due to a 941 // an error. The error will be propagated 942 void MetaspaceShared::writing_error(const char* message) { 943 log_error(cds)("An error has occurred while writing the shared archive file."); 944 if (message != nullptr) { 945 log_error(cds)("%s", message); 946 } 947 } 948 949 void MetaspaceShared::initialize_runtime_shared_and_meta_spaces() { 950 assert(CDSConfig::is_using_archive(), "Must be called when UseSharedSpaces is enabled"); 951 MapArchiveResult result = MAP_ARCHIVE_OTHER_FAILURE; 952 953 FileMapInfo* static_mapinfo = open_static_archive(); 954 FileMapInfo* dynamic_mapinfo = nullptr; 955 956 if (static_mapinfo != nullptr) { 957 log_info(cds)("Core region alignment: " SIZE_FORMAT, static_mapinfo->core_region_alignment()); 958 dynamic_mapinfo = open_dynamic_archive(); 959 960 // First try to map at the requested address 961 result = map_archives(static_mapinfo, dynamic_mapinfo, true); 962 if (result == MAP_ARCHIVE_MMAP_FAILURE) { 963 // Mapping has failed (probably due to ASLR). Let's map at an address chosen 964 // by the OS. 965 log_info(cds)("Try to map archive(s) at an alternative address"); 966 result = map_archives(static_mapinfo, dynamic_mapinfo, false); 967 } 968 } 969 970 if (result == MAP_ARCHIVE_SUCCESS) { 971 bool dynamic_mapped = (dynamic_mapinfo != nullptr && dynamic_mapinfo->is_mapped()); 972 char* cds_base = static_mapinfo->mapped_base(); 973 char* cds_end = dynamic_mapped ? dynamic_mapinfo->mapped_end() : static_mapinfo->mapped_end(); 974 // Register CDS memory region with LSan. 975 LSAN_REGISTER_ROOT_REGION(cds_base, cds_end - cds_base); 976 set_shared_metaspace_range(cds_base, static_mapinfo->mapped_end(), cds_end); 977 _relocation_delta = static_mapinfo->relocation_delta(); 978 _requested_base_address = static_mapinfo->requested_base_address(); 979 if (dynamic_mapped) { 980 FileMapInfo::set_shared_path_table(dynamic_mapinfo); 981 // turn AutoCreateSharedArchive off if successfully mapped 982 AutoCreateSharedArchive = false; 983 } else { 984 FileMapInfo::set_shared_path_table(static_mapinfo); 985 } 986 } else { 987 set_shared_metaspace_range(nullptr, nullptr, nullptr); 988 if (CDSConfig::is_dumping_dynamic_archive()) { 989 log_warning(cds)("-XX:ArchiveClassesAtExit is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info."); 990 } 991 UseSharedSpaces = false; 992 // The base archive cannot be mapped. We cannot dump the dynamic shared archive. 993 AutoCreateSharedArchive = false; 994 CDSConfig::disable_dumping_dynamic_archive(); 995 log_info(cds)("Unable to map shared spaces"); 996 if (PrintSharedArchiveAndExit) { 997 MetaspaceShared::unrecoverable_loading_error("Unable to use shared archive."); 998 } else if (RequireSharedSpaces) { 999 MetaspaceShared::unrecoverable_loading_error("Unable to map shared spaces"); 1000 } 1001 } 1002 1003 // If mapping failed and -XShare:on, the vm should exit 1004 bool has_failed = false; 1005 if (static_mapinfo != nullptr && !static_mapinfo->is_mapped()) { 1006 has_failed = true; 1007 delete static_mapinfo; 1008 } 1009 if (dynamic_mapinfo != nullptr && !dynamic_mapinfo->is_mapped()) { 1010 has_failed = true; 1011 delete dynamic_mapinfo; 1012 } 1013 if (RequireSharedSpaces && has_failed) { 1014 MetaspaceShared::unrecoverable_loading_error("Unable to map shared spaces"); 1015 } 1016 } 1017 1018 FileMapInfo* MetaspaceShared::open_static_archive() { 1019 const char* static_archive = CDSConfig::static_archive_path(); 1020 assert(static_archive != nullptr, "sanity"); 1021 FileMapInfo* mapinfo = new FileMapInfo(static_archive, true); 1022 if (!mapinfo->initialize()) { 1023 delete(mapinfo); 1024 return nullptr; 1025 } 1026 return mapinfo; 1027 } 1028 1029 FileMapInfo* MetaspaceShared::open_dynamic_archive() { 1030 if (CDSConfig::is_dumping_dynamic_archive()) { 1031 return nullptr; 1032 } 1033 const char* dynamic_archive = CDSConfig::dynamic_archive_path(); 1034 if (dynamic_archive == nullptr) { 1035 return nullptr; 1036 } 1037 1038 FileMapInfo* mapinfo = new FileMapInfo(dynamic_archive, false); 1039 if (!mapinfo->initialize()) { 1040 delete(mapinfo); 1041 if (RequireSharedSpaces) { 1042 MetaspaceShared::unrecoverable_loading_error("Failed to initialize dynamic archive"); 1043 } 1044 return nullptr; 1045 } 1046 return mapinfo; 1047 } 1048 1049 // use_requested_addr: 1050 // true = map at FileMapHeader::_requested_base_address 1051 // false = map at an alternative address picked by OS. 1052 MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo, 1053 bool use_requested_addr) { 1054 if (use_requested_addr && static_mapinfo->requested_base_address() == nullptr) { 1055 log_info(cds)("Archive(s) were created with -XX:SharedBaseAddress=0. Always map at os-selected address."); 1056 return MAP_ARCHIVE_MMAP_FAILURE; 1057 } 1058 1059 PRODUCT_ONLY(if (ArchiveRelocationMode == 1 && use_requested_addr) { 1060 // For product build only -- this is for benchmarking the cost of doing relocation. 1061 // For debug builds, the check is done below, after reserving the space, for better test coverage 1062 // (see comment below). 1063 log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address"); 1064 return MAP_ARCHIVE_MMAP_FAILURE; 1065 }); 1066 1067 if (ArchiveRelocationMode == 2 && !use_requested_addr) { 1068 log_info(cds)("ArchiveRelocationMode == 2: never map archive(s) at an alternative address"); 1069 return MAP_ARCHIVE_MMAP_FAILURE; 1070 }; 1071 1072 if (dynamic_mapinfo != nullptr) { 1073 // Ensure that the OS won't be able to allocate new memory spaces between the two 1074 // archives, or else it would mess up the simple comparison in MetaspaceObj::is_shared(). 1075 assert(static_mapinfo->mapping_end_offset() == dynamic_mapinfo->mapping_base_offset(), "no gap"); 1076 } 1077 1078 ReservedSpace total_space_rs, archive_space_rs, class_space_rs; 1079 MapArchiveResult result = MAP_ARCHIVE_OTHER_FAILURE; 1080 char* mapped_base_address = reserve_address_space_for_archives(static_mapinfo, 1081 dynamic_mapinfo, 1082 use_requested_addr, 1083 total_space_rs, 1084 archive_space_rs, 1085 class_space_rs); 1086 if (mapped_base_address == nullptr) { 1087 result = MAP_ARCHIVE_MMAP_FAILURE; 1088 log_debug(cds)("Failed to reserve spaces (use_requested_addr=%u)", (unsigned)use_requested_addr); 1089 } else { 1090 1091 #ifdef ASSERT 1092 // Some sanity checks after reserving address spaces for archives 1093 // and class space. 1094 assert(archive_space_rs.is_reserved(), "Sanity"); 1095 if (Metaspace::using_class_space()) { 1096 // Class space must closely follow the archive space. Both spaces 1097 // must be aligned correctly. 1098 assert(class_space_rs.is_reserved(), 1099 "A class space should have been reserved"); 1100 assert(class_space_rs.base() >= archive_space_rs.end(), 1101 "class space should follow the cds archive space"); 1102 assert(is_aligned(archive_space_rs.base(), 1103 core_region_alignment()), 1104 "Archive space misaligned"); 1105 assert(is_aligned(class_space_rs.base(), 1106 Metaspace::reserve_alignment()), 1107 "class space misaligned"); 1108 } 1109 #endif // ASSERT 1110 1111 log_info(cds)("Reserved archive_space_rs [" INTPTR_FORMAT " - " INTPTR_FORMAT "] (" SIZE_FORMAT ") bytes", 1112 p2i(archive_space_rs.base()), p2i(archive_space_rs.end()), archive_space_rs.size()); 1113 log_info(cds)("Reserved class_space_rs [" INTPTR_FORMAT " - " INTPTR_FORMAT "] (" SIZE_FORMAT ") bytes", 1114 p2i(class_space_rs.base()), p2i(class_space_rs.end()), class_space_rs.size()); 1115 1116 if (MetaspaceShared::use_windows_memory_mapping()) { 1117 // We have now reserved address space for the archives, and will map in 1118 // the archive files into this space. 1119 // 1120 // Special handling for Windows: on Windows we cannot map a file view 1121 // into an existing memory mapping. So, we unmap the address range we 1122 // just reserved again, which will make it available for mapping the 1123 // archives. 1124 // Reserving this range has not been for naught however since it makes 1125 // us reasonably sure the address range is available. 1126 // 1127 // But still it may fail, since between unmapping the range and mapping 1128 // in the archive someone else may grab the address space. Therefore 1129 // there is a fallback in FileMap::map_region() where we just read in 1130 // the archive files sequentially instead of mapping it in. We couple 1131 // this with use_requested_addr, since we're going to patch all the 1132 // pointers anyway so there's no benefit to mmap. 1133 if (use_requested_addr) { 1134 assert(!total_space_rs.is_reserved(), "Should not be reserved for Windows"); 1135 log_info(cds)("Windows mmap workaround: releasing archive space."); 1136 archive_space_rs.release(); 1137 } 1138 } 1139 MapArchiveResult static_result = map_archive(static_mapinfo, mapped_base_address, archive_space_rs); 1140 MapArchiveResult dynamic_result = (static_result == MAP_ARCHIVE_SUCCESS) ? 1141 map_archive(dynamic_mapinfo, mapped_base_address, archive_space_rs) : MAP_ARCHIVE_OTHER_FAILURE; 1142 1143 DEBUG_ONLY(if (ArchiveRelocationMode == 1 && use_requested_addr) { 1144 // This is for simulating mmap failures at the requested address. In 1145 // debug builds, we do it here (after all archives have possibly been 1146 // mapped), so we can thoroughly test the code for failure handling 1147 // (releasing all allocated resource, etc). 1148 log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address"); 1149 if (static_result == MAP_ARCHIVE_SUCCESS) { 1150 static_result = MAP_ARCHIVE_MMAP_FAILURE; 1151 } 1152 if (dynamic_result == MAP_ARCHIVE_SUCCESS) { 1153 dynamic_result = MAP_ARCHIVE_MMAP_FAILURE; 1154 } 1155 }); 1156 1157 if (static_result == MAP_ARCHIVE_SUCCESS) { 1158 if (dynamic_result == MAP_ARCHIVE_SUCCESS) { 1159 result = MAP_ARCHIVE_SUCCESS; 1160 } else if (dynamic_result == MAP_ARCHIVE_OTHER_FAILURE) { 1161 assert(dynamic_mapinfo != nullptr && !dynamic_mapinfo->is_mapped(), "must have failed"); 1162 // No need to retry mapping the dynamic archive again, as it will never succeed 1163 // (bad file, etc) -- just keep the base archive. 1164 log_warning(cds, dynamic)("Unable to use shared archive. The top archive failed to load: %s", 1165 dynamic_mapinfo->full_path()); 1166 result = MAP_ARCHIVE_SUCCESS; 1167 // TODO, we can give the unused space for the dynamic archive to class_space_rs, but there's no 1168 // easy API to do that right now. 1169 } else { 1170 result = MAP_ARCHIVE_MMAP_FAILURE; 1171 } 1172 } else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) { 1173 result = MAP_ARCHIVE_OTHER_FAILURE; 1174 } else { 1175 result = MAP_ARCHIVE_MMAP_FAILURE; 1176 } 1177 } 1178 1179 if (result == MAP_ARCHIVE_SUCCESS) { 1180 SharedBaseAddress = (size_t)mapped_base_address; 1181 #ifdef _LP64 1182 if (Metaspace::using_class_space()) { 1183 // Set up ccs in metaspace. 1184 Metaspace::initialize_class_space(class_space_rs); 1185 1186 // Set up compressed Klass pointer encoding: the encoding range must 1187 // cover both archive and class space. 1188 address cds_base = (address)static_mapinfo->mapped_base(); 1189 address ccs_end = (address)class_space_rs.end(); 1190 assert(ccs_end > cds_base, "Sanity check"); 1191 #if INCLUDE_CDS_JAVA_HEAP 1192 // We archived objects with pre-computed narrow Klass id. Set up encoding such that these Ids stay valid. 1193 address precomputed_narrow_klass_base = cds_base; 1194 const int precomputed_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift; 1195 CompressedKlassPointers::initialize_for_given_encoding( 1196 cds_base, ccs_end - cds_base, // Klass range 1197 precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveHeapWriter 1198 ); 1199 #else 1200 CompressedKlassPointers::initialize ( 1201 cds_base, ccs_end - cds_base // Klass range 1202 ); 1203 #endif // INCLUDE_CDS_JAVA_HEAP 1204 // map_or_load_heap_region() compares the current narrow oop and klass encodings 1205 // with the archived ones, so it must be done after all encodings are determined. 1206 static_mapinfo->map_or_load_heap_region(); 1207 } 1208 #endif // _LP64 1209 log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled"); 1210 log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled"); 1211 } else { 1212 unmap_archive(static_mapinfo); 1213 unmap_archive(dynamic_mapinfo); 1214 release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs); 1215 } 1216 1217 return result; 1218 } 1219 1220 1221 // This will reserve two address spaces suitable to house Klass structures, one 1222 // for the cds archives (static archive and optionally dynamic archive) and 1223 // optionally one move for ccs. 1224 // 1225 // Since both spaces must fall within the compressed class pointer encoding 1226 // range, they are allocated close to each other. 1227 // 1228 // Space for archives will be reserved first, followed by a potential gap, 1229 // followed by the space for ccs: 1230 // 1231 // +-- Base address A B End 1232 // | | | | 1233 // v v v v 1234 // +-------------+--------------+ +----------------------+ 1235 // | static arc | [dyn. arch] | [gap] | compr. class space | 1236 // +-------------+--------------+ +----------------------+ 1237 // 1238 // (The gap may result from different alignment requirements between metaspace 1239 // and CDS) 1240 // 1241 // If UseCompressedClassPointers is disabled, only one address space will be 1242 // reserved: 1243 // 1244 // +-- Base address End 1245 // | | 1246 // v v 1247 // +-------------+--------------+ 1248 // | static arc | [dyn. arch] | 1249 // +-------------+--------------+ 1250 // 1251 // Base address: If use_archive_base_addr address is true, the Base address is 1252 // determined by the address stored in the static archive. If 1253 // use_archive_base_addr address is false, this base address is determined 1254 // by the platform. 1255 // 1256 // If UseCompressedClassPointers=1, the range encompassing both spaces will be 1257 // suitable to en/decode narrow Klass pointers: the base will be valid for 1258 // encoding, the range [Base, End) not surpass KlassEncodingMetaspaceMax. 1259 // 1260 // Return: 1261 // 1262 // - On success: 1263 // - total_space_rs will be reserved as whole for archive_space_rs and 1264 // class_space_rs if UseCompressedClassPointers is true. 1265 // On Windows, try reserve archive_space_rs and class_space_rs 1266 // separately first if use_archive_base_addr is true. 1267 // - archive_space_rs will be reserved and large enough to host static and 1268 // if needed dynamic archive: [Base, A). 1269 // archive_space_rs.base and size will be aligned to CDS reserve 1270 // granularity. 1271 // - class_space_rs: If UseCompressedClassPointers=1, class_space_rs will 1272 // be reserved. Its start address will be aligned to metaspace reserve 1273 // alignment, which may differ from CDS alignment. It will follow the cds 1274 // archive space, close enough such that narrow class pointer encoding 1275 // covers both spaces. 1276 // If UseCompressedClassPointers=0, class_space_rs remains unreserved. 1277 // - On error: null is returned and the spaces remain unreserved. 1278 char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_mapinfo, 1279 FileMapInfo* dynamic_mapinfo, 1280 bool use_archive_base_addr, 1281 ReservedSpace& total_space_rs, 1282 ReservedSpace& archive_space_rs, 1283 ReservedSpace& class_space_rs) { 1284 1285 address const base_address = (address) (use_archive_base_addr ? static_mapinfo->requested_base_address() : nullptr); 1286 const size_t archive_space_alignment = core_region_alignment(); 1287 1288 // Size and requested location of the archive_space_rs (for both static and dynamic archives) 1289 assert(static_mapinfo->mapping_base_offset() == 0, "Must be"); 1290 size_t archive_end_offset = (dynamic_mapinfo == nullptr) ? static_mapinfo->mapping_end_offset() : dynamic_mapinfo->mapping_end_offset(); 1291 size_t archive_space_size = align_up(archive_end_offset, archive_space_alignment); 1292 1293 if (!Metaspace::using_class_space()) { 1294 // Get the simple case out of the way first: 1295 // no compressed class space, simple allocation. 1296 1297 // When running without class space, requested archive base should be aligned to cds core alignment. 1298 assert(is_aligned(base_address, archive_space_alignment), 1299 "Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.", 1300 p2i(base_address), archive_space_alignment); 1301 1302 archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment, 1303 os::vm_page_size(), (char*)base_address); 1304 if (archive_space_rs.is_reserved()) { 1305 assert(base_address == nullptr || 1306 (address)archive_space_rs.base() == base_address, "Sanity"); 1307 // Register archive space with NMT. 1308 MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared); 1309 return archive_space_rs.base(); 1310 } 1311 return nullptr; 1312 } 1313 1314 #ifdef _LP64 1315 1316 // Complex case: two spaces adjacent to each other, both to be addressable 1317 // with narrow class pointers. 1318 // We reserve the whole range spanning both spaces, then split that range up. 1319 1320 const size_t class_space_alignment = Metaspace::reserve_alignment(); 1321 1322 // When running with class space, requested archive base must satisfy both cds core alignment 1323 // and class space alignment. 1324 const size_t base_address_alignment = MAX2(class_space_alignment, archive_space_alignment); 1325 assert(is_aligned(base_address, base_address_alignment), 1326 "Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.", 1327 p2i(base_address), base_address_alignment); 1328 1329 size_t class_space_size = CompressedClassSpaceSize; 1330 assert(CompressedClassSpaceSize > 0 && 1331 is_aligned(CompressedClassSpaceSize, class_space_alignment), 1332 "CompressedClassSpaceSize malformed: " 1333 SIZE_FORMAT, CompressedClassSpaceSize); 1334 1335 const size_t ccs_begin_offset = align_up(archive_space_size, class_space_alignment); 1336 const size_t gap_size = ccs_begin_offset - archive_space_size; 1337 1338 // Reduce class space size if it would not fit into the Klass encoding range 1339 constexpr size_t max_encoding_range_size = 4 * G; 1340 guarantee(archive_space_size < max_encoding_range_size - class_space_alignment, "Archive too large"); 1341 if ((archive_space_size + gap_size + class_space_size) > max_encoding_range_size) { 1342 class_space_size = align_down(max_encoding_range_size - archive_space_size - gap_size, class_space_alignment); 1343 log_info(metaspace)("CDS initialization: reducing class space size from " SIZE_FORMAT " to " SIZE_FORMAT, 1344 CompressedClassSpaceSize, class_space_size); 1345 FLAG_SET_ERGO(CompressedClassSpaceSize, class_space_size); 1346 } 1347 1348 const size_t total_range_size = 1349 archive_space_size + gap_size + class_space_size; 1350 1351 assert(total_range_size > ccs_begin_offset, "must be"); 1352 if (use_windows_memory_mapping() && use_archive_base_addr) { 1353 if (base_address != nullptr) { 1354 // On Windows, we cannot safely split a reserved memory space into two (see JDK-8255917). 1355 // Hence, we optimistically reserve archive space and class space side-by-side. We only 1356 // do this for use_archive_base_addr=true since for use_archive_base_addr=false case 1357 // caller will not split the combined space for mapping, instead read the archive data 1358 // via sequential file IO. 1359 address ccs_base = base_address + archive_space_size + gap_size; 1360 archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment, 1361 os::vm_page_size(), (char*)base_address); 1362 class_space_rs = ReservedSpace(class_space_size, class_space_alignment, 1363 os::vm_page_size(), (char*)ccs_base); 1364 } 1365 if (!archive_space_rs.is_reserved() || !class_space_rs.is_reserved()) { 1366 release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs); 1367 return nullptr; 1368 } 1369 // NMT: fix up the space tags 1370 MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared); 1371 MemTracker::record_virtual_memory_type(class_space_rs.base(), mtClass); 1372 } else { 1373 if (use_archive_base_addr && base_address != nullptr) { 1374 total_space_rs = ReservedSpace(total_range_size, base_address_alignment, 1375 os::vm_page_size(), (char*) base_address); 1376 } else { 1377 // We did not manage to reserve at the preferred address, or were instructed to relocate. In that 1378 // case we reserve wherever possible, but the start address needs to be encodable as narrow Klass 1379 // encoding base since the archived heap objects contain nKlass IDs pre-calculated toward the start 1380 // of the shared Metaspace. That prevents us from using zero-based encoding and therefore we won't 1381 // try allocating in low-address regions. 1382 total_space_rs = Metaspace::reserve_address_space_for_compressed_classes(total_range_size, false /* optimize_for_zero_base */); 1383 } 1384 1385 if (!total_space_rs.is_reserved()) { 1386 return nullptr; 1387 } 1388 1389 // Paranoid checks: 1390 assert(base_address == nullptr || (address)total_space_rs.base() == base_address, 1391 "Sanity (" PTR_FORMAT " vs " PTR_FORMAT ")", p2i(base_address), p2i(total_space_rs.base())); 1392 assert(is_aligned(total_space_rs.base(), base_address_alignment), "Sanity"); 1393 assert(total_space_rs.size() == total_range_size, "Sanity"); 1394 1395 // Now split up the space into ccs and cds archive. For simplicity, just leave 1396 // the gap reserved at the end of the archive space. Do not do real splitting. 1397 archive_space_rs = total_space_rs.first_part(ccs_begin_offset, 1398 (size_t)archive_space_alignment); 1399 class_space_rs = total_space_rs.last_part(ccs_begin_offset); 1400 MemTracker::record_virtual_memory_split_reserved(total_space_rs.base(), total_space_rs.size(), 1401 ccs_begin_offset, mtClassShared, mtClass); 1402 } 1403 assert(is_aligned(archive_space_rs.base(), archive_space_alignment), "Sanity"); 1404 assert(is_aligned(archive_space_rs.size(), archive_space_alignment), "Sanity"); 1405 assert(is_aligned(class_space_rs.base(), class_space_alignment), "Sanity"); 1406 assert(is_aligned(class_space_rs.size(), class_space_alignment), "Sanity"); 1407 1408 1409 return archive_space_rs.base(); 1410 1411 #else 1412 ShouldNotReachHere(); 1413 return nullptr; 1414 #endif 1415 1416 } 1417 1418 void MetaspaceShared::release_reserved_spaces(ReservedSpace& total_space_rs, 1419 ReservedSpace& archive_space_rs, 1420 ReservedSpace& class_space_rs) { 1421 if (total_space_rs.is_reserved()) { 1422 log_debug(cds)("Released shared space (archive + class) " INTPTR_FORMAT, p2i(total_space_rs.base())); 1423 total_space_rs.release(); 1424 } else { 1425 if (archive_space_rs.is_reserved()) { 1426 log_debug(cds)("Released shared space (archive) " INTPTR_FORMAT, p2i(archive_space_rs.base())); 1427 archive_space_rs.release(); 1428 } 1429 if (class_space_rs.is_reserved()) { 1430 log_debug(cds)("Released shared space (classes) " INTPTR_FORMAT, p2i(class_space_rs.base())); 1431 class_space_rs.release(); 1432 } 1433 } 1434 } 1435 1436 static int archive_regions[] = { MetaspaceShared::rw, MetaspaceShared::ro }; 1437 static int archive_regions_count = 2; 1438 1439 MapArchiveResult MetaspaceShared::map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs) { 1440 assert(CDSConfig::is_using_archive(), "must be runtime"); 1441 if (mapinfo == nullptr) { 1442 return MAP_ARCHIVE_SUCCESS; // The dynamic archive has not been specified. No error has happened -- trivially succeeded. 1443 } 1444 1445 mapinfo->set_is_mapped(false); 1446 if (mapinfo->core_region_alignment() != (size_t)core_region_alignment()) { 1447 log_info(cds)("Unable to map CDS archive -- core_region_alignment() expected: " SIZE_FORMAT 1448 " actual: " SIZE_FORMAT, mapinfo->core_region_alignment(), core_region_alignment()); 1449 return MAP_ARCHIVE_OTHER_FAILURE; 1450 } 1451 1452 MapArchiveResult result = 1453 mapinfo->map_regions(archive_regions, archive_regions_count, mapped_base_address, rs); 1454 1455 if (result != MAP_ARCHIVE_SUCCESS) { 1456 unmap_archive(mapinfo); 1457 return result; 1458 } 1459 1460 if (!mapinfo->validate_shared_path_table()) { 1461 unmap_archive(mapinfo); 1462 return MAP_ARCHIVE_OTHER_FAILURE; 1463 } 1464 1465 mapinfo->set_is_mapped(true); 1466 return MAP_ARCHIVE_SUCCESS; 1467 } 1468 1469 void MetaspaceShared::unmap_archive(FileMapInfo* mapinfo) { 1470 assert(CDSConfig::is_using_archive(), "must be runtime"); 1471 if (mapinfo != nullptr) { 1472 mapinfo->unmap_regions(archive_regions, archive_regions_count); 1473 mapinfo->unmap_region(MetaspaceShared::bm); 1474 mapinfo->set_is_mapped(false); 1475 } 1476 } 1477 1478 // For -XX:PrintSharedArchiveAndExit 1479 class CountSharedSymbols : public SymbolClosure { 1480 private: 1481 int _count; 1482 public: 1483 CountSharedSymbols() : _count(0) {} 1484 void do_symbol(Symbol** sym) { 1485 _count++; 1486 } 1487 int total() { return _count; } 1488 1489 }; 1490 1491 // Read the miscellaneous data from the shared file, and 1492 // serialize it out to its various destinations. 1493 1494 void MetaspaceShared::initialize_shared_spaces() { 1495 FileMapInfo *static_mapinfo = FileMapInfo::current_info(); 1496 1497 // Verify various attributes of the archive, plus initialize the 1498 // shared string/symbol tables. 1499 char* buffer = static_mapinfo->serialized_data(); 1500 intptr_t* array = (intptr_t*)buffer; 1501 ReadClosure rc(&array); 1502 serialize(&rc); 1503 1504 // Finish up archived heap initialization. These must be 1505 // done after ReadClosure. 1506 static_mapinfo->patch_heap_embedded_pointers(); 1507 ArchiveHeapLoader::finish_initialization(); 1508 Universe::load_archived_object_instances(); 1509 1510 // Close the mapinfo file 1511 static_mapinfo->close(); 1512 1513 static_mapinfo->unmap_region(MetaspaceShared::bm); 1514 1515 FileMapInfo *dynamic_mapinfo = FileMapInfo::dynamic_info(); 1516 if (dynamic_mapinfo != nullptr) { 1517 intptr_t* buffer = (intptr_t*)dynamic_mapinfo->serialized_data(); 1518 ReadClosure rc(&buffer); 1519 ArchiveBuilder::serialize_dynamic_archivable_items(&rc); 1520 DynamicArchive::setup_array_klasses(); 1521 dynamic_mapinfo->close(); 1522 dynamic_mapinfo->unmap_region(MetaspaceShared::bm); 1523 } 1524 1525 // Set up LambdaFormInvokers::_lambdaform_lines for dynamic dump 1526 if (CDSConfig::is_dumping_dynamic_archive()) { 1527 // Read stored LF format lines stored in static archive 1528 LambdaFormInvokers::read_static_archive_invokers(); 1529 } 1530 1531 if (PrintSharedArchiveAndExit) { 1532 // Print archive names 1533 if (dynamic_mapinfo != nullptr) { 1534 tty->print_cr("\n\nBase archive name: %s", CDSConfig::static_archive_path()); 1535 tty->print_cr("Base archive version %d", static_mapinfo->version()); 1536 } else { 1537 tty->print_cr("Static archive name: %s", static_mapinfo->full_path()); 1538 tty->print_cr("Static archive version %d", static_mapinfo->version()); 1539 } 1540 1541 SystemDictionaryShared::print_shared_archive(tty); 1542 if (dynamic_mapinfo != nullptr) { 1543 tty->print_cr("\n\nDynamic archive name: %s", dynamic_mapinfo->full_path()); 1544 tty->print_cr("Dynamic archive version %d", dynamic_mapinfo->version()); 1545 SystemDictionaryShared::print_shared_archive(tty, false/*dynamic*/); 1546 } 1547 1548 // collect shared symbols and strings 1549 CountSharedSymbols cl; 1550 SymbolTable::shared_symbols_do(&cl); 1551 tty->print_cr("Number of shared symbols: %d", cl.total()); 1552 tty->print_cr("Number of shared strings: %zu", StringTable::shared_entry_count()); 1553 tty->print_cr("VM version: %s\r\n", static_mapinfo->vm_version()); 1554 if (FileMapInfo::current_info() == nullptr || _archive_loading_failed) { 1555 tty->print_cr("archive is invalid"); 1556 vm_exit(1); 1557 } else { 1558 tty->print_cr("archive is valid"); 1559 vm_exit(0); 1560 } 1561 } 1562 } 1563 1564 // JVM/TI RedefineClasses() support: 1565 bool MetaspaceShared::remap_shared_readonly_as_readwrite() { 1566 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1567 1568 if (CDSConfig::is_using_archive()) { 1569 // remap the shared readonly space to shared readwrite, private 1570 FileMapInfo* mapinfo = FileMapInfo::current_info(); 1571 if (!mapinfo->remap_shared_readonly_as_readwrite()) { 1572 return false; 1573 } 1574 if (FileMapInfo::dynamic_info() != nullptr) { 1575 mapinfo = FileMapInfo::dynamic_info(); 1576 if (!mapinfo->remap_shared_readonly_as_readwrite()) { 1577 return false; 1578 } 1579 } 1580 _remapped_readwrite = true; 1581 } 1582 return true; 1583 } 1584 1585 void MetaspaceShared::print_on(outputStream* st) { 1586 if (CDSConfig::is_using_archive()) { 1587 st->print("CDS archive(s) mapped at: "); 1588 address base = (address)MetaspaceObj::shared_metaspace_base(); 1589 address static_top = (address)_shared_metaspace_static_top; 1590 address top = (address)MetaspaceObj::shared_metaspace_top(); 1591 st->print("[" PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(static_top), p2i(top)); 1592 st->print("size " SIZE_FORMAT ", ", top - base); 1593 st->print("SharedBaseAddress: " PTR_FORMAT ", ArchiveRelocationMode: %d.", SharedBaseAddress, ArchiveRelocationMode); 1594 } else { 1595 st->print("CDS archive(s) not mapped"); 1596 } 1597 st->cr(); 1598 }