[code-reflection] RFR: Split support for reflectable lambdas from lambda metafactory

Paul Sandoz psandoz at openjdk.org
Thu Nov 20 19:29:23 UTC 2025


On Thu, 20 Nov 2025 19:00:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR introduces a new class, called `ReflectableLambdaMetafactory`, which lives in the incubating code reflection module.
>> 
>> All capture requests for reflectable lambdas are now re-routed by javac to the new bootstrap methods defined in this class. This allows us to evolve the bootstrap protocol for reflectable lambda without negatively affecting other, non-reflectable lambdas (esp. at startup).
>> 
>> Some magic was required to wire up the pieces: javac cannot refer to symbols in the incubating module, so I decided to let `ReflectMethods` leave a trail of crumbs for `LambdaToMethod` to go on (as `LambdaToMethod` needs to know the name of the class in which the bootstrap method lives).
>> 
>> Some restructuring to `LambdaMetafactory` was also necessary, so that we could access the implementation internals from the new class. The new `xyzInternal` methods are exposed through `SharedSecrects` and are invoked by the reflectable metafactory, which also passes up extra information that the metafactory implementation needs to generate the additional code for reflectable lambdas.
>> 
>> This also allowed me to get rid of the `CodeReflectionSupport` class in `InnerClassLambdaMetafactory` and the related module layer dance.
>
> src/jdk.incubator.code/share/classes/jdk/incubator/code/runtime/ReflectableLambdaMetafactory.java line 27:
> 
>> 25: 
>> 26:     /**
>> 27:      * Facilitates the creation of simple "function objects" that implement one
> 
> For now I've just copied the javadoc of the original metafactory. If you want to go a different way, please shout. Perhaps a better way could be to say more succinctly that this works in the same way as the lambda metafactory but XYZ... (e.g. focus on the differences, rather than on the similarities)

Yes, that would be more succinct. We can revisit after integration of this PR.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/688#discussion_r2547372750


More information about the babylon-dev mailing list