changeset 18913:51680f58e681

Clean up in Kind class. Introduce Kind#getSlotCount and Kind#needsTwoSlots methods.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 20 Jan 2015 16:40:45 +0100
parents 9536c47658a2
children 0607cc136dd5
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TailcallNode.java graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractFrameStateBuilder.java graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java
diffstat 9 files changed, 45 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java	Tue Jan 20 16:40:45 2015 +0100
@@ -168,7 +168,7 @@
         for (int i = 0; i < numLocals + numStack; i++) {
             if (values[i] != null) {
                 Kind kind = values[i].getKind();
-                if (kind == Kind.Long || kind == Kind.Double) {
+                if (kind.needsTwoSlots()) {
                     assert values.length > i + 1 : String.format("missing second word %s", this);
                     assert values[i + 1] == null || values[i + 1].getKind() == Kind.Illegal;
                 }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java	Tue Jan 20 16:40:45 2015 +0100
@@ -33,37 +33,37 @@
  */
 public enum Kind implements PlatformKind {
     /** The primitive boolean kind, represented as an int on the stack. */
-    Boolean('z', "boolean", true, java.lang.Boolean.TYPE, java.lang.Boolean.class),
+    Boolean('z', "boolean", 1, true, java.lang.Boolean.TYPE, java.lang.Boolean.class),
 
     /** The primitive byte kind, represented as an int on the stack. */
-    Byte('b', "byte", true, java.lang.Byte.TYPE, java.lang.Byte.class),
+    Byte('b', "byte", 1, true, java.lang.Byte.TYPE, java.lang.Byte.class),
 
     /** The primitive short kind, represented as an int on the stack. */
-    Short('s', "short", true, java.lang.Short.TYPE, java.lang.Short.class),
+    Short('s', "short", 1, true, java.lang.Short.TYPE, java.lang.Short.class),
 
     /** The primitive char kind, represented as an int on the stack. */
-    Char('c', "char", true, java.lang.Character.TYPE, java.lang.Character.class),
+    Char('c', "char", 1, true, java.lang.Character.TYPE, java.lang.Character.class),
 
     /** The primitive int kind, represented as an int on the stack. */
-    Int('i', "int", true, java.lang.Integer.TYPE, java.lang.Integer.class),
+    Int('i', "int", 1, true, java.lang.Integer.TYPE, java.lang.Integer.class),
 
     /** The primitive float kind. */
-    Float('f', "float", false, java.lang.Float.TYPE, java.lang.Float.class),
+    Float('f', "float", 1, false, java.lang.Float.TYPE, java.lang.Float.class),
 
     /** The primitive long kind. */
-    Long('j', "long", false, java.lang.Long.TYPE, java.lang.Long.class),
+    Long('j', "long", 2, false, java.lang.Long.TYPE, java.lang.Long.class),
 
     /** The primitive double kind. */
-    Double('d', "double", false, java.lang.Double.TYPE, java.lang.Double.class),
+    Double('d', "double", 2, false, java.lang.Double.TYPE, java.lang.Double.class),
 
     /** The Object kind, also used for arrays. */
-    Object('a', "Object", false, null, null),
+    Object('a', "Object", 1, false, null, null),
 
     /** The void float kind. */
-    Void('v', "void", false, java.lang.Void.TYPE, java.lang.Void.class),
+    Void('v', "void", 0, false, java.lang.Void.TYPE, java.lang.Void.class),
 
     /** The non-type. */
-    Illegal('-', "illegal", false, null, null);
+    Illegal('-', "illegal", 0, false, null, null);
 
     private final char typeChar;
     private final String javaName;
@@ -71,10 +71,12 @@
     private final Class<?> primitiveJavaClass;
     private final Class<?> boxedJavaClass;
     private final EnumKey key = new EnumKey(this);
+    private final int slotCount;
 
-    private Kind(char typeChar, String javaName, boolean isStackInt, Class<?> primitiveJavaClass, Class<?> boxedJavaClass) {
+    private Kind(char typeChar, String javaName, int slotCount, boolean isStackInt, Class<?> primitiveJavaClass, Class<?> boxedJavaClass) {
         this.typeChar = typeChar;
         this.javaName = javaName;
+        this.slotCount = slotCount;
         this.isStackInt = isStackInt;
         this.primitiveJavaClass = primitiveJavaClass;
         this.boxedJavaClass = boxedJavaClass;
@@ -82,6 +84,21 @@
     }
 
     /**
+     * Returns the number of stack slots occupied by this kind according to the Java bytecodes
+     * specification.
+     */
+    public int getSlotCount() {
+        return this.slotCount;
+    }
+
+    /**
+     * Returns whether this kind occupied two stack slots.
+     */
+    public boolean needsTwoSlots() {
+        return this.slotCount == 2;
+    }
+
+    /**
      * Returns the name of the kind as a single character.
      */
     public char getTypeChar() {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java	Tue Jan 20 16:40:45 2015 +0100
@@ -354,7 +354,7 @@
             // mirroring the calculations in c1_GraphBuilder.cpp (setup_osr_entry_block)
             int localsOffset = (graph.method().getMaxLocals() - 1) * 8;
             for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.class)) {
-                int size = HIRFrameStateBuilder.stackSlots(osrLocal.getKind());
+                int size = osrLocal.getKind().getSlotCount();
                 int offset = localsOffset - (osrLocal.index() + size - 1) * 8;
                 IndexedLocationNode location = graph.unique(new IndexedLocationNode(ANY_LOCATION, offset, ConstantNode.forLong(0, graph), 1));
                 ReadNode load = graph.add(new ReadNode(buffer, location, osrLocal.stamp(), BarrierType.NONE));
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TailcallNode.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TailcallNode.java	Tue Jan 20 16:40:45 2015 +0100
@@ -61,7 +61,7 @@
         JavaType[] signature = method.getSignature().toParameterTypes(isStatic ? null : method.getDeclaringClass());
         CallingConvention cc = lirGen.getResult().getFrameMapBuilder().getRegisterConfig().getCallingConvention(CallingConvention.Type.JavaCall, null, signature, lirGen.target(), false);
         List<ValueNode> parameters = new ArrayList<>();
-        for (int i = 0, slot = 0; i < cc.getArgumentCount(); i++, slot += HIRFrameStateBuilder.stackSlots(frameState.localAt(slot).getKind())) {
+        for (int i = 0, slot = 0; i < cc.getArgumentCount(); i++, slot += frameState.localAt(slot).getKind().getSlotCount()) {
             parameters.add(frameState.localAt(slot));
         }
         Value[] args = gen.visitInvokeArguments(cc, parameters);
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractFrameStateBuilder.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractFrameStateBuilder.java	Tue Jan 20 16:40:45 2015 +0100
@@ -171,8 +171,8 @@
      */
     public T loadLocal(int i) {
         T x = locals[i];
-        assert !isTwoSlot(x.getKind()) || locals[i + 1] == null;
-        assert i == 0 || locals[i - 1] == null || !isTwoSlot(locals[i - 1].getKind());
+        assert x.getKind().getSlotCount() == 1 || locals[i + 1] == null;
+        assert i == 0 || locals[i - 1] == null || locals[i - 1].getKind().getSlotCount() == 1;
         return x;
     }
 
@@ -186,13 +186,13 @@
     public void storeLocal(int i, T x) {
         assert x == null || x.getKind() != Kind.Void && x.getKind() != Kind.Illegal : "unexpected value: " + x;
         locals[i] = x;
-        if (x != null && isTwoSlot(x.getKind())) {
+        if (x != null && x.getKind().needsTwoSlots()) {
             // if this is a double word, then kill i+1
             locals[i + 1] = null;
         }
         if (x != null && i > 0) {
             T p = locals[i - 1];
-            if (p != null && isTwoSlot(p.getKind())) {
+            if (p != null && p.getKind().needsTwoSlots()) {
                 // if there was a double word at i - 1, then kill it
                 locals[i - 1] = null;
             }
@@ -213,7 +213,7 @@
     public void push(Kind kind, T x) {
         assert x.getKind() != Kind.Void && x.getKind() != Kind.Illegal;
         xpush(assertKind(kind, x));
-        if (isTwoSlot(kind)) {
+        if (kind.needsTwoSlots()) {
             xpush(null);
         }
     }
@@ -289,7 +289,7 @@
      */
     public T pop(Kind kind) {
         assert kind != Kind.Void;
-        if (isTwoSlot(kind)) {
+        if (kind.needsTwoSlots()) {
             xpop();
         }
         return assertKind(kind, xpop());
@@ -366,9 +366,9 @@
             if (stack[newStackSize] == null) {
                 /* Two-slot value. */
                 newStackSize--;
-                assert stackSlots(stack[newStackSize].getKind()) == 2;
+                assert stack[newStackSize].getKind().needsTwoSlots();
             } else {
-                assert stackSlots(stack[newStackSize].getKind()) == 1;
+                assert stack[newStackSize].getKind().getSlotCount() == 1;
             }
             result[i] = stack[newStackSize];
         }
@@ -389,17 +389,13 @@
         for (int i = 0; i < argumentNumber; i++) {
             if (stackAt(idx) == null) {
                 idx--;
-                assert isTwoSlot(stackAt(idx).getKind());
+                assert stackAt(idx).getKind().needsTwoSlots();
             }
             idx--;
         }
         return stackAt(idx);
     }
 
-    public static int stackSlots(Kind kind) {
-        return isTwoSlot(kind) ? 2 : 1;
-    }
-
     /**
      * Clears all values on this stack.
      */
@@ -407,11 +403,6 @@
         stackSize = 0;
     }
 
-    protected static boolean isTwoSlot(Kind kind) {
-        assert kind != Kind.Void && kind != Kind.Illegal;
-        return kind == Kind.Long || kind == Kind.Double;
-    }
-
     private T assertKind(Kind kind, T x) {
         assert x != null && x.getKind() == kind : "kind=" + kind + ", value=" + x + ((x == null) ? "" : ", value.kind=" + x.getKind());
         return x;
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Tue Jan 20 16:40:45 2015 +0100
@@ -78,7 +78,7 @@
             }
             ParameterNode param = graph.unique(new ParameterNode(index, stamp));
             storeLocal(javaIndex, param);
-            javaIndex += stackSlots(kind);
+            javaIndex += kind.getSlotCount();
             index++;
         }
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Tue Jan 20 16:40:45 2015 +0100
@@ -238,7 +238,7 @@
         }
         for (ValueNode node : pushedValues) {
             copy.add(node);
-            if (node.getKind() == Kind.Long || node.getKind() == Kind.Double) {
+            if (node.getKind().needsTwoSlots()) {
                 copy.add(null);
             }
         }
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Tue Jan 20 16:40:45 2015 +0100
@@ -123,7 +123,7 @@
                     names[i] = method.getLocalVariableTable().getLocal(slotIdx, 0).getName();
 
                     Kind kind = method.getSignature().getParameterKind(i);
-                    slotIdx += kind == Kind.Long || kind == Kind.Double ? 2 : 1;
+                    slotIdx += kind.getSlotCount();
                 }
                 return true;
             }
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Tue Jan 20 16:09:23 2015 +0100
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Tue Jan 20 16:40:45 2015 +0100
@@ -407,7 +407,7 @@
                 while (valueIndex < values.length) {
                     Kind otherKind = entries[valueIndex].getKind();
                     Kind entryKind = object.entryKind(valueIndex);
-                    if (entryKind == Kind.Int && (otherKind == Kind.Long || otherKind == Kind.Double)) {
+                    if (entryKind == Kind.Int && otherKind.needsTwoSlots()) {
                         if (twoSlotKinds == null) {
                             twoSlotKinds = new Kind[values.length];
                         }