Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java @ 11638:269e6794e1ec
Truffle: Frame restructuring.
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Sun, 15 Sep 2013 02:39:07 +0200 |
parents | 51dcddfa25a6 |
children | 139b84d713bc |
comparison
equal
deleted
inserted
replaced
11637:126e20d36563 | 11638:269e6794e1ec |
---|---|
40 public DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { | 40 public DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { |
41 this.descriptor = descriptor; | 41 this.descriptor = descriptor; |
42 this.caller = caller; | 42 this.caller = caller; |
43 this.arguments = arguments; | 43 this.arguments = arguments; |
44 this.locals = new Object[descriptor.getSize()]; | 44 this.locals = new Object[descriptor.getSize()]; |
45 Arrays.fill(locals, descriptor.getTypeConversion().getDefaultValue()); | |
45 this.tags = new byte[descriptor.getSize()]; | 46 this.tags = new byte[descriptor.getSize()]; |
46 } | 47 } |
47 | 48 |
48 @SuppressWarnings("unchecked") | 49 @SuppressWarnings("unchecked") |
49 @Override | 50 @Override |
71 verifyGet(slot, FrameSlotKind.Object); | 72 verifyGet(slot, FrameSlotKind.Object); |
72 return locals[slot.getIndex()]; | 73 return locals[slot.getIndex()]; |
73 } | 74 } |
74 | 75 |
75 @Override | 76 @Override |
76 public void setObject(FrameSlot slot, Object value) throws FrameSlotTypeException { | 77 public void setObject(FrameSlot slot, Object value) { |
77 verifySet(slot, FrameSlotKind.Object); | 78 verifySetObject(slot); |
78 locals[slot.getIndex()] = value; | 79 locals[slot.getIndex()] = value; |
79 } | 80 } |
80 | 81 |
81 @Override | 82 @Override |
82 public byte getByte(FrameSlot slot) throws FrameSlotTypeException { | 83 public byte getByte(FrameSlot slot) throws FrameSlotTypeException { |
155 return this.descriptor; | 156 return this.descriptor; |
156 } | 157 } |
157 | 158 |
158 @Override | 159 @Override |
159 public Object getValue(FrameSlot slot) { | 160 public Object getValue(FrameSlot slot) { |
160 int index = slot.getIndex(); | 161 int slotIndex = slot.getIndex(); |
161 if (index >= tags.length) { | 162 if (slotIndex >= tags.length) { |
162 assert index >= 0 && index < descriptor.getSize(); | 163 resize(); |
163 return descriptor.getTypeConversion().getDefaultValue(); | 164 } |
164 } | 165 return locals[slotIndex]; |
165 byte tag = tags[index]; | |
166 if (tag == FrameSlotKind.Illegal.ordinal()) { | |
167 return descriptor.getTypeConversion().getDefaultValue(); | |
168 } else { | |
169 return locals[index]; | |
170 } | |
171 } | 166 } |
172 | 167 |
173 private void verifySet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { | 168 private void verifySet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { |
174 FrameSlotKind slotKind = slot.getKind(); | 169 FrameSlotKind slotKind = slot.getKind(); |
175 if (slotKind != accessKind) { | 170 if (slotKind != accessKind) { |
184 resize(); | 179 resize(); |
185 } | 180 } |
186 tags[slotIndex] = (byte) accessKind.ordinal(); | 181 tags[slotIndex] = (byte) accessKind.ordinal(); |
187 } | 182 } |
188 | 183 |
184 private void verifySetObject(FrameSlot slot) { | |
185 if (slot.getKind() != FrameSlotKind.Object) { | |
186 slot.setKind(FrameSlotKind.Object); | |
187 } | |
188 int slotIndex = slot.getIndex(); | |
189 if (slotIndex >= tags.length) { | |
190 resize(); | |
191 } | |
192 tags[slotIndex] = (byte) FrameSlotKind.Object.ordinal(); | |
193 } | |
194 | |
189 private void verifyGet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { | 195 private void verifyGet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { |
190 FrameSlotKind slotKind = slot.getKind(); | 196 int slotIndex = slot.getIndex(); |
191 if (slotKind != accessKind) { | 197 if (slotIndex >= tags.length) { |
192 if (slotKind == FrameSlotKind.Illegal && accessKind == FrameSlotKind.Object) { | 198 resize(); |
193 slot.setKind(FrameSlotKind.Object); | 199 } |
194 this.setObject(slot, descriptor.getTypeConversion().getDefaultValue()); | 200 byte tag = tags[slotIndex]; |
195 } else { | 201 if (accessKind == FrameSlotKind.Object ? (tag & 0xfe) != 0 : tag != accessKind.ordinal()) { |
196 throw new FrameSlotTypeException(); | 202 if (slot.getKind() == accessKind || tag == 0) { |
203 descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot)); | |
204 if (tags[slotIndex] == accessKind.ordinal()) { | |
205 return; | |
206 } | |
197 } | 207 } |
198 } | 208 throw new FrameSlotTypeException(); |
199 int slotIndex = slot.getIndex(); | |
200 if (slotIndex >= tags.length) { | |
201 resize(); | |
202 } | |
203 if (tags[slotIndex] != accessKind.ordinal()) { | |
204 descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot)); | |
205 if (tags[slotIndex] != accessKind.ordinal()) { | |
206 throw new FrameSlotTypeException(); | |
207 } | |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
211 private void resize() { | 212 private void resize() { |
213 int oldSize = tags.length; | |
212 int newSize = descriptor.getSize(); | 214 int newSize = descriptor.getSize(); |
213 if (newSize > tags.length) { | 215 if (newSize > oldSize) { |
214 locals = Arrays.copyOf(locals, newSize); | 216 locals = Arrays.copyOf(locals, newSize); |
217 Arrays.fill(locals, oldSize, newSize, descriptor.getTypeConversion().getDefaultValue()); | |
215 tags = Arrays.copyOf(tags, newSize); | 218 tags = Arrays.copyOf(tags, newSize); |
216 } | 219 } |
217 } | 220 } |
218 | 221 |
219 @Override | 222 @Override |
220 public boolean isInitialized(FrameSlot slot) { | 223 public boolean isInitialized(FrameSlot slot) { |
221 try { | 224 int slotIndex = slot.getIndex(); |
222 return tags[slot.getIndex()] != 0; | 225 if (slotIndex >= tags.length) { |
223 } catch (ArrayIndexOutOfBoundsException ex) { | 226 resize(); |
224 if (slot.getIndex() >= 0 && slot.getIndex() < descriptor.getSize()) { | 227 } |
225 return false; | 228 return tags[slotIndex] != 0; |
226 } | |
227 throw ex; | |
228 } | |
229 } | 229 } |
230 } | 230 } |