Microsoft KB Archive/259989

= FIX: Unsigned Right Shift Operator Returns Incorrect Result =

Article ID: 259989

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q259989



SYMPTOMS
When you perform an unsigned right shift assignment on a byte variable while the Just In Time compiler (JIT) is turned on, the results obtained are incorrect.



CAUSE
This is caused by a bug in the JIT in which the shift operation is incorrectly optimized.



RESOLUTION
A possible way to work around this problem is to turn off the JIT (although this can cause some Java programs to run slower).



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug has been verified to occur in both the 3100 and 3200 series of the Microsoft virtual machine.

This problem was corrected in Windows 2000 Service Pack 1.



Steps to Reproduce Behavior
The following Java code reproduces the problem:

RSTest.java public class RSTest { public static void main(String args[]) {   byte b=(byte)0x80; System.out.println(&quot;Should read: ffffff80 got:&quot;+Integer.toHexString(b)); b >>>= 1; System.out.println(&quot;Should read: ffffffc0 got:&quot;+Integer.toHexString(b)); b >>>= 1; System.out.println(&quot;Should read: ffffffe0 got:&quot;+Integer.toHexString(b)); b=(byte)0x80; b >>>= 2; System.out.println(&quot;Should read: ffffffe0 got:&quot;+Integer.toHexString(b)); } }

Compile RSTest.java, and then to see result, type from the command line:

jview RSTest

To turn off the JIT:
 * 1) From the View menu in Internet Explorer, select Options.
 * 2) Select the Advanced tab.
 * 3) Clear the check box for Enable Java JIT Compiler.

Rerun the test code and the expected results appear.

