-
Bug
-
Resolution: Fixed
-
P3
-
hs10
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2171024 | 7 | Tom Rodriguez | P3 | Closed | Fixed | b43 |
JDK-2170219 | 6u12 | Tom Rodriguez | P3 | Resolved | Fixed | b01 |
JDK-2169323 | hs11 | Tom Rodriguez | P3 | Closed | Fixed | b17 |
Static variable leads to wrong comparison results in client compiler.
The following code produces wrong results when running with "-client -Xcomp".
public class TesterSmall {
static boolean var_bad_static;
public static void main(String[] args)
{
boolean var_good_local;
long res;
// wrong result in case static var is used
var_bad_static = true;
res = ( (1 > ((var_bad_static) ? 1L : 0)) ? 1 : 0);
System.out.println("var_bad_static = " + var_bad_static);
System.out.println("res = " + res);
System.out.println();
// correct result in case local var is used
var_good_local = true;
res = ( (1 > ((var_good_local) ? 1L : 0)) ? 1 : 0);
System.out.println("var_good_local = " + var_good_local);
System.out.println("res = " + res);
System.out.println();
}
}
> java -client -Xcomp TesterSmall
var_bad_static = true
res = 1
var_good_local = true
res = 0
expected results are:
> java -client -Xmixed TesterSmall
var_bad_static = true
res = 0
var_good_local = true
res = 0
var_good_local is used just to demonstrate that the problem is with static variable.
Also, there is no problem in case int will be used instead of long.
i.e. the following code will work:
res = ( (1 > ((var_bad_static) ? 1 : 0)) ? 1 : 0);
The following code produces wrong results when running with "-client -Xcomp".
public class TesterSmall {
static boolean var_bad_static;
public static void main(String[] args)
{
boolean var_good_local;
long res;
// wrong result in case static var is used
var_bad_static = true;
res = ( (1 > ((var_bad_static) ? 1L : 0)) ? 1 : 0);
System.out.println("var_bad_static = " + var_bad_static);
System.out.println("res = " + res);
System.out.println();
// correct result in case local var is used
var_good_local = true;
res = ( (1 > ((var_good_local) ? 1L : 0)) ? 1 : 0);
System.out.println("var_good_local = " + var_good_local);
System.out.println("res = " + res);
System.out.println();
}
}
> java -client -Xcomp TesterSmall
var_bad_static = true
res = 1
var_good_local = true
res = 0
expected results are:
> java -client -Xmixed TesterSmall
var_bad_static = true
res = 0
var_good_local = true
res = 0
var_good_local is used just to demonstrate that the problem is with static variable.
Also, there is no problem in case int will be used instead of long.
i.e. the following code will work:
res = ( (1 > ((var_bad_static) ? 1 : 0)) ? 1 : 0);
- backported by
-
JDK-2170219 if (k cond (a ? : b: c)) returns reversed answer if k is constant and b and c are longs
- Resolved
-
JDK-2169323 if (k cond (a ? : b: c)) returns reversed answer if k is constant and b and c are longs
- Closed
-
JDK-2171024 if (k cond (a ? : b: c)) returns reversed answer if k is constant and b and c are longs
- Closed