Mercurial > hg > graal-compiler
comparison 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 |
comparison
equal
deleted
inserted
replaced
2847:caf55daa41dc | 2848:c061a6be3728 |
---|---|
336 | 336 |
337 public boolean isCatchAll(RiExceptionHandler handler) { | 337 public boolean isCatchAll(RiExceptionHandler handler) { |
338 return handler.catchTypeCPI() == 0; | 338 return handler.catchTypeCPI() == 0; |
339 } | 339 } |
340 | 340 |
341 private void handleException(Instruction x, int bci) { | 341 private Instruction handleException(Value exceptionObject, int bci) { |
342 if (!hasHandler()) { | |
343 return; | |
344 } | |
345 | |
346 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; | 342 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; |
347 | 343 |
348 RiExceptionHandler firstHandler = null; | 344 RiExceptionHandler firstHandler = null; |
349 RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers(); | 345 RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers(); |
350 // join with all potential exception handlers | 346 // join with all potential exception handlers |
387 } | 383 } |
388 FrameState entryState = frameState.duplicateWithEmptyStack(bci); | 384 FrameState entryState = frameState.duplicateWithEmptyStack(bci); |
389 | 385 |
390 StateSplit entry = new Placeholder(graph); | 386 StateSplit entry = new Placeholder(graph); |
391 entry.setStateBefore(entryState); | 387 entry.setStateBefore(entryState); |
392 ExceptionObject exception = new ExceptionObject(graph); | 388 |
393 entry.setNext(exception); | 389 Instruction currentNext = entry; |
394 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); | 390 Value currentExceptionObject = exceptionObject; |
391 if (currentExceptionObject == null) { | |
392 ExceptionObject exception = new ExceptionObject(graph); | |
393 entry.setNext(exception); | |
394 currentNext = exception; | |
395 currentExceptionObject = exception; | |
396 } | |
397 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, currentExceptionObject); | |
395 | 398 |
396 Instruction successor = createTarget(dispatchBlock, stateWithException); | 399 Instruction successor = createTarget(dispatchBlock, stateWithException); |
397 Anchor end = new Anchor(successor, graph); | 400 currentNext.setNext(successor); |
398 exception.setNext(end); | 401 return entry; |
399 if (x instanceof Invoke) { | 402 } |
400 ((Invoke) x).setExceptionEdge(entry); | 403 return null; |
401 } else { | |
402 ((Throw) x).setExceptionEdge(entry); | |
403 } | |
404 } | |
405 } | 404 } |
406 | 405 |
407 private void genLoadConstant(int cpi) { | 406 private void genLoadConstant(int cpi) { |
408 Object con = constantPool().lookupConstant(cpi); | 407 Object con = constantPool().lookupConstant(cpi); |
409 | 408 |
607 assert !x.isDeleted() && !y.isDeleted(); | 606 assert !x.isDeleted() && !y.isDeleted(); |
608 ifNode(x, cond, y); | 607 ifNode(x, cond, y); |
609 } | 608 } |
610 | 609 |
611 private void genThrow(int bci) { | 610 private void genThrow(int bci) { |
612 FrameState stateBefore = frameState.create(bci); | 611 Value exception = frameState.apop(); |
613 Throw t = new Throw(frameState.apop(), graph); | 612 append(new NullCheck(exception, graph)); |
614 t.setStateBefore(stateBefore); | 613 Instruction entry = handleException(exception, bci); |
615 appendWithBCI(t); | 614 if (entry == null) { |
616 handleException(t, bci); | 615 entry = new Unwind(exception, graph.end(), graph); |
616 } | |
617 append(entry); | |
617 } | 618 } |
618 | 619 |
619 private void genCheckCast() { | 620 private void genCheckCast() { |
620 int cpi = stream().readCPI(); | 621 int cpi = stream().readCPI(); |
621 RiType type = constantPool().lookupType(cpi, CHECKCAST); | 622 RiType type = constantPool().lookupType(cpi, CHECKCAST); |
830 | 831 |
831 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) { |
832 CiKind resultType = returnKind(target); | 833 CiKind resultType = returnKind(target); |
833 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); |
834 Value result = appendWithBCI(invoke); | 835 Value result = appendWithBCI(invoke); |
835 handleException(invoke, bci()); | 836 invoke.setExceptionEdge(handleException(null, bci())); |
836 frameState.pushReturn(resultType, result); | 837 frameState.pushReturn(resultType, result); |
837 } | 838 } |
838 | 839 |
839 private RiType getExactType(RiType staticType, Value receiver) { | 840 private RiType getExactType(RiType staticType, Value receiver) { |
840 RiType exact = staticType.exactType(); | 841 RiType exact = staticType.exactType(); |
1008 private Value append(Value v) { | 1009 private Value append(Value v) { |
1009 return v; | 1010 return v; |
1010 } | 1011 } |
1011 | 1012 |
1012 private Value appendWithBCI(Instruction x) { | 1013 private Value appendWithBCI(Instruction x) { |
1013 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"; |
1014 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() + ")"; |
1015 lastInstr.setNext(x); | 1016 lastInstr.setNext(x); |
1016 | 1017 |
1017 lastInstr = x; | 1018 lastInstr = x; |
1018 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { | 1019 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { |
1078 assert lock != null; | 1079 assert lock != null; |
1079 assert frameState.locksSize() > 0 && frameState.lockAt(frameState.locksSize() - 1) == lock; | 1080 assert frameState.locksSize() > 0 && frameState.lockAt(frameState.locksSize() - 1) == lock; |
1080 | 1081 |
1081 // Exit the monitor and unwind the stack. | 1082 // Exit the monitor and unwind the stack. |
1082 genMonitorExit(lock); | 1083 genMonitorExit(lock); |
1083 append(new Unwind(frameState.apop(), graph)); | 1084 append(new Unwind(frameState.apop(), graph.end(), graph)); |
1084 | 1085 |
1085 // The sync handler is always the last thing to add => we can clear the frameState. | 1086 // The sync handler is always the last thing to add => we can clear the frameState. |
1086 frameState = null; | 1087 frameState = null; |
1087 lastInstr = null; | 1088 lastInstr = null; |
1088 } | 1089 } |
1147 append(lockAddress); | 1148 append(lockAddress); |
1148 } | 1149 } |
1149 append(new MonitorExit(rootMethodSynchronizedObject, lockAddress, lockNumber, graph)); | 1150 append(new MonitorExit(rootMethodSynchronizedObject, lockAddress, lockNumber, graph)); |
1150 frameState.unlock(); | 1151 frameState.unlock(); |
1151 } | 1152 } |
1152 append(new Unwind(frameState.apop(), graph)); | 1153 append(new Unwind(frameState.apop(), graph.end(), graph)); |
1153 } else { | 1154 } else { |
1154 assert frameState.stackSize() == 1; | 1155 assert frameState.stackSize() == 1; |
1155 | 1156 |
1156 if (block.handler.catchType().isResolved()) { | 1157 if (block.handler.catchType().isResolved()) { |
1157 Instruction catchSuccessor = createTarget(blockFromBci[block.handler.handlerBCI()], frameState); | 1158 Instruction catchSuccessor = createTarget(blockFromBci[block.handler.handlerBCI()], frameState); |
1492 * in the worklist | 1493 * in the worklist |
1493 */ | 1494 */ |
1494 private Block removeFromWorkList() { | 1495 private Block removeFromWorkList() { |
1495 return workList.poll(); | 1496 return workList.poll(); |
1496 } | 1497 } |
1497 | |
1498 /** | |
1499 * Checks whether this graph has any handlers. | |
1500 * @return {@code true} if there are any exception handlers | |
1501 */ | |
1502 private boolean hasHandler() { | |
1503 return Modifier.isSynchronized(compilation.method.accessFlags()) || (compilation.method.exceptionHandlers() != null && compilation.method.exceptionHandlers().length > 0); | |
1504 } | |
1505 } | 1498 } |