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

Tobias Hartmann tobias.hartmann at oracle.com
Fri Jul 13 12:43:10 UTC 2018


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