Skip to content

Commit afd5921

Browse files
committed
8298610: Refactor archiving of ConstantPool::resolved_references()
Reviewed-by: dholmes, ccheung
1 parent 937ba1c commit afd5921

File tree

6 files changed

+37
-27
lines changed

6 files changed

+37
-27
lines changed

src/hotspot/share/cds/heapShared.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "utilities/copy.hpp"
6262
#if INCLUDE_G1GC
6363
#include "gc/g1/g1CollectedHeap.hpp"
64+
#include "gc/g1/heapRegion.hpp"
6465
#endif
6566

6667
#if INCLUDE_CDS_JAVA_HEAP
@@ -289,6 +290,15 @@ void HeapShared::clear_root(int index) {
289290
}
290291
}
291292

293+
bool HeapShared::is_too_large_to_archive(oop o) {
294+
// TODO: To make the CDS heap mappable for all collectors, this function should
295+
// reject objects that may be too large for *any* collector.
296+
assert(UseG1GC, "implementation limitation");
297+
size_t sz = align_up(o->size() * HeapWordSize, ObjectAlignmentInBytes);
298+
size_t max = /*G1*/HeapRegion::min_region_size_in_words() * HeapWordSize;
299+
return (sz > max);
300+
}
301+
292302
oop HeapShared::archive_object(oop obj) {
293303
assert(DumpSharedSpaces, "dump-time only");
294304

@@ -443,7 +453,14 @@ void HeapShared::archive_java_mirrors() {
443453
// archive the resolved_referenes array
444454
if (buffered_k->is_instance_klass()) {
445455
InstanceKlass* ik = InstanceKlass::cast(buffered_k);
446-
ik->constants()->archive_resolved_references();
456+
oop rr = ik->constants()->prepare_resolved_references_for_archiving();
457+
if (rr != nullptr && !is_too_large_to_archive(rr)) {
458+
oop archived_obj = HeapShared::archive_reachable_objects_from(1, _default_subgraph_info, rr,
459+
/*is_closed_archive=*/false);
460+
assert(archived_obj != NULL, "already checked not too large to archive");
461+
int root_index = append_root(archived_obj);
462+
ik->constants()->cache()->set_archived_references(root_index);
463+
}
447464
}
448465
}
449466
}

src/hotspot/share/cds/heapShared.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ class HeapShared: AllStatic {
371371
}
372372
}
373373

374+
static bool is_too_large_to_archive(oop o);
374375
static oop find_archived_heap_object(oop obj);
375376
static oop archive_object(oop obj);
376377

src/hotspot/share/oops/constantPool.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -267,50 +267,42 @@ void ConstantPool::klass_at_put(int class_index, Klass* k) {
267267
}
268268

269269
#if INCLUDE_CDS_JAVA_HEAP
270-
// Archive the resolved references
271-
void ConstantPool::archive_resolved_references() {
270+
// Returns the _resolved_reference array after removing unarchivable items from it.
271+
// Returns nullptr if this class is not supported, or _resolved_reference doesn't exist.
272+
objArrayOop ConstantPool::prepare_resolved_references_for_archiving() {
272273
if (_cache == NULL) {
273-
return; // nothing to do
274+
return nullptr; // nothing to do
274275
}
275276

276277
InstanceKlass *ik = pool_holder();
277278
if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
278279
ik->is_shared_app_class())) {
279280
// Archiving resolved references for classes from non-builtin loaders
280281
// is not yet supported.
281-
return;
282+
return nullptr;
282283
}
283284

284285
objArrayOop rr = resolved_references();
285-
Array<u2>* ref_map = reference_map();
286-
if (rr != NULL) {
286+
if (rr != nullptr) {
287+
Array<u2>* ref_map = reference_map();
287288
int ref_map_len = ref_map == NULL ? 0 : ref_map->length();
288289
int rr_len = rr->length();
289290
for (int i = 0; i < rr_len; i++) {
290291
oop obj = rr->obj_at(i);
291-
rr->obj_at_put(i, NULL);
292+
rr->obj_at_put(i, nullptr);
292293
if (obj != NULL && i < ref_map_len) {
293294
int index = object_to_cp_index(i);
294295
if (tag_at(index).is_string()) {
295-
oop archived_string = HeapShared::find_archived_heap_object(obj);
296-
// Update the reference to point to the archived copy
297-
// of this string.
298-
// If the string is too large to archive, NULL is
299-
// stored into rr. At run time, string_at_impl() will create and intern
300-
// the string.
301-
rr->obj_at_put(i, archived_string);
296+
assert(java_lang_String::is_instance(obj), "must be");
297+
typeArrayOop value = java_lang_String::value_no_keepalive(obj);
298+
if (!HeapShared::is_too_large_to_archive(value)) {
299+
rr->obj_at_put(i, obj);
300+
}
302301
}
303302
}
304303
}
305-
306-
oop archived = HeapShared::archive_object(rr);
307-
// If the resolved references array is not archived (too large),
308-
// the 'archived' object is NULL. No need to explicitly check
309-
// the return value of archive_object() here. At runtime, the
310-
// resolved references will be created using the normal process
311-
// when there is no archived value.
312-
_cache->set_archived_references(archived);
313304
}
305+
return rr;
314306
}
315307

316308
void ConstantPool::add_dumped_interned_strings() {

src/hotspot/share/oops/constantPool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ class ConstantPool : public Metadata {
697697

698698
#if INCLUDE_CDS
699699
// CDS support
700-
void archive_resolved_references() NOT_CDS_JAVA_HEAP_RETURN;
700+
objArrayOop prepare_resolved_references_for_archiving() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
701701
void add_dumped_interned_strings() NOT_CDS_JAVA_HEAP_RETURN;
702702
bool maybe_archive_resolved_klass_at(int cp_index);
703703
void remove_unshareable_info();

src/hotspot/share/oops/cpCache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,9 @@ void ConstantPoolCache::clear_archived_references() {
770770
}
771771
}
772772

773-
void ConstantPoolCache::set_archived_references(oop o) {
773+
void ConstantPoolCache::set_archived_references(int root_index) {
774774
assert(DumpSharedSpaces, "called only during runtime");
775-
_archived_references_index = HeapShared::append_root(o);
775+
_archived_references_index = root_index;
776776
}
777777
#endif
778778

src/hotspot/share/oops/cpCache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class ConstantPoolCache: public MetaspaceObj {
444444
MetaspaceObj::Type type() const { return ConstantPoolCacheType; }
445445

446446
oop archived_references() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
447-
void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
447+
void set_archived_references(int root_index) NOT_CDS_JAVA_HEAP_RETURN;
448448
void clear_archived_references() NOT_CDS_JAVA_HEAP_RETURN;
449449

450450
inline objArrayOop resolved_references();

0 commit comments

Comments
 (0)