deduplicating lambda methods
B. Blaser
bsrbnd at gmail.com
Sun Mar 4 17:37:56 UTC 2018
On 4 March 2018 at 17:25, B. Blaser <bsrbnd at gmail.com> wrote:
> On 4 March 2018 at 14:11, Remi Forax <forax at univ-mlv.fr> wrote:
>> Hi Vincente,
>>
>> ----- Mail original -----
>>> De: "Vicente Romero" <vicente.romero at oracle.com>
>>> À: "Liam Miller-Cushon" <cushon at google.com>, "amber-dev" <amber-dev at openjdk.java.net>, "Brian Goetz"
>>> <brian.goetz at oracle.com>
>>> Envoyé: Samedi 3 Mars 2018 05:01:47
>>> Objet: Re: deduplicating lambda methods
>>
>> [...]
>>
>>>>
>>>> 2) Debug info: the optimization is safe if line numbers are not being
>>>> emitted. If they are, is there a way to deduplicate the methods
>>>> without breaking debug info?
>>>
>>> I haven't tried to debug a method with more than one LNT, the spec
>>> allows it but not sure how IDEs will operate on that
>>
>> from JVMS 4.7.13,
>> "The LocalVariableTable attribute is an optional variable-length attribute in the attributes table of a Code attribute (§4.7.3). It may be used by debuggers to determine the value of a given local variable during the execution of a method.
>> If multiple LocalVariableTable attributes are present in the attributes table of a Code attribute, then they may appear in any order.
>> There may be no more than one LocalVariableTable attribute per local variable in the attributes table of a Code attribute. "
>>
>> You can not have several LNTs that map different parts of a compilation unit to the same bytecode because if you have several attributes it's like you can merge them into one attribute,
>> so deduplication if there are debug info is not possible as far as i know.
>
> The LVT is simply mapping local variable symbols ('name_index') to
> their memory offsets ('index'). It should be possible to merge them as
> the bytecode (modulo my previous comments to retrieve the right LNT)
> for identical lambdas, I think.
For example:
$ cat R.java
class R {
void f() {
Runnable r = () -> { int i = 0; };
r = () -> { int i = 0; };
}
}
$ javac -g R.java
$ javap -l -c -p R.class
Compiled from "R.java"
class R {
[...]
private static void lambda$f$1();
Code:
0: iconst_0
1: istore_0
2: return
LineNumberTable:
line 4: 0
LocalVariableTable:
Start Length Slot Name Signature
2 1 0 i I
private static void lambda$f$0();
Code:
0: iconst_0
1: istore_0
2: return
LineNumberTable:
line 3: 0
LocalVariableTable:
Start Length Slot Name Signature
2 1 0 i I
}
B.
> Bernard
>
>>> Vicente
>>
>> Rémi
More information about the amber-dev
mailing list