changeset 23099:1705cb8e3dfe

Reduce number of loads from tags array in FrameWithoutBoxing
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 26 Nov 2015 22:27:50 -0800
parents a7801d761e17
children 9f0138a3545a 80cf19158674
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java
diffstat 1 files changed, 58 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java	Thu Nov 26 22:23:37 2015 -0800
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java	Thu Nov 26 22:27:50 2015 -0800
@@ -92,8 +92,8 @@
     @Override
     public Object getObject(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, OBJECT_TAG);
-        return getObjectUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, OBJECT_TAG);
+        return getObjectUnsafe(slotIndex, slot, condition);
     }
 
     private Object[] getLocals() {
@@ -108,8 +108,7 @@
         return unsafeCast(tags, byte[].class, true, true);
     }
 
-    private Object getObjectUnsafe(int slotIndex, FrameSlot slot) {
-        boolean condition = this.getTags()[slotIndex] == OBJECT_TAG;
+    private Object getObjectUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         return unsafeGetObject(getLocals(), Unsafe.ARRAY_OBJECT_BASE_OFFSET + slotIndex * (long) Unsafe.ARRAY_OBJECT_INDEX_SCALE, condition, slot);
     }
 
@@ -127,13 +126,12 @@
     @Override
     public byte getByte(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, BYTE_TAG);
-        return getByteUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, BYTE_TAG);
+        return getByteUnsafe(slotIndex, slot, condition);
     }
 
-    private byte getByteUnsafe(int slotIndex, FrameSlot slot) {
+    private byte getByteUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slotIndex] == BYTE_TAG;
         return (byte) unsafeGetInt(getPrimitiveLocals(), offset, condition, slot);
     }
 
@@ -152,13 +150,12 @@
     @Override
     public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, BOOLEAN_TAG);
-        return getBooleanUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, BOOLEAN_TAG);
+        return getBooleanUnsafe(slotIndex, slot, condition);
     }
 
-    private boolean getBooleanUnsafe(int slotIndex, FrameSlot slot) {
+    private boolean getBooleanUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slotIndex] == BOOLEAN_TAG;
         return unsafeGetInt(getPrimitiveLocals(), offset, condition, slot) != 0;
     }
 
@@ -177,13 +174,12 @@
     @Override
     public float getFloat(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, FLOAT_TAG);
-        return getFloatUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, FLOAT_TAG);
+        return getFloatUnsafe(slotIndex, slot, condition);
     }
 
-    private float getFloatUnsafe(int slotIndex, FrameSlot slot) {
+    private float getFloatUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slotIndex] == FLOAT_TAG;
         return unsafeGetFloat(getPrimitiveLocals(), offset, condition, slot);
     }
 
@@ -202,13 +198,12 @@
     @Override
     public long getLong(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, LONG_TAG);
-        return getLongUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, LONG_TAG);
+        return getLongUnsafe(slotIndex, slot, condition);
     }
 
-    private long getLongUnsafe(int slotIndex, FrameSlot slot) {
+    private long getLongUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slotIndex] == LONG_TAG;
         return unsafeGetLong(getPrimitiveLocals(), offset, condition, slot);
     }
 
@@ -227,13 +222,12 @@
     @Override
     public int getInt(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, INT_TAG);
-        return getIntUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, INT_TAG);
+        return getIntUnsafe(slotIndex, slot, condition);
     }
 
-    private int getIntUnsafe(int slotIndex, FrameSlot slot) {
+    private int getIntUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slot.getIndex()] == INT_TAG;
         return unsafeGetInt(getPrimitiveLocals(), offset, condition, slot);
     }
 
@@ -252,13 +246,12 @@
     @Override
     public double getDouble(FrameSlot slot) throws FrameSlotTypeException {
         int slotIndex = slot.getIndex();
-        verifyGet(slotIndex, DOUBLE_TAG);
-        return getDoubleUnsafe(slotIndex, slot);
+        boolean condition = verifyGet(slotIndex, DOUBLE_TAG);
+        return getDoubleUnsafe(slotIndex, slot, condition);
     }
 
-    private double getDoubleUnsafe(int slotIndex, FrameSlot slot) {
+    private double getDoubleUnsafe(int slotIndex, FrameSlot slot, boolean condition) {
         long offset = getPrimitiveOffset(slotIndex);
-        boolean condition = this.getTags()[slotIndex] == DOUBLE_TAG;
         return unsafeGetDouble(getPrimitiveLocals(), offset, condition, slot);
     }
 
@@ -284,12 +277,14 @@
         getTags()[slotIndex] = tag;
     }
 
-    private void verifyGet(int slotIndex, byte tag) throws FrameSlotTypeException {
+    private boolean verifyGet(int slotIndex, byte tag) throws FrameSlotTypeException {
         checkSlotIndex(slotIndex);
-        if (getTags()[slotIndex] != tag) {
+        boolean condition = getTags()[slotIndex] == tag;
+        if (!condition) {
             CompilerDirectives.transferToInterpreter();
             throw new FrameSlotTypeException();
         }
+        return condition;
     }
 
     private void checkSlotIndex(int slotIndex) {
@@ -312,22 +307,34 @@
             resize();
         }
         byte tag = getTags()[slotIndex];
-        if (tag == BOOLEAN_TAG) {
-            return getBooleanUnsafe(slotIndex, slot);
-        } else if (tag == BYTE_TAG) {
-            return getByteUnsafe(slotIndex, slot);
-        } else if (tag == INT_TAG) {
-            return getIntUnsafe(slotIndex, slot);
-        } else if (tag == DOUBLE_TAG) {
-            return getDoubleUnsafe(slotIndex, slot);
-        } else if (tag == LONG_TAG) {
-            return getLongUnsafe(slotIndex, slot);
-        } else if (tag == FLOAT_TAG) {
-            return getFloatUnsafe(slotIndex, slot);
-        } else {
-            assert tag == OBJECT_TAG;
-            return getObjectUnsafe(slotIndex, slot);
+        boolean condition = (tag == BOOLEAN_TAG);
+        if (condition) {
+            return getBooleanUnsafe(slotIndex, slot, condition);
+        }
+        condition = (tag == BYTE_TAG);
+        if (condition) {
+            return getByteUnsafe(slotIndex, slot, condition);
+        }
+        condition = (tag == INT_TAG);
+        if (condition) {
+            return getIntUnsafe(slotIndex, slot, condition);
         }
+        condition = (tag == DOUBLE_TAG);
+        if (condition) {
+            return getDoubleUnsafe(slotIndex, slot, condition);
+        }
+        condition = (tag == LONG_TAG);
+        if (condition) {
+            return getLongUnsafe(slotIndex, slot, condition);
+        }
+        condition = (tag == FLOAT_TAG);
+        if (condition) {
+            return getFloatUnsafe(slotIndex, slot, condition);
+        }
+        condition = tag == OBJECT_TAG;
+        assert condition;
+        return getObjectUnsafe(slotIndex, slot, condition);
+
     }
 
     private boolean resize() {
@@ -345,10 +352,13 @@
 
     private byte getTag(FrameSlot slot) {
         int slotIndex = slot.getIndex();
-        if (slotIndex >= getTags().length) {
-            CompilerDirectives.transferToInterpreter();
-            resize();
+        byte[] cachedTags = getTags();
+        if (slotIndex < cachedTags.length) {
+            return cachedTags[slotIndex];
         }
+
+        CompilerDirectives.transferToInterpreter();
+        resize();
         return getTags()[slotIndex];
     }