changeset 16741:705cebda4776

Clone CompositeValue in LIRIntrospection.forEachComponent().
author Josef Eisl <josef.eisl@jku.at>
date Fri, 08 Aug 2014 18:13:50 +0200
parents bc1b601dabc9
children 6052c5456170
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Thu Aug 07 14:36:28 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Fri Aug 08 18:13:50 2014 +0200
@@ -153,6 +153,7 @@
 
     protected static CompositeValue forEachComponent(LIRInstruction inst, CompositeValue obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags,
                     InstructionValueProcedure proc) {
+        CompositeValue newCompValue = null;
         for (int i = 0; i < offsets.length; i++) {
             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(flags[i]);
 
@@ -165,9 +166,16 @@
                 } else {
                     newValue = proc.doValue(inst, value, mode, flags[i]);
                 }
-                setValue(obj, offsets[i], newValue);
+                if (!value.identityEquals(newValue)) {
+                    // lazy initialize
+                    if (newCompValue == null) {
+                        newCompValue = obj.clone();
+                    }
+                    setValue(newCompValue, offsets[i], newValue);
+                }
             } else {
                 Value[] values = getValueArray(obj, offsets[i]);
+                Value[] newValues = null;
                 for (int j = 0; j < values.length; j++) {
                     Value value = values[j];
                     Value newValue;
@@ -177,11 +185,20 @@
                     } else {
                         newValue = proc.doValue(inst, value, mode, flags[i]);
                     }
-                    values[j] = newValue;
+                    if (!value.identityEquals(newValue)) {
+                        // lazy initialize
+                        if (newValues == null) {
+                            if (newCompValue == null) {
+                                newCompValue = obj.clone();
+                            }
+                            newValues = getValueArray(newCompValue, offsets[i]);
+                        }
+                        newValues[j] = newValue;
+                    }
                 }
             }
         }
-        return obj;
+        return newCompValue != null ? newCompValue : obj;
     }
 
     protected static void forEach(LIRInstruction inst, Object obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, ValuePositionProcedure proc,