changeset 13611:427f4c99b29e

8186706: ArchivedObjectCache obj_hash() is broken. Summary: Use oop's identity_hash. Also use larger table size. Reviewed-by: ccheung, iklam, coleenp
author jiangli
date Sun, 27 Aug 2017 15:48:52 -0400
parents ab8afbbf2ace
children ec4c21cf8ba1
files src/share/vm/memory/metaspaceShared.cpp src/share/vm/memory/metaspaceShared.hpp
diffstat 2 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/memory/metaspaceShared.cpp	Tue Aug 01 14:58:38 2017 +0800
+++ b/src/share/vm/memory/metaspaceShared.cpp	Sun Aug 27 15:48:52 2017 -0400
@@ -1613,6 +1613,8 @@
     tty->print_cr("Dumping objects to open archive heap region ...");
     _open_archive_heap_regions = new GrowableArray<MemRegion>(2);
     MetaspaceShared::dump_open_archive_heap_objects(_open_archive_heap_regions);
+
+    MetaspaceShared::destroy_archive_object_cache();
   }
 
   G1HeapVerifier::verify_archive_regions();
--- a/src/share/vm/memory/metaspaceShared.hpp	Tue Aug 01 14:58:38 2017 +0800
+++ b/src/share/vm/memory/metaspaceShared.hpp	Sun Aug 27 15:48:52 2017 -0400
@@ -29,6 +29,7 @@
 #include "memory/allocation.hpp"
 #include "memory/memRegion.hpp"
 #include "memory/virtualspace.hpp"
+#include "oops/oop.inline.hpp"
 #include "utilities/exceptions.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/resourceHash.hpp"
@@ -96,11 +97,16 @@
     return p1 == p2;
   }
   static unsigned obj_hash(oop const& p) {
-    unsigned hash = (unsigned)((uintptr_t)&p);
-    return hash ^ (hash >> LogMinObjAlignment);
+    assert(!p->mark()->has_bias_pattern(),
+           "this object should never have been locked");  // so identity_hash won't safepoin
+    unsigned hash = (unsigned)p->identity_hash();
+    return hash;
   }
   typedef ResourceHashtable<oop, oop,
-      MetaspaceShared::obj_hash, MetaspaceShared::obj_equals> ArchivedObjectCache;
+      MetaspaceShared::obj_hash,
+      MetaspaceShared::obj_equals,
+      15889, // prime number
+      ResourceObj::C_HEAP> ArchivedObjectCache;
   static ArchivedObjectCache* _archive_object_cache;
 
  public:
@@ -115,7 +121,10 @@
     NOT_CDS_JAVA_HEAP(return false;)
   }
   static void create_archive_object_cache() {
-    CDS_JAVA_HEAP_ONLY(_archive_object_cache = new ArchivedObjectCache(););
+    CDS_JAVA_HEAP_ONLY(_archive_object_cache = new (ResourceObj::C_HEAP, mtClass)ArchivedObjectCache(););
+  }
+  static void destroy_archive_object_cache() {
+    CDS_JAVA_HEAP_ONLY(delete _archive_object_cache; _archive_object_cache = NULL;);
   }
   static void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;