RFR: 8261137: Optimization of Box nodes in uncommon_trap [v9]

Vladimir Kozlov kvn at openjdk.java.net
Tue Mar 23 17:21:05 UTC 2021


On Tue, 23 Mar 2021 08:32:34 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
>
> Wang Huang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains ten additional commits since the last revision:
> 
>  - Merge branch 'master' into JDK-8261137
>  - refactor
>  - refactor some codes
>  - fix bugs
>  - add debuginfo optimization
>  - delete useless line
>  - fix some bugs
>  - refactor codes
>  - 8261137: Optimization of Box nodes in uncommon_trap

test/hotspot/jtreg/compiler/c2/TestEliminateBoxInDebugInfo.java line 1:

> 1: /*

The test should be in `compiler/eliminateAutobox` directory. `compiler/c2` is collection of old unsorted tests.

test/hotspot/jtreg/compiler/c2/TestEliminateBoxInDebugInfo.java line 27:

> 25:  * @test
> 26:  * @bug 8261137
> 27:  * @requires vm.debug == true & vm.flavor == "server"

Exclude Graal because it would not have output you expect. Instead of checking for "server" check for C2:
`@requires vm.debug == true & vm.compiler2.enabled`

test/hotspot/jtreg/compiler/c2/TestIdentityWithEliminateBoxInDebugInfo.java line 1:

> 1: /*

The test should be in compiler/eliminateAutobox directory.

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

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


More information about the hotspot-compiler-dev mailing list