@@ -742,6 +742,9 @@ void Metaspace::global_initialize() {
742
742
#if INCLUDE_CDS
743
743
// case (a)
744
744
if (UseSharedSpaces) {
745
+ if (!FLAG_IS_DEFAULT (CompressedClassSpaceBaseAddress)) {
746
+ log_warning (metaspace)(" CDS active - ignoring CompressedClassSpaceBaseAddress." );
747
+ }
745
748
MetaspaceShared::initialize_runtime_shared_and_meta_spaces ();
746
749
// If any of the archived space fails to map, UseSharedSpaces
747
750
// is reset to false.
@@ -757,23 +760,49 @@ void Metaspace::global_initialize() {
757
760
if (using_class_space () && !class_space_is_initialized ()) {
758
761
assert (!UseSharedSpaces, " CDS archive is not mapped at this point" );
759
762
760
- // case (b)
763
+ // case (b) (No CDS)
761
764
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
-
772
765
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
+ }
777
806
}
778
807
}
779
808
0 commit comments