Skip to content

Commit

Permalink
8297313: Refactor APIs for calculating address of CDS archive heap re…
Browse files Browse the repository at this point in the history
…gions

Reviewed-by: matsaave, ccheung
  • Loading branch information
iklam committed Dec 1, 2022
1 parent 0962957 commit 391599b
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 153 deletions.
36 changes: 30 additions & 6 deletions src/hotspot/share/cds/archiveHeapLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
bool ArchiveHeapLoader::_closed_regions_mapped = false;
bool ArchiveHeapLoader::_open_regions_mapped = false;
bool ArchiveHeapLoader::_is_loaded = false;

bool ArchiveHeapLoader::_narrow_oop_base_initialized = false;
address ArchiveHeapLoader::_narrow_oop_base;
int ArchiveHeapLoader::_narrow_oop_shift;

Expand All @@ -59,10 +61,26 @@ intx ArchiveHeapLoader::_runtime_offset_2 = 0;
intx ArchiveHeapLoader::_runtime_offset_3 = 0;
bool ArchiveHeapLoader::_loading_failed = false;

// Support for mapped heap (!UseCompressedOops only)
ptrdiff_t ArchiveHeapLoader::_runtime_delta = 0;
// Support for mapped heap.
bool ArchiveHeapLoader::_mapped_heap_relocation_initialized = false;
ptrdiff_t ArchiveHeapLoader::_mapped_heap_delta = 0;

// Every mapped region is offset by _mapped_heap_delta from its requested address.
// See FileMapInfo::heap_region_requested_address().
void ArchiveHeapLoader::init_mapped_heap_relocation(ptrdiff_t delta, int dumptime_oop_shift) {
assert(!_mapped_heap_relocation_initialized, "only once");
if (!UseCompressedOops) {
assert(dumptime_oop_shift == 0, "sanity");
}
assert(can_map(), "sanity");
init_narrow_oop_decoding(CompressedOops::base() + delta, dumptime_oop_shift);
_mapped_heap_delta = delta;
_mapped_heap_relocation_initialized = true;
}

void ArchiveHeapLoader::init_narrow_oop_decoding(address base, int shift) {
assert(!_narrow_oop_base_initialized, "only once");
_narrow_oop_base_initialized = true;
_narrow_oop_base = base;
_narrow_oop_shift = shift;
}
Expand Down Expand Up @@ -112,7 +130,7 @@ class PatchUncompressedEmbeddedPointers: public BitMapClosure {
oop* p = _start + offset;
intptr_t dumptime_oop = (intptr_t)((void*)*p);
assert(dumptime_oop != 0, "null oops should have been filtered out at dump time");
intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::runtime_delta();
intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::mapped_heap_delta();
RawAccess<IS_NOT_NULL>::oop_store(p, cast_to_oop(runtime_oop));
return true;
}
Expand Down Expand Up @@ -192,6 +210,10 @@ void ArchiveHeapLoader::init_loaded_heap_relocation(LoadedArchiveHeapRegion* loa
}

bool ArchiveHeapLoader::can_load() {
if (!UseCompressedOops) {
// Pointer relocation for uncompressed oops is unimplemented.
return false;
}
return Universe::heap()->can_load_archived_objects();
}

Expand Down Expand Up @@ -227,13 +249,13 @@ class PatchLoadedRegionPointers: public BitMapClosure {
}

bool do_bit(size_t offset) {
assert(UseCompressedOops, "PatchLoadedRegionPointers for uncompressed oops is unimplemented");
narrowOop* p = _start + offset;
narrowOop v = *p;
assert(!CompressedOops::is_null(v), "null oops should have been filtered out at dump time");
uintptr_t o = cast_from_oop<uintptr_t>(ArchiveHeapLoader::decode_from_archive(v));
assert(_base_0 <= o && o < _top, "must be");


// We usually have only 2 regions for the default archive. Use template to avoid unnecessary comparisons.
if (NUM_LOADED_REGIONS > 3 && o >= _base_3) {
o += _offset_3;
Expand Down Expand Up @@ -264,7 +286,7 @@ int ArchiveHeapLoader::init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHe
LoadedArchiveHeapRegion* ri = &loaded_regions[num_loaded_regions++];
ri->_region_index = i;
ri->_region_size = r->used();
ri->_dumptime_base = (uintptr_t)mapinfo->start_address_as_decoded_from_archive(r);
ri->_dumptime_base = (uintptr_t)mapinfo->heap_region_dumptime_address(r);
}
}

Expand Down Expand Up @@ -346,6 +368,7 @@ bool ArchiveHeapLoader::load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegi
}

bool ArchiveHeapLoader::load_heap_regions(FileMapInfo* mapinfo) {
assert(UseCompressedOops, "loaded heap for !UseCompressedOops is unimplemented");
init_narrow_oop_decoding(mapinfo->narrow_oop_base(), mapinfo->narrow_oop_shift());

LoadedArchiveHeapRegion loaded_regions[MetaspaceShared::max_num_heap_regions];
Expand Down Expand Up @@ -386,7 +409,8 @@ class VerifyLoadedHeapEmbeddedPointers: public BasicOopIterateClosure {
}
}
virtual void do_oop(oop* p) {
ShouldNotReachHere();
// Uncompressed oops are not supported by loaded heaps.
Unimplemented();
}
};

Expand Down
23 changes: 11 additions & 12 deletions src/hotspot/share/cds/archiveHeapLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class ArchiveHeapLoader : AllStatic {
return is_loaded() || is_mapped();
}

static ptrdiff_t runtime_delta() {
assert(!UseCompressedOops, "must be");
CDS_JAVA_HEAP_ONLY(return _runtime_delta;)
static ptrdiff_t mapped_heap_delta() {
CDS_JAVA_HEAP_ONLY(assert(!is_loaded(), "must be"));
CDS_JAVA_HEAP_ONLY(assert(_mapped_heap_relocation_initialized, "must be"));
CDS_JAVA_HEAP_ONLY(return _mapped_heap_delta;)
NOT_CDS_JAVA_HEAP_RETURN_(0L);
}

Expand All @@ -102,14 +103,13 @@ class ArchiveHeapLoader : AllStatic {
// function instead.
inline static oop decode_from_archive(narrowOop v) NOT_CDS_JAVA_HEAP_RETURN_(NULL);

static void init_narrow_oop_decoding(address base, int shift) NOT_CDS_JAVA_HEAP_RETURN;

static void patch_embedded_pointers(MemRegion region, address oopmap,
size_t oopmap_in_bits) NOT_CDS_JAVA_HEAP_RETURN;

static void fixup_regions() NOT_CDS_JAVA_HEAP_RETURN;

#if INCLUDE_CDS_JAVA_HEAP
static void init_mapped_heap_relocation(ptrdiff_t delta, int dumptime_oop_shift);
private:
static bool _closed_regions_mapped;
static bool _open_regions_mapped;
Expand All @@ -132,12 +132,16 @@ class ArchiveHeapLoader : AllStatic {
static bool _loading_failed;

// UseCompressedOops only: Used by decode_from_archive
static bool _narrow_oop_base_initialized;
static address _narrow_oop_base;
static int _narrow_oop_shift;

// !UseCompressedOops only: used to relocate pointers to the archived objects
static ptrdiff_t _runtime_delta;
// is_mapped() only: the mapped address of each region is offset by this amount from
// their requested address.
static ptrdiff_t _mapped_heap_delta;
static bool _mapped_heap_relocation_initialized;

static void init_narrow_oop_decoding(address base, int shift);
static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
MemRegion& archive_space);
static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
Expand All @@ -161,11 +165,6 @@ class ArchiveHeapLoader : AllStatic {
static void assert_in_loaded_heap(uintptr_t o) {
assert(is_in_loaded_heap(o), "must be");
}

static void set_runtime_delta(ptrdiff_t delta) {
assert(!UseCompressedOops, "must be");
_runtime_delta = delta;
}
#endif // INCLUDE_CDS_JAVA_HEAP

};
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/cds/archiveHeapLoader.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

inline oop ArchiveHeapLoader::decode_from_archive(narrowOop v) {
assert(!CompressedOops::is_null(v), "narrow oop value can never be zero");
assert(_narrow_oop_base_initialized, "relocation information must have been initialized");
uintptr_t p = ((uintptr_t)_narrow_oop_base) + ((uintptr_t)v << _narrow_oop_shift);
if (p >= _dumptime_base_0) {
assert(p < _dumptime_top, "must be");
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/cds/archiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ void ReadClosure::do_oop(oop *p) {
if (dumptime_oop == 0 || !ArchiveHeapLoader::is_fully_available()) {
*p = NULL;
} else {
intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::runtime_delta();
assert(!ArchiveHeapLoader::is_loaded(), "ArchiveHeapLoader::can_load() is not supported for uncompessed oops");
intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::mapped_heap_delta();
*p = cast_to_oop(runtime_oop);
}
}
Expand Down

1 comment on commit 391599b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.