[code-reflection] RFR: BytecodeGenerator support of lambdas [v7]

Adam Sotona asotona at openjdk.org
Tue Apr 16 13:39:07 UTC 2024


On Mon, 15 Apr 2024 23:47:30 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> An unfortunate consequence is it is now possible to get linkage errors when generating bytecode for two code model functions with the same name. This causes the `CoreBinaryOpsTest` to fail.
>> 
>> One solution is to append a randomly generated UUID to the class name. Another is to checking if the existing name already resolves to a class, and if so append a count, and repeat until resolution fails. Although that would require some synchronation to protect against races.
>
>> Unfortunately this is a different case. We generate a hidden class with lambda implementation method inside and `LambdaMetafactory` could not (and according to the spec should not) find the class.
> 
> I believe they can all be of the same nest, but I suppose`InnerClassLambdaMetafactory` would need to patch the hidden target class instance into the constant pool (in theory it could).
> 
> It is aware about the target class being hidden when generating the lambda class name:
> 
> 
>     private static String lambdaClassName(Class<?> targetClass) {
>         String name = targetClass.getName();
>         if (targetClass.isHidden()) {
>             // use the original class name
>             name = name.replace('/', '_');
>         }
>         return name.replace('.', '/') + "$$Lambda";
>     }

`InnerClassLambdaMetafactory` generates the hidden inner class (for example: `lambda_0x00007ff000189400$$Lambda/0x00007ff000117a08`) and then it all fails with:

java.lang.ClassNotFoundException: lambda.0x00007ff000189400
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	at TestBytecode.consume(TestBytecode.java:291)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
	at TestBytecode.lambda$testGenerate$14(TestBytecode.java:476)
	at TestBytecode.permutateAllArgs(TestBytecode.java:412)
	at TestBytecode.testGenerate(TestBytecode.java:475)

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

PR Review Comment: https://git.openjdk.org/babylon/pull/48#discussion_r1567377342


More information about the babylon-dev mailing list