JDK-8296155 : Simplify CDS heap region address calculation
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2022-10-31
  • Updated: 2022-11-21
  • Resolved: 2022-11-17
Related Reports
Relates :  
Description
The runtime location of a CDS heap region is calculated using this field:

https://github.com/openjdk/jdk/blob/4999f2cb164743ebf4badd3848a862609528dde3/src/hotspot/share/include/cds.h#L53-L55

typedef struct CDSFileMapRegion {
  size_t  _mapping_offset;    // This region should be mapped at this offset from the base address
                              // - for non-heap regions, the base address is SharedBaseAddress
                              // - for heap regions, the base address is the compressed oop encoding base

using very convoluted code:

https://github.com/openjdk/jdk/blob/4999f2cb164743ebf4badd3848a862609528dde3/src/hotspot/share/cds/filemap.cpp#L2063-L2071

address FileMapInfo::decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode) {
  size_t offset = spc->mapping_offset();
  narrowOop n = CompressedOops::narrow_oop_cast(offset);
  if (with_current_oop_encoding_mode) {
    return cast_from_oop<address>(CompressedOops::decode_raw_not_null(n));
  } else {
    return cast_from_oop<address>(ArchiveHeapLoader::decode_from_archive(n));
  }
}

=========================
This can be greatly simplified:

For each heap region, save its dumptime address in CDSFileMapRegion.

At runtime, the address for this region = (dumptime address) + ArchiveHeapLoader::runtime_delta();


Comments
After further consideration, this PR is not the right way to do it. If we remember the absolute address of the heap regions during dump time, it may cause unnecessary relocation at run time. We should keep using CDSFileMapRegion::_mapping_offset to encode the requested address for the heap regions. However, the code should be cleaned up and documentation shoukld be corrected. I'll open a new RFE. Closing this RFE as will-not-fix.
17-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10923 Date: 2022-10-31 22:54:24 +0000
31-10-2022