Skip to content

Skip branch folding in ilgen if OSR enabled#23097

Merged
vijaysun-omr merged 1 commit intoeclipse-openj9:masterfrom
a7ehuo:fix-branchfolding-osr
Dec 14, 2025
Merged

Skip branch folding in ilgen if OSR enabled#23097
vijaysun-omr merged 1 commit intoeclipse-openj9:masterfrom
a7ehuo:fix-branchfolding-osr

Conversation

@a7ehuo
Copy link
Contributor

@a7ehuo a7ehuo commented Dec 12, 2025

Do not perform branch folding in ilgen if OSR is enabled. OSR def and liveness analyses rely on dataflow over the IL trees to make conclusions about the bytecode. To ensure correctness, the IL must accurately reflect the bytecode at the time of OSR analysis: It should preserve the same CFG and perform all local variable loads and stores at the same points as in the bytecode. Branch folding will likely be taken care of by later optimizations after OSR analyses such as tree simplification, etc.

Do not perform branch folding in ilgen if OSR is enabled.
OSR def and liveness analyses rely on dataflow over the
IL trees to make conclusions about the bytecode.
To ensure correctness, the IL must accurately reflect the
bytecode at the time of OSR analysis: It should preserve
the same CFG and perform all local variable loads and stores
at the same points as in the bytecode. Branch folding will
likely be taken care of by later optimizations after OSR
analyses such as tree simplification, etc.

Signed-off-by: Annabelle Huo <[email protected]>
@a7ehuo
Copy link
Contributor Author

a7ehuo commented Dec 12, 2025

A little more information on what the trees will look like with this change if OSR is enabled.

Without this change, ificmpeq is folded away in ILGen before OSR analyses

<optimization id=2 name=osrDefAnalysis method=MyClass4.test()I>
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
n30n      BBStart <block_2>                                                                   [0x738a88404430] bci=[-1,0,68] rc=0 vc=0 vn=- li=- udi=- nc=0
n34n      goto --> block_3 BBStart at n2n                                                     [0x738a88404570] bci=[-1,3,68] rc=0 vc=0 vn=- li=- udi=- nc=0
n29n      BBEnd </block_2> =====                                                              [0x738a884043e0] bci=[-1,3,68] rc=0 vc=0 vn=- li=- udi=- nc=0

n2n       BBStart <block_3>                                                                   [0x738a88403b70] bci=[-1,226,113] rc=0 vc=0 vn=- li=- udi=- nc=0
n36n      ireturn                                                                             [0x738a88404610] bci=[-1,227,113] rc=0 vc=0 vn=- li=- udi=- nc=1
n35n        iconst -1 (X!=0 X<=0 )                                                            [0x738a884045c0] bci=[-1,226,113] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x204
n1n       BBEnd </block_3>                                                                    [0x738a88403b20] bci=[-1,227,113] rc=0 vc=0 vn=- li=- udi=- nc=0

With this change before osrLiveRangeAnalysis:

<optimization id=1 name=osrLiveRangeAnalysis method=MyClass4.test()I>
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
n30n      BBStart <block_2>                                                                   [0x754c8b004430] bci=[-1,0,68] rc=0 vc=0 vn=- li=- udi=- nc=0
n36n      ificmpeq --> block_13 BBStart at n2n (swappedChildren )                             [0x754c8b004610] bci=[-1,3,68] rc=0 vc=0 vn=- li=- udi=- nc=2 flg=0x20020
n33n        iconst 0 (X==0 X>=0 X<=0 )                                                        [0x754c8b004520] bci=[-1,3,68] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x302
n31n        iconst 0 (X==0 X>=0 X<=0 )                                                        [0x754c8b004480] bci=[-1,0,68] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x302
n29n      BBEnd </block_2> =====                                                              [0x754c8b0043e0] bci=[-1,3,68] rc=0 vc=0 vn=- li=- udi=- nc=0

...
...
n2n       BBStart <block_13>                                                                  [0x754c8b003b70] bci=[-1,226,113] rc=0 vc=0 vn=- li=- udi=- nc=0
n55n      ireturn                                                                             [0x754c8b0900f0] bci=[-1,227,113] rc=0 vc=0 vn=- li=- udi=- nc=1
n54n        iconst -1 (X!=0 X<=0 )                                                            [0x754c8b0900a0] bci=[-1,226,113] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x204
n1n       BBEnd </block_13> =====                                                             [0x754c8b003b20] bci=[-1,227,113] rc=0 vc=0 vn=- li=- udi=- nc=0
...

With this change after treeSimplification:

<optimization id=21 name=treeSimplification method=MyClass4.test()I>
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
n30n      BBStart <block_2>                                                                   [0x754c8b004430] bci=[-1,226,113] rc=0 vc=81 vn=- li=- udi=- nc=0
n55n      ireturn                                                                             [0x754c8b0900f0] bci=[-1,227,113] rc=0 vc=81 vn=- li=- udi=- nc=1
n54n        iconst -1 (X!=0 X<=0 )                                                            [0x754c8b0900a0] bci=[-1,226,113] rc=1 vc=81 vn=- li=- udi=- nc=0 flg=0x204
n1n       BBEnd </block_2>                                                                    [0x754c8b003b20] bci=[-1,227,113] rc=0 vc=81 vn=- li=- udi=- nc=0

@vijaysun-omr May I ask you to review this change? Thank you!

@jdmpapin Thank you very much for your help in identifying the proper fix!

@a7ehuo a7ehuo requested a review from vijaysun-omr December 12, 2025 14:35
@vijaysun-omr
Copy link
Contributor

jenkins test sanity all jdk21

@a7ehuo
Copy link
Contributor Author

a7ehuo commented Dec 13, 2025

Three test failures are all known issues or have been observed in other PR build tests.

(1)
Test_openjdk21_j9_sanity.openjdk_x86-64_mac_Personal failed in jdk_vector_double128_j9_0.
This test failure had been observed in other PR builds as well: #23012 (comment)

12:33:43  java.lang.Exception: failures: 9
12:33:43  	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:104)
12:33:43  	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:58)
12:33:43  	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
12:33:43  	at java.base/java.lang.reflect.Method.invoke(Method.java:586)
12:33:43  	at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
12:33:43  	at java.base/java.lang.Thread.run(Thread.java:1595)
12:33:43  
12:33:43  JavaTest Message: Test threw exception: java.lang.Exception: failures: 9
12:33:43  JavaTest Message: shutting down test
12:33:43  
12:33:43  STATUS:Failed.`main' threw exception: java.lang.Exception: failures: 9

(2)
Test_openjdk21_j9_sanity.functional_ppc64_aix_Personal failed in J9vmTest_1.
It is a known issue: #9969. It also failed in night build 599

[2025-12-12T18:05:14.152Z] JVMDUMP055I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError", exception "Java heap space" at 2025/12/12 18:05:19 - please wait.
...
[2025-12-12T18:05:16.962Z] *** Test FAILED *** (j9vm.test.arraylets.ArrayletAllocateTest)

(3)
Test_openjdk21_j9_sanity.functional_x86-64_windows_Personal failed in testSCCMLModularity_3.
It is a known issue: #22758 (comment)

[2025-12-12T18:55:18.102Z] Test result: FAILED
[2025-12-12T18:55:18.102Z]  [ERR] JVMSHRC241E Error: unable to delete shared class cache file
[2025-12-12T18:55:18.102Z]  [ERR] JVMSHRC336E Port layer error code = -102
[2025-12-12T18:55:18.102Z]  [ERR] JVMSHRC337E Platform error message: (5) Access is denied.
[2025-12-12T18:55:18.102Z]  [ERR] JVMSHRC430I Failed to remove current generation of shared class cache "ShareClassesCMLTests"

@vijaysun-omr vijaysun-omr merged commit 4a66694 into eclipse-openj9:master Dec 14, 2025
23 of 27 checks passed
a7ehuo added a commit to a7ehuo/openj9 that referenced this pull request Jan 29, 2026
…hfolding-osr"

This reverts commit 4a66694, reversing
changes made to 4bc8b21.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants