changeset 10759:7f186f1486f7

Use initializing write node in object clone snippets.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 15 Jul 2013 16:24:08 +0200
parents e82c28e94f08
children 59d2d6a30d29
files graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java
diffstat 3 files changed, 44 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java	Mon Jul 15 16:24:03 2013 +0200
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java	Mon Jul 15 16:24:08 2013 +0200
@@ -365,6 +365,20 @@
     void writeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity);
 
     /**
+     * Initializes the memory at address {@code (this + offset)}. Both the base address and offset
+     * are in bytes. The memory must be uninitialized or zero prior to this operation.
+     * <p>
+     * The offset is always treated as a {@link Signed} value. However, the static type is
+     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
+     * knows that the highest-order bit of the unsigned value is never used).
+     * 
+     * @param offset the signed offset for the memory access
+     * @param locationIdentity the identity of the write (see {@link LocationNode})
+     * @param val the value to be written to memory
+     */
+    void initializeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity);
+
+    /**
      * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
      * bytes.
      * <p>
@@ -459,6 +473,16 @@
     void writeWord(int offset, WordBase val, LocationIdentity locationIdentity);
 
     /**
+     * Initializes the memory at address {@code (this + offset)}. Both the base address and offset
+     * are in bytes. The memory must be uninitialized or zero prior to this operation.
+     * 
+     * @param offset the signed offset for the memory access
+     * @param locationIdentity the identity of the write (see {@link LocationNode})
+     * @param val the value to be written to memory
+     */
+    void initializeWord(int offset, WordBase val, LocationIdentity locationIdentity);
+
+    /**
      * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
      * bytes.
      * 
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java	Mon Jul 15 16:24:03 2013 +0200
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java	Mon Jul 15 16:24:08 2013 +0200
@@ -61,6 +61,7 @@
          READ,
          READ_COMPRESSED,
          WRITE,
+         INITIALIZE,
          ZERO,
          FROM_UNSIGNED,
          FROM_SIGNED,
@@ -758,6 +759,12 @@
     }
 
     @Override
+    @Operation(opcode = Opcode.INITIALIZE)
+    public void initializeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity) {
+        unsafe.putAddress(add((Word) offset).unbox(), ((Word) val).unbox());
+    }
+
+    @Override
     @Operation(opcode = Opcode.WRITE)
     public native void writeObject(WordBase offset, Object val, LocationIdentity locationIdentity);
 
@@ -810,6 +817,12 @@
     }
 
     @Override
+    @Operation(opcode = Opcode.INITIALIZE)
+    public void initializeWord(int offset, WordBase val, LocationIdentity locationIdentity) {
+        initializeWord(signed(offset), val, locationIdentity);
+    }
+
+    @Override
     @Operation(opcode = Opcode.WRITE)
     public void writeObject(int offset, Object val, LocationIdentity locationIdentity) {
         writeObject(signed(offset), val, locationIdentity);
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Mon Jul 15 16:24:03 2013 +0200
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Mon Jul 15 16:24:08 2013 +0200
@@ -38,6 +38,7 @@
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.util.*;
 import com.oracle.graal.word.*;
+import com.oracle.graal.word.Word.Opcode;
 import com.oracle.graal.word.Word.Operation;
 
 /**
@@ -184,7 +185,8 @@
                         replace(invoke, readOp(graph, arguments.get(0), invoke, location, true));
                         break;
                     }
-                    case WRITE: {
+                    case WRITE:
+                    case INITIALIZE: {
                         assert arguments.size() == 3 || arguments.size() == 4;
                         Kind writeKind = asKind(targetMethod.getSignature().getParameterType(1, targetMethod.getDeclaringClass()));
                         LocationNode location;
@@ -193,7 +195,7 @@
                         } else {
                             location = makeLocation(graph, arguments.get(1), writeKind, arguments.get(3));
                         }
-                        replace(invoke, writeOp(graph, arguments.get(0), arguments.get(2), invoke, location));
+                        replace(invoke, writeOp(graph, arguments.get(0), arguments.get(2), invoke, location, operation.opcode()));
                         break;
                     }
                     case ZERO:
@@ -330,8 +332,9 @@
         return read;
     }
 
-    private static ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode value, Invoke invoke, LocationNode location) {
-        WriteNode write = graph.add(new WriteNode(base, value, location, WriteBarrierType.NONE, false));
+    private static ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode value, Invoke invoke, LocationNode location, Opcode op) {
+        assert op == Opcode.WRITE || op == Opcode.INITIALIZE;
+        WriteNode write = graph.add(new WriteNode(base, value, location, WriteBarrierType.NONE, false, op == Opcode.WRITE));
         write.setStateAfter(invoke.stateAfter());
         graph.addBeforeFixed(invoke.asNode(), write);
         return write;