RFR: JDK-8316991: Reduce nullable allocation merges

Cesar Soares Lucas cslucas at openjdk.org
Mon Oct 16 16:18:17 UTC 2023


On Tue, 3 Oct 2023 08:43:46 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

>> ### Description
>> 
>> Many, if not most, allocation merges (Phis) are nullable because they join object allocations with "NULL", or objects returned from method calls, etc. Please review this Pull Request that improves Reduce Allocation Merge implementation so that it can reduce at least some of these allocation merges.
>> 
>> Overall, the improvements are related to 1) making rematerialization of merges able to represent "NULL" objects, and 2) being able to reduce merges used by CmpP/N and CastPP. 
>> 
>> The approach to reducing CmpP/N and CastPP is pretty similar to that used in the `MemNode::split_through_phi` method: a clone of the node being split is added on each input of the Phi. I make use of `optimize_ptr_compare` and some type information to remove redundant CmpP and CastPP nodes. I added a bunch of ASCII diagrams illustrating what some of the more important methods are doing.
>> 
>> ### Benchmarking
>> 
>> **Note:** In some of these tests no reduction happens. I left them in to validate that no perf. regression happens in that case.
>> **Note 2:** Marging of error was negligible.
>> 
>> | Benchmark                            |  No RAM (ms/op)  |   Yes RAM (ms/op) |
>> |--------------------------------------|------------------|-------------------|
>> | TestTrapAfterMerge                   |      19.515      |      13.386       |
>> | TestArgEscape                        |      33.165      |      33.254       |
>> | TestCallTwoSide                      |      70.547      |      69.427       |
>> | TestCmpAfterMerge                    |      16.400      |       2.984       |
>> | TestCmpMergeWithNull_Second          |      27.204      |      27.293       |
>> | TestCmpMergeWithNull                 |       8.248      |       4.920       |
>> | TestCondAfterMergeWithAllocate       |      12.890      |       5.252       |
>> | TestCondAfterMergeWithNull           |       6.265      |       5.078       |
>> | TestCondLoadAfterMerge               |      12.713      |       5.163       |
>> | TestConsecutiveSimpleMerge           |      30.863      |       4.068       |
>> | TestDoubleIfElseMerge                |      16.069      |       2.444       |
>> | TestEscapeInCallAfterMerge           |      23.111      |      22.924       |
>> | TestGlobalEscape                     |      14.459      |      14.425       |
>> | TestIfElseInLoop                     |     246.061      |      42.786       |
>> | TestLoadAfterLoopAlias               |      45.808      |      45.812       |
>> ...
>
> I didn't look at this in detail yet but submitted testing. I see the following failures.
> 
> `compiler/eliminateAutobox/TestByteBoxing.java` with `-ea -esa -XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -server -XX:-TieredCompilation`:
> 
> 
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (/workspace/open/src/hotspot/share/opto/loopnode.cpp:2178), pid=951972, tid=951999
> #  assert(inner->is_valid_counted_loop(T_INT) && inner->is_strip_mined()) failed: OuterStripMinedLoop should have been removed
> #
> # JRE version: Java(TM) SE Runtime Environment (22.0) (fastdebug build 22-internal-2023-10-03-0709344.tobias.hartmann.jdk2)
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-internal-2023-10-03-0709344.tobias.hartmann.jdk2, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
> # Problematic frame:
> # V  [libjvm.so+0x128082c]  LoopNode::verify_strip_mined(int) const+0xcc
> 
> Current CompileTask:
> C2:   1438  263 %  b        compiler.eliminateAutobox.TestByteBoxing::main @ 1358 (1805 bytes)
> 
> Stack: [0x00007f0efc9cb000,0x00007f0efcacb000],  sp=0x00007f0efcac57a0,  free space=1001k
> Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
> V  [libjvm.so+0x128082c]  LoopNode::verify_strip_mined(int) const+0xcc  (loopnode.cpp:2178)
> V  [libjvm.so+0x1256ead]  PathFrequency::to(Node*)+0x70d  (loopPredicate.cpp:988)
> V  [libjvm.so+0x1258b49]  PhaseIdealLoop::loop_predication_impl(IdealLoopTree*)+0x8e9  (loopPredicate.cpp:1462)
> V  [libjvm.so+0x125989a]  IdealLoopTree::loop_predication(PhaseIdealLoop*)+0x9a  (loopPredicate.cpp:1536)
> V  [libjvm.so+0x12a28d7]  PhaseIdealLoop::build_and_optimize()+0xf57  (loopnode.cpp:4582)
> V  [libjvm.so+0x9ee7fb]  PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x3ab  (loopnode.hpp:1114)
> V  [libjvm.so+0x9e9db6]  Compile::Optimize()+0xdf6  (compile.cpp:2362)
> 
> 
> `compiler/eliminateAutobox/TestByteBoxing.java` with  `-XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:+StressArrayCopyMacroNode -XX:+StressLCM -XX:+StressGCM -XX:+StressIGVN -XX:+StressCCP -XX:+StressMethodHandleLinkerInlining -XX:+StressCompiledExceptionHandlers`:
> 
> 
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (workspace/open/src/hotspot/share/opto/loopnode.cpp:6035), pid=1353611, tid=1353627
> #  Error: ShouldNotReachHere()
> #
> # JRE version: Java(TM) SE Runtime Environment (22.0) (fastdebug build 22-internal-2023-10-03-0709344.tobias.hartma...

Thank you @TobiHartmann . I'll take a look into the failures.

Hello @TobiHartmann, I pushed a fix for the test failures that you reported. Could you please re-run your tests? Thank you.

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

PR Comment: https://git.openjdk.org/jdk/pull/15825#issuecomment-1745344848
PR Comment: https://git.openjdk.org/jdk/pull/15825#issuecomment-1753928457


More information about the hotspot-dev mailing list