JDK-8253191 : C2: Masked byte comparisons with large masks produce wrong result on x86
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 12,13,14,15,16
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • CPU: x86
  • Submitted: 2020-09-15
  • Updated: 2024-12-06
  • Resolved: 2020-10-08
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 15 JDK 16
15.0.2Fixed 16 b20Fixed
Related Reports
Relates :  
Relates :  
Description
Whilst testing some fairly simple code in eXist-db which does VBE (Variable Byte Encoding) of java.lang.short values to/from byte[], we discovered that the tests would always pass on JDKs 8 through 11, but fail in what appeared to be a random intermittent manner on JDKs 12 through 15 (with HotSpot).

A deeper investigation, enabled me to extract the minimum reproducible code into a standalone test example. We have subsequently tested all adoptOpenJDK from 8 through 14 with both HotSpot and J9, we have also tested JDK 15 with HotSpot from java.net.

1. On JDK versions from 8 to 11 with either HotSpot or J9, the code always runs correctly.
2. On JDK 12+ HotSpot versions the code often fails in a non-deterministic manner, sometimes it fails on the 2nd, 3rd, or 4th iteration. It performs upto 10 iterations by default. Sometimes it will even pass.
3. The code always passes on JDK 12+ J9 versions.
4. Disabling C2 on HotSpot by setting `-XX:TieredStopAtLevel=3` causes the code to pass correctly.
Therefore we suspect a regression in HotSpot in Java 12, which has propagated to 13, 14, and now 15 also.

The test code itself is entirely deterministic - constant input values, no threads, no random, and no system time. The code with instructions for reproducing is available from: https://github.com/adamretter/vbe-test. The results of my testing against all the JDKs is visible here: https://github.com/adamretter/vbe-test#testing-results. There are also Travis-CI results here: https://travis-ci.com/github/adamretter/vbe-test.

We consider this to be a critical issue, as the VBE is used in the persistent storage layer of the eXist-db database. The failure of the tests indicate that data corruption will likely occur when it is run on Java HotSpot 12+.

Many thanks to the AdoptOpenJDK Slack group, especially Ben Evans, MBien, and Patrick Reinhart, who helped me pin-point the issue towards HotSpot and C2.
Comments
Fix Request (15u) This fixes the new regression introduced in 15. The backport applies cleanly to 15u, passes tier{1,2} tests, new test fails without the patch, passes with it. There is a little testbug follow up (JDK-8255067), which we can backport a bit later.
21-10-2020

Changeset: 6d13c766 Author: Vladimir Ivanov <vlivanov@openjdk.org> Date: 2020-10-08 12:41:46 +0000 URL: https://git.openjdk.java.net/jdk/commit/6d13c766
08-10-2020

It's the very same problem fixed by JDK-8204479, but JDK-8214027 reincarnated it in 12. PS: kudos for providing excellent test case, Patrick [~reinhapa]!
06-10-2020