RFR: 6983726: remove Proxy from MethodHandleProxies.asInterfaceInstance SAM conversion

Jorn Vernee jvernee at openjdk.org
Tue Mar 28 14:03:15 UTC 2023


On Tue, 28 Mar 2023 13:34:05 GMT, Chen Liang <liach at openjdk.org> wrote:

> 



> > I believe you can have better performance if you pass the method handle as the class data of the hidden class and you load it with a constant dynamic [https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClassWithClassData(byte[],java.lang.Object,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClassWithClassData(byte%5B%5D,java.lang.Object,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)) and https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/invoke/MethodHandles.html#classData(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.Class)
> 
> With one class per method handle + classdata, you do have better performance for invocations, but the penalties on creation is insurmountable: [JMH results comparison](https://jmh.morethan.io/?gists=bf98de7b2128e7e5d14e697fd9921eb9,08abb39f224574550925beb8be1b2f59) between OracleJDK 20 and [my initial patch](https://github.com/openjdk/jdk/commit/72dbf9d4e01c455854d9b865cb2a47c38f37a8e0), implemented based on this idea

But this doesn't implement the same ClassValue cache. And spinning byte code can indeed be slow (I've seen this in other profiles).

I think it should be possible to spin the class bytes once, stick the result in a `ClassValue` cache, but then use the bytes to define multiple classes with different class data (MethodHandles).

Also, it would be nice if you could include the benchmarks you used in the patch as well.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13197#issuecomment-1486950348


More information about the core-libs-dev mailing list