RFR: 8261137: Optimization of Box nodes in uncommon_trap [v4]
Vladimir Ivanov
vlivanov at openjdk.java.net
Wed Feb 10 21:28:39 UTC 2021
On Wed, 10 Feb 2021 06:58:57 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:
>
> delete useless line
The improvement you are proposing is not specific to uncommon traps, but can be generalized to any debug usage at safepoints.
The downside is that, in general, rematerialization logic has to use the corresponding pure function in order to materialize the eliminated instance. In this particular case (primitive boxing), it has to take into account the caching effects of primitive box factories. Otherwise, user code can encounter identity paradoxes with rematerialized primitive box instances.
I don't see how the scalarization logic you propose preserves identity constraints imposed by `valueOf` factories.
-------------
Changes requested by vlivanov (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/2401
More information about the hotspot-compiler-dev
mailing list