Skip to content

Commit b524a74

Browse files
committed
8301106: Allow archived Java strings to be moved by GC
Reviewed-by: dholmes
1 parent 9643f65 commit b524a74

File tree

13 files changed

+237
-145
lines changed

13 files changed

+237
-145
lines changed

src/hotspot/share/cds/archiveHeapLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void ArchiveHeapLoader::fixup_regions() {
9191
} else if (_loading_failed) {
9292
fill_failed_loaded_heap();
9393
}
94-
if (is_fully_available()) {
94+
if (is_in_use()) {
9595
if (!MetaspaceShared::use_full_module_graph()) {
9696
// Need to remove all the archived java.lang.Module objects from HeapShared::roots().
9797
ClassLoaderDataShared::clear_archived_oops();
@@ -472,7 +472,7 @@ void ArchiveHeapLoader::finish_initialization() {
472472
verify_loaded_heap();
473473
}
474474
}
475-
if (is_fully_available()) {
475+
if (is_in_use()) {
476476
patch_native_pointers();
477477
}
478478
}

src/hotspot/share/cds/archiveHeapLoader.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ class ArchiveHeapLoader : AllStatic {
6565
NOT_CDS_JAVA_HEAP(return false;)
6666
}
6767

68-
static bool are_archived_strings_available() {
69-
return is_loaded() || closed_regions_mapped();
70-
}
71-
static bool are_archived_mirrors_available() {
72-
return is_fully_available();
73-
}
74-
static bool is_fully_available() {
68+
static bool is_in_use() {
7569
return is_loaded() || is_mapped();
7670
}
7771

src/hotspot/share/cds/archiveUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,16 @@ void ReadClosure::do_tag(int tag) {
316316
void ReadClosure::do_oop(oop *p) {
317317
if (UseCompressedOops) {
318318
narrowOop o = CompressedOops::narrow_oop_cast(nextPtr());
319-
if (CompressedOops::is_null(o) || !ArchiveHeapLoader::is_fully_available()) {
319+
if (CompressedOops::is_null(o) || !ArchiveHeapLoader::is_in_use()) {
320320
*p = nullptr;
321321
} else {
322322
assert(ArchiveHeapLoader::can_use(), "sanity");
323-
assert(ArchiveHeapLoader::is_fully_available(), "must be");
323+
assert(ArchiveHeapLoader::is_in_use(), "must be");
324324
*p = ArchiveHeapLoader::decode_from_archive(o);
325325
}
326326
} else {
327327
intptr_t dumptime_oop = nextPtr();
328-
if (dumptime_oop == 0 || !ArchiveHeapLoader::is_fully_available()) {
328+
if (dumptime_oop == 0 || !ArchiveHeapLoader::is_in_use()) {
329329
*p = nullptr;
330330
} else {
331331
assert(!ArchiveHeapLoader::is_loaded(), "ArchiveHeapLoader::can_load() is not supported for uncompessed oops");

src/hotspot/share/cds/heapShared.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ oop HeapShared::get_root(int index, bool clear) {
261261
void HeapShared::clear_root(int index) {
262262
assert(index >= 0, "sanity");
263263
assert(UseSharedSpaces, "must be");
264-
if (ArchiveHeapLoader::is_fully_available()) {
264+
if (ArchiveHeapLoader::is_in_use()) {
265265
if (log_is_enabled(Debug, cds, heap)) {
266266
oop old = roots()->obj_at(index);
267267
log_debug(cds, heap)("Clearing root %d: was " PTR_FORMAT, index, p2i(old));
@@ -378,8 +378,6 @@ void HeapShared::remove_scratch_objects(Klass* k) {
378378
}
379379

380380
void HeapShared::archive_java_mirrors() {
381-
init_seen_objects_table();
382-
383381
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
384382
BasicType bt = (BasicType)i;
385383
if (!is_reference_type(bt)) {
@@ -404,7 +402,7 @@ void HeapShared::archive_java_mirrors() {
404402
if (m != nullptr) {
405403
Klass* buffered_k = ArchiveBuilder::get_buffered_klass(orig_k);
406404
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");
408406
buffered_k->set_archived_java_mirror(append_root(m));
409407
ResourceMark rm;
410408
log_trace(cds, heap, mirror)(
@@ -425,8 +423,16 @@ void HeapShared::archive_java_mirrors() {
425423
}
426424
}
427425
}
426+
}
428427

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));
430436
}
431437

432438
void HeapShared::mark_native_pointers(oop orig_obj) {
@@ -501,7 +507,7 @@ void HeapShared::check_enum_obj(int level,
501507

502508
// See comments in HeapShared::check_enum_obj()
503509
bool HeapShared::initialize_enum_klass(InstanceKlass* k, TRAPS) {
504-
if (!ArchiveHeapLoader::is_fully_available()) {
510+
if (!ArchiveHeapLoader::is_in_use()) {
505511
return false;
506512
}
507513

@@ -556,22 +562,20 @@ void HeapShared::archive_objects(GrowableArray<MemRegion>* closed_regions,
556562
}
557563

558564
ArchiveHeapWriter::write(_pending_roots, closed_regions, open_regions, closed_bitmaps, open_bitmaps);
559-
StringTable::write_shared_table(_dumped_interned_strings);
560565
}
561566

562567
void HeapShared::copy_interned_strings() {
563568
init_seen_objects_table();
564569

565570
auto copier = [&] (oop s, bool value_ignored) {
566571
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);
575579
};
576580
_dumped_interned_strings->iterate_all(copier);
577581

@@ -589,10 +593,18 @@ void HeapShared::copy_closed_objects() {
589593
false /* is_full_module_graph */);
590594
}
591595

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+
592604
void HeapShared::copy_open_objects() {
593605
assert(HeapShared::can_write(), "must be");
594606

595-
archive_java_mirrors();
607+
copy_special_open_objects();
596608

597609
archive_object_subgraphs(open_archive_subgraph_entry_fields,
598610
false /* is_closed_archive */,
@@ -861,7 +873,7 @@ void HeapShared::serialize_root(SerializeClosure* soc) {
861873
assert(oopDesc::is_oop_or_null(roots_oop), "is oop");
862874
// Create an OopHandle only if we have actually mapped or loaded the roots
863875
if (roots_oop != nullptr) {
864-
assert(ArchiveHeapLoader::is_fully_available(), "must be");
876+
assert(ArchiveHeapLoader::is_in_use(), "must be");
865877
_roots = OopHandle(Universe::vm_global(), roots_oop);
866878
}
867879
} else {
@@ -921,7 +933,7 @@ static void verify_the_heap(Klass* k, const char* which) {
921933
// this case, we will not load the ArchivedKlassSubGraphInfoRecord and will clear its roots.
922934
void HeapShared::resolve_classes(JavaThread* current) {
923935
assert(UseSharedSpaces, "runtime only!");
924-
if (!ArchiveHeapLoader::is_fully_available()) {
936+
if (!ArchiveHeapLoader::is_in_use()) {
925937
return; // nothing to do
926938
}
927939
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)
954966

955967
void HeapShared::initialize_from_archived_subgraph(JavaThread* current, Klass* k) {
956968
JavaThread* THREAD = current;
957-
if (!ArchiveHeapLoader::is_fully_available()) {
969+
if (!ArchiveHeapLoader::is_in_use()) {
958970
return; // nothing to do
959971
}
960972

src/hotspot/share/cds/heapShared.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class HeapShared: AllStatic {
344344
static void mark_native_pointers(oop orig_obj);
345345
static bool has_been_archived(oop orig_obj);
346346
static void archive_java_mirrors();
347+
static void archive_strings();
347348
public:
348349
static void reset_archived_object_states(TRAPS);
349350
static void create_archived_object_cache() {
@@ -364,6 +365,7 @@ class HeapShared: AllStatic {
364365
GrowableArray<ArchiveHeapBitmapInfo>* open_bitmaps);
365366
static void copy_closed_objects();
366367
static void copy_open_objects();
368+
static void copy_special_open_objects();
367369

368370
static bool archive_reachable_objects_from(int level,
369371
KlassSubGraphInfo* subgraph_info,

src/hotspot/share/cds/metaspaceShared.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ void MetaspaceShared::preload_and_dump_impl(TRAPS) {
801801
log_info(cds)("Rewriting and linking classes: done");
802802

803803
#if INCLUDE_CDS_JAVA_HEAP
804+
StringTable::allocate_shared_strings_array(CHECK);
804805
ArchiveHeapWriter::init();
805806
if (use_full_module_graph()) {
806807
HeapShared::reset_archived_object_states(CHECK);
@@ -1437,9 +1438,6 @@ void MetaspaceShared::initialize_shared_spaces() {
14371438
ReadClosure rc(&array);
14381439
serialize(&rc);
14391440

1440-
// Initialize the run-time symbol table.
1441-
SymbolTable::create_table();
1442-
14431441
// Finish up archived heap initialization. These must be
14441442
// done after ReadClosure.
14451443
static_mapinfo->patch_heap_embedded_pointers();

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ void java_lang_Class::fixup_mirror(Klass* k, TRAPS) {
889889
}
890890

891891
if (k->is_shared() && k->has_archived_mirror_index()) {
892-
if (ArchiveHeapLoader::are_archived_mirrors_available()) {
892+
if (ArchiveHeapLoader::is_in_use()) {
893893
bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
894894
assert(present, "Missing archived mirror for %s", k->external_name());
895895
return;

0 commit comments

Comments
 (0)