Do we need to force slots for temporaries in self-assign?

XMLWordPrintable

    • Type: Task
    • Resolution: Fixed
    • Priority: P4
    • 8
    • Affects Version/s: 8
    • Component/s: core-libs
    • None
    • b108
    • generic
    • generic

      Currently, we force the temporary symbol for an index expression in a self-assignment to get a slot. It used to be needed to avoid double evaluation of the index, e.g. in

      x[y()] += z

      However, these days we compile this to:

          ALOAD 1
          DUP
          ALOAD 2
          ACONST_NULL
          INVOKEDYNAMIC dyn:call
          ASTORE 5
          ALOAD 5
          DUP_X1
          INVOKEDYNAMIC dyn:getElem
          ALOAD 3
          INVOKEDYNAMIC ADD:OOO_I
          INVOKEDYNAMIC dyn:setElem

      Note that due to the use of DUP_X1, the ASTORE 5 and ALOAD 5 are not necessary. If we didn't use DUP_X1, then indeed we'd need the local variable slot:

          ASTORE 5
          ALOAD 5
          INVOKEDYNAMIC dyn:getElem
          ALOAD 3
          INVOKEDYNAMIC ADD:OOO_I
      -> ALOAD 5
          INVOKEDYNAMIC dyn:setElem

      It should be investigated if we can eliminate the ASTORE/ALOAD in every self-assignment scenario.

            Assignee:
            Attila Szegedi
            Reporter:
            Attila Szegedi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: