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"
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/instanceMirrorKlass.hpp"
71
#include "oops/klass.inline.hpp"
72
#include "oops/objArrayOop.hpp"
73
#include "oops/oop.inline.hpp"
74
#include "oops/oopHandle.hpp"
75
#include "prims/jvmtiExport.hpp"
76
#include "runtime/arguments.hpp"
77
#include "runtime/globals.hpp"
78
#include "runtime/globals_extension.hpp"
79
#include "runtime/handles.inline.hpp"
80
#include "runtime/os.inline.hpp"
81
#include "runtime/safepointVerifiers.hpp"
82
#include "runtime/sharedRuntime.hpp"
83
#include "runtime/vmOperations.hpp"
84
#include "runtime/vmThread.hpp"
85
#include "sanitizers/leak.hpp"
86
#include "utilities/align.hpp"
87
#include "utilities/bitMap.inline.hpp"
88
#include "utilities/defaultStream.hpp"
89
#include "utilities/ostream.hpp"
90
#include "utilities/resourceHash.hpp"
92
ReservedSpace MetaspaceShared::_symbol_rs;
93
VirtualSpace MetaspaceShared::_symbol_vs;
94
bool MetaspaceShared::_archive_loading_failed = false;
95
bool MetaspaceShared::_remapped_readwrite = false;
96
void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
97
intx MetaspaceShared::_relocation_delta;
98
char* MetaspaceShared::_requested_base_address;
99
bool MetaspaceShared::_use_optimized_module_handling = true;
124
static DumpRegion _symbol_region("symbols");
126
char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) {
127
return _symbol_region.allocate(num_bytes);
139
size_t MetaspaceShared::core_region_alignment() {
140
return os::cds_core_region_alignment();
143
static bool shared_base_valid(char* shared_base) {
153
return AARCH64_ONLY(is_aligned(shared_base, 4 * G)) NOT_AARCH64(true);
156
class DumpClassListCLDClosure : public CLDClosure {
157
static const int INITIAL_TABLE_SIZE = 1987;
158
static const int MAX_TABLE_SIZE = 61333;
161
ResizeableResourceHashtable<InstanceKlass*, bool,
162
AnyObj::C_HEAP, mtClassShared> _dumped_classes;
164
void dump(InstanceKlass* ik) {
166
_dumped_classes.put_if_absent(ik, &created);
170
if (_dumped_classes.maybe_grow()) {
171
log_info(cds, hashtables)("Expanded _dumped_classes table to %d", _dumped_classes.table_size());
173
if (ik->java_super()) {
174
dump(ik->java_super());
176
Array<InstanceKlass*>* interfaces = ik->local_interfaces();
177
int len = interfaces->length();
178
for (int i = 0; i < len; i++) {
179
dump(interfaces->at(i));
181
ClassListWriter::write_to_stream(ik, _stream);
185
DumpClassListCLDClosure(fileStream* f)
186
: CLDClosure(), _dumped_classes(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE) {
190
void do_cld(ClassLoaderData* cld) {
191
for (Klass* klass = cld->klasses(); klass != nullptr; klass = klass->next_link()) {
192
if (klass->is_instance_klass()) {
193
dump(InstanceKlass::cast(klass));
199
void MetaspaceShared::dump_loaded_classes(const char* file_name, TRAPS) {
200
fileStream stream(file_name, "w");
201
if (stream.is_open()) {
202
MutexLocker lock(ClassLoaderDataGraph_lock);
203
MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag);
204
DumpClassListCLDClosure collect_classes(&stream);
205
ClassLoaderDataGraph::loaded_cld_do(&collect_classes);
207
THROW_MSG(vmSymbols::java_io_IOException(), "Failed to open file");
211
static bool shared_base_too_high(char* specified_base, char* aligned_base, size_t cds_max) {
212
if (specified_base != nullptr && aligned_base < specified_base) {
217
if (max_uintx - uintx(aligned_base) < uintx(cds_max)) {
225
static char* compute_shared_base(size_t cds_max) {
226
char* specified_base = (char*)SharedBaseAddress;
227
char* aligned_base = align_up(specified_base, MetaspaceShared::core_region_alignment());
228
if (UseCompressedClassPointers) {
229
aligned_base = align_up(specified_base, Metaspace::reserve_alignment());
232
if (aligned_base != specified_base) {
233
log_info(cds)("SharedBaseAddress (" INTPTR_FORMAT ") aligned up to " INTPTR_FORMAT,
234
p2i(specified_base), p2i(aligned_base));
237
const char* err = nullptr;
238
if (shared_base_too_high(specified_base, aligned_base, cds_max)) {
240
} else if (!shared_base_valid(aligned_base)) {
241
err = "invalid for this platform";
246
log_warning(cds)("SharedBaseAddress (" INTPTR_FORMAT ") is %s. Reverted to " INTPTR_FORMAT,
247
p2i((void*)SharedBaseAddress), err,
248
p2i((void*)Arguments::default_SharedBaseAddress()));
250
specified_base = (char*)Arguments::default_SharedBaseAddress();
251
aligned_base = align_up(specified_base, MetaspaceShared::core_region_alignment());
254
assert(!shared_base_too_high(specified_base, aligned_base, cds_max), "Sanity");
255
assert(shared_base_valid(aligned_base), "Sanity");
259
void MetaspaceShared::initialize_for_static_dump() {
260
assert(CDSConfig::is_dumping_static_archive(), "sanity");
261
log_info(cds)("Core region alignment: " SIZE_FORMAT, core_region_alignment());
265
const size_t reserve_alignment = core_region_alignment();
268
const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
269
cds_max = align_down(UnscaledClassSpaceMax, reserve_alignment);
273
cds_max = align_down(256*M, reserve_alignment);
276
_requested_base_address = compute_shared_base(cds_max);
277
SharedBaseAddress = (size_t)_requested_base_address;
279
size_t symbol_rs_size = LP64_ONLY(3 * G) NOT_LP64(128 * M);
280
_symbol_rs = ReservedSpace(symbol_rs_size);
281
if (!_symbol_rs.is_reserved()) {
282
log_error(cds)("Unable to reserve memory for symbols: " SIZE_FORMAT " bytes.", symbol_rs_size);
283
MetaspaceShared::unrecoverable_writing_error();
285
_symbol_region.init(&_symbol_rs, &_symbol_vs);
289
void MetaspaceShared::post_initialize(TRAPS) {
290
if (CDSConfig::is_using_archive()) {
291
int size = FileMapInfo::get_number_of_shared_paths();
293
CDSProtectionDomain::allocate_shared_data_arrays(size, CHECK);
294
if (!CDSConfig::is_dumping_dynamic_archive()) {
296
if (FileMapInfo::dynamic_info() == nullptr) {
297
info = FileMapInfo::current_info();
299
info = FileMapInfo::dynamic_info();
301
ClassLoaderExt::init_paths_start_index(info->app_class_paths_start_index());
302
ClassLoaderExt::init_app_module_paths_start_index(info->app_module_paths_start_index());
308
static GrowableArrayCHeap<OopHandle, mtClassShared>* _extra_interned_strings = nullptr;
309
static GrowableArrayCHeap<Symbol*, mtClassShared>* _extra_symbols = nullptr;
311
void MetaspaceShared::read_extra_data(JavaThread* current, const char* filename) {
312
_extra_interned_strings = new GrowableArrayCHeap<OopHandle, mtClassShared>(10000);
313
_extra_symbols = new GrowableArrayCHeap<Symbol*, mtClassShared>(1000);
315
HashtableTextDump reader(filename);
316
reader.check_version("VERSION: 1.0");
318
while (reader.remain() > 0) {
320
int prefix_type = reader.scan_prefix(&utf8_length);
321
ResourceMark rm(current);
322
if (utf8_length == 0x7fffffff) {
324
log_error(cds)("string length too large: %d", utf8_length);
325
MetaspaceShared::unrecoverable_loading_error();
327
int buf_len = utf8_length+1;
328
char* utf8_buffer = NEW_RESOURCE_ARRAY(char, buf_len);
329
reader.get_utf8(utf8_buffer, utf8_length);
330
utf8_buffer[utf8_length] = '\0';
332
if (prefix_type == HashtableTextDump::SymbolPrefix) {
333
_extra_symbols->append(SymbolTable::new_permanent_symbol(utf8_buffer));
335
assert(prefix_type == HashtableTextDump::StringPrefix, "Sanity");
336
ExceptionMark em(current);
337
JavaThread* THREAD = current;
338
oop str = StringTable::intern(utf8_buffer, THREAD);
340
if (HAS_PENDING_EXCEPTION) {
341
log_warning(cds, heap)("[line %d] extra interned string allocation failed; size too large: %d",
342
reader.last_line_no(), utf8_length);
343
CLEAR_PENDING_EXCEPTION;
345
#if INCLUDE_CDS_JAVA_HEAP
346
if (ArchiveHeapWriter::is_string_too_large_to_archive(str)) {
347
log_warning(cds, heap)("[line %d] extra interned string ignored; size too large: %d",
348
reader.last_line_no(), utf8_length);
352
assert(str != nullptr, "must succeed");
353
_extra_interned_strings->append(OopHandle(Universe::vm_global(), str));
363
void MetaspaceShared::serialize(SerializeClosure* soc) {
368
soc->do_tag(sizeof(Method));
369
soc->do_tag(sizeof(ConstMethod));
370
soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
371
soc->do_tag(sizeof(ConstantPool));
372
soc->do_tag(sizeof(ConstantPoolCache));
373
soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
374
soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
375
soc->do_tag(sizeof(Symbol));
379
CppVtables::serialize(soc);
383
JavaClasses::serialize_offsets(soc);
384
Universe::serialize(soc);
388
vmSymbols::serialize(soc);
392
SymbolTable::serialize_shared_table_header(soc);
393
StringTable::serialize_shared_table_header(soc);
394
HeapShared::serialize_tables(soc);
395
SystemDictionaryShared::serialize_dictionary_headers(soc);
397
InstanceMirrorKlass::serialize_offsets(soc);
400
SystemDictionaryShared::serialize_vm_classes(soc);
403
CDS_JAVA_HEAP_ONLY(Modules::serialize(soc);)
404
CDS_JAVA_HEAP_ONLY(ClassLoaderDataShared::serialize(soc);)
406
LambdaFormInvokers::serialize(soc);
410
static void rewrite_nofast_bytecode(const methodHandle& method) {
411
BytecodeStream bcs(method);
412
while (!bcs.is_last_bytecode()) {
413
Bytecodes::Code opcode = bcs.next();
415
case Bytecodes::_getfield: *bcs.bcp() = Bytecodes::_nofast_getfield; break;
416
case Bytecodes::_putfield: *bcs.bcp() = Bytecodes::_nofast_putfield; break;
417
case Bytecodes::_aload_0: *bcs.bcp() = Bytecodes::_nofast_aload_0; break;
418
case Bytecodes::_iload: {
419
if (!bcs.is_wide()) {
420
*bcs.bcp() = Bytecodes::_nofast_iload;
432
void MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik) {
433
for (int i = 0; i < ik->methods()->length(); i++) {
434
methodHandle m(thread, ik->methods()->at(i));
435
if (ik->can_be_verified_at_dumptime() && ik->is_linked()) {
436
rewrite_nofast_bytecode(m);
444
class VM_PopulateDumpSharedSpace : public VM_Operation {
446
ArchiveHeapInfo _heap_info;
447
FileMapInfo* _map_info;
448
StaticArchiveBuilder& _builder;
450
void dump_java_heap_objects(GrowableArray<Klass*>* klasses) NOT_CDS_JAVA_HEAP_RETURN;
451
void dump_shared_symbol_table(GrowableArray<Symbol*>* symbols) {
452
log_info(cds)("Dumping symbol table ...");
453
SymbolTable::write_to_archive(symbols);
455
char* dump_read_only_tables();
459
VM_PopulateDumpSharedSpace(StaticArchiveBuilder& b) :
460
VM_Operation(), _heap_info(), _map_info(nullptr), _builder(b) {}
462
bool skip_operation() const { return false; }
464
VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
465
ArchiveHeapInfo* heap_info() { return &_heap_info; }
466
FileMapInfo* map_info() const { return _map_info; }
468
bool allow_nested_vm_operations() const { return true; }
471
class StaticArchiveBuilder : public ArchiveBuilder {
473
StaticArchiveBuilder() : ArchiveBuilder() {}
475
virtual void iterate_roots(MetaspaceClosure* it) {
476
FileMapInfo::metaspace_pointers_do(it);
477
SystemDictionaryShared::dumptime_classes_do(it);
478
Universe::metaspace_pointers_do(it);
479
vmSymbols::metaspace_pointers_do(it);
486
if (_extra_symbols != nullptr) {
487
for (int i = 0; i < _extra_symbols->length(); i++) {
488
it->push(_extra_symbols->adr_at(i));
494
char* VM_PopulateDumpSharedSpace::dump_read_only_tables() {
495
ArchiveBuilder::OtherROAllocMark mark;
497
SystemDictionaryShared::write_to_archive();
500
LambdaFormInvokers::dump_static_archive_invokers();
502
CDS_JAVA_HEAP_ONLY(Modules::dump_main_module_name();)
504
DumpRegion* ro_region = ArchiveBuilder::current()->ro_region();
505
char* start = ro_region->top();
506
WriteClosure wc(ro_region);
507
MetaspaceShared::serialize(&wc);
512
void VM_PopulateDumpSharedSpace::doit() {
513
guarantee(!CDSConfig::is_using_archive(), "We should not be using an archive when we dump");
515
DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm);
517
FileMapInfo::check_nonempty_dir_in_shared_path_table();
519
NOT_PRODUCT(SystemDictionary::verify();)
522
MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
523
SystemDictionaryShared::check_excluded_classes();
525
_builder.gather_source_objs();
526
_builder.reserve_buffer();
528
CppVtables::dumptime_init(&_builder);
530
_builder.sort_metadata_objs();
531
_builder.dump_rw_metadata();
532
_builder.dump_ro_metadata();
533
_builder.relocate_metaspaceobj_embedded_pointers();
535
dump_java_heap_objects(_builder.klasses());
536
dump_shared_symbol_table(_builder.symbols());
538
log_info(cds)("Make classes shareable");
539
_builder.make_klasses_shareable();
541
char* serialized_data = dump_read_only_tables();
543
SystemDictionaryShared::adjust_lambda_proxy_class_dictionary();
547
CppVtables::zero_archived_vtables();
550
const char* static_archive = CDSConfig::static_archive_path();
551
assert(static_archive != nullptr, "SharedArchiveFile not set?");
552
_map_info = new FileMapInfo(static_archive, true);
553
_map_info->populate_header(MetaspaceShared::core_region_alignment());
554
_map_info->set_serialized_data(serialized_data);
555
_map_info->set_cloned_vtables(CppVtables::vtables_serialized_base());
558
class CollectCLDClosure : public CLDClosure {
559
GrowableArray<ClassLoaderData*> _loaded_cld;
560
GrowableArray<OopHandle> _loaded_cld_handles;
561
Thread* _current_thread;
563
CollectCLDClosure(Thread* thread) : _current_thread(thread) {}
564
~CollectCLDClosure() {
565
for (int i = 0; i < _loaded_cld_handles.length(); i++) {
566
_loaded_cld_handles.at(i).release(Universe::vm_global());
569
void do_cld(ClassLoaderData* cld) {
570
assert(cld->is_alive(), "must be");
571
_loaded_cld.append(cld);
572
_loaded_cld_handles.append(OopHandle(Universe::vm_global(), cld->holder()));
575
int nof_cld() const { return _loaded_cld.length(); }
576
ClassLoaderData* cld_at(int index) { return _loaded_cld.at(index); }
581
bool MetaspaceShared::may_be_eagerly_linked(InstanceKlass* ik) {
582
if (!ik->can_be_verified_at_dumptime()) {
588
if (CDSConfig::is_dumping_dynamic_archive() && ik->is_shared_unregistered_class()) {
600
bool MetaspaceShared::link_class_for_cds(InstanceKlass* ik, TRAPS) {
604
bool res = MetaspaceShared::try_link_class(THREAD, ik);
605
ClassPrelinker::dumptime_resolve_constants(ik, CHECK_(false));
609
void MetaspaceShared::link_shared_classes(bool jcmd_request, TRAPS) {
610
ClassPrelinker::initialize();
613
LambdaFormInvokers::regenerate_holder_classes(CHECK);
617
CollectCLDClosure collect_cld(THREAD);
623
MutexLocker lock(ClassLoaderDataGraph_lock);
624
ClassLoaderDataGraph::loaded_cld_do(&collect_cld);
628
bool has_linked = false;
629
for (int i = 0; i < collect_cld.nof_cld(); i++) {
630
ClassLoaderData* cld = collect_cld.cld_at(i);
631
for (Klass* klass = cld->klasses(); klass != nullptr; klass = klass->next_link()) {
632
if (klass->is_instance_klass()) {
633
InstanceKlass* ik = InstanceKlass::cast(klass);
634
if (may_be_eagerly_linked(ik)) {
635
has_linked |= link_class_for_cds(ik, CHECK);
649
void MetaspaceShared::prepare_for_dumping() {
650
assert(CDSConfig::is_dumping_archive(), "sanity");
651
CDSConfig::check_unsupported_dumping_module_options();
652
ClassLoader::initialize_shared_path(JavaThread::current());
657
void MetaspaceShared::preload_and_dump(TRAPS) {
658
ResourceMark rm(THREAD);
659
StaticArchiveBuilder builder;
660
preload_and_dump_impl(builder, THREAD);
661
if (HAS_PENDING_EXCEPTION) {
662
if (PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) {
663
log_error(cds)("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
664
SIZE_FORMAT "M", MaxHeapSize/M);
665
MetaspaceShared::writing_error();
667
log_error(cds)("%s: %s", PENDING_EXCEPTION->klass()->external_name(),
668
java_lang_String::as_utf8_string(java_lang_Throwable::message(PENDING_EXCEPTION)));
669
MetaspaceShared::writing_error("Unexpected exception, use -Xlog:cds,exceptions=trace for detail");
674
#if INCLUDE_CDS_JAVA_HEAP && defined(_LP64)
675
void MetaspaceShared::adjust_heap_sizes_for_dumping() {
676
if (!CDSConfig::is_dumping_heap() || UseCompressedOops) {
681
julong max_heap_size = (julong)(4 * G);
683
if (MinHeapSize > max_heap_size) {
684
log_debug(cds)("Setting MinHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", MinHeapSize/M);
685
FLAG_SET_ERGO(MinHeapSize, max_heap_size);
687
if (InitialHeapSize > max_heap_size) {
688
log_debug(cds)("Setting InitialHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", InitialHeapSize/M);
689
FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
691
if (MaxHeapSize > max_heap_size) {
692
log_debug(cds)("Setting MaxHeapSize to 4G for CDS dumping, original size = " SIZE_FORMAT "M", MaxHeapSize/M);
693
FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
698
void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
702
os::jvm_path(default_classlist, (jint)(buf_size));
703
for (int i = 0; i < 3; i++) {
704
char *end = strrchr(default_classlist, *os::file_separator());
705
if (end != nullptr) *end = '\0';
707
size_t classlist_path_len = strlen(default_classlist);
708
if (classlist_path_len >= 3) {
709
if (strcmp(default_classlist + classlist_path_len - 3, "lib") != 0) {
710
if (classlist_path_len < buf_size - 4) {
711
jio_snprintf(default_classlist + classlist_path_len,
712
buf_size - classlist_path_len,
713
"%slib", os::file_separator());
714
classlist_path_len += 4;
718
if (classlist_path_len < buf_size - 10) {
719
jio_snprintf(default_classlist + classlist_path_len,
720
buf_size - classlist_path_len,
721
"%sclasslist", os::file_separator());
725
void MetaspaceShared::preload_classes(TRAPS) {
726
char default_classlist[JVM_MAXPATHLEN];
727
const char* classlist_path;
729
get_default_classlist(default_classlist, sizeof(default_classlist));
730
if (SharedClassListFile == nullptr) {
731
classlist_path = default_classlist;
733
classlist_path = SharedClassListFile;
736
log_info(cds)("Loading classes to share ...");
737
ClassListParser::parse_classlist(classlist_path,
738
ClassListParser::_parse_all, CHECK);
739
if (ExtraSharedClassListFile) {
740
ClassListParser::parse_classlist(ExtraSharedClassListFile,
741
ClassListParser::_parse_all, CHECK);
743
if (classlist_path != default_classlist) {
745
if (os::stat(default_classlist, &statbuf) == 0) {
747
ClassListParser::parse_classlist(default_classlist,
748
ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
754
const char* dummy = "Manifest-Version: 1.0\n";
755
CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
757
log_info(cds)("Loading classes to share: done.");
760
void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
761
preload_classes(CHECK);
763
if (SharedArchiveConfigFile) {
764
log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile);
765
read_extra_data(THREAD, SharedArchiveConfigFile);
766
log_info(cds)("Reading extra data: done.");
770
log_info(cds)("Rewriting and linking classes ...");
776
link_shared_classes(false, CHECK);
777
log_info(cds)("Rewriting and linking classes: done");
779
#if INCLUDE_CDS_JAVA_HEAP
780
if (CDSConfig::is_dumping_heap()) {
781
if (!HeapShared::is_archived_boot_layer_available(THREAD)) {
782
log_info(cds)("archivedBootLayer not available, disabling full module graph");
783
CDSConfig::stop_dumping_full_module_graph();
785
HeapShared::init_for_dumping(CHECK);
786
ArchiveHeapWriter::init();
787
if (CDSConfig::is_dumping_full_module_graph()) {
788
HeapShared::reset_archived_object_states(CHECK);
793
StringTable::allocate_shared_strings_array(CHECK);
797
VM_PopulateDumpSharedSpace op(builder);
798
VMThread::execute(&op);
800
if (!write_static_archive(&builder, op.map_info(), op.heap_info())) {
801
THROW_MSG(vmSymbols::java_io_IOException(), "Encountered error while dumping");
805
bool MetaspaceShared::write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info) {
808
builder->relocate_to_requested();
810
map_info->open_for_write();
811
if (!map_info->is_open()) {
814
builder->write_archive(map_info, heap_info);
816
if (AllowArchivingWithJavaAgent) {
817
log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
818
"for testing purposes only and should not be used in a production environment");
824
bool MetaspaceShared::try_link_class(JavaThread* current, InstanceKlass* ik) {
825
ExceptionMark em(current);
826
JavaThread* THREAD = current;
827
assert(CDSConfig::is_dumping_archive(), "sanity");
828
if (!ik->is_shared() && ik->is_loaded() && !ik->is_linked() && ik->can_be_verified_at_dumptime() &&
829
!SystemDictionaryShared::has_class_failed_verification(ik)) {
830
bool saved = BytecodeVerificationLocal;
831
if (ik->is_shared_unregistered_class() && ik->class_loader() == nullptr) {
839
BytecodeVerificationLocal = BytecodeVerificationRemote;
841
ik->link_class(THREAD);
842
if (HAS_PENDING_EXCEPTION) {
843
ResourceMark rm(THREAD);
844
log_warning(cds)("Preload Warning: Verification failed for %s",
845
ik->external_name());
846
CLEAR_PENDING_EXCEPTION;
847
SystemDictionaryShared::set_class_has_failed_verification(ik);
849
ik->compute_has_loops_flag_for_methods();
850
BytecodeVerificationLocal = saved;
857
#if INCLUDE_CDS_JAVA_HEAP
858
void VM_PopulateDumpSharedSpace::dump_java_heap_objects(GrowableArray<Klass*>* klasses) {
859
if(!HeapShared::can_write()) {
861
"Archived java heap is not supported as UseG1GC "
862
"and UseCompressedClassPointers are required."
863
"Current settings: UseG1GC=%s, UseCompressedClassPointers=%s.",
864
BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedClassPointers));
869
for (i = 0; i < klasses->length(); i++) {
870
Klass* k = klasses->at(i);
871
if (k->is_instance_klass()) {
872
InstanceKlass* ik = InstanceKlass::cast(k);
873
if (ik->is_linked()) {
874
ik->constants()->add_dumped_interned_strings();
878
if (_extra_interned_strings != nullptr) {
879
for (i = 0; i < _extra_interned_strings->length(); i ++) {
880
OopHandle string = _extra_interned_strings->at(i);
881
HeapShared::add_to_dumped_interned_strings(string.resolve());
885
HeapShared::archive_objects(&_heap_info);
886
ArchiveBuilder::OtherROAllocMark mark;
887
HeapShared::write_subgraph_info_table();
891
void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) {
892
assert(base <= static_top && static_top <= top, "must be");
893
_shared_metaspace_static_top = static_top;
894
MetaspaceObj::set_shared_metaspace_range(base, top);
897
bool MetaspaceShared::is_shared_dynamic(void* p) {
898
if ((p < MetaspaceObj::shared_metaspace_top()) &&
899
(p >= _shared_metaspace_static_top)) {
906
bool MetaspaceShared::is_shared_static(void* p) {
907
if (is_in_shared_metaspace(p) && !is_shared_dynamic(p)) {
919
void MetaspaceShared::unrecoverable_loading_error(const char* message) {
920
log_error(cds)("An error has occurred while processing the shared archive file.");
921
if (message != nullptr) {
922
log_error(cds)("%s", message);
924
vm_exit_during_initialization("Unable to use shared archive.", nullptr);
929
void MetaspaceShared::unrecoverable_writing_error(const char* message) {
930
writing_error(message);
936
void MetaspaceShared::writing_error(const char* message) {
937
log_error(cds)("An error has occurred while writing the shared archive file.");
938
if (message != nullptr) {
939
log_error(cds)("%s", message);
943
void MetaspaceShared::initialize_runtime_shared_and_meta_spaces() {
944
assert(CDSConfig::is_using_archive(), "Must be called when UseSharedSpaces is enabled");
945
MapArchiveResult result = MAP_ARCHIVE_OTHER_FAILURE;
947
FileMapInfo* static_mapinfo = open_static_archive();
948
FileMapInfo* dynamic_mapinfo = nullptr;
950
if (static_mapinfo != nullptr) {
951
log_info(cds)("Core region alignment: " SIZE_FORMAT, static_mapinfo->core_region_alignment());
952
dynamic_mapinfo = open_dynamic_archive();
955
result = map_archives(static_mapinfo, dynamic_mapinfo, true);
956
if (result == MAP_ARCHIVE_MMAP_FAILURE) {
959
log_info(cds)("Try to map archive(s) at an alternative address");
960
result = map_archives(static_mapinfo, dynamic_mapinfo, false);
964
if (result == MAP_ARCHIVE_SUCCESS) {
965
bool dynamic_mapped = (dynamic_mapinfo != nullptr && dynamic_mapinfo->is_mapped());
966
char* cds_base = static_mapinfo->mapped_base();
967
char* cds_end = dynamic_mapped ? dynamic_mapinfo->mapped_end() : static_mapinfo->mapped_end();
969
LSAN_REGISTER_ROOT_REGION(cds_base, cds_end - cds_base);
970
set_shared_metaspace_range(cds_base, static_mapinfo->mapped_end(), cds_end);
971
_relocation_delta = static_mapinfo->relocation_delta();
972
_requested_base_address = static_mapinfo->requested_base_address();
973
if (dynamic_mapped) {
974
FileMapInfo::set_shared_path_table(dynamic_mapinfo);
976
AutoCreateSharedArchive = false;
978
FileMapInfo::set_shared_path_table(static_mapinfo);
981
set_shared_metaspace_range(nullptr, nullptr, nullptr);
982
if (CDSConfig::is_dumping_dynamic_archive()) {
983
log_warning(cds)("-XX:ArchiveClassesAtExit is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
985
UseSharedSpaces = false;
987
AutoCreateSharedArchive = false;
988
CDSConfig::disable_dumping_dynamic_archive();
989
log_info(cds)("Unable to map shared spaces");
990
if (PrintSharedArchiveAndExit) {
991
MetaspaceShared::unrecoverable_loading_error("Unable to use shared archive.");
992
} else if (RequireSharedSpaces) {
993
MetaspaceShared::unrecoverable_loading_error("Unable to map shared spaces");
998
bool has_failed = false;
999
if (static_mapinfo != nullptr && !static_mapinfo->is_mapped()) {
1001
delete static_mapinfo;
1003
if (dynamic_mapinfo != nullptr && !dynamic_mapinfo->is_mapped()) {
1005
delete dynamic_mapinfo;
1007
if (RequireSharedSpaces && has_failed) {
1008
MetaspaceShared::unrecoverable_loading_error("Unable to map shared spaces");
1012
FileMapInfo* MetaspaceShared::open_static_archive() {
1013
const char* static_archive = CDSConfig::static_archive_path();
1014
assert(static_archive != nullptr, "sanity");
1015
FileMapInfo* mapinfo = new FileMapInfo(static_archive, true);
1016
if (!mapinfo->initialize()) {
1023
FileMapInfo* MetaspaceShared::open_dynamic_archive() {
1024
if (CDSConfig::is_dumping_dynamic_archive()) {
1027
const char* dynamic_archive = CDSConfig::dynamic_archive_path();
1028
if (dynamic_archive == nullptr) {
1032
FileMapInfo* mapinfo = new FileMapInfo(dynamic_archive, false);
1033
if (!mapinfo->initialize()) {
1035
if (RequireSharedSpaces) {
1036
MetaspaceShared::unrecoverable_loading_error("Failed to initialize dynamic archive");
1046
MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
1047
bool use_requested_addr) {
1048
if (use_requested_addr && static_mapinfo->requested_base_address() == nullptr) {
1049
log_info(cds)("Archive(s) were created with -XX:SharedBaseAddress=0. Always map at os-selected address.");
1050
return MAP_ARCHIVE_MMAP_FAILURE;
1053
PRODUCT_ONLY(if (ArchiveRelocationMode == 1 && use_requested_addr) {
1057
log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address");
1058
return MAP_ARCHIVE_MMAP_FAILURE;
1061
if (ArchiveRelocationMode == 2 && !use_requested_addr) {
1062
log_info(cds)("ArchiveRelocationMode == 2: never map archive(s) at an alternative address");
1063
return MAP_ARCHIVE_MMAP_FAILURE;
1066
if (dynamic_mapinfo != nullptr) {
1069
assert(static_mapinfo->mapping_end_offset() == dynamic_mapinfo->mapping_base_offset(), "no gap");
1072
ReservedSpace total_space_rs, archive_space_rs, class_space_rs;
1073
MapArchiveResult result = MAP_ARCHIVE_OTHER_FAILURE;
1074
char* mapped_base_address = reserve_address_space_for_archives(static_mapinfo,
1080
if (mapped_base_address == nullptr) {
1081
result = MAP_ARCHIVE_MMAP_FAILURE;
1082
log_debug(cds)("Failed to reserve spaces (use_requested_addr=%u)", (unsigned)use_requested_addr);
1088
assert(archive_space_rs.is_reserved(), "Sanity");
1089
if (Metaspace::using_class_space()) {
1092
assert(class_space_rs.is_reserved(),
1093
"A class space should have been reserved");
1094
assert(class_space_rs.base() >= archive_space_rs.end(),
1095
"class space should follow the cds archive space");
1096
assert(is_aligned(archive_space_rs.base(),
1097
core_region_alignment()),
1098
"Archive space misaligned");
1099
assert(is_aligned(class_space_rs.base(),
1100
Metaspace::reserve_alignment()),
1101
"class space misaligned");
1105
log_info(cds)("Reserved archive_space_rs [" INTPTR_FORMAT " - " INTPTR_FORMAT "] (" SIZE_FORMAT ") bytes",
1106
p2i(archive_space_rs.base()), p2i(archive_space_rs.end()), archive_space_rs.size());
1107
log_info(cds)("Reserved class_space_rs [" INTPTR_FORMAT " - " INTPTR_FORMAT "] (" SIZE_FORMAT ") bytes",
1108
p2i(class_space_rs.base()), p2i(class_space_rs.end()), class_space_rs.size());
1110
if (MetaspaceShared::use_windows_memory_mapping()) {
1127
if (use_requested_addr) {
1128
assert(!total_space_rs.is_reserved(), "Should not be reserved for Windows");
1129
log_info(cds)("Windows mmap workaround: releasing archive space.");
1130
archive_space_rs.release();
1133
MapArchiveResult static_result = map_archive(static_mapinfo, mapped_base_address, archive_space_rs);
1134
MapArchiveResult dynamic_result = (static_result == MAP_ARCHIVE_SUCCESS) ?
1135
map_archive(dynamic_mapinfo, mapped_base_address, archive_space_rs) : MAP_ARCHIVE_OTHER_FAILURE;
1137
DEBUG_ONLY(if (ArchiveRelocationMode == 1 && use_requested_addr) {
1142
log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address");
1143
if (static_result == MAP_ARCHIVE_SUCCESS) {
1144
static_result = MAP_ARCHIVE_MMAP_FAILURE;
1146
if (dynamic_result == MAP_ARCHIVE_SUCCESS) {
1147
dynamic_result = MAP_ARCHIVE_MMAP_FAILURE;
1151
if (static_result == MAP_ARCHIVE_SUCCESS) {
1152
if (dynamic_result == MAP_ARCHIVE_SUCCESS) {
1153
result = MAP_ARCHIVE_SUCCESS;
1154
} else if (dynamic_result == MAP_ARCHIVE_OTHER_FAILURE) {
1155
assert(dynamic_mapinfo != nullptr && !dynamic_mapinfo->is_mapped(), "must have failed");
1158
log_warning(cds, dynamic)("Unable to use shared archive. The top archive failed to load: %s",
1159
dynamic_mapinfo->full_path());
1160
result = MAP_ARCHIVE_SUCCESS;
1164
result = MAP_ARCHIVE_MMAP_FAILURE;
1166
} else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) {
1167
result = MAP_ARCHIVE_OTHER_FAILURE;
1169
result = MAP_ARCHIVE_MMAP_FAILURE;
1173
if (result == MAP_ARCHIVE_SUCCESS) {
1174
SharedBaseAddress = (size_t)mapped_base_address;
1176
if (Metaspace::using_class_space()) {
1178
Metaspace::initialize_class_space(class_space_rs);
1182
address cds_base = (address)static_mapinfo->mapped_base();
1183
address ccs_end = (address)class_space_rs.end();
1184
assert(ccs_end > cds_base, "Sanity check");
1185
#if INCLUDE_CDS_JAVA_HEAP
1187
address precomputed_narrow_klass_base = cds_base;
1188
const int precomputed_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
1189
CompressedKlassPointers::initialize_for_given_encoding(
1190
cds_base, ccs_end - cds_base,
1191
precomputed_narrow_klass_base, precomputed_narrow_klass_shift
1194
CompressedKlassPointers::initialize (
1195
cds_base, ccs_end - cds_base
1200
static_mapinfo->map_or_load_heap_region();
1203
log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
1204
log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
1206
unmap_archive(static_mapinfo);
1207
unmap_archive(dynamic_mapinfo);
1208
release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
1272
char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
1273
FileMapInfo* dynamic_mapinfo,
1274
bool use_archive_base_addr,
1275
ReservedSpace& total_space_rs,
1276
ReservedSpace& archive_space_rs,
1277
ReservedSpace& class_space_rs) {
1279
address const base_address = (address) (use_archive_base_addr ? static_mapinfo->requested_base_address() : nullptr);
1280
const size_t archive_space_alignment = core_region_alignment();
1283
assert(static_mapinfo->mapping_base_offset() == 0, "Must be");
1284
size_t archive_end_offset = (dynamic_mapinfo == nullptr) ? static_mapinfo->mapping_end_offset() : dynamic_mapinfo->mapping_end_offset();
1285
size_t archive_space_size = align_up(archive_end_offset, archive_space_alignment);
1287
if (!Metaspace::using_class_space()) {
1292
assert(is_aligned(base_address, archive_space_alignment),
1293
"Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.",
1294
p2i(base_address), archive_space_alignment);
1296
archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment,
1297
os::vm_page_size(), (char*)base_address);
1298
if (archive_space_rs.is_reserved()) {
1299
assert(base_address == nullptr ||
1300
(address)archive_space_rs.base() == base_address, "Sanity");
1302
MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared);
1303
return archive_space_rs.base();
1314
const size_t class_space_alignment = Metaspace::reserve_alignment();
1318
const size_t base_address_alignment = MAX2(class_space_alignment, archive_space_alignment);
1319
assert(is_aligned(base_address, base_address_alignment),
1320
"Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.",
1321
p2i(base_address), base_address_alignment);
1323
size_t class_space_size = CompressedClassSpaceSize;
1324
assert(CompressedClassSpaceSize > 0 &&
1325
is_aligned(CompressedClassSpaceSize, class_space_alignment),
1326
"CompressedClassSpaceSize malformed: "
1327
SIZE_FORMAT, CompressedClassSpaceSize);
1329
const size_t ccs_begin_offset = align_up(archive_space_size, class_space_alignment);
1330
const size_t gap_size = ccs_begin_offset - archive_space_size;
1333
constexpr size_t max_encoding_range_size = 4 * G;
1334
guarantee(archive_space_size < max_encoding_range_size - class_space_alignment, "Archive too large");
1335
if ((archive_space_size + gap_size + class_space_size) > max_encoding_range_size) {
1336
class_space_size = align_down(max_encoding_range_size - archive_space_size - gap_size, class_space_alignment);
1337
log_info(metaspace)("CDS initialization: reducing class space size from " SIZE_FORMAT " to " SIZE_FORMAT,
1338
CompressedClassSpaceSize, class_space_size);
1339
FLAG_SET_ERGO(CompressedClassSpaceSize, class_space_size);
1342
const size_t total_range_size =
1343
archive_space_size + gap_size + class_space_size;
1345
assert(total_range_size > ccs_begin_offset, "must be");
1346
if (use_windows_memory_mapping() && use_archive_base_addr) {
1347
if (base_address != nullptr) {
1353
address ccs_base = base_address + archive_space_size + gap_size;
1354
archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment,
1355
os::vm_page_size(), (char*)base_address);
1356
class_space_rs = ReservedSpace(class_space_size, class_space_alignment,
1357
os::vm_page_size(), (char*)ccs_base);
1359
if (!archive_space_rs.is_reserved() || !class_space_rs.is_reserved()) {
1360
release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
1364
MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared);
1365
MemTracker::record_virtual_memory_type(class_space_rs.base(), mtClass);
1367
if (use_archive_base_addr && base_address != nullptr) {
1368
total_space_rs = ReservedSpace(total_range_size, base_address_alignment,
1369
os::vm_page_size(), (char*) base_address);
1376
total_space_rs = Metaspace::reserve_address_space_for_compressed_classes(total_range_size, false );
1379
if (!total_space_rs.is_reserved()) {
1384
assert(base_address == nullptr || (address)total_space_rs.base() == base_address,
1385
"Sanity (" PTR_FORMAT " vs " PTR_FORMAT ")", p2i(base_address), p2i(total_space_rs.base()));
1386
assert(is_aligned(total_space_rs.base(), base_address_alignment), "Sanity");
1387
assert(total_space_rs.size() == total_range_size, "Sanity");
1391
archive_space_rs = total_space_rs.first_part(ccs_begin_offset,
1392
(size_t)archive_space_alignment);
1393
class_space_rs = total_space_rs.last_part(ccs_begin_offset);
1394
MemTracker::record_virtual_memory_split_reserved(total_space_rs.base(), total_space_rs.size(),
1395
ccs_begin_offset, mtClassShared, mtClass);
1397
assert(is_aligned(archive_space_rs.base(), archive_space_alignment), "Sanity");
1398
assert(is_aligned(archive_space_rs.size(), archive_space_alignment), "Sanity");
1399
assert(is_aligned(class_space_rs.base(), class_space_alignment), "Sanity");
1400
assert(is_aligned(class_space_rs.size(), class_space_alignment), "Sanity");
1403
return archive_space_rs.base();
1406
ShouldNotReachHere();
1412
void MetaspaceShared::release_reserved_spaces(ReservedSpace& total_space_rs,
1413
ReservedSpace& archive_space_rs,
1414
ReservedSpace& class_space_rs) {
1415
if (total_space_rs.is_reserved()) {
1416
log_debug(cds)("Released shared space (archive + class) " INTPTR_FORMAT, p2i(total_space_rs.base()));
1417
total_space_rs.release();
1419
if (archive_space_rs.is_reserved()) {
1420
log_debug(cds)("Released shared space (archive) " INTPTR_FORMAT, p2i(archive_space_rs.base()));
1421
archive_space_rs.release();
1423
if (class_space_rs.is_reserved()) {
1424
log_debug(cds)("Released shared space (classes) " INTPTR_FORMAT, p2i(class_space_rs.base()));
1425
class_space_rs.release();
1430
static int archive_regions[] = { MetaspaceShared::rw, MetaspaceShared::ro };
1431
static int archive_regions_count = 2;
1433
MapArchiveResult MetaspaceShared::map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs) {
1434
assert(CDSConfig::is_using_archive(), "must be runtime");
1435
if (mapinfo == nullptr) {
1436
return MAP_ARCHIVE_SUCCESS;
1439
mapinfo->set_is_mapped(false);
1440
if (mapinfo->core_region_alignment() != (size_t)core_region_alignment()) {
1441
log_info(cds)("Unable to map CDS archive -- core_region_alignment() expected: " SIZE_FORMAT
1442
" actual: " SIZE_FORMAT, mapinfo->core_region_alignment(), core_region_alignment());
1443
return MAP_ARCHIVE_OTHER_FAILURE;
1446
MapArchiveResult result =
1447
mapinfo->map_regions(archive_regions, archive_regions_count, mapped_base_address, rs);
1449
if (result != MAP_ARCHIVE_SUCCESS) {
1450
unmap_archive(mapinfo);
1454
if (!mapinfo->validate_shared_path_table()) {
1455
unmap_archive(mapinfo);
1456
return MAP_ARCHIVE_OTHER_FAILURE;
1459
mapinfo->set_is_mapped(true);
1460
return MAP_ARCHIVE_SUCCESS;
1463
void MetaspaceShared::unmap_archive(FileMapInfo* mapinfo) {
1464
assert(CDSConfig::is_using_archive(), "must be runtime");
1465
if (mapinfo != nullptr) {
1466
mapinfo->unmap_regions(archive_regions, archive_regions_count);
1467
mapinfo->unmap_region(MetaspaceShared::bm);
1468
mapinfo->set_is_mapped(false);
1473
class CountSharedSymbols : public SymbolClosure {
1477
CountSharedSymbols() : _count(0) {}
1478
void do_symbol(Symbol** sym) {
1481
int total() { return _count; }
1488
void MetaspaceShared::initialize_shared_spaces() {
1489
FileMapInfo *static_mapinfo = FileMapInfo::current_info();
1493
char* buffer = static_mapinfo->serialized_data();
1494
intptr_t* array = (intptr_t*)buffer;
1495
ReadClosure rc(&array);
1500
static_mapinfo->patch_heap_embedded_pointers();
1501
ArchiveHeapLoader::finish_initialization();
1502
Universe::load_archived_object_instances();
1505
static_mapinfo->close();
1507
static_mapinfo->unmap_region(MetaspaceShared::bm);
1509
FileMapInfo *dynamic_mapinfo = FileMapInfo::dynamic_info();
1510
if (dynamic_mapinfo != nullptr) {
1511
intptr_t* buffer = (intptr_t*)dynamic_mapinfo->serialized_data();
1512
ReadClosure rc(&buffer);
1513
ArchiveBuilder::serialize_dynamic_archivable_items(&rc);
1514
DynamicArchive::setup_array_klasses();
1515
dynamic_mapinfo->close();
1516
dynamic_mapinfo->unmap_region(MetaspaceShared::bm);
1520
if (CDSConfig::is_dumping_dynamic_archive()) {
1522
LambdaFormInvokers::read_static_archive_invokers();
1525
if (PrintSharedArchiveAndExit) {
1527
if (dynamic_mapinfo != nullptr) {
1528
tty->print_cr("\n\nBase archive name: %s", CDSConfig::static_archive_path());
1529
tty->print_cr("Base archive version %d", static_mapinfo->version());
1531
tty->print_cr("Static archive name: %s", static_mapinfo->full_path());
1532
tty->print_cr("Static archive version %d", static_mapinfo->version());
1535
SystemDictionaryShared::print_shared_archive(tty);
1536
if (dynamic_mapinfo != nullptr) {
1537
tty->print_cr("\n\nDynamic archive name: %s", dynamic_mapinfo->full_path());
1538
tty->print_cr("Dynamic archive version %d", dynamic_mapinfo->version());
1539
SystemDictionaryShared::print_shared_archive(tty, false);
1543
CountSharedSymbols cl;
1544
SymbolTable::shared_symbols_do(&cl);
1545
tty->print_cr("Number of shared symbols: %d", cl.total());
1546
tty->print_cr("Number of shared strings: %zu", StringTable::shared_entry_count());
1547
tty->print_cr("VM version: %s\r\n", static_mapinfo->vm_version());
1548
if (FileMapInfo::current_info() == nullptr || _archive_loading_failed) {
1549
tty->print_cr("archive is invalid");
1552
tty->print_cr("archive is valid");
1559
bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
1560
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1562
if (CDSConfig::is_using_archive()) {
1564
FileMapInfo* mapinfo = FileMapInfo::current_info();
1565
if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1568
if (FileMapInfo::dynamic_info() != nullptr) {
1569
mapinfo = FileMapInfo::dynamic_info();
1570
if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1574
_remapped_readwrite = true;
1579
void MetaspaceShared::print_on(outputStream* st) {
1580
if (CDSConfig::is_using_archive()) {
1581
st->print("CDS archive(s) mapped at: ");
1582
address base = (address)MetaspaceObj::shared_metaspace_base();
1583
address static_top = (address)_shared_metaspace_static_top;
1584
address top = (address)MetaspaceObj::shared_metaspace_top();
1585
st->print("[" PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(static_top), p2i(top));
1586
st->print("size " SIZE_FORMAT ", ", top - base);
1587
st->print("SharedBaseAddress: " PTR_FORMAT ", ArchiveRelocationMode: %d.", SharedBaseAddress, ArchiveRelocationMode);
1589
st->print("CDS archive(s) not mapped");