deduplicating lambda methods
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Mar 29 14:00:12 UTC 2018
On 29/03/18 11:32, B. Blaser wrote:
> On 28 March 2018 at 23:51, B. Blaser <bsrbnd at gmail.com> wrote:
>> On 28 March 2018 at 20:09, Maurizio Cimadamore
>> <maurizio.cimadamore at oracle.com> wrote:
>>> To me this seems to suggest that, if we want to get better results out of
>>> the dedup machinery, we have to up our lowering game, so that we don't do
>>> excessive generation of fresh symbols. Right now we don't cache .class
>>> symbols and also metafactory calls with same static args and BSM - and
>>> that's the problem you are seeing, I believe.
>> You're right. The fix below tries to cache meta-factory calls, solving
>> the following de-duplication problem:
>> r1 = () -> {
>> Runnable r2 = () -> {};
>> };
> Running javac tests, I note that the cache key isn't precise enough.
> Any idea of what a good key would be?
I think the key has to take into account:
* name and type of BSM method
* dynamic type of the indy call
* values of all static args
just using the lambda impl name would not cut it, esp. if deduplication
is turned on (as the same lambda impl will be reused e.g. for a
Function<Integer, Integer> and a Function<String, String> - of the
underlying lambda is the identity x -> x ).
Maurizio
>
> Bernard
>
>
>> Bernard
>>
>> diff -r 9925be430918
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
>> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
>> Wed Mar 28 14:24:17 2018 +0100
>> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
>> Wed Mar 28 23:24:59 2018 +0200
>> @@ -226,6 +226,8 @@
>>
>> private Map<DedupedLambda, DedupedLambda> dedupedLambdas;
>>
>> + private Map<Name, DynamicMethodSymbol> dynMethSyms = new HashMap<>();
>> +
>> /**
>> * list of deserialization cases
>> */
>> @@ -1220,7 +1222,8 @@
>> staticArgs.toArray());
>>
>> JCFieldAccess qualifier =
>> make.Select(make.QualIdent(site.tsym), bsmName);
>> - qualifier.sym = dynSym;
>> + DynamicMethodSymbol existing =
>> kInfo.dynMethSyms.putIfAbsent(methName, dynSym);
>> + qualifier.sym = existing != null ? existing : dynSym;
>> qualifier.type = indyType.getReturnType();
>>
>> JCMethodInvocation proxyCall = make.Apply(List.nil(),
>> qualifier, indyArgs);
>>
>>> Maurizio
>>>
>>>> Bernard
>>>>
>>>>> Maurizio
More information about the amber-dev
mailing list