Details
-
Task
-
Resolution: Fixed
-
P4
-
8
-
None
-
b108
-
generic
-
generic
Description
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.
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.