Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java @ 22513:8d5a558f4279
turn FrameDescriptor assertions into checks that throw IllegalArgumentException
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Fri, 18 Dec 2015 14:20:50 +0100 |
parents | 67d312302970 |
children | cda3eebfa777 |
comparison
equal
deleted
inserted
replaced
22512:81c021e5448d | 22513:8d5a558f4279 |
---|---|
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.api.frame; | 25 package com.oracle.truffle.api.frame; |
26 | 26 |
27 import com.oracle.truffle.api.Assumption; | |
28 import com.oracle.truffle.api.CompilerAsserts; | |
29 import com.oracle.truffle.api.Truffle; | |
30 import java.util.ArrayList; | 27 import java.util.ArrayList; |
31 import java.util.Collections; | 28 import java.util.Collections; |
32 import java.util.HashMap; | 29 import java.util.HashMap; |
33 import java.util.List; | 30 import java.util.List; |
34 import java.util.Set; | 31 import java.util.Set; |
35 | 32 |
33 import com.oracle.truffle.api.Assumption; | |
34 import com.oracle.truffle.api.CompilerAsserts; | |
35 import com.oracle.truffle.api.Truffle; | |
36 | |
36 /** | 37 /** |
37 * Descriptor of the slots of frame objects. Multiple frame instances are associated with one such | 38 * Descriptor of the slots of frame objects. Multiple frame instances are associated with one such |
38 * descriptor. | 39 * descriptor. |
39 */ | 40 */ |
40 public final class FrameDescriptor implements Cloneable { | 41 public final class FrameDescriptor implements Cloneable { |
42 private final Object defaultValue; | 43 private final Object defaultValue; |
43 private final ArrayList<FrameSlot> slots; | 44 private final ArrayList<FrameSlot> slots; |
44 private final HashMap<Object, FrameSlot> identifierToSlotMap; | 45 private final HashMap<Object, FrameSlot> identifierToSlotMap; |
45 private Assumption version; | 46 private Assumption version; |
46 private HashMap<Object, Assumption> identifierToNotInFrameAssumptionMap; | 47 private HashMap<Object, Assumption> identifierToNotInFrameAssumptionMap; |
48 | |
49 private static final String NEVER_PART_OF_COMPILATION_MESSAGE = "interpreter-only. includes hashmap operations."; | |
47 | 50 |
48 /** | 51 /** |
49 * Constructs empty descriptor. The {@link #getDefaultValue()} is <code>null</code>. | 52 * Constructs empty descriptor. The {@link #getDefaultValue()} is <code>null</code>. |
50 */ | 53 */ |
51 public FrameDescriptor() { | 54 public FrameDescriptor() { |
121 * @param identifier key for the slot - it needs proper {@link #equals(java.lang.Object)} and | 124 * @param identifier key for the slot - it needs proper {@link #equals(java.lang.Object)} and |
122 * {@link Object#hashCode()} implementations | 125 * {@link Object#hashCode()} implementations |
123 * @param info additional {@link FrameSlot#getInfo() information for the slot} | 126 * @param info additional {@link FrameSlot#getInfo() information for the slot} |
124 * @param kind the kind of the new slot | 127 * @param kind the kind of the new slot |
125 * @return the newly created slot | 128 * @return the newly created slot |
129 * @throws IllegalArgumentException if a frame slot with the same identifier exists | |
126 */ | 130 */ |
127 public FrameSlot addFrameSlot(Object identifier, Object info, FrameSlotKind kind) { | 131 public FrameSlot addFrameSlot(Object identifier, Object info, FrameSlotKind kind) { |
128 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); | 132 CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); |
129 assert !identifierToSlotMap.containsKey(identifier); | 133 if (identifierToSlotMap.containsKey(identifier)) { |
134 throw new IllegalArgumentException("duplicate frame slot: " + identifier); | |
135 } | |
130 FrameSlot slot = new FrameSlot(this, identifier, info, slots.size(), kind); | 136 FrameSlot slot = new FrameSlot(this, identifier, info, slots.size(), kind); |
131 slots.add(slot); | 137 slots.add(slot); |
132 identifierToSlotMap.put(identifier, slot); | 138 identifierToSlotMap.put(identifier, slot); |
133 updateVersion(); | 139 updateVersion(); |
134 invalidateNotInFrameAssumption(identifier); | 140 invalidateNotInFrameAssumption(identifier); |
140 * | 146 * |
141 * @param identifier the key of the slot to search for | 147 * @param identifier the key of the slot to search for |
142 * @return the slot or <code>null</code> | 148 * @return the slot or <code>null</code> |
143 */ | 149 */ |
144 public FrameSlot findFrameSlot(Object identifier) { | 150 public FrameSlot findFrameSlot(Object identifier) { |
145 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); | 151 CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); |
146 return identifierToSlotMap.get(identifier); | 152 return identifierToSlotMap.get(identifier); |
147 } | 153 } |
148 | 154 |
149 /** | 155 /** |
150 * Finds an existing slot or creates new one. This is a slow operation. | 156 * Finds an existing slot or creates new one. This is a slow operation. |
194 /** | 200 /** |
195 * Removes a slot. If the identifier is found, its slot is removed from this descriptor. This is | 201 * Removes a slot. If the identifier is found, its slot is removed from this descriptor. This is |
196 * a slow operation. | 202 * a slow operation. |
197 * | 203 * |
198 * @param identifier identifies the slot to remove | 204 * @param identifier identifies the slot to remove |
205 * @throws IllegalArgumentException if no such frame slot exists | |
199 */ | 206 */ |
200 public void removeFrameSlot(Object identifier) { | 207 public void removeFrameSlot(Object identifier) { |
201 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); | 208 CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); |
202 assert identifierToSlotMap.containsKey(identifier); | 209 if (!identifierToSlotMap.containsKey(identifier)) { |
210 throw new IllegalArgumentException("no such frame slot: " + identifier); | |
211 } | |
203 slots.remove(identifierToSlotMap.get(identifier)); | 212 slots.remove(identifierToSlotMap.get(identifier)); |
204 identifierToSlotMap.remove(identifier); | 213 identifierToSlotMap.remove(identifier); |
205 updateVersion(); | 214 updateVersion(); |
206 getNotInFrameAssumption(identifier); | 215 getNotInFrameAssumption(identifier); |
207 } | 216 } |