comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java @ 11810:91a676d0bbbe

Truffle: add not-in-frame assumption feature.
author Andreas Woess <andreas.woess@jku.at>
date Thu, 26 Sep 2013 13:47:12 +0200
parents 0c4d7b468dd7
children e122dc0436be
comparison
equal deleted inserted replaced
11809:c7769440afd8 11810:91a676d0bbbe
37 37
38 private final FrameTypeConversion typeConversion; 38 private final FrameTypeConversion typeConversion;
39 private final ArrayList<FrameSlotImpl> slots; 39 private final ArrayList<FrameSlotImpl> slots;
40 private final HashMap<Object, FrameSlotImpl> identifierToSlotMap; 40 private final HashMap<Object, FrameSlotImpl> identifierToSlotMap;
41 private Assumption version; 41 private Assumption version;
42 private HashMap<Object, Assumption> identifierToNotInFrameAssumptionMap;
42 43
43 public FrameDescriptor() { 44 public FrameDescriptor() {
44 this(DefaultFrameTypeConversion.getInstance()); 45 this(DefaultFrameTypeConversion.getInstance());
45 } 46 }
46 47
59 assert !identifierToSlotMap.containsKey(identifier); 60 assert !identifierToSlotMap.containsKey(identifier);
60 FrameSlotImpl slot = new FrameSlotImpl(this, identifier, slots.size(), kind); 61 FrameSlotImpl slot = new FrameSlotImpl(this, identifier, slots.size(), kind);
61 slots.add(slot); 62 slots.add(slot);
62 identifierToSlotMap.put(identifier, slot); 63 identifierToSlotMap.put(identifier, slot);
63 updateVersion(); 64 updateVersion();
65 invalidateNotInFrameAssumption(identifier);
64 return slot; 66 return slot;
65 } 67 }
66 68
67 public FrameSlot findFrameSlot(Object identifier) { 69 public FrameSlot findFrameSlot(Object identifier) {
68 return identifierToSlotMap.get(identifier); 70 return identifierToSlotMap.get(identifier);
131 } 133 }
132 134
133 public FrameTypeConversion getTypeConversion() { 135 public FrameTypeConversion getTypeConversion() {
134 return typeConversion; 136 return typeConversion;
135 } 137 }
138
139 public Assumption getNotInFrameAssumption(Object identifier) {
140 if (identifierToSlotMap.containsKey(identifier)) {
141 throw new IllegalArgumentException("Cannot get not-in-frame assumption for existing frame slot!");
142 }
143
144 if (identifierToNotInFrameAssumptionMap == null) {
145 identifierToNotInFrameAssumptionMap = new HashMap<>();
146 } else {
147 Assumption assumption = identifierToNotInFrameAssumptionMap.get(identifier);
148 if (assumption != null) {
149 return assumption;
150 }
151 }
152 Assumption assumption = Truffle.getRuntime().createAssumption("not in frame: " + identifier);
153 identifierToNotInFrameAssumptionMap.put(identifier, assumption);
154 return assumption;
155 }
156
157 private void invalidateNotInFrameAssumption(Object identifier) {
158 if (identifierToNotInFrameAssumptionMap != null) {
159 Assumption assumption = identifierToNotInFrameAssumptionMap.get(identifier);
160 if (assumption != null) {
161 assumption.invalidate();
162 identifierToNotInFrameAssumptionMap.remove(identifier);
163 }
164 }
165 }
136 } 166 }