@@ -261,7 +261,7 @@ oop HeapShared::get_root(int index, bool clear) {
261
261
void HeapShared::clear_root (int index) {
262
262
assert (index >= 0 , " sanity" );
263
263
assert (UseSharedSpaces, " must be" );
264
- if (ArchiveHeapLoader::is_fully_available ()) {
264
+ if (ArchiveHeapLoader::is_in_use ()) {
265
265
if (log_is_enabled (Debug, cds, heap)) {
266
266
oop old = roots ()->obj_at (index );
267
267
log_debug (cds, heap)(" Clearing root %d: was " PTR_FORMAT, index , p2i (old));
@@ -378,8 +378,6 @@ void HeapShared::remove_scratch_objects(Klass* k) {
378
378
}
379
379
380
380
void HeapShared::archive_java_mirrors () {
381
- init_seen_objects_table ();
382
-
383
381
for (int i = T_BOOLEAN; i < T_VOID+1 ; i++) {
384
382
BasicType bt = (BasicType)i;
385
383
if (!is_reference_type (bt)) {
@@ -404,7 +402,7 @@ void HeapShared::archive_java_mirrors() {
404
402
if (m != nullptr ) {
405
403
Klass* buffered_k = ArchiveBuilder::get_buffered_klass (orig_k);
406
404
bool success = archive_reachable_objects_from (1 , _default_subgraph_info, m, /* is_closed_archive=*/ false );
407
- guarantee (success, " scratch mirrors should not point to any unachivable objects" );
405
+ guarantee (success, " scratch mirrors must point to only archivable objects" );
408
406
buffered_k->set_archived_java_mirror (append_root (m));
409
407
ResourceMark rm;
410
408
log_trace (cds, heap, mirror)(
@@ -425,8 +423,16 @@ void HeapShared::archive_java_mirrors() {
425
423
}
426
424
}
427
425
}
426
+ }
428
427
429
- delete_seen_objects_table ();
428
+ void HeapShared::archive_strings () {
429
+ oop shared_strings_array = StringTable::init_shared_table (_dumped_interned_strings);
430
+ bool success = archive_reachable_objects_from (1 , _default_subgraph_info, shared_strings_array, /* is_closed_archive=*/ false );
431
+ // We must succeed because:
432
+ // - _dumped_interned_strings do not contain any large strings.
433
+ // - StringTable::init_shared_table() doesn't create any large arrays.
434
+ assert (success, " shared strings array must not point to arrays or strings that are too large to archive" );
435
+ StringTable::set_shared_strings_array_index (append_root (shared_strings_array));
430
436
}
431
437
432
438
void HeapShared::mark_native_pointers (oop orig_obj) {
@@ -501,7 +507,7 @@ void HeapShared::check_enum_obj(int level,
501
507
502
508
// See comments in HeapShared::check_enum_obj()
503
509
bool HeapShared::initialize_enum_klass (InstanceKlass* k, TRAPS) {
504
- if (!ArchiveHeapLoader::is_fully_available ()) {
510
+ if (!ArchiveHeapLoader::is_in_use ()) {
505
511
return false ;
506
512
}
507
513
@@ -556,22 +562,20 @@ void HeapShared::archive_objects(GrowableArray<MemRegion>* closed_regions,
556
562
}
557
563
558
564
ArchiveHeapWriter::write (_pending_roots, closed_regions, open_regions, closed_bitmaps, open_bitmaps);
559
- StringTable::write_shared_table (_dumped_interned_strings);
560
565
}
561
566
562
567
void HeapShared::copy_interned_strings () {
563
568
init_seen_objects_table ();
564
569
565
570
auto copier = [&] (oop s, bool value_ignored) {
566
571
assert (s != nullptr , " sanity" );
567
- if (!ArchiveHeapWriter::is_string_too_large_to_archive (s)) {
568
- bool success = archive_reachable_objects_from (1 , _default_subgraph_info,
569
- s, /* is_closed_archive=*/ true );
570
- assert (success, " must be" );
571
- // Prevent string deduplication from changing the value field to
572
- // something not in the archive.
573
- java_lang_String::set_deduplication_forbidden (s);
574
- }
572
+ assert (!ArchiveHeapWriter::is_string_too_large_to_archive (s), " large strings must have been filtered" );
573
+ bool success = archive_reachable_objects_from (1 , _default_subgraph_info,
574
+ s, /* is_closed_archive=*/ true );
575
+ assert (success, " string must be short enough to be archived" );
576
+ // Prevent string deduplication from changing the value field to
577
+ // something not in the archive.
578
+ java_lang_String::set_deduplication_forbidden (s);
575
579
};
576
580
_dumped_interned_strings->iterate_all (copier);
577
581
@@ -589,10 +593,18 @@ void HeapShared::copy_closed_objects() {
589
593
false /* is_full_module_graph */ );
590
594
}
591
595
596
+ void HeapShared::copy_special_open_objects () {
597
+ // Archive special objects that do not belong to any subgraphs
598
+ init_seen_objects_table ();
599
+ archive_java_mirrors ();
600
+ archive_strings ();
601
+ delete_seen_objects_table ();
602
+ }
603
+
592
604
void HeapShared::copy_open_objects () {
593
605
assert (HeapShared::can_write (), " must be" );
594
606
595
- archive_java_mirrors ();
607
+ copy_special_open_objects ();
596
608
597
609
archive_object_subgraphs (open_archive_subgraph_entry_fields,
598
610
false /* is_closed_archive */ ,
@@ -861,7 +873,7 @@ void HeapShared::serialize_root(SerializeClosure* soc) {
861
873
assert (oopDesc::is_oop_or_null (roots_oop), " is oop" );
862
874
// Create an OopHandle only if we have actually mapped or loaded the roots
863
875
if (roots_oop != nullptr ) {
864
- assert (ArchiveHeapLoader::is_fully_available (), " must be" );
876
+ assert (ArchiveHeapLoader::is_in_use (), " must be" );
865
877
_roots = OopHandle (Universe::vm_global (), roots_oop);
866
878
}
867
879
} else {
@@ -921,7 +933,7 @@ static void verify_the_heap(Klass* k, const char* which) {
921
933
// this case, we will not load the ArchivedKlassSubGraphInfoRecord and will clear its roots.
922
934
void HeapShared::resolve_classes (JavaThread* current) {
923
935
assert (UseSharedSpaces, " runtime only!" );
924
- if (!ArchiveHeapLoader::is_fully_available ()) {
936
+ if (!ArchiveHeapLoader::is_in_use ()) {
925
937
return ; // nothing to do
926
938
}
927
939
resolve_classes_for_subgraphs (current, closed_archive_subgraph_entry_fields);
@@ -954,7 +966,7 @@ void HeapShared::resolve_classes_for_subgraph_of(JavaThread* current, Klass* k)
954
966
955
967
void HeapShared::initialize_from_archived_subgraph (JavaThread* current, Klass* k) {
956
968
JavaThread* THREAD = current;
957
- if (!ArchiveHeapLoader::is_fully_available ()) {
969
+ if (!ArchiveHeapLoader::is_in_use ()) {
958
970
return ; // nothing to do
959
971
}
960
972
0 commit comments