Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java @ 22490:fa86f9f3848d
change FrameDescriptor#copy to also copy info
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Thu, 10 Dec 2015 18:51:41 +0100 |
parents | dc2bfc816011 |
children | a73f1d7a5a3e |
comparison
equal
deleted
inserted
replaced
22489:28227895fa35 | 22490:fa86f9f3848d |
---|---|
52 this(null); | 52 this(null); |
53 } | 53 } |
54 | 54 |
55 /** | 55 /** |
56 * Constructs new descriptor with specified {@link #getDefaultValue()}. | 56 * Constructs new descriptor with specified {@link #getDefaultValue()}. |
57 * | 57 * |
58 * @param defaultValue to be returned from {@link #getDefaultValue()} | 58 * @param defaultValue to be returned from {@link #getDefaultValue()} |
59 */ | 59 */ |
60 public FrameDescriptor(Object defaultValue) { | 60 public FrameDescriptor(Object defaultValue) { |
61 CompilerAsserts.neverPartOfCompilation(); | 61 CompilerAsserts.neverPartOfCompilation(); |
62 this.defaultValue = defaultValue; | 62 this.defaultValue = defaultValue; |
65 version = createVersion(); | 65 version = createVersion(); |
66 } | 66 } |
67 | 67 |
68 /** | 68 /** |
69 * Use {@link #FrameDescriptor()}. | 69 * Use {@link #FrameDescriptor()}. |
70 * | 70 * |
71 * @return new instance of the descriptor | 71 * @return new instance of the descriptor |
72 * @deprecated | 72 * @deprecated |
73 */ | 73 */ |
74 @Deprecated | 74 @Deprecated |
75 public static FrameDescriptor create() { | 75 public static FrameDescriptor create() { |
76 return new FrameDescriptor(); | 76 return new FrameDescriptor(); |
77 } | 77 } |
78 | 78 |
79 /** | 79 /** |
80 * Use {@link #FrameDescriptor(java.lang.Object) }. | 80 * Use {@link #FrameDescriptor(java.lang.Object) }. |
81 * | 81 * |
82 * @return new instance of the descriptor | 82 * @return new instance of the descriptor |
83 * @deprecated | 83 * @deprecated |
84 */ | 84 */ |
85 @Deprecated | 85 @Deprecated |
86 public static FrameDescriptor create(Object defaultValue) { | 86 public static FrameDescriptor create(Object defaultValue) { |
90 /** | 90 /** |
91 * Adds frame slot. Delegates to | 91 * Adds frame slot. Delegates to |
92 * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) | 92 * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) |
93 * addFrameSlot}(identifier, <code>null</code>, {@link FrameSlotKind#Illegal}). This is slow | 93 * addFrameSlot}(identifier, <code>null</code>, {@link FrameSlotKind#Illegal}). This is slow |
94 * operation that switches to interpreter mode. | 94 * operation that switches to interpreter mode. |
95 * | 95 * |
96 * @param identifier key for the slot | 96 * @param identifier key for the slot |
97 * @return the newly created slot | 97 * @return the newly created slot |
98 */ | 98 */ |
99 public FrameSlot addFrameSlot(Object identifier) { | 99 public FrameSlot addFrameSlot(Object identifier) { |
100 return addFrameSlot(identifier, null, FrameSlotKind.Illegal); | 100 return addFrameSlot(identifier, null, FrameSlotKind.Illegal); |
103 /** | 103 /** |
104 * Adds frame slot. Delegates to | 104 * Adds frame slot. Delegates to |
105 * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) | 105 * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) |
106 * addFrameSlot}(identifier, <code>null</code>, <code>kind</code>). This is slow operation that | 106 * addFrameSlot}(identifier, <code>null</code>, <code>kind</code>). This is slow operation that |
107 * switches to interpreter mode. | 107 * switches to interpreter mode. |
108 * | 108 * |
109 * @param identifier key for the slot | 109 * @param identifier key for the slot |
110 * @param kind the kind of the new slot | 110 * @param kind the kind of the new slot |
111 * @return the newly created slot | 111 * @return the newly created slot |
112 */ | 112 */ |
113 public FrameSlot addFrameSlot(Object identifier, FrameSlotKind kind) { | 113 public FrameSlot addFrameSlot(Object identifier, FrameSlotKind kind) { |
115 } | 115 } |
116 | 116 |
117 /** | 117 /** |
118 * Adds new frame slot to {@link #getSlots()} list. This is slow operation that switches to | 118 * Adds new frame slot to {@link #getSlots()} list. This is slow operation that switches to |
119 * interpreter mode. | 119 * interpreter mode. |
120 * | 120 * |
121 * @param identifier key for the slot - it needs proper {@link #equals(java.lang.Object)} and | 121 * @param identifier key for the slot - it needs proper {@link #equals(java.lang.Object)} and |
122 * {@link Object#hashCode()} implementations | 122 * {@link Object#hashCode()} implementations |
123 * @param info additional {@link FrameSlot#getInfo() information for the slot} | 123 * @param info additional {@link FrameSlot#getInfo() information for the slot} |
124 * @param kind the kind of the new slot | 124 * @param kind the kind of the new slot |
125 * @return the newly created slot | 125 * @return the newly created slot |
135 return slot; | 135 return slot; |
136 } | 136 } |
137 | 137 |
138 /** | 138 /** |
139 * Finds an existing slot. This is slow operation. | 139 * Finds an existing slot. This is slow operation. |
140 * | 140 * |
141 * @param identifier the key of the slot to search for | 141 * @param identifier the key of the slot to search for |
142 * @return the slot or <code>null</code> | 142 * @return the slot or <code>null</code> |
143 */ | 143 */ |
144 public FrameSlot findFrameSlot(Object identifier) { | 144 public FrameSlot findFrameSlot(Object identifier) { |
145 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); | 145 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); |
146 return identifierToSlotMap.get(identifier); | 146 return identifierToSlotMap.get(identifier); |
147 } | 147 } |
148 | 148 |
149 /** | 149 /** |
150 * Finds an existing slot or creates new one. This is slow operation. | 150 * Finds an existing slot or creates new one. This is slow operation. |
151 * | 151 * |
152 * @param identifier the key of the slot to search for | 152 * @param identifier the key of the slot to search for |
153 * @return the slot | 153 * @return the slot |
154 */ | 154 */ |
155 public FrameSlot findOrAddFrameSlot(Object identifier) { | 155 public FrameSlot findOrAddFrameSlot(Object identifier) { |
156 FrameSlot result = findFrameSlot(identifier); | 156 FrameSlot result = findFrameSlot(identifier); |
160 return addFrameSlot(identifier); | 160 return addFrameSlot(identifier); |
161 } | 161 } |
162 | 162 |
163 /** | 163 /** |
164 * Finds an existing slot or creates new one. This is slow operation. | 164 * Finds an existing slot or creates new one. This is slow operation. |
165 * | 165 * |
166 * @param identifier the key of the slot to search for | 166 * @param identifier the key of the slot to search for |
167 * @param kind the kind for the newly created slot | 167 * @param kind the kind for the newly created slot |
168 * @return the found or newly created slot | 168 * @return the found or newly created slot |
169 */ | 169 */ |
170 public FrameSlot findOrAddFrameSlot(Object identifier, FrameSlotKind kind) { | 170 public FrameSlot findOrAddFrameSlot(Object identifier, FrameSlotKind kind) { |
175 return addFrameSlot(identifier, kind); | 175 return addFrameSlot(identifier, kind); |
176 } | 176 } |
177 | 177 |
178 /** | 178 /** |
179 * Finds an existing slot or creates new one. This is slow operation. | 179 * Finds an existing slot or creates new one. This is slow operation. |
180 * | 180 * |
181 * @param identifier the key of the slot to search for | 181 * @param identifier the key of the slot to search for |
182 * @param info info for the newly created slot | 182 * @param info info for the newly created slot |
183 * @param kind the kind for the newly created slot | 183 * @param kind the kind for the newly created slot |
184 * @return the found or newly created slot | 184 * @return the found or newly created slot |
185 */ | 185 */ |
192 } | 192 } |
193 | 193 |
194 /** | 194 /** |
195 * Removes a slot. If the identifier is found, its slot is removed from this descriptor. This is | 195 * Removes a slot. If the identifier is found, its slot is removed from this descriptor. This is |
196 * slow operation. | 196 * slow operation. |
197 * | 197 * |
198 * @param identifier identifies the slot to remove | 198 * @param identifier identifies the slot to remove |
199 */ | 199 */ |
200 public void removeFrameSlot(Object identifier) { | 200 public void removeFrameSlot(Object identifier) { |
201 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); | 201 CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); |
202 assert identifierToSlotMap.containsKey(identifier); | 202 assert identifierToSlotMap.containsKey(identifier); |
206 getNotInFrameAssumption(identifier); | 206 getNotInFrameAssumption(identifier); |
207 } | 207 } |
208 | 208 |
209 /** | 209 /** |
210 * Returns number of slots in the descriptor. | 210 * Returns number of slots in the descriptor. |
211 * | 211 * |
212 * @return the same value as {@link #getSlots()}.{@link List#size()} would return | 212 * @return the same value as {@link #getSlots()}.{@link List#size()} would return |
213 */ | 213 */ |
214 public int getSize() { | 214 public int getSize() { |
215 return slots.size(); | 215 return slots.size(); |
216 } | 216 } |
217 | 217 |
218 /** | 218 /** |
219 * Current set of slots in the descriptor. | 219 * Current set of slots in the descriptor. |
220 * | 220 * |
221 * @return unmodifiable list of {@link FrameSlot} | 221 * @return unmodifiable list of {@link FrameSlot} |
222 */ | 222 */ |
223 public List<? extends FrameSlot> getSlots() { | 223 public List<? extends FrameSlot> getSlots() { |
224 return Collections.unmodifiableList(slots); | 224 return Collections.unmodifiableList(slots); |
225 } | 225 } |
232 public Set<Object> getIdentifiers() { | 232 public Set<Object> getIdentifiers() { |
233 return Collections.unmodifiableSet(identifierToSlotMap.keySet()); | 233 return Collections.unmodifiableSet(identifierToSlotMap.keySet()); |
234 } | 234 } |
235 | 235 |
236 /** | 236 /** |
237 * Deeper copy of the descriptor. Copies all slots in the descriptor, but only their identifiers | 237 * Deeper copy of the descriptor. Copies all slots in the descriptor, but only their |
238 * - not their {@link FrameSlot#getInfo()} neither their {@link FrameSlot#getKind()}! | 238 * {@linkplain FrameSlot#getIdentifier() identifier} and {@linkplain FrameSlot#getInfo() info} |
239 * | 239 * but not their {@linkplain FrameSlot#getKind() kind}! |
240 * | |
240 * @return new instance of a descriptor with copies of values from this one | 241 * @return new instance of a descriptor with copies of values from this one |
241 */ | 242 */ |
242 public FrameDescriptor copy() { | 243 public FrameDescriptor copy() { |
243 FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue); | 244 FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue); |
244 for (int i = 0; i < this.getSlots().size(); i++) { | 245 for (int i = 0; i < slots.size(); i++) { |
245 Object identifier = this.getSlots().get(i).getIdentifier(); | 246 FrameSlot slot = slots.get(i); |
246 clonedFrameDescriptor.addFrameSlot(identifier); | 247 clonedFrameDescriptor.addFrameSlot(slot.getIdentifier(), slot.getInfo(), FrameSlotKind.Illegal); |
247 } | 248 } |
248 return clonedFrameDescriptor; | 249 return clonedFrameDescriptor; |
249 } | 250 } |
250 | 251 |
251 /** | 252 /** |
252 * Shallow copy of the descriptor. Re-uses the existing slots in new descriptor. As a result, if | 253 * Shallow copy of the descriptor. Re-uses the existing slots in new descriptor. As a result, if |
253 * you {@link FrameSlot#setKind(com.oracle.truffle.api.frame.FrameSlotKind) change kind} of one | 254 * you {@link FrameSlot#setKind(com.oracle.truffle.api.frame.FrameSlotKind) change kind} of one |
254 * of the slots it is changed in the original as well as in the shallow copy. | 255 * of the slots it is changed in the original as well as in the shallow copy. |
255 * | 256 * |
256 * @return new instance of a descriptor with copies of values from this one | 257 * @return new instance of a descriptor with copies of values from this one |
257 */ | 258 */ |
258 public FrameDescriptor shallowCopy() { | 259 public FrameDescriptor shallowCopy() { |
259 FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue); | 260 FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue); |
260 clonedFrameDescriptor.slots.addAll(slots); | 261 clonedFrameDescriptor.slots.addAll(slots); |
275 return Truffle.getRuntime().createAssumption("frame version"); | 276 return Truffle.getRuntime().createAssumption("frame version"); |
276 } | 277 } |
277 | 278 |
278 /** | 279 /** |
279 * Default value for the created slots. | 280 * Default value for the created slots. |
280 * | 281 * |
281 * @return value provided to {@link #FrameDescriptor(java.lang.Object)} | 282 * @return value provided to {@link #FrameDescriptor(java.lang.Object)} |
282 */ | 283 */ |
283 public Object getDefaultValue() { | 284 public Object getDefaultValue() { |
284 return defaultValue; | 285 return defaultValue; |
285 } | 286 } |