Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6758234

if (k cond (a ? : b: c)) returns reversed answer if k is constant and b and c are longs

XMLWordPrintable

    • b59
    • 6
    • b10
    • generic
    • generic
    • Verified

        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);

              never Tom Rodriguez
              epavlova Ekaterina Pavlova
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: