The server compiler replaces the expression "(x & -32) / 2" by "x >> 1" which is not correct. Actually it's ok to replace the division by a right shift, but the removal of the "and operation" is not correct.
1) Test program
DivIdealizeAndMinus32FollowedByDivConst2Bug.java:
public class DivIdealizeAndMinus32FollowedByDivConst2Bug {
public static void main(String[] args) {
long iteration = 0;
while (true) {
iteration++;
int result = andMinus32FollowedByDivConst2(255);
if (result != 112) {
System.out.println("expected 112, but got " + result + " after iteration " + iteration);
System.exit(-1);
}
}
}
private static int andMinus32FollowedByDivConst2(int x) {
return (x & -32) / 2;
}
}
2) Output of the test program on linux-x86_64
$ bin/java -showversion -classpath tests -server -XX:-UseOnStackReplacement -XX:+PrintCompilation DivIdealizeAndMinus32FollowedByDivConst2Bug
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)
1 DivIdealizeAndMinus32FollowedByDivConst2Bug::andMinus32FollowedByDivConst2 (7 bytes)
expected 112, but got 127 after iteration 171644