comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2833:1cd59ca9ac86

Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Tue, 31 May 2011 13:30:23 +0200
parents 706047ee5f2e
children c1c8a0291771 a75ef246fab3
comparison
equal deleted inserted replaced
2832:775c31be565c 2833:1cd59ca9ac86
335 335
336 public boolean isCatchAll(RiExceptionHandler handler) { 336 public boolean isCatchAll(RiExceptionHandler handler) {
337 return handler.catchTypeCPI() == 0; 337 return handler.catchTypeCPI() == 0;
338 } 338 }
339 339
340 private void handleException(Instruction x, int bci) { 340 private Instruction handleException(Value exceptionObject, int bci) {
341 if (!hasHandler()) {
342 return;
343 }
344
345 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; 341 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci";
346 342
347 RiExceptionHandler firstHandler = null; 343 RiExceptionHandler firstHandler = null;
348 RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers(); 344 RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers();
349 // join with all potential exception handlers 345 // join with all potential exception handlers
386 } 382 }
387 FrameState entryState = frameState.duplicateWithEmptyStack(bci); 383 FrameState entryState = frameState.duplicateWithEmptyStack(bci);
388 384
389 StateSplit entry = new Placeholder(graph); 385 StateSplit entry = new Placeholder(graph);
390 entry.setStateBefore(entryState); 386 entry.setStateBefore(entryState);
391 ExceptionObject exception = new ExceptionObject(graph); 387
392 entry.setNext(exception); 388 Instruction currentNext = entry;
393 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); 389 Value currentExceptionObject = exceptionObject;
390 if (currentExceptionObject == null) {
391 ExceptionObject exception = new ExceptionObject(graph);
392 entry.setNext(exception);
393 currentNext = exception;
394 currentExceptionObject = exception;
395 }
396 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, currentExceptionObject);
394 397
395 Instruction successor = createTarget(dispatchBlock, stateWithException); 398 Instruction successor = createTarget(dispatchBlock, stateWithException);
396 Anchor end = new Anchor(successor, graph); 399 Anchor end = new Anchor(successor, graph);
397 exception.setNext(end); 400 currentNext.setNext(end);
398 if (x instanceof Invoke) { 401 return entry;
399 ((Invoke) x).setExceptionEdge(entry); 402 }
400 } else { 403 return null;
401 ((Throw) x).setExceptionEdge(entry);
402 }
403 }
404 } 404 }
405 405
406 private void genLoadConstant(int cpi) { 406 private void genLoadConstant(int cpi) {
407 Object con = constantPool().lookupConstant(cpi); 407 Object con = constantPool().lookupConstant(cpi);
408 408
606 assert !x.isDeleted() && !y.isDeleted(); 606 assert !x.isDeleted() && !y.isDeleted();
607 ifNode(x, cond, y); 607 ifNode(x, cond, y);
608 } 608 }
609 609
610 private void genThrow(int bci) { 610 private void genThrow(int bci) {
611 FrameState stateBefore = frameState.create(bci); 611 Value exception = frameState.apop();
612 Throw t = new Throw(frameState.apop(), graph); 612 append(new NullCheck(exception, graph));
613 t.setStateBefore(stateBefore); 613 Instruction entry = handleException(exception, bci);
614 appendWithBCI(t); 614 if (entry == null) {
615 handleException(t, bci); 615 entry = new Unwind(exception, graph);
616 }
617 append(entry);
616 } 618 }
617 619
618 private void genCheckCast() { 620 private void genCheckCast() {
619 int cpi = stream().readCPI(); 621 int cpi = stream().readCPI();
620 RiType type = constantPool().lookupType(cpi, CHECKCAST); 622 RiType type = constantPool().lookupType(cpi, CHECKCAST);
829 831
830 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) { 832 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) {
831 CiKind resultType = returnKind(target); 833 CiKind resultType = returnKind(target);
832 Invoke invoke = new Invoke(bci(), opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph); 834 Invoke invoke = new Invoke(bci(), opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph);
833 Value result = appendWithBCI(invoke); 835 Value result = appendWithBCI(invoke);
834 handleException(invoke, bci()); 836 invoke.setExceptionEdge(handleException(null, bci()));
835 frameState.pushReturn(resultType, result); 837 frameState.pushReturn(resultType, result);
836 } 838 }
837 839
838 private RiType getExactType(RiType staticType, Value receiver) { 840 private RiType getExactType(RiType staticType, Value receiver) {
839 RiType exact = staticType.exactType(); 841 RiType exact = staticType.exactType();
1007 private Value append(Value v) { 1009 private Value append(Value v) {
1008 return v; 1010 return v;
1009 } 1011 }
1010 1012
1011 private Value appendWithBCI(Instruction x) { 1013 private Value appendWithBCI(Instruction x) {
1012 assert x.next() == null && x.predecessors().size() == 0 : "instruction should not have been appended yet"; 1014 assert x.predecessors().size() == 0 : "instruction should not have been appended yet";
1013 assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")"; 1015 assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")";
1014 lastInstr.setNext(x); 1016 lastInstr.setNext(x);
1015 1017
1016 lastInstr = x; 1018 lastInstr = x;
1017 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { 1019 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) {
1491 * in the worklist 1493 * in the worklist
1492 */ 1494 */
1493 private Block removeFromWorkList() { 1495 private Block removeFromWorkList() {
1494 return workList.poll(); 1496 return workList.poll();
1495 } 1497 }
1496
1497 /**
1498 * Checks whether this graph has any handlers.
1499 * @return {@code true} if there are any exception handlers
1500 */
1501 private boolean hasHandler() {
1502 return Modifier.isSynchronized(compilation.method.accessFlags()) || (compilation.method.exceptionHandlers() != null && compilation.method.exceptionHandlers().length > 0);
1503 }
1504 } 1498 }