Skip to content

Commit c9dbc4f

Browse files
committed
8266891: Provide a switch to force the class space to a specific location
Reviewed-by: iklam, coleenp
1 parent 2cc1977 commit c9dbc4f

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

src/hotspot/share/memory/metaspace.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ void Metaspace::global_initialize() {
742742
#if INCLUDE_CDS
743743
// case (a)
744744
if (UseSharedSpaces) {
745+
if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
746+
log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
747+
}
745748
MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
746749
// If any of the archived space fails to map, UseSharedSpaces
747750
// is reset to false.
@@ -757,23 +760,49 @@ void Metaspace::global_initialize() {
757760
if (using_class_space() && !class_space_is_initialized()) {
758761
assert(!UseSharedSpaces, "CDS archive is not mapped at this point");
759762

760-
// case (b)
763+
// case (b) (No CDS)
761764
ReservedSpace rs;
762-
763-
// If UseCompressedOops=1 and the java heap has been placed in coops-friendly
764-
// territory, i.e. its base is under 32G, then we attempt to place ccs
765-
// right above the java heap.
766-
// Otherwise the lower 32G are still free. We try to place ccs at the lowest
767-
// allowed mapping address.
768-
address base = (UseCompressedOops && (uint64_t)CompressedOops::base() < OopEncodingHeapMax) ?
769-
CompressedOops::end() : (address)HeapBaseMinAddress;
770-
base = align_up(base, Metaspace::reserve_alignment());
771-
772765
const size_t size = align_up(CompressedClassSpaceSize, Metaspace::reserve_alignment());
773-
if (base != NULL) {
774-
if (CompressedKlassPointers::is_valid_base(base)) {
775-
rs = ReservedSpace(size, Metaspace::reserve_alignment(),
776-
os::vm_page_size(), (char*)base);
766+
address base = NULL;
767+
768+
// If CompressedClassSpaceBaseAddress is set, we attempt to force-map class space to
769+
// the given address. This is a debug-only feature aiding tests. Due to the ASLR lottery
770+
// this may fail, in which case the VM will exit after printing an appropiate message.
771+
// Tests using this switch should cope with that.
772+
if (CompressedClassSpaceBaseAddress != 0) {
773+
base = (address)CompressedClassSpaceBaseAddress;
774+
if (!is_aligned(base, Metaspace::reserve_alignment())) {
775+
vm_exit_during_initialization(
776+
err_msg("CompressedClassSpaceBaseAddress=" PTR_FORMAT " invalid "
777+
"(must be aligned to " SIZE_FORMAT_HEX ").",
778+
CompressedClassSpaceBaseAddress, Metaspace::reserve_alignment()));
779+
}
780+
rs = ReservedSpace(size, Metaspace::reserve_alignment(),
781+
os::vm_page_size() /* large */, (char*)base);
782+
if (rs.is_reserved()) {
783+
log_info(metaspace)("Sucessfully forced class space address to " PTR_FORMAT, p2i(base));
784+
} else {
785+
vm_exit_during_initialization(
786+
err_msg("CompressedClassSpaceBaseAddress=" PTR_FORMAT " given, but reserving class space failed.",
787+
CompressedClassSpaceBaseAddress));
788+
}
789+
}
790+
791+
if (!rs.is_reserved()) {
792+
// If UseCompressedOops=1 and the java heap has been placed in coops-friendly
793+
// territory, i.e. its base is under 32G, then we attempt to place ccs
794+
// right above the java heap.
795+
// Otherwise the lower 32G are still free. We try to place ccs at the lowest
796+
// allowed mapping address.
797+
base = (UseCompressedOops && (uint64_t)CompressedOops::base() < OopEncodingHeapMax) ?
798+
CompressedOops::end() : (address)HeapBaseMinAddress;
799+
base = align_up(base, Metaspace::reserve_alignment());
800+
801+
if (base != NULL) {
802+
if (CompressedKlassPointers::is_valid_base(base)) {
803+
rs = ReservedSpace(size, Metaspace::reserve_alignment(),
804+
os::vm_page_size(), (char*)base);
805+
}
777806
}
778807
}
779808

src/hotspot/share/runtime/globals.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,10 @@ const intx ObjectAlignmentInBytes = 8;
14661466
"class pointers are used") \
14671467
range(1*M, 3*G) \
14681468
\
1469+
develop(size_t, CompressedClassSpaceBaseAddress, 0, \
1470+
"Force the class space to be allocated at this address or " \
1471+
"fails VM initialization (requires -Xshare=off.") \
1472+
\
14691473
product(ccstr, MetaspaceReclaimPolicy, "balanced", \
14701474
"options: balanced, aggressive, none") \
14711475
\

0 commit comments

Comments
 (0)