# HG changeset patch # User Andreas Woess # Date 1366906448 -7200 # Node ID cd1a1d92b3e39b29633eb445a34d03a5b17e7eb7 # Parent 3ef5689248b06ef6dea370e3ce42e71012ba9962 Frame API: Introduce FrameSlotKind. diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java Thu Apr 25 18:14:08 2013 +0200 @@ -34,7 +34,7 @@ *

* Dynamically typed languages can speculate on the type of a frame slot and only fall back at run * time to a more generic type if necessary. The new type of a frame slot can be set using the - * {@link FrameSlot#setType(Class)} method. + * {@link FrameSlot#setKind(FrameSlotKind)} method. *

* *

@@ -48,13 +48,13 @@ public void test() { TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); - FrameSlot slot = frameDescriptor.addFrameSlot("localVar", int.class); + FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); TestRootNode rootNode = new TestRootNode(new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); - Assert.assertEquals(int.class, slot.getType()); + Assert.assertEquals(FrameSlotKind.Int, slot.getKind()); Object result = target.call(); Assert.assertEquals("42", result); - Assert.assertEquals(Object.class, slot.getType()); + Assert.assertEquals(FrameSlotKind.Object, slot.getKind()); } class TestRootNode extends RootNode { diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java Thu Apr 25 18:14:08 2013 +0200 @@ -35,9 +35,9 @@ * The frame is the preferred data structure for passing values between nodes. It can in particular * be used for storing the values of local variables of the guest language. The * {@link FrameDescriptor} represents the current structure of the frame. The method - * {@link FrameDescriptor#addFrameSlot(Object, Class)} can be used to create predefined frame slots. - * The setter and getter methods in the {@link Frame} class can be used to access the current value - * of a particular frame slot. + * {@link FrameDescriptor#addFrameSlot(Object, FrameSlotKind)} can be used to create predefined + * frame slots. The setter and getter methods in the {@link Frame} class can be used to access the + * current value of a particular frame slot. *

* *

@@ -64,7 +64,7 @@ public void test() { TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); - FrameSlot slot = frameDescriptor.addFrameSlot("localVar", int.class); + FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); TestRootNode rootNode = new TestRootNode(new AssignLocal(slot), new ReadLocal(slot)); CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); Object result = target.call(); diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java Thu Apr 25 18:14:08 2013 +0200 @@ -47,13 +47,13 @@ public void test() { TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); - FrameSlot slot = frameDescriptor.addFrameSlot("localVar", int.class); + FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); TestRootNode rootNode = new TestRootNode(new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); - Assert.assertEquals(int.class, slot.getType()); + Assert.assertEquals(FrameSlotKind.Int, slot.getKind()); Object result = target.call(); Assert.assertEquals("42", result); - Assert.assertEquals(Object.class, slot.getType()); + Assert.assertEquals(FrameSlotKind.Object, slot.getKind()); } class TestRootNode extends RootNode { diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Thu Apr 25 18:14:08 2013 +0200 @@ -53,9 +53,9 @@ return addFrameSlot(identifier, null); } - public FrameSlot addFrameSlot(Object identifier, Class type) { + public FrameSlot addFrameSlot(Object identifier, FrameSlotKind kind) { assert !identifierToSlotMap.containsKey(identifier); - FrameSlotImpl slot = new FrameSlotImpl(this, identifier, slots.size(), type); + FrameSlotImpl slot = new FrameSlotImpl(this, identifier, slots.size(), kind); slots.add(slot); identifierToSlotMap.put(identifier, slot); updateVersion(); @@ -74,12 +74,12 @@ return addFrameSlot(identifier); } - public FrameSlot findOrAddFrameSlot(Object identifier, Class type) { + public FrameSlot findOrAddFrameSlot(Object identifier, FrameSlotKind kind) { FrameSlot result = findFrameSlot(identifier); if (result != null) { return result; } - return addFrameSlot(identifier, type); + return addFrameSlot(identifier, kind); } public int getSize() { diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlot.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlot.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlot.java Thu Apr 25 18:14:08 2013 +0200 @@ -31,9 +31,9 @@ int getIndex(); - Class getType(); + FrameSlotKind getKind(); - void setType(Class type); + void setKind(FrameSlotKind kind); FrameDescriptor getFrameDescriptor(); } diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotImpl.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotImpl.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotImpl.java Thu Apr 25 18:14:08 2013 +0200 @@ -27,13 +27,13 @@ private final FrameDescriptor descriptor; private final Object identifier; private final int index; - private Class type; + private FrameSlotKind kind; - protected FrameSlotImpl(FrameDescriptor descriptor, Object identifier, int index, Class type) { + protected FrameSlotImpl(FrameDescriptor descriptor, Object identifier, int index, FrameSlotKind kind) { this.descriptor = descriptor; this.identifier = identifier; this.index = index; - this.type = type; + this.kind = kind; } public Object getIdentifier() { @@ -44,19 +44,19 @@ return index; } - public Class getType() { - return type; + public FrameSlotKind getKind() { + return kind; } - public void setType(final Class type) { - assert this.type != type; - this.type = type; + public void setKind(final FrameSlotKind kind) { + assert this.kind != kind; + this.kind = kind; this.descriptor.updateVersion(); } @Override public String toString() { - return "[" + index + "," + identifier + "," + type + "]"; + return "[" + index + "," + identifier + "," + kind + "]"; } @Override diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotKind.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameSlotKind.java Thu Apr 25 18:14:08 2013 +0200 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013, 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.truffle.api.frame; + +public enum FrameSlotKind { + Illegal, Object, Long, Int, Double, Float, Boolean; +} diff -r 3ef5689248b0 -r cd1a1d92b3e3 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 Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java Thu Apr 25 18:14:08 2013 +0200 @@ -33,8 +33,8 @@ * @param value the new value of the local variable */ public static void setObjectSafe(Frame frame, FrameSlot slot, Object value) { - if (slot.getType() != Object.class) { - slot.setType(Object.class); + if (slot.getKind() != FrameSlotKind.Object) { + slot.setKind(FrameSlotKind.Object); } try { frame.setObject(slot, value); @@ -52,8 +52,8 @@ * @param value the new value of the local variable */ public static void setBooleanSafe(Frame frame, FrameSlot slot, boolean value) { - if (slot.getType() != boolean.class) { - slot.setType(boolean.class); + if (slot.getKind() != FrameSlotKind.Boolean) { + slot.setKind(FrameSlotKind.Boolean); } try { frame.setBoolean(slot, value); @@ -71,8 +71,8 @@ * @param value the new value of the local variable */ public static void setIntSafe(Frame frame, FrameSlot slot, int value) { - if (slot.getType() != int.class) { - slot.setType(int.class); + if (slot.getKind() != FrameSlotKind.Int) { + slot.setKind(FrameSlotKind.Int); } try { frame.setInt(slot, value); @@ -90,8 +90,8 @@ * @param value the new value of the local variable */ public static void setLongSafe(Frame frame, FrameSlot slot, long value) { - if (slot.getType() != long.class) { - slot.setType(long.class); + if (slot.getKind() != FrameSlotKind.Long) { + slot.setKind(FrameSlotKind.Long); } try { frame.setLong(slot, value); @@ -109,8 +109,8 @@ * @param value the new value of the local variable */ public static void setFloatSafe(Frame frame, FrameSlot slot, float value) { - if (slot.getType() != float.class) { - slot.setType(float.class); + if (slot.getKind() != FrameSlotKind.Float) { + slot.setKind(FrameSlotKind.Float); } try { frame.setFloat(slot, value); @@ -128,8 +128,8 @@ * @param value the new value of the local variable */ public static void setDoubleSafe(Frame frame, FrameSlot slot, double value) { - if (slot.getType() != double.class) { - slot.setType(double.class); + if (slot.getKind() != FrameSlotKind.Double) { + slot.setKind(FrameSlotKind.Double); } try { frame.setDouble(slot, value); diff -r 3ef5689248b0 -r cd1a1d92b3e3 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 Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Thu Apr 25 18:14:08 2013 +0200 @@ -33,14 +33,14 @@ private final PackedFrame caller; private final Arguments arguments; private Object[] locals; - private Class[] tags; + private byte[] tags; public DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { this.descriptor = descriptor; this.caller = caller; this.arguments = arguments; this.locals = new Object[descriptor.getSize()]; - this.tags = new Class[descriptor.getSize()]; + this.tags = new byte[descriptor.getSize()]; } @Override @@ -65,73 +65,73 @@ @Override public Object getObject(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, Object.class); + verifyGet(slot, FrameSlotKind.Object); return locals[slot.getIndex()]; } @Override public void setObject(FrameSlot slot, Object value) throws FrameSlotTypeException { - verifySet(slot, Object.class); + verifySet(slot, FrameSlotKind.Object); locals[slot.getIndex()] = value; } @Override public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, boolean.class); + verifyGet(slot, FrameSlotKind.Boolean); return (boolean) locals[slot.getIndex()]; } @Override public void setBoolean(FrameSlot slot, boolean value) throws FrameSlotTypeException { - verifySet(slot, boolean.class); + verifySet(slot, FrameSlotKind.Boolean); locals[slot.getIndex()] = value; } @Override public int getInt(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, int.class); + verifyGet(slot, FrameSlotKind.Int); return (int) locals[slot.getIndex()]; } @Override public void setInt(FrameSlot slot, int value) throws FrameSlotTypeException { - verifySet(slot, int.class); + verifySet(slot, FrameSlotKind.Int); locals[slot.getIndex()] = value; } @Override public long getLong(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, long.class); + verifyGet(slot, FrameSlotKind.Long); return (long) locals[slot.getIndex()]; } @Override public void setLong(FrameSlot slot, long value) throws FrameSlotTypeException { - verifySet(slot, long.class); + verifySet(slot, FrameSlotKind.Long); locals[slot.getIndex()] = value; } @Override public float getFloat(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, float.class); + verifyGet(slot, FrameSlotKind.Float); return (float) locals[slot.getIndex()]; } @Override public void setFloat(FrameSlot slot, float value) throws FrameSlotTypeException { - verifySet(slot, float.class); + verifySet(slot, FrameSlotKind.Float); locals[slot.getIndex()] = value; } @Override public double getDouble(FrameSlot slot) throws FrameSlotTypeException { - verifyGet(slot, double.class); + verifyGet(slot, FrameSlotKind.Double); return (double) locals[slot.getIndex()]; } @Override public void setDouble(FrameSlot slot, double value) throws FrameSlotTypeException { - verifySet(slot, double.class); + verifySet(slot, FrameSlotKind.Double); locals[slot.getIndex()] = value; } @@ -147,19 +147,19 @@ assert index >= 0 && index < descriptor.getSize(); return descriptor.getTypeConversion().getDefaultValue(); } - Class tag = tags[index]; - if (tag == null) { + byte tag = tags[index]; + if (tag == FrameSlotKind.Illegal.ordinal()) { return descriptor.getTypeConversion().getDefaultValue(); } else { return locals[index]; } } - private void verifySet(FrameSlot slot, Class accessType) throws FrameSlotTypeException { - Class slotType = slot.getType(); - if (slotType != accessType) { - if (slotType == null) { - slot.setType(accessType); + private void verifySet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { + FrameSlotKind slotKind = slot.getKind(); + if (slotKind != accessKind) { + if (slotKind == FrameSlotKind.Illegal) { + slot.setKind(accessKind); } else { throw new FrameSlotTypeException(); } @@ -168,14 +168,14 @@ if (slotIndex >= tags.length) { resize(); } - tags[slotIndex] = accessType; + tags[slotIndex] = (byte) accessKind.ordinal(); } - private void verifyGet(FrameSlot slot, Class accessType) throws FrameSlotTypeException { - Class slotType = slot.getType(); - if (slotType != accessType) { - if (slotType == null && accessType == Object.class) { - slot.setType(Object.class); + private void verifyGet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { + FrameSlotKind slotKind = slot.getKind(); + if (slotKind != accessKind) { + if (slotKind == FrameSlotKind.Illegal && accessKind == FrameSlotKind.Object) { + slot.setKind(FrameSlotKind.Object); this.setObject(slot, descriptor.getTypeConversion().getDefaultValue()); } else { throw new FrameSlotTypeException(); @@ -185,9 +185,9 @@ if (slotIndex >= tags.length) { resize(); } - if (tags[slotIndex] != accessType) { + if (tags[slotIndex] != accessKind.ordinal()) { descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot)); - if (tags[slotIndex] != accessType) { + if (tags[slotIndex] != accessKind.ordinal()) { throw new FrameSlotTypeException(); } } diff -r 3ef5689248b0 -r cd1a1d92b3e3 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java Thu Apr 25 23:17:58 2013 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java Thu Apr 25 18:14:08 2013 +0200 @@ -59,7 +59,7 @@ } public TypedNode createLocal(String name) { - return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, int.class)); + return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, FrameSlotKind.Int)); } public TypedNode createStringLiteral(String value) { @@ -67,7 +67,7 @@ } public StatementNode createAssignment(String name, TypedNode right) { - return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, int.class), right); + return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, FrameSlotKind.Int), right); } public StatementNode createPrint(List expressions) { @@ -123,7 +123,7 @@ } public StatementNode createReturn(TypedNode value) { - FrameSlot slot = frameDescriptor.findOrAddFrameSlot("", int.class); + FrameSlot slot = frameDescriptor.findOrAddFrameSlot("", FrameSlotKind.Int); if (returnValue == null) { returnValue = ReadLocalNodeFactory.create(slot); }