JDK-8267773 : PhaseStringOpts::int_stringSize doesn't handle min_jint correctly
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11.0.9,16,17
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux_ubuntu,windows_10
  • CPU: x86_64
  • Submitted: 2021-05-26
  • Updated: 2021-08-09
  • Resolved: 2021-06-02
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 11 JDK 16 JDK 17
11.0.13-oracleFixed 16.0.2Fixed 17 b25Fixed
Related Reports
Relates :  
Description
Problem: Calling StringIndexOutOfBoundsException(Integer.MIN_VALUE) and checking the "toString()" return value eventually (after 10k+ tries) returns an error message indicating the value passed in was "-2".

Correct toString() return value: "java.lang.StringIndexOutOfBoundsException: String index out of range: -2147483648"

Incorrect toString() return value:
"java.lang.StringIndexOutOfBoundsException: String index out of range: -2"

This error does not occur on JDK8, but does occur in 4 out of 5 complete runs on JDK11, and all runs on JDK16.

On JDK11 we see the failure once between 10k and 20k, and on JDK16 and 17 we see the failure once between 10k and 20k, with continuous occurrences starting around the 30k-40k mark.

(A minimal testcase will be attached. I limited the failures to 20 to avoid swamping. Feel free to edit as needed.)

Since this bug doesn't occur when the jit is disabled, and the occurrences only start around the 10k mark, I'm assuming this is a JIT defect. Will ask the community if anyone with JIT skills could take a look.
Comments
Verified by running jdk/java/lang/String/concat/IntegerMinValue.java in mach5 in JDK17 ATR configurations.
09-08-2021

Hi [~afarley], maybe you want to open backport PRs for both, 11u and 16u to see if it applies cleanly and the bots are fine with it? You should go by this process: https://wiki.openjdk.java.net/display/SKARA/Backports#Backports-Creatingbackports, it's fairly straightforward. Especially the WebUI way via /backport for clean backports...
04-06-2021

Fix Request Backport requested for JDK11 and 16, as this defect was seen there as well. The code appears to backport cleanly, no changes. JDK8 does *not* see this defect, so thankfully a backport is not required there as well.
04-06-2021

Thanks Christoph :) Will do.
04-06-2021

Changeset: d47a77d2 Author: Nils Eliasson <neliasso@openjdk.org> Date: 2021-06-02 07:57:08 +0000 URL: https://git.openjdk.java.net/jdk/commit/d47a77d2d54ee8c41ef969b42b3336a646dffd7b
02-06-2021

Quick commandline repro: java -Xcomp -XX:+PrintCompilation -XX:-TieredCompilation -XX:CICompilerCount=1 StringIndexOutOfBoundsExceptionTest Failed on invocation 1: obj.toString() = "java.lang.StringIndexOutOfBoundsException: String index out of range: -2", not "java.lang.StringIndexOutOfBoundsException: String index out of range: -2147483648"
26-05-2021

A quick look - Only happens with C2. Stops happening with -XX:-OptimizeStringConcat ILW=Wrong behaviour, reproduced, -XX:-OptimizeStringConcat = HHL = P2
26-05-2021