# HG changeset patch # User Christian Wirth # Date 1377534340 -7200 # Node ID 51dcddfa25a6d8d2ebb6faf1494034a8bd9ac7d8 # Parent 7c4c1a7c875afb1dda8d2097735cae33a2a40c70 Truffle: add Byte to Frame diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java Mon Aug 26 18:25:40 2013 +0200 @@ -100,6 +100,26 @@ } @Override + public byte getByte(FrameSlot slot) throws FrameSlotTypeException { + verifyGet(slot, FrameSlotKind.Byte); + return getByteUnsafe(slot); + } + + private byte getByteUnsafe(FrameSlot slot) { + return unsafe.getByte(primitiveLocals, (long) slot.getIndex() * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET); + } + + @Override + public void setByte(FrameSlot slot, byte value) throws FrameSlotTypeException { + verifySet(slot, FrameSlotKind.Byte); + setByteUnsafe(slot, value); + } + + private void setByteUnsafe(FrameSlot slot, byte value) { + unsafe.putByte(primitiveLocals, (long) slot.getIndex() * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET, value); + } + + @Override public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException { verifyGet(slot, FrameSlotKind.Boolean); return getBooleanUnsafe(slot); diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/Frame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/Frame.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/Frame.java Mon Aug 26 18:25:40 2013 +0200 @@ -67,6 +67,23 @@ void setObject(FrameSlot slot, Object value) throws FrameSlotTypeException; /** + * Read access to a local variable of type byte. + * + * @param slot the slot of the local variable + * @return the current value of the local variable + */ + byte getByte(FrameSlot slot) throws FrameSlotTypeException; + + /** + * Write access to a local variable of type byte. + * + * @param slot the slot of the local variable + * @param value the new value of the local variable + */ + + void setByte(FrameSlot slot, byte value) throws FrameSlotTypeException; + + /** * Read access to a local variable of type boolean. * * @param slot the slot of the local variable diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotKind.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotKind.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotKind.java Mon Aug 26 18:25:40 2013 +0200 @@ -25,5 +25,5 @@ package com.oracle.truffle.api.frame; public enum FrameSlotKind { - Illegal, Object, Long, Int, Double, Float, Boolean; + Illegal, Object, Long, Int, Double, Float, Boolean, Byte; } diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java Mon Aug 26 18:25:40 2013 +0200 @@ -46,6 +46,25 @@ } /** + * Write access to a local variable of type {@code byte}. + * + * Sets the frame slot type to {@code byte} if it isn't already. + * + * @param slot the slot of the local variable + * @param value the new value of the local variable + */ + public static void setByteSafe(Frame frame, FrameSlot slot, byte value) { + if (slot.getKind() != FrameSlotKind.Byte) { + slot.setKind(FrameSlotKind.Byte); + } + try { + frame.setByte(slot, value); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** * Write access to a local variable of type {@code boolean}. * * Sets the frame slot type to {@code boolean} if it isn't already. diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/NativeFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/NativeFrame.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/NativeFrame.java Mon Aug 26 18:25:40 2013 +0200 @@ -57,6 +57,16 @@ } @Override + public byte getByte(FrameSlot slot) { + throw new UnsupportedOperationException("native frame"); + } + + @Override + public void setByte(FrameSlot slot, byte value) { + throw new UnsupportedOperationException("native frame"); + } + + @Override public boolean getBoolean(FrameSlot slot) { throw new UnsupportedOperationException("native frame"); } diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Mon Aug 26 18:25:40 2013 +0200 @@ -51,6 +51,16 @@ } @Override + public byte getByte(FrameSlot slot) throws FrameSlotTypeException { + return wrapped.getByte(slot); + } + + @Override + public void setByte(FrameSlot slot, byte value) throws FrameSlotTypeException { + wrapped.setByte(slot, value); + } + + @Override public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException { return wrapped.getBoolean(slot); } diff -r 7c4c1a7c875a -r 51dcddfa25a6 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Mon Aug 26 17:10:45 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Mon Aug 26 18:25:40 2013 +0200 @@ -79,6 +79,18 @@ } @Override + public byte getByte(FrameSlot slot) throws FrameSlotTypeException { + verifyGet(slot, FrameSlotKind.Byte); + return (byte) locals[slot.getIndex()]; + } + + @Override + public void setByte(FrameSlot slot, byte value) throws FrameSlotTypeException { + verifySet(slot, FrameSlotKind.Byte); + locals[slot.getIndex()] = value; + } + + @Override public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException { verifyGet(slot, FrameSlotKind.Boolean); return (boolean) locals[slot.getIndex()];