From d9238aabf22497024b52c68c31c42c8e9c0a17e6 Mon Sep 17 00:00:00 2001 From: stuefe Date: Thu, 14 May 2020 08:48:36 +0200 Subject: [PATCH] 8244777: ClassLoaderStats VM Op uses constant hash value Reviewed-by: coleenp, jbachorik --- src/share/vm/classfile/classLoaderStats.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/share/vm/classfile/classLoaderStats.hpp b/src/share/vm/classfile/classLoaderStats.hpp index 72904c12d..b9e0fc2cd 100644 --- a/src/share/vm/classfile/classLoaderStats.hpp +++ b/src/share/vm/classfile/classLoaderStats.hpp @@ -101,8 +101,17 @@ protected: } 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(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