|
|
@ -209,23 +209,28 @@ public class TransformExceptionHandlers { |
|
|
|
* This transforms a sub routine, that is checks if the beginning |
|
|
|
* This transforms a sub routine, that is checks if the beginning |
|
|
|
* local assignment matches the final ret and then returns. |
|
|
|
* local assignment matches the final ret and then returns. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean transformSubRoutine(FlowBlock subRoutine) { |
|
|
|
boolean transformSubRoutine(StructuredBlock subRoutine) { |
|
|
|
try { |
|
|
|
if (!(subRoutine instanceof SequentialBlock) |
|
|
|
SequentialBlock sequBlock = (SequentialBlock) subRoutine.block; |
|
|
|
|| !(subRoutine.getSubBlocks()[0] instanceof InstructionBlock)) |
|
|
|
LocalStoreOperator store = (LocalStoreOperator) |
|
|
|
return false; |
|
|
|
((InstructionBlock)sequBlock.subBlocks[0]).instr.getOperator(); |
|
|
|
SequentialBlock sequBlock = (SequentialBlock) subRoutine; |
|
|
|
|
|
|
|
InstructionBlock instr = (InstructionBlock)sequBlock.subBlocks[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! (instr.getInstruction() instanceof LocalStoreOperator)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
LocalStoreOperator store = (LocalStoreOperator) instr.getInstruction(); |
|
|
|
|
|
|
|
|
|
|
|
while (sequBlock.subBlocks[1] instanceof SequentialBlock) |
|
|
|
while (sequBlock.subBlocks[1] instanceof SequentialBlock) |
|
|
|
sequBlock = (SequentialBlock) sequBlock.subBlocks[1]; |
|
|
|
sequBlock = (SequentialBlock) sequBlock.subBlocks[1]; |
|
|
|
RetBlock retBlock = (RetBlock)sequBlock.subBlocks[1]; |
|
|
|
|
|
|
|
if (! retBlock.local.equals(store.getLocalInfo())) |
|
|
|
if (! (sequBlock.subBlocks[1] instanceof RetBlock) |
|
|
|
/* Ret doesn't match */ |
|
|
|
|| !(((RetBlock)sequBlock.subBlocks[1]) |
|
|
|
|
|
|
|
.local.equals(store.getLocalInfo()))) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
subRoutine.block.getSubBlocks()[0].removeBlock(); |
|
|
|
|
|
|
|
retBlock.removeBlock(); |
|
|
|
instr.removeBlock(); |
|
|
|
|
|
|
|
sequBlock.subBlocks[1].removeBlock(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} catch (ClassCastException ex) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -351,7 +356,10 @@ public class TransformExceptionHandlers { |
|
|
|
/* Now we have a jump with a wrong destination. |
|
|
|
/* Now we have a jump with a wrong destination. |
|
|
|
* Complain! |
|
|
|
* Complain! |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
System.err.println("non well formed try-finally block"); |
|
|
|
DescriptionBlock msg |
|
|
|
|
|
|
|
= new DescriptionBlock("ERROR: NO JSR TO FINALLY"); |
|
|
|
|
|
|
|
prev.appendBlock(msg); |
|
|
|
|
|
|
|
msg.moveJump(jumps); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
removeJSR(tryFlow, subRoutine); |
|
|
|
removeJSR(tryFlow, subRoutine); |
|
|
@ -386,7 +394,7 @@ public class TransformExceptionHandlers { |
|
|
|
|
|
|
|
|
|
|
|
subRoutine = jumps.destination; |
|
|
|
subRoutine = jumps.destination; |
|
|
|
subRoutine.analyze(startMonExit, endMonExit); |
|
|
|
subRoutine.analyze(startMonExit, endMonExit); |
|
|
|
transformSubRoutine(subRoutine); |
|
|
|
transformSubRoutine(subRoutine.block); |
|
|
|
|
|
|
|
|
|
|
|
if (subRoutine.block instanceof InstructionBlock) { |
|
|
|
if (subRoutine.block instanceof InstructionBlock) { |
|
|
|
Expression instr = |
|
|
|
Expression instr = |
|
|
@ -466,7 +474,10 @@ public class TransformExceptionHandlers { |
|
|
|
/* Now we have a jump that is not preceded by a monitorexit. |
|
|
|
/* Now we have a jump that is not preceded by a monitorexit. |
|
|
|
* Complain! |
|
|
|
* Complain! |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
System.err.println("non well formed synchronized block"); |
|
|
|
DescriptionBlock msg |
|
|
|
|
|
|
|
= new DescriptionBlock("ERROR: NO MONITOREXIT"); |
|
|
|
|
|
|
|
prev.appendBlock(msg); |
|
|
|
|
|
|
|
msg.moveJump(jumps); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -548,32 +559,8 @@ public class TransformExceptionHandlers { |
|
|
|
|
|
|
|
|
|
|
|
private boolean analyzeFinally(FlowBlock tryFlow, FlowBlock catchFlow, |
|
|
|
private boolean analyzeFinally(FlowBlock tryFlow, FlowBlock catchFlow, |
|
|
|
int end) { |
|
|
|
int end) { |
|
|
|
if (!(catchFlow.block instanceof SequentialBlock |
|
|
|
|
|
|
|
&& catchFlow.block.getSubBlocks()[0] |
|
|
|
|
|
|
|
instanceof InstructionBlock)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SequentialBlock catchBlock = (SequentialBlock) catchFlow.block; |
|
|
|
|
|
|
|
Expression instr = |
|
|
|
|
|
|
|
((InstructionBlock)catchBlock.subBlocks[0]).getInstruction(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (catchBlock.subBlocks[1] instanceof SequentialBlock |
|
|
|
|
|
|
|
&& catchBlock.subBlocks[1].getSubBlocks()[0] |
|
|
|
|
|
|
|
instanceof JsrBlock |
|
|
|
|
|
|
|
&& instr instanceof LocalStoreOperator |
|
|
|
|
|
|
|
&& catchBlock.subBlocks[1].getSubBlocks()[1] |
|
|
|
|
|
|
|
instanceof ThrowBlock |
|
|
|
|
|
|
|
&& ((ThrowBlock)catchBlock.subBlocks[1] |
|
|
|
|
|
|
|
.getSubBlocks()[1]).instr |
|
|
|
|
|
|
|
instanceof LocalLoadOperator |
|
|
|
|
|
|
|
&& ((LocalStoreOperator) instr) |
|
|
|
|
|
|
|
.matches((LocalLoadOperator) |
|
|
|
|
|
|
|
((ThrowBlock)catchBlock.subBlocks[1] |
|
|
|
|
|
|
|
.getSubBlocks()[1]).instr)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Wow that was complicated :-) |
|
|
|
/* Layout of a try-finally block: |
|
|
|
* But now we know that the catch block looks |
|
|
|
|
|
|
|
* exactly like an try finally block: |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* tryFlow: |
|
|
|
* tryFlow: |
|
|
|
* |- first instruction |
|
|
|
* |- first instruction |
|
|
@ -593,28 +580,124 @@ public class TransformExceptionHandlers { |
|
|
|
* return_n |
|
|
|
* return_n |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
FlowBlock subRoutine = |
|
|
|
if (!(catchFlow.block instanceof SequentialBlock) |
|
|
|
((JsrBlock)catchBlock.subBlocks[1].getSubBlocks()[0]) |
|
|
|
|| !(catchFlow.block.getSubBlocks()[0] |
|
|
|
.innerBlock.jump.destination; |
|
|
|
instanceof InstructionBlock) |
|
|
|
|
|
|
|
|| !(catchFlow.block.getSubBlocks()[1] |
|
|
|
|
|
|
|
instanceof SequentialBlock)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StructuredBlock finallyBlock = null; |
|
|
|
|
|
|
|
SequentialBlock catchBlock = (SequentialBlock) catchFlow.block; |
|
|
|
|
|
|
|
Expression instr = |
|
|
|
|
|
|
|
((InstructionBlock)catchBlock.subBlocks[0]).getInstruction(); |
|
|
|
|
|
|
|
catchBlock = (SequentialBlock)catchBlock.subBlocks[1]; |
|
|
|
|
|
|
|
|
|
|
|
/* Now remove the two jumps of the catch block |
|
|
|
if (catchBlock.subBlocks[0] instanceof LoopBlock) { |
|
|
|
* so that we can forget about them. |
|
|
|
/* In case the try block has no exit (that means, it throws |
|
|
|
* This are the jsr and the throw. |
|
|
|
* an exception), the finallyBlock was already merged with |
|
|
|
|
|
|
|
* the catchBlock. We have to check for this case separately: |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* do { |
|
|
|
|
|
|
|
* JSR |
|
|
|
|
|
|
|
* break; |
|
|
|
|
|
|
|
* throw local_x |
|
|
|
|
|
|
|
* } while(false); |
|
|
|
|
|
|
|
* finallyBlock; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
catchBlock.subBlocks[1].getSubBlocks()[0].getSubBlocks()[0] |
|
|
|
LoopBlock doWhileFalse = (LoopBlock)catchBlock.subBlocks[0]; |
|
|
|
.jump.destination.predecessors.removeElement(catchFlow); |
|
|
|
if (doWhileFalse.type == LoopBlock.DOWHILE |
|
|
|
catchBlock.subBlocks[1].getSubBlocks()[1] |
|
|
|
&& doWhileFalse.cond == LoopBlock.FALSE |
|
|
|
|
|
|
|
&& doWhileFalse.bodyBlock instanceof SequentialBlock) { |
|
|
|
|
|
|
|
finallyBlock = catchBlock.subBlocks[1]; |
|
|
|
|
|
|
|
catchBlock = (SequentialBlock) doWhileFalse.bodyBlock; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (catchBlock instanceof SequentialBlock |
|
|
|
|
|
|
|
&& catchBlock.getSubBlocks()[0] instanceof JsrBlock |
|
|
|
|
|
|
|
&& instr instanceof LocalStoreOperator |
|
|
|
|
|
|
|
&& catchBlock.getSubBlocks()[1] instanceof ThrowBlock |
|
|
|
|
|
|
|
&& (((ThrowBlock)catchBlock.getSubBlocks()[1]).instr |
|
|
|
|
|
|
|
instanceof LocalLoadOperator) |
|
|
|
|
|
|
|
&& (((LocalStoreOperator) instr).matches |
|
|
|
|
|
|
|
((LocalLoadOperator) |
|
|
|
|
|
|
|
((ThrowBlock)catchBlock.getSubBlocks()[1]).instr))) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Wow that was complicated :-) |
|
|
|
|
|
|
|
* But now we know that the catch block looks |
|
|
|
|
|
|
|
* exactly like it should: |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* catchBlock: |
|
|
|
|
|
|
|
* JSR |
|
|
|
|
|
|
|
* finally |
|
|
|
|
|
|
|
* throw local_n <- matches the local in instr. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (finallyBlock != null) { |
|
|
|
|
|
|
|
/* Check if the jsr breaks (see two comments above). We don't |
|
|
|
|
|
|
|
* need to check if it breaks to the right block, because |
|
|
|
|
|
|
|
* we know that there is only one Block around the jsr. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if (!(((JsrBlock)catchBlock.getSubBlocks()[0]).innerBlock |
|
|
|
|
|
|
|
instanceof BreakBlock)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if the try block has no exit (except throws) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Jump throwJumps = (Jump) |
|
|
|
|
|
|
|
tryFlow.successors.get(FlowBlock.END_OF_METHOD); |
|
|
|
|
|
|
|
if (tryFlow.successors.size() > 1 |
|
|
|
|
|
|
|
|| (tryFlow.successors.size() > 0 && throwJumps == null)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (/**/; throwJumps != null; throwJumps = throwJumps.next) { |
|
|
|
|
|
|
|
if (!(throwJumps.prev instanceof ThrowBlock)) |
|
|
|
|
|
|
|
/* There is a return exit in the try block */ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* Remove the jump of the throw instruction. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
catchBlock.getSubBlocks()[1] |
|
|
|
.jump.destination.predecessors.removeElement(catchFlow); |
|
|
|
.jump.destination.predecessors.removeElement(catchFlow); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Replace the catchBlock with the finallyBlock. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
finallyBlock.replace(catchFlow.block); |
|
|
|
|
|
|
|
transformSubRoutine(finallyBlock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateInOutCatch(tryFlow, catchFlow); |
|
|
|
|
|
|
|
tryFlow.length += catchFlow.length; |
|
|
|
|
|
|
|
finallyBlock = catchFlow.block; |
|
|
|
|
|
|
|
tryFlow.mergeSuccessors(catchFlow); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
FlowBlock subRoutine = |
|
|
|
|
|
|
|
((JsrBlock)catchBlock.getSubBlocks()[0]) |
|
|
|
|
|
|
|
.innerBlock.jump.destination; |
|
|
|
|
|
|
|
|
|
|
|
subRoutine.analyze(catchFlow.addr+catchFlow.length, end); |
|
|
|
subRoutine.analyze(catchFlow.addr+catchFlow.length, end); |
|
|
|
if (!transformSubRoutine(subRoutine)) |
|
|
|
if (!transformSubRoutine(subRoutine.block)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
updateInOutCatch(tryFlow, subRoutine); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tryFlow.length += catchFlow.length; |
|
|
|
tryFlow.length += catchFlow.length; |
|
|
|
|
|
|
|
|
|
|
|
checkAndRemoveJSR(tryFlow, subRoutine); |
|
|
|
checkAndRemoveJSR(tryFlow, subRoutine); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateInOutCatch(tryFlow, subRoutine); |
|
|
|
|
|
|
|
tryFlow.length += subRoutine.length; |
|
|
|
|
|
|
|
tryFlow.mergeSuccessors(subRoutine); |
|
|
|
|
|
|
|
finallyBlock = subRoutine.block; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Now remove the jump to the JSR from the catch block |
|
|
|
|
|
|
|
* and the jump of the throw instruction. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
catchBlock.getSubBlocks()[0].getSubBlocks()[0] |
|
|
|
|
|
|
|
.jump.destination.predecessors.removeElement(catchFlow); |
|
|
|
|
|
|
|
catchBlock.getSubBlocks()[1] |
|
|
|
|
|
|
|
.jump.destination.predecessors.removeElement(catchFlow); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TryBlock tryBlock = (TryBlock)tryFlow.block; |
|
|
|
TryBlock tryBlock = (TryBlock)tryFlow.block; |
|
|
|
if (tryBlock.getSubBlocks()[0] instanceof TryBlock) { |
|
|
|
if (tryBlock.getSubBlocks()[0] instanceof TryBlock) { |
|
|
|
/* remove the nested tryBlock */ |
|
|
|
/* remove the nested tryBlock */ |
|
|
@ -625,10 +708,8 @@ public class TransformExceptionHandlers { |
|
|
|
tryFlow.lastModified = innerTry; |
|
|
|
tryFlow.lastModified = innerTry; |
|
|
|
} |
|
|
|
} |
|
|
|
FinallyBlock newBlock = new FinallyBlock(); |
|
|
|
FinallyBlock newBlock = new FinallyBlock(); |
|
|
|
newBlock.setCatchBlock(subRoutine.block); |
|
|
|
newBlock.setCatchBlock(finallyBlock); |
|
|
|
tryBlock.addCatchBlock(newBlock); |
|
|
|
tryBlock.addCatchBlock(newBlock); |
|
|
|
tryFlow.mergeSuccessors(subRoutine); |
|
|
|
|
|
|
|
tryFlow.length += subRoutine.length; |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -660,7 +741,7 @@ public class TransformExceptionHandlers { |
|
|
|
Object key = keys.nextElement(); |
|
|
|
Object key = keys.nextElement(); |
|
|
|
if (key == succ) |
|
|
|
if (key == succ) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
if (key != tryFlow.END_OF_METHOD) { |
|
|
|
if (key != FlowBlock.END_OF_METHOD) { |
|
|
|
/* There is another exit in the try block, bad */ |
|
|
|
/* There is another exit in the try block, bad */ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|