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

JIT makes optimisations not permitted by the spec

XMLWordPrintable

    • 1.2fcs
    • x86
    • windows_nt
    • Not verified



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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: