boxing + unboxing a VT is not a no-op ?

forax at univ-mlv.fr forax at univ-mlv.fr
Mon Jul 16 20:20:53 UTC 2018


----- Mail original -----
> De: "Tobias Hartmann" <tobias.hartmann at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Envoyé: Lundi 16 Juillet 2018 16:16:51
> Objet: Re: boxing + unboxing a VT is not a no-op ?

> Thanks Remi!
> 
> When trying to re-produce, I'm hitting JDK-8207346. I'll fix that first and then
> investigate the performance issue.

Ok, cool !

> 
> Tobias

Rémi

> 
> On 13.07.2018 15:11, forax at univ-mlv.fr wrote:
>> the source code is here:
>>   https://github.com/forax/valuetype-lworld/blob/master/src/test/java/fr.umlv.valuetype/fr/umlv/valuetype/perf/ReifiedListBenchMark.java#L118
>> 
>> the instructions about how to build are here:
>>   https://github.com/forax/valuetype-lworld
>> 
>> Rémi
>> 
>> ----- Mail original -----
>>> De: "Tobias Hartmann" <tobias.hartmann at oracle.com>
>>> À: "Remi Forax" <forax at univ-mlv.fr>, "valhalla-dev"
>>> <valhalla-dev at openjdk.java.net>
>>> Envoyé: Vendredi 13 Juillet 2018 14:43:10
>>> Objet: Re: boxing + unboxing a VT is not a no-op ?
>> 
>>> Hi Remi,
>>>
>>> thanks for reporting. Could you please provide the full source code so we can
>>> have a closer look?
>>>
>>> Best regards,
>>> Tobias
>>>
>>> On 12.07.2018 20:43, Remi Forax wrote:
>>>> Hi guys,
>>>> it seems that operations likes VT -> Object -> VT are not optimized has being a
>>>> no-op.
>>>>
>>>> with IntBox being a value type that wrap an int,
>>>> this code is slow (not very slow, i.e not interpreter slow)
>>>>
>>>>    public int valuelist_intbox_innervalue_inlined_reduce() {
>>>>     __ByValue class Adder implements BiFunction<IntBox, IntBox, IntBox> {
>>>>       private final boolean nonEmpty;
>>>>       
>>>>       Adder() {
>>>>         nonEmpty = false;
>>>>         throw new AssertionError();
>>>>       }
>>>>       
>>>>       public IntBox apply(IntBox acc, IntBox element) {
>>>>         return acc.add(element);
>>>>       }
>>>>     }
>>>>     BiFunction<IntBox, IntBox, IntBox> mapper = __MakeDefault Adder();
>>>>     var sum = IntBox.zero();
>>>>     int size = valueList.size();
>>>>     for(int i = 0; i < size; i++) {
>>>>       sum = mapper.apply(sum, valueList.get(i));
>>>>     }
>>>>     return sum.intValue();
>>>>   }
>>>>
>>>> while this code is fast (more than 10 times faster)
>>>>   public int valuelist_intbox_inlined_reduce() {
>>>>     var sum = IntBox.zero();
>>>>     int size = valueList.size();
>>>>     for(int i = 0; i < size; i++) {
>>>>       sum = sum.add(valueList.get(i));
>>>>     }
>>>>     return sum.intValue();
>>>>   }
>>>>
>>>> the difference is that instead of calling add on an IntBox to do the addition,
>>>> i used an anonymous value class which implement a functional interface which
>>>> used Objects.
>>>> (valueList is just an array of IntBox wrapped in a value type).
>>>>
>>>> regards,
>>>> Rémi


More information about the valhalla-dev mailing list