changeset 6362:6d232ee6a62d

factored shared snippet functionality into HotSpotSnippetUtils
author Doug Simon <doug.simon@oracle.com>
date Wed, 12 Sep 2012 12:34:48 +0200
parents f8416485a37f
children a73fcf1639fc
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java
diffstat 5 files changed, 184 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java	Wed Sep 12 11:29:34 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java	Wed Sep 12 12:34:48 2012 +0200
@@ -21,6 +21,8 @@
  * questions.
  */
 package com.oracle.graal.hotspot.snippets;
+import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
+
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.hotspot.*;
 import com.oracle.graal.nodes.*;
@@ -209,35 +211,4 @@
             }
         }
     }
-
-    @Fold
-    static int arrayBaseOffset(Kind elementKind) {
-        return elementKind.getArrayBaseOffset();
-    }
-
-    @Fold
-    static int arrayIndexScale(Kind elementKind) {
-        return elementKind.getArrayIndexScale();
-    }
-
-    static {
-        assert arrayIndexScale(Kind.Byte) == 1;
-        assert arrayIndexScale(Kind.Boolean) == 1;
-        assert arrayIndexScale(Kind.Char) == 2;
-        assert arrayIndexScale(Kind.Short) == 2;
-        assert arrayIndexScale(Kind.Int) == 4;
-        assert arrayIndexScale(Kind.Long) == 8;
-        assert arrayIndexScale(Kind.Float) == 4;
-        assert arrayIndexScale(Kind.Double) == 8;
-    }
-
-    @Fold
-    private static int cardTableShift() {
-        return HotSpotGraalRuntime.getInstance().getConfig().cardtableShift;
-    }
-
-    @Fold
-    private static long cardTableStart() {
-        return HotSpotGraalRuntime.getInstance().getConfig().cardtableStartAddress;
-    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java	Wed Sep 12 11:29:34 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java	Wed Sep 12 12:34:48 2012 +0200
@@ -21,7 +21,7 @@
  * questions.
  */
 package com.oracle.graal.hotspot.snippets;
-import static com.oracle.graal.hotspot.snippets.ArrayCopySnippets.*;
+import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
 import static com.oracle.graal.snippets.Snippet.Varargs.*;
 import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*;
 
@@ -37,7 +37,6 @@
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.snippets.*;
 import com.oracle.graal.snippets.Snippet.ConstantParameter;
-import com.oracle.graal.snippets.Snippet.Fold;
 import com.oracle.graal.snippets.Snippet.Parameter;
 import com.oracle.graal.snippets.Snippet.VarargsParameter;
 import com.oracle.graal.snippets.SnippetTemplate.AbstractTemplates;
@@ -65,7 +64,7 @@
             isNull.inc();
             return object;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (objectHub != exactHub) {
             exactMiss.inc();
             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ClassCastException);
@@ -91,7 +90,7 @@
             isNull.inc();
             return object;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (UnsafeLoadNode.loadObject(objectHub, 0, superCheckOffset, true) != hub) {
             displayMiss.inc();
             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ClassCastException);
@@ -113,7 +112,7 @@
             isNull.inc();
             return object;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         // if we get an exact match: succeed immediately
         ExplodeLoopNode.explodeLoop();
         for (int i = 0; i < hints.length; i++) {
@@ -143,7 +142,7 @@
             isNull.inc();
             return object;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         // if we get an exact match: succeed immediately
         ExplodeLoopNode.explodeLoop();
         for (int i = 0; i < hints.length; i++) {
@@ -232,26 +231,6 @@
         return false;
     }
 
-    @Fold
-    private static int superCheckOffsetOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().superCheckOffsetOffset;
-    }
-
-    @Fold
-    private static int secondarySuperCacheOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().secondarySuperCacheOffset;
-    }
-
-    @Fold
-    private static int secondarySupersOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().secondarySupersOffset;
-    }
-
-    @Fold
-    private static int hubOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().hubOffset;
-    }
-
     public static class Templates extends AbstractTemplates<CheckCastSnippets> {
 
         private final ResolvedJavaMethod exact;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java	Wed Sep 12 12:34:48 2012 +0200
@@ -0,0 +1,168 @@
+/*
+ * 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.snippets;
+
+import static com.oracle.graal.nodes.extended.UnsafeLoadNode.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.code.Register.RegisterFlag;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.hotspot.*;
+import com.oracle.graal.hotspot.nodes.*;
+import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.snippets.Snippet.Fold;
+import com.oracle.graal.snippets.*;
+import com.oracle.max.asm.target.amd64.*;
+
+//JaCoCo Exclude
+
+/**
+ * A collection of methods used in HotSpot snippets.
+ */
+public class HotSpotSnippetUtils {
+
+    @Fold
+    static boolean verifyOops() {
+        return HotSpotGraalRuntime.getInstance().getConfig().verifyOops;
+    }
+
+    @Fold
+    static int threadTlabTopOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().threadTlabTopOffset;
+    }
+
+    @Fold
+    static int threadTlabEndOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().threadTlabEndOffset;
+    }
+
+    @Fold
+    static Kind wordKind() {
+        return HotSpotGraalRuntime.getInstance().getTarget().wordKind;
+    }
+
+    @Fold
+    static Register stackPointerReg() {
+        return AMD64.rsp;
+    }
+
+    @Fold
+    static int wordSize() {
+        return HotSpotGraalRuntime.getInstance().getTarget().wordSize;
+    }
+
+    @Fold
+    static int pageSize() {
+        return HotSpotGraalRuntime.getInstance().getTarget().pageSize;
+    }
+
+    @Fold
+    static int markOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().markOffset;
+    }
+
+    @Fold
+    static int hubOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().hubOffset;
+    }
+
+    @Fold
+    static int arrayLengthOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().arrayLengthOffset;
+    }
+
+    @Fold
+    static int arrayBaseOffset(Kind elementKind) {
+        return elementKind.getArrayBaseOffset();
+    }
+
+    @Fold
+    static int arrayIndexScale(Kind elementKind) {
+        return elementKind.getArrayIndexScale();
+    }
+
+    @Fold
+    static int cardTableShift() {
+        return HotSpotGraalRuntime.getInstance().getConfig().cardtableShift;
+    }
+
+    @Fold
+    static long cardTableStart() {
+        return HotSpotGraalRuntime.getInstance().getConfig().cardtableStartAddress;
+    }
+
+    @Fold
+    static int superCheckOffsetOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().superCheckOffsetOffset;
+    }
+
+    @Fold
+    static int secondarySuperCacheOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().secondarySuperCacheOffset;
+    }
+
+    @Fold
+    static int secondarySupersOffset() {
+        return HotSpotGraalRuntime.getInstance().getConfig().secondarySupersOffset;
+    }
+
+    /**
+     * Loads the hub from a object, null checking it first.
+     */
+    static Object loadHub(Object object) {
+        return UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+    }
+
+
+    static Object verifyOop(Object object) {
+        if (verifyOops()) {
+            VerifyOopStubCall.call(object);
+        }
+        return object;
+    }
+
+    static Word asWord(Object object) {
+        return Word.fromObject(object);
+    }
+
+    static Word loadWord(Word address, int offset) {
+        Object value = loadObject(address, 0, offset, true);
+        return asWord(value);
+    }
+
+    static {
+        assert arrayIndexScale(Kind.Byte) == 1;
+        assert arrayIndexScale(Kind.Boolean) == 1;
+        assert arrayIndexScale(Kind.Char) == 2;
+        assert arrayIndexScale(Kind.Short) == 2;
+        assert arrayIndexScale(Kind.Int) == 4;
+        assert arrayIndexScale(Kind.Long) == 8;
+        assert arrayIndexScale(Kind.Float) == 4;
+        assert arrayIndexScale(Kind.Double) == 8;
+    }
+
+    public static Register getStubParameterRegister(int index) {
+        RegisterConfig regConfig = HotSpotGraalRuntime.getInstance().getRuntime().getGlobalStubRegisterConfig();
+        return regConfig.getCallingConventionRegisters(CallingConvention.Type.RuntimeCall, RegisterFlag.CPU)[index];
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java	Wed Sep 12 11:29:34 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java	Wed Sep 12 12:34:48 2012 +0200
@@ -23,6 +23,7 @@
 package com.oracle.graal.hotspot.snippets;
 import static com.oracle.graal.hotspot.snippets.CheckCastSnippets.*;
 import static com.oracle.graal.hotspot.snippets.CheckCastSnippets.Templates.*;
+import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
 import static com.oracle.graal.snippets.Snippet.Varargs.*;
 import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*;
 import static com.oracle.graal.snippets.nodes.JumpNode.*;
@@ -41,7 +42,6 @@
 import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.snippets.*;
 import com.oracle.graal.snippets.Snippet.ConstantParameter;
-import com.oracle.graal.snippets.Snippet.Fold;
 import com.oracle.graal.snippets.Snippet.Parameter;
 import com.oracle.graal.snippets.Snippet.VarargsParameter;
 import com.oracle.graal.snippets.SnippetTemplate.AbstractTemplates;
@@ -73,7 +73,7 @@
             isNull.inc();
             return falseValue;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (objectHub != exactHub) {
             exactMiss.inc();
             return falseValue;
@@ -95,7 +95,7 @@
             jump(IfNode.FALSE_EDGE);
             return;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (objectHub != exactHub) {
             exactMiss.inc();
             jump(IfNode.FALSE_EDGE);
@@ -120,7 +120,7 @@
             isNull.inc();
             return falseValue;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (UnsafeLoadNode.loadObject(objectHub, 0, superCheckOffset, true) != hub) {
             displayMiss.inc();
             return falseValue;
@@ -143,7 +143,7 @@
             jump(IfNode.FALSE_EDGE);
             return;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         if (UnsafeLoadNode.loadObject(objectHub, 0, superCheckOffset, true) != hub) {
             displayMiss.inc();
             jump(IfNode.FALSE_EDGE);
@@ -169,7 +169,7 @@
             isNull.inc();
             return falseValue;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         // if we get an exact match: succeed immediately
         ExplodeLoopNode.explodeLoop();
         for (int i = 0; i < hints.length; i++) {
@@ -199,7 +199,7 @@
             jump(IfNode.FALSE_EDGE);
             return;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         // if we get an exact match: succeed immediately
         ExplodeLoopNode.explodeLoop();
         for (int i = 0; i < hints.length; i++) {
@@ -233,7 +233,7 @@
             isNull.inc();
             return falseValue;
         }
-        Object objectHub = UnsafeLoadNode.loadObject(object, 0, hubOffset(), true);
+        Object objectHub = loadHub(object);
         // if we get an exact match: succeed immediately
         ExplodeLoopNode.explodeLoop();
         for (int i = 0; i < hints.length; i++) {
@@ -276,22 +276,6 @@
         return false;
     }
 
-    @Fold
-    private static int secondarySuperCacheOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().secondarySuperCacheOffset;
-    }
-
-    @Fold
-    private static int secondarySupersOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().secondarySupersOffset;
-    }
-
-    @Fold
-    private static int hubOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().hubOffset;
-    }
-
-
     public static class Templates extends AbstractTemplates<InstanceOfSnippets> {
 
         private final ResolvedJavaMethod ifExact;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Wed Sep 12 11:29:34 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Wed Sep 12 12:34:48 2012 +0200
@@ -24,7 +24,7 @@
 
 import static com.oracle.graal.hotspot.nodes.CastFromHub.*;
 import static com.oracle.graal.hotspot.nodes.RegisterNode.*;
-import static com.oracle.graal.nodes.extended.UnsafeLoadNode.*;
+import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
 import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*;
 import static com.oracle.graal.snippets.nodes.DirectObjectStoreNode.*;
 import static com.oracle.graal.snippets.nodes.ExplodeLoopNode.*;
@@ -43,7 +43,6 @@
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.snippets.*;
 import com.oracle.graal.snippets.Snippet.ConstantParameter;
-import com.oracle.graal.snippets.Snippet.Fold;
 import com.oracle.graal.snippets.Snippet.Parameter;
 import com.oracle.graal.snippets.SnippetTemplate.AbstractTemplates;
 import com.oracle.graal.snippets.SnippetTemplate.Arguments;
@@ -155,22 +154,6 @@
         return size & mask;
     }
 
-    private static Object verifyOop(Object object) {
-        if (verifyOops()) {
-            VerifyOopStubCall.call(object);
-        }
-        return object;
-    }
-
-    private static Word asWord(Object object) {
-        return Word.fromObject(object);
-    }
-
-    private static Word loadWord(Word address, int offset) {
-        Object value = loadObject(address, 0, offset, true);
-        return asWord(value);
-    }
-
     /**
      * Maximum size of an object whose body is initialized by a sequence of
      * zero-stores to its fields. Larger objects have their bodies initialized
@@ -350,46 +333,6 @@
         }
     }
 
-    @Fold
-    private static boolean verifyOops() {
-        return HotSpotGraalRuntime.getInstance().getConfig().verifyOops;
-    }
-
-    @Fold
-    private static int threadTlabTopOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().threadTlabTopOffset;
-    }
-
-    @Fold
-    private static int threadTlabEndOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().threadTlabEndOffset;
-    }
-
-    @Fold
-    private static Kind wordKind() {
-        return HotSpotGraalRuntime.getInstance().getTarget().wordKind;
-    }
-
-    @Fold
-    private static int wordSize() {
-        return HotSpotGraalRuntime.getInstance().getTarget().wordSize;
-    }
-
-    @Fold
-    private static int markOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().markOffset;
-    }
-
-    @Fold
-    private static int hubOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().hubOffset;
-    }
-
-    @Fold
-    private static int arrayLengthOffset() {
-        return HotSpotGraalRuntime.getInstance().getConfig().arrayLengthOffset;
-    }
-
     private static final SnippetCounter.Group countersNew = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewInstance") : null;
     private static final SnippetCounter new_seqInit = new SnippetCounter(countersNew, "tlabSeqInit", "TLAB alloc with unrolled zeroing");
     private static final SnippetCounter new_loopInit = new SnippetCounter(countersNew, "tlabLoopInit", "TLAB alloc with zeroing in a loop");