@@ -359,8 +359,43 @@ void MetaspaceShared::read_extra_data(JavaThread* current, const char* filename)
359
359
}
360
360
}
361
361
362
- // Read/write a data stream for restoring/preserving metadata pointers and
363
- // miscellaneous data from/to the shared archive file.
362
+ // About "serialize" --
363
+ //
364
+ // This is (probably a badly named) way to read/write a data stream of pointers and
365
+ // miscellaneous data from/to the shared archive file. The usual code looks like this:
366
+ //
367
+ // // These two global C++ variables are initialized during dump time.
368
+ // static int _archived_int;
369
+ // static MetaspaceObj* archived_ptr;
370
+ //
371
+ // void MyClass::serialize(SerializeClosure* soc) {
372
+ // soc->do_int(&_archived_int);
373
+ // soc->do_int(&_archived_ptr);
374
+ // }
375
+ //
376
+ // At dumptime, these two variables are stored into the CDS archive.
377
+ // At runtime, these two variables are loaded from the CDS archive.
378
+ // In addition, the pointer is relocated as necessary.
379
+ //
380
+ // Some of the xxx::serialize() functions may have side effects and assume that
381
+ // the archive is already mapped. For example, SymbolTable::serialize_shared_table_header()
382
+ // unconditionally makes the set of archived symbols available. Therefore, we put most
383
+ // of these xxx::serialize() functions inside MetaspaceShared::serialize(), which
384
+ // is called AFTER we made the decision to map the archive.
385
+ //
386
+ // However, some of the "serialized" data are used to decide whether an archive should
387
+ // be mapped or not (e.g., for checking if the -Djdk.module.main property is compatible
388
+ // with the archive). The xxx::serialize() functions for these data must be put inside
389
+ // MetaspaceShared::early_serialize(). Such functions must not produce side effects that
390
+ // assume we will always decides to map the archive.
391
+
392
+ void MetaspaceShared::early_serialize (SerializeClosure* soc) {
393
+ int tag = 0 ;
394
+ soc->do_tag (--tag);
395
+ CDS_JAVA_HEAP_ONLY (Modules::serialize (soc);)
396
+ CDS_JAVA_HEAP_ONLY (Modules::serialize_addmods_names (soc);)
397
+ soc->do_tag (666 );
398
+ }
364
399
365
400
void MetaspaceShared::serialize (SerializeClosure* soc) {
366
401
int tag = 0 ;
@@ -402,8 +437,6 @@ void MetaspaceShared::serialize(SerializeClosure* soc) {
402
437
SystemDictionaryShared::serialize_vm_classes (soc);
403
438
soc->do_tag (--tag);
404
439
405
- CDS_JAVA_HEAP_ONLY (Modules::serialize (soc);)
406
- CDS_JAVA_HEAP_ONLY (Modules::serialize_addmods_names (soc);)
407
440
CDS_JAVA_HEAP_ONLY (ClassLoaderDataShared::serialize (soc);)
408
441
409
442
LambdaFormInvokers::serialize (soc);
@@ -455,6 +488,7 @@ class VM_PopulateDumpSharedSpace : public VM_Operation {
455
488
log_info (cds)(" Dumping symbol table ..." );
456
489
SymbolTable::write_to_archive (symbols);
457
490
}
491
+ char * dump_early_read_only_tables ();
458
492
char * dump_read_only_tables ();
459
493
460
494
public:
@@ -494,17 +528,29 @@ class StaticArchiveBuilder : public ArchiveBuilder {
494
528
}
495
529
};
496
530
531
+ char * VM_PopulateDumpSharedSpace::dump_early_read_only_tables () {
532
+ ArchiveBuilder::OtherROAllocMark mark;
533
+
534
+ // Write module name into archive
535
+ CDS_JAVA_HEAP_ONLY (Modules::dump_main_module_name ();)
536
+ // Write module names from --add-modules into archive
537
+ CDS_JAVA_HEAP_ONLY (Modules::dump_addmods_names ();)
538
+
539
+ DumpRegion* ro_region = ArchiveBuilder::current ()->ro_region ();
540
+ char * start = ro_region->top ();
541
+ WriteClosure wc (ro_region);
542
+ MetaspaceShared::early_serialize (&wc);
543
+ return start;
544
+ }
545
+
497
546
char * VM_PopulateDumpSharedSpace::dump_read_only_tables () {
498
547
ArchiveBuilder::OtherROAllocMark mark;
499
548
500
549
SystemDictionaryShared::write_to_archive ();
501
550
502
551
// Write lambform lines into archive
503
552
LambdaFormInvokers::dump_static_archive_invokers ();
504
- // Write module name into archive
505
- CDS_JAVA_HEAP_ONLY (Modules::dump_main_module_name ();)
506
- // Write module names from --add-modules into archive
507
- CDS_JAVA_HEAP_ONLY (Modules::dump_addmods_names ();)
553
+
508
554
// Write the other data to the output array.
509
555
DumpRegion* ro_region = ArchiveBuilder::current ()->ro_region ();
510
556
char * start = ro_region->top ();
@@ -543,6 +589,7 @@ void VM_PopulateDumpSharedSpace::doit() {
543
589
log_info (cds)(" Make classes shareable" );
544
590
_builder.make_klasses_shareable ();
545
591
592
+ char * early_serialized_data = dump_early_read_only_tables ();
546
593
char * serialized_data = dump_read_only_tables ();
547
594
548
595
SystemDictionaryShared::adjust_lambda_proxy_class_dictionary ();
@@ -556,6 +603,7 @@ void VM_PopulateDumpSharedSpace::doit() {
556
603
assert (static_archive != nullptr , " SharedArchiveFile not set?" );
557
604
_map_info = new FileMapInfo (static_archive, true );
558
605
_map_info->populate_header (MetaspaceShared::core_region_alignment ());
606
+ _map_info->set_early_serialized_data (early_serialized_data);
559
607
_map_info->set_serialized_data (serialized_data);
560
608
_map_info->set_cloned_vtables (CppVtables::vtables_serialized_base ());
561
609
}
@@ -1473,6 +1521,14 @@ MapArchiveResult MetaspaceShared::map_archive(FileMapInfo* mapinfo, char* mapped
1473
1521
return MAP_ARCHIVE_OTHER_FAILURE;
1474
1522
}
1475
1523
1524
+ if (mapinfo->is_static ()) {
1525
+ // Currently, only static archive uses early serialized data.
1526
+ char * buffer = mapinfo->early_serialized_data ();
1527
+ intptr_t * array = (intptr_t *)buffer;
1528
+ ReadClosure rc (&array, (intptr_t )mapped_base_address);
1529
+ early_serialize (&rc);
1530
+ }
1531
+
1476
1532
mapinfo->set_is_mapped (true );
1477
1533
return MAP_ARCHIVE_SUCCESS;
1478
1534
}
@@ -1509,7 +1565,7 @@ void MetaspaceShared::initialize_shared_spaces() {
1509
1565
// shared string/symbol tables.
1510
1566
char * buffer = static_mapinfo->serialized_data ();
1511
1567
intptr_t * array = (intptr_t *)buffer;
1512
- ReadClosure rc (&array);
1568
+ ReadClosure rc (&array, ( intptr_t )SharedBaseAddress );
1513
1569
serialize (&rc);
1514
1570
1515
1571
// Finish up archived heap initialization. These must be
@@ -1526,7 +1582,7 @@ void MetaspaceShared::initialize_shared_spaces() {
1526
1582
FileMapInfo *dynamic_mapinfo = FileMapInfo::dynamic_info ();
1527
1583
if (dynamic_mapinfo != nullptr ) {
1528
1584
intptr_t * buffer = (intptr_t *)dynamic_mapinfo->serialized_data ();
1529
- ReadClosure rc (&buffer);
1585
+ ReadClosure rc (&buffer, ( intptr_t )SharedBaseAddress );
1530
1586
ArchiveBuilder::serialize_dynamic_archivable_items (&rc);
1531
1587
DynamicArchive::setup_array_klasses ();
1532
1588
dynamic_mapinfo->close ();
0 commit comments