The following code in Meatspace::global_initialize() limits cdc_total size + compressed_class_space_size to less than 4G during dump time (on 64 platforms with compressed class pointer enabled). Thus, the narrow_klass_shift is always 0 when CDS is enabled. That is not necessary.
void Metaspace::global_initialize() {
...
#ifdef _LP64
if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
vm_exit_during_initialization("Unable to dump shared archive.",
err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
"klass limit: " UINT64_FORMAT, cds_total, compressed_class_space_size(),
cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
}
// Set the compressed klass pointer base so that decoding of these pointers works
// properly when creating the shared archive.
assert(UseCompressedOops && UseCompressedClassPointers,
"UseCompressedOops and UseCompressedClassPointers must be set");
Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
log_develop_trace(gc, metaspace)("Setting_narrow_klass_base to Address: " PTR_FORMAT,
p2i(_space_list->current_virtual_space()->bottom()));
Universe::set_narrow_klass_shift(0);
#endif // _LP64
Metaspace::set_narrow_klass_base_and_shift() takes both CDS shared space and compressed class space into account when setting the narrow klass base and shift at runtime (when shift is enabled). CDS archives dump time narrow klass base and shift. If the narrow klass base and shift are different and runtime, CDS invalidates the archived narrow klass pointers (currently only from shared strings by skipping the shared string data). The dump time limit can be removed.
void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
// Figure out the narrow_klass_base and the narrow_klass_shift. The
// narrow_klass_base is the lower of the metaspace base and the cds base
// (if cds is enabled). The narrow_klass_shift depends on the distance
// between the lower base and higher address.
address lower_base;
address higher_address;
#if INCLUDE_CDS
if (UseSharedSpaces) {
higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
(address)(metaspace_base + compressed_class_space_size()));
lower_base = MIN2(metaspace_base, cds_base);
} else
#endif
{
higher_address = metaspace_base + compressed_class_space_size();
lower_base = metaspace_base;
uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
// If compressed class space fits in lower 32G, we don't need a base.
if (higher_address <= (address)klass_encoding_max) {
lower_base = 0; // Effectively lower base is zero.
}
}
Universe::set_narrow_klass_base(lower_base);
if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
Universe::set_narrow_klass_shift(0);
} else {
assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
}
}
void Metaspace::global_initialize() {
...
#ifdef _LP64
if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
vm_exit_during_initialization("Unable to dump shared archive.",
err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
"klass limit: " UINT64_FORMAT, cds_total, compressed_class_space_size(),
cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
}
// Set the compressed klass pointer base so that decoding of these pointers works
// properly when creating the shared archive.
assert(UseCompressedOops && UseCompressedClassPointers,
"UseCompressedOops and UseCompressedClassPointers must be set");
Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
log_develop_trace(gc, metaspace)("Setting_narrow_klass_base to Address: " PTR_FORMAT,
p2i(_space_list->current_virtual_space()->bottom()));
Universe::set_narrow_klass_shift(0);
#endif // _LP64
Metaspace::set_narrow_klass_base_and_shift() takes both CDS shared space and compressed class space into account when setting the narrow klass base and shift at runtime (when shift is enabled). CDS archives dump time narrow klass base and shift. If the narrow klass base and shift are different and runtime, CDS invalidates the archived narrow klass pointers (currently only from shared strings by skipping the shared string data). The dump time limit can be removed.
void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
// Figure out the narrow_klass_base and the narrow_klass_shift. The
// narrow_klass_base is the lower of the metaspace base and the cds base
// (if cds is enabled). The narrow_klass_shift depends on the distance
// between the lower base and higher address.
address lower_base;
address higher_address;
#if INCLUDE_CDS
if (UseSharedSpaces) {
higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
(address)(metaspace_base + compressed_class_space_size()));
lower_base = MIN2(metaspace_base, cds_base);
} else
#endif
{
higher_address = metaspace_base + compressed_class_space_size();
lower_base = metaspace_base;
uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
// If compressed class space fits in lower 32G, we don't need a base.
if (higher_address <= (address)klass_encoding_max) {
lower_base = 0; // Effectively lower base is zero.
}
}
Universe::set_narrow_klass_base(lower_base);
if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
Universe::set_narrow_klass_shift(0);
} else {
assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
}
}
- duplicates
-
JDK-8072061 Automatically determine optimal sizes for the CDS regions
-
- Closed
-
- relates to
-
JDK-8174986 CDS archived java heap region may not compatible with AOT
-
- Resolved
-
-
JDK-8072061 Automatically determine optimal sizes for the CDS regions
-
- Closed
-