< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page
@@ -159,12 +159,15 @@
    }
    SystemDictionaryShared::update_archived_mirror_native_pointers();
  }
  
  unsigned HeapShared::oop_hash(oop const& p) {
-   unsigned hash = (unsigned)p->identity_hash();
-   return hash;
+   // We are at a safepoint, so the object won't move. It's OK to use its
+   // address as the hashcode.
+   // We can't use p->identity_hash() as it's not available for primitive oops.
+   assert_at_safepoint();
+   return (unsigned)(p2i(p) >> LogBytesPerWord);
  }
  
  static void reset_states(oop obj, TRAPS) {
    Handle h_obj(THREAD, obj);
    InstanceKlass* klass = InstanceKlass::cast(obj->klass());

@@ -294,16 +297,18 @@
      //
      // We need to retain the identity_hash, because it may have been used by some hashtables
      // in the shared heap. This also has the side effect of pre-initializing the
      // identity_hash for all shared objects, so they are less likely to be written
      // into during run time, increasing the potential of memory sharing.
-     int hash_original = obj->identity_hash();
-     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));
-     assert(archived_oop->mark().is_unlocked(), "sanity");
+     if (!(EnableValhalla && obj->mark().is_inline_type())) {
+       int hash_original = obj->identity_hash();
+       archived_oop->set_mark(archived_oop->klass()->prototype_header().copy_set_hash(hash_original));
+       assert(archived_oop->mark().is_unlocked(), "sanity");
  
-     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
-     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
+       DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
+       assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
+     }
  
      ArchivedObjectCache* cache = archived_object_cache();
      cache->put(obj, archived_oop);
      if (log_is_enabled(Debug, cds, heap)) {
        ResourceMark rm;

@@ -434,11 +439,11 @@
    HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
  
    memset(mem, 0, size * BytesPerWord);
    {
      // This is copied from MemAllocator::finish
-     oopDesc::set_mark(mem, markWord::prototype());
+     oopDesc::set_mark(mem, k->prototype_header());
      oopDesc::release_set_klass(mem, k);
    }
    {
      // This is copied from ObjArrayAllocator::initialize
      arrayOopDesc::set_length(mem, length);
< prev index next >