JDK-8071865 : Byte.valueOf() cause bitwise operators got wrong result
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8u20,8u25,8u31
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2015-01-28
  • Updated: 2023-07-21
  • Resolved: 2023-07-21
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 8
8u40Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
windows 8
windows xp
CentOS release 6.6 (Final)


A DESCRIPTION OF THE PROBLEM :
Byte.valueOf() cause bitwise operators got wrong result

REGRESSION.  Last worked in version 8u11

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
with -server option to run the code


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
	public static void main(String[] args) throws Exception {
		for (int i = 0, k = 20; i < Integer.MAX_VALUE; i++) {
			final Byte b = (byte) -1; // new Byte((byte) -1) won't work
			final int x = b.byteValue() & 0xff;
			if (i % 100 == 0) Thread.sleep(1); // or other operations to make this code run slower
			if (x == -1) System.out.println(x + " is -1 (" + i + ")"); // never happened
			if (x != 255) {
				System.out.println(x + " is not 255 (" + i + ")");
				if (x == -1) System.out.println(x + " is not 255 but -1 (" + i + ")"); // only once
				if (--k == 0) break; // change k value if you want more samples
			}
		}
	}
}
---------- END SOURCE ----------


Comments
Verified that this issue is fixed by JDK-8058847 in 8u40 b17. Closed as duplicate.
30-01-2015

[~thartmann], can you verify it's a duplicate of JDK-8058847?
29-01-2015

Pretty sure it is. -XX:-EliminateAutoBox makes the bug go away.
29-01-2015

Can be a duplicate of JDK-8058847.
29-01-2015

The bug does not exist in 8u11.
29-01-2015

SPARC is also affected. But the bug is fixed in 8u40: $ /java/re/jdk/8u31/promoted/latest/binaries/solaris-sparcv9/bin/java -XX:-TieredCompilation -XX:+PrintCompilation Test 1059 1 java.lang.String::hashCode (55 bytes) 1215 2 java.lang.Byte::valueOf (10 bytes) 1215 3 java.lang.Byte::byteValue (5 bytes) 1264 4 % Test::main @ 5 (192 bytes) 1275 4 % Test::main @ -2 (192 bytes) made not entrant -1 (ffffffff) is not 255 (15587) -1 is not 255 but -1 (15587) 1288 5 % Test::main @ 5 (192 bytes) -1 (ffffffff) is not 255 (18659) -1 (ffffffff) is not 255 (18660) -1 (ffffffff) is not 255 (18661) -1 (ffffffff) is not 255 (18662) -1 (ffffffff) is not 255 (18663) -1 (ffffffff) is not 255 (18664) -1 (ffffffff) is not 255 (18665) -1 (ffffffff) is not 255 (18666) -1 (ffffffff) is not 255 (18667) -1 (ffffffff) is not 255 (18668) -1 (ffffffff) is not 255 (18669) -1 (ffffffff) is not 255 (18670) -1 (ffffffff) is not 255 (18671) -1 (ffffffff) is not 255 (18672) -1 (ffffffff) is not 255 (18673) -1 (ffffffff) is not 255 (18674) -1 (ffffffff) is not 255 (18675) -1 (ffffffff) is not 255 (18676) -1 (ffffffff) is not 255 (18677) $ /java/re/jdk/8u40/promoted/latest/binaries/solaris-sparcv9/bin/java -XX:-TieredCompilation -XX:+PrintCompilation Test 830 1 java.lang.String::hashCode (55 bytes) 984 2 java.lang.Byte::valueOf (10 bytes) 985 3 java.lang.Byte::byteValue (5 bytes) 1033 4 % Test::main @ 5 (192 bytes) 11190 5 n java.lang.Thread::sleep (native) (static)
29-01-2015

Seems to be a C2 issue: $ java -XX:-TieredCompilation Test -1 is not 255 (15587) -1 is not 255 but -1 (15587) / is not 255 (17635) / is not 255 (17636) / is not 255 (17637) / is not 255 (17638) / is not 255 (17639) / is not 255 (17640) / is not 255 (17641) / is not 255 (17642) / is not 255 (17643) / is not 255 (17644) / is not 255 (17645) / is not 255 (17646) / is not 255 (17647) / is not 255 (17648) / is not 255 (17649) / is not 255 (17650) / is not 255 (17651) / is not 255 (17652) / is not 255 (17653)
29-01-2015

It's probably better if this is evaluated first by the compiler team as this doesn't appear to duplicate with -Xint.
29-01-2015

Checked this for JDK 8u25, 8u31 and 8u40 ea and the result varies between them. Couldn't confirm this with 8u11 as the run fails to complete.
29-01-2015