JDK-8362117 : C2: compiler/stringopts/TestStackedConcatsAppendUncommonTrap.java fails with a wrong result
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,25
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2025-07-14
  • Updated: 2025-08-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26Unresolved
Related Reports
Causes :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
compiler/stringopts/TestStackedConcatsAppendUncommonTrap.java fails with a wrong result after stacked string concatenation optimizations when run with stress flags.

-Xcomp -XX:CompileThreshold=100 -XX:-TieredCompilation -XX:+DeoptimizeALot

These flags inline 'f' into the main method which is OSR compiled in the failure case (and maybe they avoid the uncommon trap that JDK-8357105 was caused by).

This bug is hidden by JDK-8273612 since JDK 18, but to my understanding, that fix should not affect correctness, only inlining decisions for the -Xcomp mode.

===

The test runs fine before JDK-8271341, then starts crashing until JDK-8291775, and after that it produces the wrong result. The failure mode looks similar to JDK-7179138 since in both cases a result with the wrong length is produced.
Comments
JDK-8291775 changed the folding of a diamond If-pattern "Region -> (True, False) -> If" by setting the If-test input to a constant zero instead of replacing the Region by the If's input, to prevent a too quick propagation of top() through the graph. One assumption behind that was that the data Phis of the Region would be removed during PhaseRemoveUseless. However, in the attached test case, that does not apply. The data phi is retained until IGVN where the diamond if is first collapsed, then the Phi is transformed as it's replaced by the input from the corresponding "False" branch, which gives the wrong result.
04-08-2025

Reproducer that requires less extra flags: https://github.com/openjdk/jdk/compare/master...danielogh:jdk:stringopts-wrong-result?expand=1 -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler.stringopts.TestStackedConcatsAppendUncommonTrap::f -XX:+OptimizeStringConcat === Attached [35_before_stringopts.png] from a run of this test. It looks like the last append is picking up "xx" in the expression (s == "xx") ? s : "aa" and adding it to the string.
24-07-2025

Seems to affect 8 too. It just silently bails out though. EDIT. or maybe we just don't have JDK-8271341 ?
15-07-2025

Thank you!
14-07-2025

I can give it a try.
14-07-2025

[~dskantz] do you plan to look into this or should we assign to someone else? Thanks for the report!
14-07-2025

ILW = Incorrect result of C2 compiled program (string concat), with string concat and stress options, -XX:-OptimizeStringConcat = HLM = P3
14-07-2025

Workaround: -XX:-OptimizeStringConcat
14-07-2025

Another bug with stacked concatenations and a complex merge point between the pair of string builders.
14-07-2025