RFR: 8261137: Optimization of Box nodes in uncommon_trap [v2]
Vladimir Kozlov
kvn at openjdk.java.net
Mon Feb 8 18:48:46 UTC 2021
On Fri, 5 Feb 2021 07:29:00 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.
>
> Wang Huang has updated the pull request incrementally with one additional commit since the last revision:
>
> refactor codes
I am a little concern about stretching uses of input value outside scope where it is created (for example, loop's variable or a value depending on it).
This optimization may work only because boxed values are immutable.
I will run our tests with this changes.
src/hotspot/share/opto/callGenerator.cpp line 582:
> 580: Node* uncommon_trap_node = delay_boxes.pop();
> 581: int in_edge = uncommon_trap_node->find_edge(res);
> 582: assert(in_edge > 0, "sanity");
If there are several references you need to replace all of them.
src/hotspot/share/opto/callGenerator.cpp line 591:
> 589: Node* sobj = new SafePointScalarObjectNode(gvn.type(res)->isa_oopptr(),
> 590: #ifdef ASSERT
> 591: NULL,
I would suggest to record `call` node here treating it as allocation.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2401
More information about the hotspot-compiler-dev
mailing list