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

[Lworld] Javac generates bad code for value constructors involving chained assignments

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • tools
    • generic
    • generic

      As reported by Paul Sandoz on Valhalla-dev:

      The following program fails with a verify error upon running:

      public class X {
      static final __ByValue class Point {
          final int x;
          final int y;

          Point() {
              x = y = 0; // This is the cause
          }

          static Point point(int x, int y) {
              Point p = __MakeDefault Point();
              p = __WithField(p.x, x);
              p = __WithField(p.y, y);
              return p;
          }

          @Override
          public boolean equals(Object o) {
              if (!(o instanceof Point)) return false;
              Point op = (Point) o;

              return x == op.x && y == op.y;
          }

          static Point point() {
              return point(0, 0);
          }
      }

      public static void main(String[] args) {
        Point p = Point.point();
      }
      }

      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          X$Point.$makeValue$()LX$Point; @12: i2b
        Reason:
          Type 'X$Point' (current frame, stack[1]) is not assignable to integer
        Current Frame:
          bci: @12
          flags: { }
          locals: { 'X$Point' }
          stack: { 'X$Point', 'X$Point' }
        Bytecode:
          0000000: cb00 024b 2a2a 03cc 0004 594b 91cc 0003
          0000010: 4b2a b0

      at X.main(X.java:31)

      The culprit seems to be the chained assignment
          x = y = 0; // This is the cause

      If it was broken down into two statement, things are fine.

            sadayapalam Srikanth Adayapalam (Inactive)
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: