Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/hotspot/share/classfile/classLoaderData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ 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 {
return (unsigned)((uintptr_t)this >> 3);
}

JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
};

Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/prims/resolvedMethodTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "precompiled.hpp"
#include "classfile/classLoaderData.hpp"
#include "classfile/javaClasses.hpp"
#include "logging/log.hpp"
#include "memory/allocation.hpp"
Expand Down Expand Up @@ -78,7 +79,8 @@ oop ResolvedMethodTable::lookup(int index, unsigned int hash, Method* method) {
}

unsigned int ResolvedMethodTable::compute_hash(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ private MethodHandle generate(String className) throws ReflectiveOperationExcept
return MethodHandles.publicLookup().findStatic(cls, "m", MethodType.methodType(void.class));
}

private MethodHandle generateWithSameName() throws ReflectiveOperationException {
byte[] buf = new byte[100];
int size = writeClass(buf, "MH$$");
// use different classloader instances to load the classes with the same name
Class<?> cls = new ResolvedMethodTableHash().defineClass(null, buf, 0, size);
return MethodHandles.publicLookup().findStatic(cls, "m", MethodType.methodType(void.class));
}

// Produce a class file with the given name and a single method:
// public static native void m();
private int writeClass(byte[] buf, String className) {
Expand Down Expand Up @@ -82,7 +90,12 @@ public static void main(String[] args) throws Exception {
int count = args.length > 0 ? Integer.parseInt(args[0]) : 200000;

for (int i = 0; i < count; i++) {
handles.add(generator.generate("MH$" + i));
// prevents metaspace oom
if (i % 20 != 0) {
handles.add(generator.generate("MH$" + i));
} else {
handles.add(generator.generateWithSameName());
}
if (i % 1000 == 0) {
System.out.println("Generated " + i + " handles");
}
Expand Down