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

JIT makes optimisations not permitted by the spec

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.1.6, 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: vm-legacy
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Not verified

      Description



      Name: tb29552 Date: 07/23/98


      /*
       * If you run this with the jit, the output is:
       * equals = true
       * equals = true
       * equals = true
       * equals = true
       * equals = true
       *
       * Without the jit, the output is:
       * equals = false
       * equals = false
       * equals = false
       * equals = false
       * equals = false
       *
       * Basically, with the jit, an object can never say that
       * it's not equal to itself. The equals method never even
       * gets called when the references are equal. In most
       * cases this is okay, but it does limit how an object can
       * define equality. This actually caused me some
       * headaches and workarounds. I thought everyone might
       * find it interesting.
       *
       * I think the JIT is taking unwarranted liberties
       * here. Nowhere in the VM or language specs does it say
       * that the specification of a method can be used to
       * optimise it, in cases where that would change the
       * behaviour (except possibly for final methods in classes
       * that can be considered part of the VM, e.g. Object,
       * Class, etc.)
       */

      public class JitTest {
        public boolean equals(Object other) {
            return false;
        }

        public static void main(String[] args) {
            JitTest test = new JitTest();
            for (int i = 0; i < 5; i++)
              System.out.println("equals = " + test.equals(test));
          }
      }

      (Review ID: 35397)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dviswanasunw Deepa Viswanathan (Inactive)
              Reporter:
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: