changeset 8578:f29c17fa7d96

Merge
author Matthias Grimmer <grimmer@ssw.jku.at>
date Fri, 29 Mar 2013 09:59:06 +0100
parents 6388d983385a (current diff) c324983e5d28 (diff)
children 847cd24fc4cf
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPost.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPre.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/SerialWriteBarrierPost.java
diffstat 10 files changed, 253 insertions(+), 324 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Fri Mar 29 09:58:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Fri Mar 29 09:59:06 2013 +0100
@@ -610,12 +610,18 @@
             FixedWithNextNode first = memoryWrite;
 
             if (field.getKind() == Kind.Object && !memoryWrite.value().objectStamp().alwaysNull()) {
-                WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(memoryWrite.object(), null, memoryWrite.location(), true));
-                WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(memoryWrite.object(), memoryWrite.value(), memoryWrite.location(), false));
-                graph.addBeforeFixed(memoryWrite, writeBarrierPre);
-                graph.addAfterFixed(memoryWrite, writeBarrierPost);
-                first = writeBarrierPre;
-                last = writeBarrierPost;
+                if (config.useG1GC) {
+                    WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(memoryWrite.object(), null, memoryWrite.location(), true));
+                    WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(memoryWrite.object(), memoryWrite.value(), memoryWrite.location(), false));
+                    graph.addBeforeFixed(memoryWrite, writeBarrierPre);
+                    graph.addAfterFixed(memoryWrite, writeBarrierPost);
+                    first = writeBarrierPre;
+                    last = writeBarrierPost;
+                } else {
+                    FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(memoryWrite.object()));
+                    graph.addAfterFixed(memoryWrite, writeBarrier);
+                    last = writeBarrier;
+                }
             }
             if (storeField.isVolatile()) {
                 MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_WRITE));
@@ -630,14 +636,25 @@
             LocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, cas.expected().kind(), cas.displacement(), cas.offset(), graph, 1);
             if (expected.kind() == Kind.Object && !cas.newValue().objectStamp().alwaysNull()) {
                 ResolvedJavaType type = cas.object().objectStamp().type();
-                WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(cas.object(), null, location, true));
-                graph.addBeforeFixed(cas, writeBarrierPre);
                 if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) {
-                    WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, false));
-                    graph.addAfterFixed(cas, writeBarrierPost);
+                    // Use a field write barrier since it's not an array store
+                    if (config.useG1GC) {
+                        WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(cas.object(), null, location, true));
+                        WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, false));
+                        graph.addBeforeFixed(cas, writeBarrierPre);
+                        graph.addAfterFixed(cas, writeBarrierPost);
+                    } else {
+                        graph.addAfterFixed(cas, graph.add(new FieldWriteBarrier(cas.object())));
+                    }
                 } else {
-                    WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, true));
-                    graph.addAfterFixed(cas, writeBarrierPost);
+                    // This may be an array store so use an array write barrier
+                    if (config.useG1GC) {
+                        WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(cas.object(), null, location, true));
+                        graph.addBeforeFixed(cas, writeBarrierPre);
+                        graph.addAfterFixed(cas, graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, true)));
+                    } else {
+                        graph.addAfterFixed(cas, graph.add(new ArrayWriteBarrier(cas.object(), location)));
+                    }
                 }
             }
         } else if (n instanceof LoadIndexedNode) {
@@ -681,10 +698,14 @@
             graph.replaceFixedWithFixed(storeIndexed, memoryWrite);
 
             if (elementKind == Kind.Object && !value.objectStamp().alwaysNull()) {
-                WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(array, null, arrayLocation, true));
-                graph.addBeforeFixed(memoryWrite, writeBarrierPre);
-                WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(array, value, arrayLocation, true));
-                graph.addAfterFixed(memoryWrite, writeBarrierPost);
+                if (config.useG1GC) {
+                    WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(array, null, arrayLocation, true));
+                    graph.addBeforeFixed(memoryWrite, writeBarrierPre);
+                    WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(array, value, arrayLocation, true));
+                    graph.addAfterFixed(memoryWrite, writeBarrierPost);
+                } else {
+                    graph.addAfterFixed(memoryWrite, graph.add(new ArrayWriteBarrier(array, arrayLocation)));
+                }
             }
         } else if (n instanceof UnsafeLoadNode) {
             UnsafeLoadNode load = (UnsafeLoadNode) n;
@@ -704,12 +725,25 @@
             graph.replaceFixedWithFixed(store, write);
             if (write.value().kind() == Kind.Object && !write.value().objectStamp().alwaysNull()) {
                 ResolvedJavaType type = object.objectStamp().type();
-                WriteBarrierPre writeBarrierPre = new WriteBarrierPre(object, null, location, true);
-                graph.addBeforeFixed(write, graph.add(writeBarrierPre));
+                // WriteBarrier writeBarrier;
                 if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) {
-                    graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, false)));
+                    // Use a field write barrier since it's not an array store
+                    if (config.useG1GC) {
+                        WriteBarrierPre writeBarrierPre = new WriteBarrierPre(object, null, location, true);
+                        graph.addBeforeFixed(write, graph.add(writeBarrierPre));
+                        graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, false)));
+                    } else {
+                        graph.addAfterFixed(write, graph.add(new FieldWriteBarrier(object)));
+                    }
                 } else {
-                    graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, true)));
+                    // This may be an array store so use an array write barrier
+                    if (config.useG1GC) {
+                        WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(object, null, location, true));
+                        graph.addBeforeFixed(write, writeBarrierPre);
+                        graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, true)));
+                    } else {
+                        graph.addAfterFixed(write, graph.add(new ArrayWriteBarrier(object, location)));
+                    }
                 }
             }
         } else if (n instanceof LoadHubNode) {
@@ -742,12 +776,14 @@
             monitorSnippets.lower((MonitorEnterNode) n, tool);
         } else if (n instanceof MonitorExitNode) {
             monitorSnippets.lower((MonitorExitNode) n, tool);
-        } else if (n instanceof SerialWriteBarrierPost) {
-            writeBarrierSnippets.lower((SerialWriteBarrierPost) n, tool);
-        } else if (n instanceof G1WriteBarrierPre) {
-            writeBarrierSnippets.lower((G1WriteBarrierPre) n, tool);
-        } else if (n instanceof G1WriteBarrierPost) {
-            writeBarrierSnippets.lower((G1WriteBarrierPost) n, tool);
+        } else if (n instanceof FieldWriteBarrier) {
+            writeBarrierSnippets.lower((FieldWriteBarrier) n, tool);
+        } else if (n instanceof ArrayWriteBarrier) {
+            writeBarrierSnippets.lower((ArrayWriteBarrier) n, tool);
+        } else if (n instanceof WriteBarrierPre) {
+            writeBarrierSnippets.lower((WriteBarrierPre) n, tool);
+        } else if (n instanceof WriteBarrierPost) {
+            writeBarrierSnippets.lower((WriteBarrierPost) n, tool);
         } else if (n instanceof TLABAllocateNode) {
             newObjectSnippets.lower((TLABAllocateNode) n, tool);
         } else if (n instanceof InitializeObjectNode) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java	Fri Mar 29 09:59:06 2013 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.nodes;
+
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
+
+public final class ArrayWriteBarrier extends FixedWithNextNode implements Lowerable {
+
+    @Input private ValueNode object;
+    @Input private LocationNode location;
+
+    public ValueNode getObject() {
+        return object;
+    }
+
+    public LocationNode getLocation() {
+        return location;
+    }
+
+    public ArrayWriteBarrier(ValueNode object, LocationNode location) {
+        super(StampFactory.forVoid());
+        this.object = object;
+        this.location = location;
+    }
+
+    public void lower(LoweringTool generator) {
+        generator.getRuntime().lower(this, generator);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/FieldWriteBarrier.java	Fri Mar 29 09:59:06 2013 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.nodes;
+
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
+
+public final class FieldWriteBarrier extends FixedWithNextNode implements Lowerable {
+
+    @Input private ValueNode object;
+
+    public ValueNode getObject() {
+        return object;
+    }
+
+    public FieldWriteBarrier(ValueNode object) {
+        super(StampFactory.forVoid());
+        this.object = object;
+    }
+
+    public void lower(LoweringTool generator) {
+        generator.getRuntime().lower(this, generator);
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPost.java	Fri Mar 29 09:58:26 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.oracle.graal.hotspot.nodes;
-
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.spi.*;
-
-public class G1WriteBarrierPost extends WriteBarrierPost implements Lowerable {
-
-    @Input private ValueNode object;
-    @Input private ValueNode value;
-    @Input private LocationNode location;
-    private final boolean precise;
-
-    @Override
-    public ValueNode getObject() {
-        return object;
-    }
-
-    @Override
-    public ValueNode getValue() {
-        return value;
-    }
-
-    @Override
-    public LocationNode getLocation() {
-        return location;
-    }
-
-    @Override
-    public boolean usePrecise() {
-        return precise;
-    }
-
-    public G1WriteBarrierPost(ValueNode object, ValueNode value, LocationNode location, boolean precise) {
-        this.object = object;
-        this.value = value;
-        this.location = location;
-        this.precise = precise;
-    }
-
-    @Override
-    public void lower(LoweringTool generator) {
-        generator.getRuntime().lower(this, generator);
-    }
-
-}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPre.java	Fri Mar 29 09:58:26 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.oracle.graal.hotspot.nodes;
-
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.spi.*;
-
-public final class G1WriteBarrierPre extends WriteBarrierPre implements Lowerable {
-
-    @Input private ValueNode object;
-    @Input private LocationNode location;
-    @Input private ValueNode expectedObject;
-    private final boolean doLoad;
-
-    @Override
-    public ValueNode getObject() {
-        return object;
-    }
-
-    @Override
-    public ValueNode getExpectedObject() {
-        return expectedObject;
-    }
-
-    @Override
-    public boolean doLoad() {
-        return doLoad;
-    }
-
-    @Override
-    public LocationNode getLocation() {
-        return location;
-    }
-
-    public G1WriteBarrierPre(ValueNode object, ValueNode expectedObject, LocationNode location, boolean doLoad) {
-        this.object = object;
-        this.doLoad = doLoad;
-        this.location = location;
-        this.expectedObject = expectedObject;
-    }
-
-    @Override
-    public void lower(LoweringTool generator) {
-        generator.getRuntime().lower(this, generator);
-    }
-
-}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/SerialWriteBarrierPost.java	Fri Mar 29 09:58:26 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.oracle.graal.hotspot.nodes;
-
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.spi.*;
-
-public class SerialWriteBarrierPost extends WriteBarrierPost implements Lowerable {
-
-    @Input private ValueNode object;
-    @Input private LocationNode location;
-    private final boolean usePrecise;
-
-    public SerialWriteBarrierPost(ValueNode object, LocationNode location, boolean usePrecise) {
-        this.object = object;
-        this.location = location;
-        this.usePrecise = usePrecise;
-    }
-
-    @Override
-    public ValueNode getObject() {
-        return object;
-    }
-
-    @Override
-    public LocationNode getLocation() {
-        return location;
-    }
-
-    @Override
-    public boolean usePrecise() {
-        return usePrecise;
-    }
-
-    @Override
-    public void lower(LoweringTool generator) {
-        generator.getRuntime().lower(this, generator);
-    }
-
-}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPost.java	Fri Mar 29 09:58:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPost.java	Fri Mar 29 09:59:06 2013 +0100
@@ -22,18 +22,15 @@
  */
 package com.oracle.graal.hotspot.nodes;
 
-import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*;
-
-import com.oracle.graal.api.meta.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
 
-public class WriteBarrierPost extends WriteBarrier implements Lowerable {
+public final class WriteBarrierPost extends FixedWithNextNode implements Lowerable {
 
     @Input private ValueNode object;
     @Input private ValueNode value;
-    @Input private ValueNode index;
     @Input private LocationNode location;
     private final boolean precise;
 
@@ -53,45 +50,15 @@
         return precise;
     }
 
-    public WriteBarrierPost() {
-        this.precise = false;
-    }
-
-    public WriteBarrierPost(ValueNode object, ValueNode value, ValueNode index) {
-        this.object = object;
-        this.value = value;
-        this.index = index;
-        this.precise = true;
-        this.location = null;
-    }
-
     public WriteBarrierPost(ValueNode object, ValueNode value, LocationNode location, boolean precise) {
+        super(StampFactory.forVoid());
         this.object = object;
         this.value = value;
         this.location = location;
         this.precise = precise;
     }
 
-    @Override
     public void lower(LoweringTool generator) {
-        StructuredGraph graph = (StructuredGraph) this.graph();
-        if (location == null) { // Come from array copy intrinsic
-            LocationNode arrayLocation = IndexedLocationNode.create(LocationNode.getArrayLocation(Kind.Object), Kind.Object, arrayBaseOffset(Kind.Object), index, graph, arrayIndexScale(Kind.Object));
-            if (useG1GC()) {
-                graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPost(object, value, arrayLocation, true)));
-            } else {
-                graph.replaceFixedWithFixed(this, graph().add(new SerialWriteBarrierPost(object, arrayLocation, true)));
-            }
-        } else { // Normal WriteBarrier
-            assert location != null;
-            if (useG1GC()) {
-                graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPost(object, value, location, precise)));
-            } else {
-                graph.replaceFixedWithFixed(this, graph().add(new SerialWriteBarrierPost(object, location, precise)));
-            }
-        }
+        generator.getRuntime().lower(this, generator);
     }
-
-    @NodeIntrinsic
-    public static native void arrayCopyWriteBarrier(Object array, Object value, long index);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPre.java	Fri Mar 29 09:58:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPre.java	Fri Mar 29 09:59:06 2013 +0100
@@ -22,13 +22,12 @@
  */
 package com.oracle.graal.hotspot.nodes;
 
-import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*;
-
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
 
-public class WriteBarrierPre extends WriteBarrier implements Lowerable {
+public final class WriteBarrierPre extends FixedWithNextNode implements Lowerable {
 
     @Input private ValueNode object;
     @Input private LocationNode location;
@@ -51,25 +50,16 @@
         return location;
     }
 
-    public WriteBarrierPre() {
-        this.doLoad = false;
-    }
-
     public WriteBarrierPre(ValueNode object, ValueNode expectedObject, LocationNode location, boolean doLoad) {
+        super(StampFactory.forVoid());
         this.object = object;
         this.doLoad = doLoad;
         this.location = location;
         this.expectedObject = expectedObject;
     }
 
-    @Override
     public void lower(LoweringTool generator) {
-        StructuredGraph graph = (StructuredGraph) this.graph();
-        if (useG1GC()) {
-            graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPre(getObject(), getExpectedObject(), getLocation(), doLoad())));
-        } else {
-            graph.removeFixed(this);
-        }
+        generator.getRuntime().lower(this, generator);
     }
 
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java	Fri Mar 29 09:58:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java	Fri Mar 29 09:59:06 2013 +0100
@@ -37,7 +37,7 @@
 import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.replacements.*;
-import com.oracle.graal.replacements.Snippet.ConstantParameter;
+import com.oracle.graal.replacements.Snippet.*;
 import com.oracle.graal.replacements.nodes.*;
 import com.oracle.graal.word.*;
 
@@ -236,8 +236,9 @@
         }
     }
 
+    // Does NOT perform store checks
     @Snippet
-    private static void arrayObjectCopy(Object src, int srcPos, Object dest, int destPos, int length) {
+    public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) {
         objectCounter.inc();
         checkNonNull(src);
         checkNonNull(dest);
@@ -246,49 +247,45 @@
         int header = arrayBaseOffset(Kind.Object);
         if (src == dest && srcPos < destPos) { // bad aliased case
             long start = (long) (length - 1) * scale;
-            long j = (long) (length) - 1;
             for (long i = start; i >= 0; i -= scale) {
                 Object a = UnsafeLoadNode.load(src, header, i + (long) srcPos * scale, Kind.Object);
                 DirectObjectStoreNode.storeObject(dest, header, i + (long) destPos * scale, a);
-                WriteBarrierPost.arrayCopyWriteBarrier(dest, a, j);
-                j--;
             }
         } else {
             long end = (long) length * scale;
-            long j = srcPos;
             for (long i = 0; i < end; i += scale) {
                 Object a = UnsafeLoadNode.load(src, header, i + (long) srcPos * scale, Kind.Object);
                 DirectObjectStoreNode.storeObject(dest, header, i + (long) destPos * scale, a);
-                WriteBarrierPost.arrayCopyWriteBarrier(dest, a, j);
-                j++;
+
+            }
+        }
+        if (length > 0) {
+            int cardShift = cardTableShift();
+            long cardStart = cardTableStart();
+            long dstAddr = GetObjectAddressNode.get(dest);
+            long start = (dstAddr + header + (long) destPos * scale) >>> cardShift;
+            long end = (dstAddr + header + ((long) destPos + length - 1) * scale) >>> cardShift;
+            long count = end - start + 1;
+            while (count-- > 0) {
+                DirectStoreNode.store((start + cardStart) + count, false, Kind.Boolean);
             }
         }
     }
 
-    // Does NOT perform store checks
-    @Snippet
-    public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) {
-        arrayObjectCopy(src, srcPos, dest, destPos, length);
-    }
-
     @Snippet
     public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) {
+
+        // loading the hubs also checks for nullness
         Word srcHub = loadHub(src);
         Word destHub = loadHub(dest);
+
         int layoutHelper = checkArrayType(srcHub);
-        int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask();
-        final boolean isObjectArray = ((layoutHelper & layoutHelperElementTypePrimitiveInPlace()) == 0);
         if (srcHub.equal(destHub) && src != dest) {
             probability(FAST_PATH_PROBABILITY);
+
             checkLimits(src, srcPos, dest, destPos, length);
-            if (isObjectArray) {
-                genericObjectExactCallCounter.inc();
-                probability(FAST_PATH_PROBABILITY);
-                arrayObjectCopy(src, srcPos, dest, destPos, length);
-            } else {
-                genericPrimitiveCallCounter.inc();
-                arraycopyInnerloop(src, srcPos, dest, destPos, length, layoutHelper);
-            }
+
+            arraycopyInnerloop(src, srcPos, dest, destPos, length, layoutHelper);
         } else {
             genericObjectCallCounter.inc();
             System.arraycopy(src, srcPos, dest, destPos, length);
@@ -316,11 +313,29 @@
             srcOffset = srcOffset.add(1);
         }
         while (destOffset.belowThan(destEnd)) {
-            Word word = srcOffset.readWord(0, UNKNOWN_LOCATION);
-            destOffset.writeWord(0, word, ANY_LOCATION);
+            destOffset.writeWord(0, srcOffset.readWord(0, UNKNOWN_LOCATION), ANY_LOCATION);
             destOffset = destOffset.add(wordSize());
             srcOffset = srcOffset.add(wordSize());
         }
+
+        if ((layoutHelper & layoutHelperElementTypePrimitiveInPlace()) != 0) {
+            genericPrimitiveCallCounter.inc();
+
+        } else {
+            probability(LIKELY_PROBABILITY);
+            genericObjectExactCallCounter.inc();
+
+            if (length > 0) {
+                int cardShift = cardTableShift();
+                long cardStart = cardTableStart();
+                Word destCardOffset = destStart.unsignedShiftRight(cardShift).add(Word.unsigned(cardStart));
+                Word destCardEnd = destEnd.subtract(1).unsignedShiftRight(cardShift).add(Word.unsigned(cardStart));
+                while (destCardOffset.belowOrEqual(destCardEnd)) {
+                    DirectStoreNode.store(destCardOffset.rawValue(), false, Kind.Boolean);
+                    destCardOffset = destCardOffset.add(1);
+                }
+            }
+        }
     }
 
     private static final SnippetCounter.Group checkCounters = GraalOptions.SnippetCounters ? new SnippetCounter.Group("System.arraycopy checkInputs") : null;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java	Fri Mar 29 09:58:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java	Fri Mar 29 09:59:06 2013 +0100
@@ -40,7 +40,7 @@
 public class WriteBarrierSnippets implements Snippets {
 
     @Snippet
-    public static void g1WriteBarrierPre(@Parameter("object") Object obj, @Parameter("expectedObject") Object expobj, @Parameter("location") Object location,
+    public static void g1PreWriteBarrier(@Parameter("object") Object obj, @Parameter("expectedObject") Object expobj, @Parameter("location") Object location,
                     @ConstantParameter("doLoad") boolean doLoad) {
         Word thread = thread();
         Object object = FixedValueAnchorNode.getObject(obj);
@@ -48,9 +48,11 @@
         Word field = (Word) Word.fromArray(object, location);
         Word previousOop = (Word) Word.fromObject(expectedObject);
         byte markingValue = thread.readByte(HotSpotSnippetUtils.g1SATBQueueMarkingOffset());
+
         Word bufferAddress = thread.readWord(HotSpotSnippetUtils.g1SATBQueueBufferOffset());
         Word indexAddress = thread.add(HotSpotSnippetUtils.g1SATBQueueIndexOffset());
         Word indexValue = indexAddress.readWord(0);
+
         if (markingValue != (byte) 0) {
             if (doLoad) {
                 previousOop = field.readWord(0);
@@ -63,13 +65,14 @@
                     indexAddress.writeWord(0, nextIndex);
                 } else {
                     WriteBarrierPreStubCall.call(previousOop);
+
                 }
             }
         }
     }
 
     @Snippet
-    public static void g1WriteBarrierPost(@Parameter("object") Object obj, @Parameter("value") Object value, @Parameter("location") Object location, @ConstantParameter("usePrecise") boolean usePrecise) {
+    public static void g1PostWriteBarrier(@Parameter("object") Object obj, @Parameter("value") Object value, @Parameter("location") Object location, @ConstantParameter("usePrecise") boolean usePrecise) {
         Word thread = thread();
         Object object = FixedValueAnchorNode.getObject(obj);
         Object wrObject = FixedValueAnchorNode.getObject(value);
@@ -96,6 +99,7 @@
             cardBase = cardBase.add(Word.unsigned(cardTableStart()));
         }
         Word cardAddress = cardBase.add(displacement);
+
         if (xorResult.notEqual(Word.zero())) {
             if (writtenValue.notEqual(Word.zero())) {
                 byte cardByte = cardAddress.readByte(0);
@@ -115,14 +119,24 @@
     }
 
     @Snippet
-    public static void serialWriteBarrierPost(@Parameter("object") Object obj, @Parameter("location") Object location, @ConstantParameter("usePrecise") boolean usePrecise) {
+    public static void serialFieldWriteBarrier(@Parameter("object") Object obj) {
         Object object = FixedValueAnchorNode.getObject(obj);
-        Pointer oop;
-        if (usePrecise) {
-            oop = Word.fromArray(object, location);
+        Pointer oop = Word.fromObject(object);
+        Word base = (Word) oop.unsignedShiftRight(cardTableShift());
+        long startAddress = cardTableStart();
+        int displacement = 0;
+        if (((int) startAddress) == startAddress) {
+            displacement = (int) startAddress;
         } else {
-            oop = Word.fromObject(object);
+            base = base.add(Word.unsigned(cardTableStart()));
         }
+        base.writeByte(displacement, (byte) 0);
+    }
+
+    @Snippet
+    public static void serialArrayWriteBarrier(@Parameter("object") Object obj, @Parameter("location") Object location) {
+        Object object = FixedValueAnchorNode.getObject(obj);
+        Pointer oop = Word.fromArray(object, location);
         Word base = (Word) oop.unsignedShiftRight(cardTableShift());
         long startAddress = cardTableStart();
         int displacement = 0;
@@ -136,30 +150,40 @@
 
     public static class Templates extends AbstractTemplates<WriteBarrierSnippets> {
 
-        private final ResolvedJavaMethod serialWriteBarrierPost;
-        private final ResolvedJavaMethod g1WriteBarrierPre;
-        private final ResolvedJavaMethod g1WriteBarrierPost;
+        private final ResolvedJavaMethod serialFieldWriteBarrier;
+        private final ResolvedJavaMethod serialArrayWriteBarrier;
+        private final ResolvedJavaMethod g1PreWriteBarrier;
+        private final ResolvedJavaMethod g1PostWriteBarrier;
 
         public Templates(CodeCacheProvider runtime, Assumptions assumptions, TargetDescription target) {
             super(runtime, assumptions, target, WriteBarrierSnippets.class);
-            serialWriteBarrierPost = snippet("serialWriteBarrierPost", Object.class, Object.class, boolean.class);
-            g1WriteBarrierPre = snippet("g1WriteBarrierPre", Object.class, Object.class, Object.class, boolean.class);
-            g1WriteBarrierPost = snippet("g1WriteBarrierPost", Object.class, Object.class, Object.class, boolean.class);
+            serialFieldWriteBarrier = snippet("serialFieldWriteBarrier", Object.class);
+            serialArrayWriteBarrier = snippet("serialArrayWriteBarrier", Object.class, Object.class);
+            g1PreWriteBarrier = snippet("g1PreWriteBarrier", Object.class, Object.class, Object.class, boolean.class);
+            g1PostWriteBarrier = snippet("g1PostWriteBarrier", Object.class, Object.class, Object.class, boolean.class);
         }
 
-        public void lower(SerialWriteBarrierPost fieldWriteBarrier, @SuppressWarnings("unused") LoweringTool tool) {
-            ResolvedJavaMethod method = serialWriteBarrierPost;
+        public void lower(ArrayWriteBarrier arrayWriteBarrier, @SuppressWarnings("unused") LoweringTool tool) {
+            ResolvedJavaMethod method = serialArrayWriteBarrier;
             Key key = new Key(method);
-            key.add("usePrecise", fieldWriteBarrier.usePrecise());
+            Arguments arguments = new Arguments();
+            arguments.add("object", arrayWriteBarrier.getObject());
+            arguments.add("location", arrayWriteBarrier.getLocation());
+            SnippetTemplate template = cache.get(key, assumptions);
+            template.instantiate(runtime, arrayWriteBarrier, DEFAULT_REPLACER, arguments);
+        }
+
+        public void lower(FieldWriteBarrier fieldWriteBarrier, @SuppressWarnings("unused") LoweringTool tool) {
+            ResolvedJavaMethod method = serialFieldWriteBarrier;
+            Key key = new Key(method);
             Arguments arguments = new Arguments();
             arguments.add("object", fieldWriteBarrier.getObject());
-            arguments.add("location", fieldWriteBarrier.getLocation());
             SnippetTemplate template = cache.get(key, assumptions);
             template.instantiate(runtime, fieldWriteBarrier, DEFAULT_REPLACER, arguments);
         }
 
-        public void lower(G1WriteBarrierPre writeBarrierPre, @SuppressWarnings("unused") LoweringTool tool) {
-            ResolvedJavaMethod method = g1WriteBarrierPre;
+        public void lower(WriteBarrierPre writeBarrierPre, @SuppressWarnings("unused") LoweringTool tool) {
+            ResolvedJavaMethod method = g1PreWriteBarrier;
             Key key = new Key(method);
             key.add("doLoad", writeBarrierPre.doLoad());
             Arguments arguments = new Arguments();
@@ -170,8 +194,8 @@
             template.instantiate(runtime, writeBarrierPre, DEFAULT_REPLACER, arguments);
         }
 
-        public void lower(G1WriteBarrierPost writeBarrierPost, @SuppressWarnings("unused") LoweringTool tool) {
-            ResolvedJavaMethod method = g1WriteBarrierPost;
+        public void lower(WriteBarrierPost writeBarrierPost, @SuppressWarnings("unused") LoweringTool tool) {
+            ResolvedJavaMethod method = g1PostWriteBarrier;
             Key key = new Key(method);
             key.add("usePrecise", writeBarrierPost.usePrecise());
             Arguments arguments = new Arguments();