changeset 59284:a44396903fd8

8244777: ClassLoaderStats VM Op uses constant hash value Reviewed-by: coleenp, jbachorik
author stuefe
date Thu, 14 May 2020 08:48:36 +0200
parents a9dbb1e23a06
children 6b9d41cd75e3
files src/hotspot/share/classfile/classLoaderStats.hpp
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classLoaderStats.hpp	Thu May 14 09:25:49 2020 +0800
+++ b/src/hotspot/share/classfile/classLoaderStats.hpp	Thu May 14 08:48:36 2020 +0200
@@ -102,8 +102,17 @@
   }
 
   static unsigned oop_hash(oop const& s1) {
-    unsigned hash = (unsigned)((uintptr_t)&s1);
-    return hash ^ (hash >> LogMinObjAlignment);
+    // Robert Jenkins 1996 & Thomas Wang 1997
+    // http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
+    uintptr_t tmp = cast_from_oop<uintptr_t>(s1);
+    unsigned hash = (unsigned)tmp;
+    hash = ~hash + (hash << 15);
+    hash = hash ^ (hash >> 12);
+    hash = hash + (hash << 2);
+    hash = hash ^ (hash >> 4);
+    hash = hash * 2057;
+    hash = hash ^ (hash >> 16);
+    return hash;
   }
 
   typedef ResourceHashtable<oop, ClassLoaderStats*,