runOnce

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue Sep 25 03:16:21 PDT 2012


This is bulky and requires Runners class per each call site.

BTW, realized this seem to be pure jsr292 topic, not jsr335.

-Aleksey.

On 09/25/2012 01:59 PM, Remi Forax wrote:
> without any javac translation:
> 
>   static class Runners {static { System.out.println("Boo!"); } static
> void runOnce() {}}
>   public static void foo() {
>     Runners.runOnce();
>   }
> 
> Rémi
> 
> On 09/25/2012 11:45 AM, Aleksey Shipilev wrote:
>> Hi guys,
>>
>> This thread [1] makes me thinking if we want to introduce something like
>> runOnce() to record per-callsite invocation information. I.e. instead of
>> messing with maps and flags to guard this behavior, one can possibly do:
>>
>>    Runners.runOnce(() -> System.out.println("Boo!"));
>>
>> ...where runOnce will be desugared by Javac into indy call in which
>> bootstrap method calls the callee, and then emits the constant callsite
>> holding the result. This will effectively record the "invoked" property
>> into callsite, so that this code:
>>
>>    Runners.runOnce(() -> System.out.println("foo"));
>>    Runners.runOnce(() -> System.out.println("bar"));
>>
>> would yield:
>>    foo
>>    bar
>>
>> It might be yet another convenient way to make singletons (err...
>> thread-safe identity caches), like:
>>
>>   public T getInstance() { return Runners.runOnce(() -> new T()); }
>>
>> Was something like this considered before?
>>
>> -Aleksey.
>>
>> [1]
>> http://mail.openjdk.java.net/pipermail/lambda-dev/2012-September/006015.html
>>
> 



More information about the lambda-libs-spec-observers mailing list