comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java @ 7530:5e3d1a68664e

applied mx eclipseformat to all Java files
author Doug Simon <doug.simon@oracle.com>
date Wed, 23 Jan 2013 16:34:57 +0100
parents a4b84ba6dc2e
children 07f8d136a05e
comparison
equal deleted inserted replaced
7529:4a11124a3563 7530:5e3d1a68664e
26 26
27 import com.oracle.truffle.api.*; 27 import com.oracle.truffle.api.*;
28 import com.oracle.truffle.api.frame.*; 28 import com.oracle.truffle.api.frame.*;
29 import com.oracle.truffle.api.nodes.*; 29 import com.oracle.truffle.api.nodes.*;
30 30
31
32 /** 31 /**
33 * <h3>Specializing Frame Slot Types</h3> 32 * <h3>Specializing Frame Slot Types</h3>
34 * 33 *
35 * <p> 34 * <p>
36 * Dynamically typed languages can speculate on the type of a frame slot and only fall back at run time to a more 35 * Dynamically typed languages can speculate on the type of a frame slot and only fall back at run
37 * generic type if necessary. The new type of a frame slot can be set using the {@link FrameSlot#setType(Class)} method. 36 * time to a more generic type if necessary. The new type of a frame slot can be set using the
38 * It is the responsibility of the language implementor to update the content of currently active frames (using 37 * {@link FrameSlot#setType(Class)} method. It is the responsibility of the language implementor to
39 * {@link Frame#updateToLatestVersion()}). Also, nodes that depend a specific type of a frame slot must be replaced. 38 * update the content of currently active frames (using {@link Frame#updateToLatestVersion()}).
40 * Such node can register a listener that implements {@link FrameSlotTypeListener} using 39 * Also, nodes that depend a specific type of a frame slot must be replaced. Such node can register
41 * {@link FrameSlot#registerOneShotTypeListener(FrameSlotTypeListener)}. The event of a type change on the frame slot 40 * a listener that implements {@link FrameSlotTypeListener} using
42 * will fire only once for the next upcoming change. 41 * {@link FrameSlot#registerOneShotTypeListener(FrameSlotTypeListener)}. The event of a type change
42 * on the frame slot will fire only once for the next upcoming change.
43 * </p> 43 * </p>
44 * 44 *
45 * <p> 45 * <p>
46 * The next part of the Truffle API introduction is at {@link com.oracle.truffle.api.test.ReturnTypeSpecializationTest}. 46 * The next part of the Truffle API introduction is at
47 * {@link com.oracle.truffle.api.test.ReturnTypeSpecializationTest}.
47 * </p> 48 * </p>
48 */ 49 */
49 public class FrameSlotTypeSpecializationTest { 50 public class FrameSlotTypeSpecializationTest {
50 51
51 @Test 52 @Test
77 return right.execute(frame); 78 return right.execute(frame);
78 } 79 }
79 } 80 }
80 81
81 abstract class TestChildNode extends Node { 82 abstract class TestChildNode extends Node {
83
82 abstract Object execute(VirtualFrame frame); 84 abstract Object execute(VirtualFrame frame);
83 } 85 }
84 86
85 abstract class FrameSlotNode extends TestChildNode { 87 abstract class FrameSlotNode extends TestChildNode {
88
86 protected final FrameSlot slot; 89 protected final FrameSlot slot;
87 90
88 public FrameSlotNode(FrameSlot slot) { 91 public FrameSlotNode(FrameSlot slot) {
89 this.slot = slot; 92 this.slot = slot;
90 } 93 }
98 } 101 }
99 102
100 } 103 }
101 104
102 class IntAssignLocal extends FrameSlotNode implements FrameSlotTypeListener { 105 class IntAssignLocal extends FrameSlotNode implements FrameSlotTypeListener {
106
103 @Child private TestChildNode value; 107 @Child private TestChildNode value;
104 108
105 IntAssignLocal(FrameSlot slot, TestChildNode value) { 109 IntAssignLocal(FrameSlot slot, TestChildNode value) {
106 super(slot); 110 super(slot);
107 this.value = adoptChild(value); 111 this.value = adoptChild(value);
120 } 124 }
121 return null; 125 return null;
122 } 126 }
123 127
124 @Override 128 @Override
125 public void typeChanged(FrameSlot changedSlot, Class< ? > oldType) { 129 public void typeChanged(FrameSlot changedSlot, Class<?> oldType) {
126 if (changedSlot.getType() == Object.class) { 130 if (changedSlot.getType() == Object.class) {
127 this.replace(new ObjectAssignLocal(changedSlot, value)); 131 this.replace(new ObjectAssignLocal(changedSlot, value));
128 } 132 }
129 } 133 }
130 } 134 }
131 135
132 class ObjectAssignLocal extends FrameSlotNode { 136 class ObjectAssignLocal extends FrameSlotNode {
137
133 @Child private TestChildNode value; 138 @Child private TestChildNode value;
134 139
135 ObjectAssignLocal(FrameSlot slot, TestChildNode value) { 140 ObjectAssignLocal(FrameSlot slot, TestChildNode value) {
136 super(slot); 141 super(slot);
137 this.value = adoptChild(value); 142 this.value = adoptChild(value);
144 return null; 149 return null;
145 } 150 }
146 } 151 }
147 152
148 class IntReadLocal extends FrameSlotNode implements FrameSlotTypeListener { 153 class IntReadLocal extends FrameSlotNode implements FrameSlotTypeListener {
154
149 IntReadLocal(FrameSlot slot) { 155 IntReadLocal(FrameSlot slot) {
150 super(slot); 156 super(slot);
151 slot.registerOneShotTypeListener(this); 157 slot.registerOneShotTypeListener(this);
152 } 158 }
153 159
155 Object execute(VirtualFrame frame) { 161 Object execute(VirtualFrame frame) {
156 return frame.getInt(slot); 162 return frame.getInt(slot);
157 } 163 }
158 164
159 @Override 165 @Override
160 public void typeChanged(FrameSlot changedSlot, Class< ? > oldType) { 166 public void typeChanged(FrameSlot changedSlot, Class<?> oldType) {
161 if (changedSlot.getType() == Object.class) { 167 if (changedSlot.getType() == Object.class) {
162 this.replace(new ObjectReadLocal(changedSlot)); 168 this.replace(new ObjectReadLocal(changedSlot));
163 } 169 }
164 } 170 }
165 } 171 }
166 172
167 class ObjectReadLocal extends FrameSlotNode { 173 class ObjectReadLocal extends FrameSlotNode {
174
168 ObjectReadLocal(FrameSlot slot) { 175 ObjectReadLocal(FrameSlot slot) {
169 super(slot); 176 super(slot);
170 } 177 }
171 178
172 @Override 179 @Override
173 Object execute(VirtualFrame frame) { 180 Object execute(VirtualFrame frame) {
174 return frame.getObject(slot); 181 return frame.getObject(slot);
175 } 182 }
176 } 183 }
177 } 184 }
178