< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page
@@ -1156,23 +1156,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
< prev index next >