RFR: 8266642: improve ResolvedMethodTable hash function [v6]
Vladimir Ivanov
vlivanov at openjdk.java.net
Fri May 14 10:05:59 UTC 2021
On Wed, 12 May 2021 17:34:25 GMT, Denghui Dong <ddong at openjdk.org> wrote:
>> JDK-8249719 has fixed the bad hash function problem, however, the performance problem still exists when there are a large number of classes with the same name.
>> Adding the address of the corresponding ClassLoaderData as a factor of hash can solve the problem.
>
> Denghui Dong has updated the pull request incrementally with one additional commit since the last revision:
>
> use ClassLoaderData* as factor
What about the following variant?
diff --git a/src/hotspot/share/classfile/classLoaderData.hpp b/src/hotspot/share/classfile/classLoaderData.hpp
index 6fd5b9b8203..f1f1c82f591 100644
--- a/src/hotspot/share/classfile/classLoaderData.hpp
+++ b/src/hotspot/share/classfile/classLoaderData.hpp
@@ -325,6 +325,11 @@ class ClassLoaderData : public CHeapObj<mtClass> {
const char* loader_name_and_id() const;
Symbol* name_and_id() const { return _name_and_id; }
+ unsigned identity_hash() const {
+ unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3));
+ return addr_bits;
+ }
+
JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
};
diff --git a/src/hotspot/share/prims/resolvedMethodTable.cpp b/src/hotspot/share/prims/resolvedMethodTable.cpp
index 5e5761094f1..527a39f3646 100644
--- a/src/hotspot/share/prims/resolvedMethodTable.cpp
+++ b/src/hotspot/share/prims/resolvedMethodTable.cpp
@@ -23,6 +23,7 @@
*/
#include "precompiled.hpp"
+#include "classfile/classLoaderData.hpp"
#include "classfile/javaClasses.hpp"
#include "gc/shared/oopStorage.inline.hpp"
#include "gc/shared/oopStorageSet.hpp"
@@ -53,7 +54,8 @@ static const size_t GROW_HINT = 32;
static const size_t ResolvedMethodTableSizeLog = 10;
unsigned int method_hash(const Method* method) {
- unsigned int hash = method->klass_name()->identity_hash();
+ unsigned int hash = method->method_holder()->class_loader_data()->identity_hash();
+ hash = (hash * 31) ^ method->klass_name()->identity_hash();
hash = (hash * 31) ^ method->name()->identity_hash();
hash = (hash * 31) ^ method->signature()->identity_hash();
return hash;
-------------
PR: https://git.openjdk.java.net/jdk/pull/3901
More information about the hotspot-dev
mailing list