Condy for LambdaMetafactory?

Luke Sandberg lukes at google.com
Fri Oct 20 20:29:22 UTC 2023


Classic story of development scope creep :P, thanks for confirming.

Experimentally, I can trigger the special case in BootstrapMethodInvoker by
just writing my own shim bootstrap method

  public static Object constantMetafactory(
      MethodHandles.Lookup lookup,
      String name,
      Class<?> type,
      MethodType samMethodType,
      MethodHandle implMethod,
      MethodType instantiatedMethodType)
      throws Throwable {
    return LambdaMetafactory.metafactory(
            lookup, name, methodType(type), samMethodType, implMethod,
instantiatedMethodType)
        .getTarget()
        .invoke();
  }

This allows me to retarget a number of invokedynamic callsites to constant
dynamic and saves a small amount of classfile bytes.

Do you think this is a valuable optimization?  I'm guessing it would only
make a difference in terms of bootstrapping.. perhaps condy is a simpler
thing for the vm to manage than an indy+constantcallsite?  Or perhaps I
should just assume that since the vm engineers abandoned working on this,
it wasn't particularly valuable?

Thanks again!
-Luke



On Fri, Oct 20, 2023 at 1:14 PM Brian Goetz <brian.goetz at oracle.com> wrote:

> There was an experiment to translate non-capturing lambdas with condy,
> which was never integrated.  As you observed, it requires changes to the
> bootstrap method signature; when we started adding the alternate bootstrap
> method, we realized there were some cleanups in the LMF spec/implementation
> we wanted to do, but these ended up getting back-burnered.
>
> On 10/20/2023 4:10 PM, Luke Sandberg wrote:
>
> Hi, as part of a custom compiler I am working on I stumbled across
> https://bugs.openjdk.org/browse/JDK-8198418 which references invoking
> LambdaMetafactory.metafactory from a condy instruction when there are no
> bound parameters.
>
> I see that there is support for this in BootstrapMethodInvoker:
> https://github.com/openjdk/jdk/blob/77b2394c46bd304ffc0658cb758d971f1f2940b6/src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java#L136C28-L136C55
>
> But there is no method implementing this signature that i can find.
>
> Is this a half implemented idea from the original condy implementation? Or
> am I missing something?  Initially i thought that BootstrapMethodInvoker
> might handle the signature delta, but experimentally that is not true :D
>
> Thanks,
> -Luke
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231020/ca3d3092/attachment.htm>


More information about the amber-dev mailing list