I think basically I want the following API, but ideally thread safe and 
optimizable like a real LDC.

public final class LazyConstant {
    private ConstantDesc desc;
    private Object result;


    public LazyConstant(ConstantDesc desc) {
        this.desc = desc;
    }


    public Object resolve(MethodHandles.Lookup lookup) throws 
ReflectiveOperationException {
        if (null == result) {
            result = desc.resolveConstantDesc(lookup);
        }
        return result;
    }
}


On Thursday, April 30, 2020 at 6:57:19 PM UTC-7, Steven Stewart-Gallus 
wrote:
>
> Hello,
>
> I've stumbled upon a puzzler while writing a compiler from System F 
> embedded in Java to methodhandles.
>
> Given a DynamicConstantDesc how do I convert it to a MethodHandle that 
> lazily loads the value alike ldc ?
> It seems absurd spin an entire class for this.
> I could create a MutableCallSite or perhaps a SwitchPoint for this but I 
> don't really understand which would be better.
>
> A regularly old object that does lazy initialisation with a flag would 
> probably be fine but I feel like I should be able to do better.
>
> I think I might be able to abuse the jit's handling of private finals in 
> lambda objects to do this but I'm not quite certain that would work.
>
> Thanks
> Steven Stewart-Gallus
>

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/mechanical-sympathy/fba63bb3-c81d-484c-9b53-444a41d8abae%40googlegroups.com.

Reply via email to