Mercurial > hg > graal-compiler
diff graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2848:c061a6be3728
merge
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Tue, 31 May 2011 15:19:30 +0200 |
parents | caf55daa41dc 7b5831f0e913 |
children | 7474789a8120 |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue May 31 15:19:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue May 31 15:19:30 2011 +0200 @@ -338,11 +338,7 @@ return handler.catchTypeCPI() == 0; } - private void handleException(Instruction x, int bci) { - if (!hasHandler()) { - return; - } - + private Instruction handleException(Value exceptionObject, int bci) { assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; RiExceptionHandler firstHandler = null; @@ -389,19 +385,22 @@ StateSplit entry = new Placeholder(graph); entry.setStateBefore(entryState); - ExceptionObject exception = new ExceptionObject(graph); - entry.setNext(exception); - FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); + + Instruction currentNext = entry; + Value currentExceptionObject = exceptionObject; + if (currentExceptionObject == null) { + ExceptionObject exception = new ExceptionObject(graph); + entry.setNext(exception); + currentNext = exception; + currentExceptionObject = exception; + } + FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, currentExceptionObject); Instruction successor = createTarget(dispatchBlock, stateWithException); - Anchor end = new Anchor(successor, graph); - exception.setNext(end); - if (x instanceof Invoke) { - ((Invoke) x).setExceptionEdge(entry); - } else { - ((Throw) x).setExceptionEdge(entry); - } + currentNext.setNext(successor); + return entry; } + return null; } private void genLoadConstant(int cpi) { @@ -609,11 +608,13 @@ } private void genThrow(int bci) { - FrameState stateBefore = frameState.create(bci); - Throw t = new Throw(frameState.apop(), graph); - t.setStateBefore(stateBefore); - appendWithBCI(t); - handleException(t, bci); + Value exception = frameState.apop(); + append(new NullCheck(exception, graph)); + Instruction entry = handleException(exception, bci); + if (entry == null) { + entry = new Unwind(exception, graph.end(), graph); + } + append(entry); } private void genCheckCast() { @@ -832,7 +833,7 @@ CiKind resultType = returnKind(target); Invoke invoke = new Invoke(bci(), opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph); Value result = appendWithBCI(invoke); - handleException(invoke, bci()); + invoke.setExceptionEdge(handleException(null, bci())); frameState.pushReturn(resultType, result); } @@ -1010,7 +1011,7 @@ } private Value appendWithBCI(Instruction x) { - assert x.next() == null && x.predecessors().size() == 0 : "instruction should not have been appended yet"; + assert x.predecessors().size() == 0 : "instruction should not have been appended yet"; assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")"; lastInstr.setNext(x); @@ -1080,7 +1081,7 @@ // Exit the monitor and unwind the stack. genMonitorExit(lock); - append(new Unwind(frameState.apop(), graph)); + append(new Unwind(frameState.apop(), graph.end(), graph)); // The sync handler is always the last thing to add => we can clear the frameState. frameState = null; @@ -1149,7 +1150,7 @@ append(new MonitorExit(rootMethodSynchronizedObject, lockAddress, lockNumber, graph)); frameState.unlock(); } - append(new Unwind(frameState.apop(), graph)); + append(new Unwind(frameState.apop(), graph.end(), graph)); } else { assert frameState.stackSize() == 1; @@ -1494,12 +1495,4 @@ private Block removeFromWorkList() { return workList.poll(); } - - /** - * Checks whether this graph has any handlers. - * @return {@code true} if there are any exception handlers - */ - private boolean hasHandler() { - return Modifier.isSynchronized(compilation.method.accessFlags()) || (compilation.method.exceptionHandlers() != null && compilation.method.exceptionHandlers().length > 0); - } }