RFR: 8261137: Optimization of Box nodes in uncommon_trap [v6]
Vladimir Ivanov
vlivanov at openjdk.java.net
Fri Mar 5 22:46:09 UTC 2021
On Sat, 27 Feb 2021 07:17:22 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 incrementally with one additional commit since the last revision:
>
> fix bugs
test/hotspot/jtreg/compiler/c2/TestEliminateBoxInDebugInfo.java line 49:
> 47: "-XX:CompileCommand=compileonly,compiler/c2/TestEliminateBoxInDebugInfo$Test.foo",
> 48: "-XX:CompileCommand=dontinline,compiler/c2/TestEliminateBoxInDebugInfo$Test.black",
> 49: "-XX:+PrintEliminateAllocations",
Add `-Xbatch` to ensure the compilation is complete by the time the test finishes.
test/hotspot/jtreg/compiler/c2/TestIdentityWithEliminateBoxInDebugInfo.java line 31:
> 29: * @library /test/lib
> 30: *
> 31: * @run main/othervm compiler.c2.TestIdentityWithEliminateBoxInDebugInfo
Same here: add `-Xbatch`.
src/hotspot/share/opto/callGenerator.cpp line 659:
> 657:
> 658: if (C->eliminate_boxing()) {
> 659: replace_box_to_scalar(call, callprojs.resproj);
I suggest to lift the checks from `replace_box_to_scalar` to here. Otherwise, it's confusing to apply the method to an arbitrary call.
if (resproj != nullptr && call->is_CallStaticJava() &&
call->as_CallStaticJava()->is_boxing_method())
src/hotspot/share/opto/callGenerator.cpp line 573:
> 571:
> 572: #ifndef PRODUCT
> 573: if (PrintEliminateAllocations && safepoints.size() > 0) {
Strictly speaking, `PrintEliminateAllocations` is EA-specific flag.
Not sure it has to cover `EliminateAutoBox`/`AggressiveUnboxing`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2401
More information about the hotspot-compiler-dev
mailing list