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

incorrect primitive long arithmetic error with Java 1.3.0 Solaris HotSpot

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.1
    • 1.3.0, 1.3.1
    • hotspot
    • beta
    • x86, sparc
    • solaris_8



        Name: tb29552 Date: 11/02/2000


        /*
        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
        Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

        Simple arithmetic on primitive longs returns an incorrect
        value. So far, we have only seen this is a set of loops on
        primitive longs running with HotSpot. The bug does not occur
        in 1.2.2, previous versions of Java, or in 1.3.0 with the
        interpreter.

        The class below shows the error when run on the 1.3.0 JVM
        with HotSpot on Solaris 6 or Solaris 8. I haven't tried
        Solaris 7.

        The bug is that the variable "k" gets an incorrect result
        for "k++" at one point in the loop. So far as I can tell,
        all five loops need to be present for the bug to
        occur. Removing the loops that are OUTSIDE or AFTER the loop
        on "k" causes the bug to *appear* to vanish, suggesting this
        is a peephole optimization error in HotSpot.

        The println() statements display the variables starting
        shortly before the error occurs. When i==0 and j==166 and
        k==135, k++ yields 455572 instead of 136.


        -----------------------------------------------------------
        */
        public class Crashes130SolarisWithHotSpot {
            public static void main(String[] argv)
            {
                System.out.println("First Loop");
                for (long i = 0; i < 1; i++)
                {
                    for (long j = 1; j < 192 - i; j++)
                    {
                        Object o = new Object();
                        for (long k = i; k < i + j; k++)
                        {
                            if (i == 0 && j == 166 && k > 120)
                                System.out.println("i=" + i + ", j=" + j + ", k=" + k);
                            if (k > 192)
                            {
                                System.out.println("BUG!!!");
                                System.exit(-1);
                            }
                        }
                    }
                }

                System.out.println("Second Loop");
                for (long i = 0; i < 1; i++)
                {
                    for (long j = 0; j < 1; j++)
                    {
                        Object o = new Object();
                    }
                }
                System.out.println("Success!!");
            }
        }

        (Review ID: 111729)
        ======================================================================

              dmcox David Cox (Inactive)
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: