Integrated: 8261137: Optimization of Box nodes in uncommon_trap

Wang Huang whuang at openjdk.java.net
Wed Apr 7 10:51:52 UTC 2021


On Thu, 4 Feb 2021 08:43:35 GMT, Wang Huang <whuang at openjdk.org> wrote:

> JDK-8075052 has  removed useless autobox. However, in some cases, the box is still saved. For instance:
> @Benchmark
> public void testMethod(Blackhole bh) {
>   int sum = 0;
>   for (int i = 0; i < data.length; i++) {
>       Integer ii = Integer.valueOf(data[i]);
>       if (i < data.length) {
>           sum += ii.intValue();
>       }
>   }
>   bh.consume(sum);
> }
> Although the variable ii is only used at ii.intValue(), it cannot be eliminated as a result of being used by a hidden uncommon_trap.
> The uncommon_trap is generated by the optimized "if", because its condition is always true.
> 
> We can postpone box in uncommon_trap in this situation. We treat box as a scalarized object by adding a SafePointScalarObjectNode in the uncommon_trap node,
> and deleting the use of box:
> 
> There is no additional fail/error(s) of jtreg after this patch.
> 
> I adjust my codes and add a new benchmark
> 
> public class MyBenchmark {
> 
>     static int[] data = new int[10000];
> 
>     static {
>         for(int i = 0; i < data.length; ++i) {
>             data[i] = i * 1337 % 7331;
>         }
>     }
> 
>     @Benchmark
>     public void testMethod(Blackhole bh) {
>       int sum = 0;
>       for (int i = 0; i < data.length; i++) {
>           Integer ii = Integer.valueOf(data[i]);
>           black();
>           if (i < 100000) {
>               sum += ii.intValue();
>           }
>       }
>       bh.consume(sum);
>     }
> 
>     public void black(){}
> }
> 
> 
> aarch64:  
> base line:
> Benchmark                     Mode  Samples   Score  Score error  Units
> o.s.MyBenchmark.testMethod    avgt       30  88.513        1.111  us/op
> 
> opt:
> Benchmark                     Mode  Samples   Score  Score error  Units
> o.s.MyBenchmark.testMethod    avgt       30  52.776        0.096  us/op
> 
> x86:  
> base line:
> Benchmark                     Mode  Samples   Score  Score error  Units
> o.s.MyBenchmark.testMethod    avgt       30  81.066        3.156  us/op
> 
> opt:
> Benchmark                     Mode  Samples   Score  Score error  Units
> o.s.MyBenchmark.testMethod    avgt       30  55.596        0.775  us/op

This pull request has now been integrated.

Changeset: eab84554
Author:    Wang Huang <whuang at openjdk.org>
Committer: Vladimir Ivanov <vlivanov at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/eab84554
Stats:     308 lines in 10 files changed: 284 ins; 2 del; 22 mod

8261137: Optimization of Box nodes in uncommon_trap

Co-authored-by: Wu Yan <wuyan34 at huawei.com>
Co-authored-by: Ai Jiaming <aijiaming1 at huawei.com>
Reviewed-by: kvn, vlivanov, thartmann

-------------

PR: https://git.openjdk.java.net/jdk/pull/2401


More information about the hotspot-compiler-dev mailing list