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

Paul Sandoz psandoz at openjdk.org
Mon Apr 15 23:50:00 UTC 2024


On Mon, 15 Apr 2024 22:44:24 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> 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.
>
> 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";
    }

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

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


More information about the babylon-dev mailing list