diff --git a/src/hotspot/share/prims/resolvedMethodTable.cpp b/src/hotspot/share/prims/resolvedMethodTable.cpp index bde76b8ccc5..b0c16148ca0 100644 --- a/src/hotspot/share/prims/resolvedMethodTable.cpp +++ b/src/hotspot/share/prims/resolvedMethodTable.cpp @@ -53,9 +53,10 @@ static const size_t GROW_HINT = 32; static const size_t ResolvedMethodTableSizeLog = 10; unsigned int method_hash(const Method* method) { - unsigned int name_hash = method->name()->identity_hash(); - unsigned int signature_hash = method->signature()->identity_hash(); - return name_hash ^ signature_hash; + unsigned int hash = method->klass_name()->identity_hash(); + hash = (hash * 31) ^ method->name()->identity_hash(); + hash = (hash * 31) ^ method->signature()->identity_hash(); + return hash; } typedef ConcurrentHashTable cls = 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) { + return ByteBuffer.wrap(buf) + .putInt(0xCAFEBABE) // magic + .putInt(50) // version: 50 + .putShort((short) 7) // constant_pool_count: 7 + .put((byte) 7).putShort((short) 2) + .put((byte) 1).putShort((short) className.length()).put(className.getBytes()) + .put((byte) 7).putShort((short) 4) + .put((byte) 1).putShort((short) 16).put("java/lang/Object".getBytes()) + .put((byte) 1).putShort((short) 1).put("m".getBytes()) + .put((byte) 1).putShort((short) 3).put("()V".getBytes()) + .putShort((short) 0x21) // access_flags: public super + .putShort((short) 1) // this_class: #1 + .putShort((short) 3) // super_class: #3 + .putShort((short) 0) // interfaces_count: 0 + .putShort((short) 0) // fields_count: 0 + .putShort((short) 1) // methods_count: 1 + .putShort((short) 0x109) // access_flags: public static native + .putShort((short) 5) // name_index: #5 + .putShort((short) 6) // descriptor_index: #6 + .putShort((short) 0) // attributes_count: 0 + .putShort((short) 0) // attributes_count: 0 + .position(); + } + + public static void main(String[] args) throws Exception { + ResolvedMethodTableHash generator = new ResolvedMethodTableHash(); + List handles = new ArrayList<>(); + + int count = args.length > 0 ? Integer.parseInt(args[0]) : 200000; + + for (int i = 0; i < count; i++) { + handles.add(generator.generate("MH$" + i)); + if (i % 1000 == 0) { + System.out.println("Generated " + i + " handles"); + } + } + + System.out.println("Test passed"); + } +}