< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page
@@ -84,10 +84,11 @@
  #include "runtime/vmThread.hpp"
  #include "sanitizers/leak.hpp"
  #include "utilities/align.hpp"
  #include "utilities/bitMap.inline.hpp"
  #include "utilities/defaultStream.hpp"
+ #include "utilities/macros.hpp"
  #include "utilities/ostream.hpp"
  #include "utilities/resourceHash.hpp"
  
  ReservedSpace MetaspaceShared::_symbol_rs;
  VirtualSpace MetaspaceShared::_symbol_vs;

@@ -1156,23 +1157,29 @@
            // Set up compressed Klass pointer encoding: the encoding range must
            //  cover both archive and class space.
            address cds_base = (address)static_mapinfo->mapped_base();
            address ccs_end = (address)class_space_rs.end();
            assert(ccs_end > cds_base, "Sanity check");
- #if INCLUDE_CDS_JAVA_HEAP
-           // We archived objects with pre-computed narrow Klass id. Set up encoding such that these Ids stay valid.
-           address precomputed_narrow_klass_base = cds_base;
-           const int precomputed_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
-           CompressedKlassPointers::initialize_for_given_encoding(
-             cds_base, ccs_end - cds_base, // Klass range
-             precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveHeapWriter
-             );
- #else
-           CompressedKlassPointers::initialize (
-             cds_base, ccs_end - cds_base // Klass range
+           if (INCLUDE_CDS_JAVA_HEAP || UseCompactObjectHeaders) {
+             // The CDS archive may contain narrow Klass IDs that were precomputed at archive generation time:
+             // - every archived java object header (only if INCLUDE_CDS_JAVA_HEAP)
+             // - every archived Klass' prototype   (only if +UseCompactObjectHeaders)
+             //
+             // In order for those IDs to still be valid, we need to dictate base and shift: base should be the
+             // mapping start, shift the shift used at archive generation time.
+             address precomputed_narrow_klass_base = cds_base;
+             const int precomputed_narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
+             CompressedKlassPointers::initialize_for_given_encoding(
+               cds_base, ccs_end - cds_base, // Klass range
+               precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveBuilder
              );
- #endif // INCLUDE_CDS_JAVA_HEAP
+           } else {
+             // Let JVM freely chose encoding base and shift
+             CompressedKlassPointers::initialize (
+               cds_base, ccs_end - cds_base // Klass range
+               );
+           }
            // map_or_load_heap_region() compares the current narrow oop and klass encodings
            // with the archived ones, so it must be done after all encodings are determined.
            static_mapinfo->map_or_load_heap_region();
          }
  #endif // _LP64

@@ -1223,11 +1230,11 @@
  //  use_archive_base_addr address is false, this base address is determined
  //  by the platform.
  //
  // If UseCompressedClassPointers=1, the range encompassing both spaces will be
  //  suitable to en/decode narrow Klass pointers: the base will be valid for
- //  encoding, the range [Base, End) not surpass KlassEncodingMetaspaceMax.
+ //  encoding, the range [Base, End) and not surpass the max. range for that encoding.
  //
  // Return:
  //
  // - On success:
  //    - total_space_rs will be reserved as whole for archive_space_rs and
< prev index next >