comparison graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractFrameStateBuilder.java @ 19496:9525e4d5b385

disable (asserting) type checks in the FrameStateBuilder when parsing a replacement added GraphBuilderContext.getCurrentBlockGuard()
author Doug Simon <doug.simon@oracle.com>
date Thu, 19 Feb 2015 11:16:19 +0100
parents 7837f7aab5ed
children 71a6d0ba3a49
comparison
equal deleted inserted replaced
19495:c4173ea6c8c7 19496:9525e4d5b385
34 protected final T[] locals; 34 protected final T[] locals;
35 protected final T[] stack; 35 protected final T[] stack;
36 protected T[] lockedObjects; 36 protected T[] lockedObjects;
37 37
38 /** 38 /**
39 * Specifies if asserting type checks are enabled.
40 */
41 protected final boolean checkTypes;
42
43 /**
39 * @see BytecodeFrame#rethrowException 44 * @see BytecodeFrame#rethrowException
40 */ 45 */
41 protected boolean rethrowException; 46 protected boolean rethrowException;
42 47
43 public AbstractFrameStateBuilder(ResolvedJavaMethod method) { 48 public AbstractFrameStateBuilder(ResolvedJavaMethod method, boolean checkTypes) {
44 this.method = method; 49 this.method = method;
45 this.locals = allocateArray(method.getMaxLocals()); 50 this.locals = allocateArray(method.getMaxLocals());
46 this.stack = allocateArray(Math.max(1, method.getMaxStackSize())); 51 this.stack = allocateArray(Math.max(1, method.getMaxStackSize()));
47 this.lockedObjects = allocateArray(0); 52 this.lockedObjects = allocateArray(0);
53 this.checkTypes = checkTypes;
48 } 54 }
49 55
50 protected AbstractFrameStateBuilder(S other) { 56 protected AbstractFrameStateBuilder(S other) {
51 this.method = other.method; 57 this.method = other.method;
52 this.stackSize = other.stackSize; 58 this.stackSize = other.stackSize;
53 this.locals = other.locals.clone(); 59 this.locals = other.locals.clone();
54 this.stack = other.stack.clone(); 60 this.stack = other.stack.clone();
55 this.lockedObjects = other.lockedObjects.length == 0 ? other.lockedObjects : other.lockedObjects.clone(); 61 this.lockedObjects = other.lockedObjects.length == 0 ? other.lockedObjects : other.lockedObjects.clone();
56 this.rethrowException = other.rethrowException; 62 this.rethrowException = other.rethrowException;
63 this.checkTypes = other.checkTypes;
57 64
58 assert locals.length == method.getMaxLocals(); 65 assert locals.length == method.getMaxLocals();
59 assert stack.length == Math.max(1, method.getMaxStackSize()); 66 assert stack.length == Math.max(1, method.getMaxStackSize());
60 } 67 }
61 68
169 * @return the instruction that produced the specified local 176 * @return the instruction that produced the specified local
170 */ 177 */
171 public T loadLocal(int i) { 178 public T loadLocal(int i) {
172 T x = locals[i]; 179 T x = locals[i];
173 assert x != null : i; 180 assert x != null : i;
174 assert x.getKind().getSlotCount() == 1 || locals[i + 1] == null; 181 assert !checkTypes || (x.getKind().getSlotCount() == 1 || locals[i + 1] == null);
175 assert i == 0 || locals[i - 1] == null || locals[i - 1].getKind().getSlotCount() == 1; 182 assert !checkTypes || (i == 0 || locals[i - 1] == null || locals[i - 1].getKind().getSlotCount() == 1);
176 return x; 183 return x;
177 } 184 }
178 185
179 /** 186 /**
180 * Stores a given local variable at the specified index. If the value occupies two slots, then 187 * Stores a given local variable at the specified index. If the value occupies two slots, then
182 * 189 *
183 * @param i the index at which to store 190 * @param i the index at which to store
184 * @param x the instruction which produces the value for the local 191 * @param x the instruction which produces the value for the local
185 */ 192 */
186 public void storeLocal(int i, T x) { 193 public void storeLocal(int i, T x) {
187 assert x == null || x.getKind() != Kind.Void && x.getKind() != Kind.Illegal : "unexpected value: " + x; 194 assert x == null || !checkTypes || (x.getKind() != Kind.Void && x.getKind() != Kind.Illegal) : "unexpected value: " + x;
188 locals[i] = x; 195 locals[i] = x;
189 if (x != null && x.getKind().needsTwoSlots()) { 196 if (x != null && x.getKind().needsTwoSlots()) {
190 // if this is a double word, then kill i+1 197 // if this is a double word, then kill i+1
191 locals[i + 1] = null; 198 locals[i + 1] = null;
192 } 199 }
209 * 216 *
210 * @param kind the type expected for this instruction 217 * @param kind the type expected for this instruction
211 * @param x the instruction to push onto the stack 218 * @param x the instruction to push onto the stack
212 */ 219 */
213 public void push(Kind kind, T x) { 220 public void push(Kind kind, T x) {
214 assert x.getKind() != Kind.Void && x.getKind() != Kind.Illegal; 221 assert !checkTypes || (x.getKind() != Kind.Void && x.getKind() != Kind.Illegal) : x;
215 xpush(assertKind(kind, x)); 222 xpush(assertKind(kind, x));
216 if (kind.needsTwoSlots()) { 223 if (kind.needsTwoSlots()) {
217 xpush(null); 224 xpush(null);
218 } 225 }
219 } 226 }
222 * Pushes a value onto the stack without checking the type. 229 * Pushes a value onto the stack without checking the type.
223 * 230 *
224 * @param x the instruction to push onto the stack 231 * @param x the instruction to push onto the stack
225 */ 232 */
226 public void xpush(T x) { 233 public void xpush(T x) {
227 assert x == null || (x.getKind() != Kind.Void && x.getKind() != Kind.Illegal); 234 assert !checkTypes || (x == null || (x.getKind() != Kind.Void && x.getKind() != Kind.Illegal));
228 stack[stackSize++] = x; 235 stack[stackSize++] = x;
229 } 236 }
230 237
231 /** 238 /**
232 * Pushes a value onto the stack and checks that it is an int. 239 * Pushes a value onto the stack and checks that it is an int.
366 if (stack[newStackSize] == null) { 373 if (stack[newStackSize] == null) {
367 /* Two-slot value. */ 374 /* Two-slot value. */
368 newStackSize--; 375 newStackSize--;
369 assert stack[newStackSize].getKind().needsTwoSlots(); 376 assert stack[newStackSize].getKind().needsTwoSlots();
370 } else { 377 } else {
371 assert stack[newStackSize].getKind().getSlotCount() == 1; 378 assert !checkTypes || (stack[newStackSize].getKind().getSlotCount() == 1);
372 } 379 }
373 result[i] = stack[newStackSize]; 380 result[i] = stack[newStackSize];
374 } 381 }
375 stackSize = newStackSize; 382 stackSize = newStackSize;
376 return result; 383 return result;
402 public void clearStack() { 409 public void clearStack() {
403 stackSize = 0; 410 stackSize = 0;
404 } 411 }
405 412
406 private T assertKind(Kind kind, T x) { 413 private T assertKind(Kind kind, T x) {
407 assert x != null && x.getKind() == kind : "kind=" + kind + ", value=" + x + ((x == null) ? "" : ", value.kind=" + x.getKind()); 414 assert x != null && (!checkTypes || x.getKind() == kind) : "kind=" + kind + ", value=" + x + ((x == null) ? "" : ", value.kind=" + x.getKind());
408 return x; 415 return x;
409 } 416 }
410 417
411 private T assertLong(T x) { 418 private T assertLong(T x) {
412 assert x != null && (x.getKind() == Kind.Long); 419 assert x != null && (x.getKind() == Kind.Long);
422 assert x != null && (x.getKind() == Kind.Float); 429 assert x != null && (x.getKind() == Kind.Float);
423 return x; 430 return x;
424 } 431 }
425 432
426 private T assertObject(T x) { 433 private T assertObject(T x) {
427 assert x != null && (x.getKind() == Kind.Object); 434 assert x != null && (!checkTypes || (x.getKind() == Kind.Object)) : x + ":" + x.getKind();
428 return x; 435 return x;
429 } 436 }
430 437
431 private T assertDouble(T x) { 438 private T assertDouble(T x) {
432 assert x != null && (x.getKind() == Kind.Double); 439 assert x != null && (x.getKind() == Kind.Double);