finally and synchronized improvements, clean up and speed up

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@70 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent b596c66503
commit a891c3b82c
  1. 3
      jode/jode/flow/CatchBlock.java
  2. 30
      jode/jode/flow/CatchFinallyBlock.java
  3. 1
      jode/jode/flow/CombineIfGotoExpressions.java
  4. 24
      jode/jode/flow/CompleteSynchronized.java
  5. 2
      jode/jode/flow/CreateExpression.java
  6. 25
      jode/jode/flow/CreateForInitializer.java
  7. 52
      jode/jode/flow/CreateIfThenElseOperator.java
  8. 1542
      jode/jode/flow/FlowBlock.java
  9. 8
      jode/jode/flow/LoopBlock.java
  10. 5
      jode/jode/flow/RemoveEmpty.java
  11. 7
      jode/jode/flow/SequentialBlock.java
  12. 46
      jode/jode/flow/StructuredBlock.java
  13. 7
      jode/jode/flow/SynchronizedBlock.java

@ -88,7 +88,8 @@ public class CatchBlock extends StructuredBlock {
? new EmptyBlock()
: catchBlock.getSubBlocks()[1]);
newCatchBlock.moveJump(catchBlock.jump);
if (catchBlock.jump != null)
newCatchBlock.moveJump(catchBlock.jump);
catchBlock = newCatchBlock;
}
}

@ -36,22 +36,22 @@ public class CatchFinallyBlock extends CatchBlock {
fin.setFlowBlock(flowBlock);
}
/**
* Returns the block where the control will normally flow to, when
* the given sub block is finished (<em>not</em> ignoring the jump
* after this block). FinallyBlock have a special behaviour, since
* the try block has the finallyblock as successor and the
* finallyblock has no default successor at all!!
*
* @return null, if the control flows to another FlowBlock.
*/
public StructuredBlock getNextBlock(StructuredBlock subBlock) {
return subBlock == tryBlock ? finallyBlock : null;
}
// /**
// * Returns the block where the control will normally flow to, when
// * the given sub block is finished (<em>not</em> ignoring the jump
// * after this block). FinallyBlock have a special behaviour, since
// * the try block has the finallyblock as successor and the
// * finallyblock has no default successor at all!!
// *
// * @return null, if the control flows to another FlowBlock.
// */
// public StructuredBlock getNextBlock(StructuredBlock subBlock) {
// return subBlock == tryBlock ? finallyBlock : null;
// }
public FlowBlock getNextFlowBlock(StructuredBlock subBlock) {
return null;
}
// public FlowBlock getNextFlowBlock(StructuredBlock subBlock) {
// return null;
// }
/**
* Replaces the given sub block with a new block.

@ -80,6 +80,7 @@ public class CombineIfGotoExpressions implements Transformation{
} catch (NullPointerException ex) {
return false;
}
flow.removeSuccessor(prevJump);
prevJump.prev.removeJump();
Expression cond =
new ComplexExpression

@ -33,12 +33,15 @@ public class CompleteSynchronized implements Transformation {
*/
public boolean transform(FlowBlock flow) {
SynchronizedBlock synBlock;
try {
synBlock = (SynchronizedBlock) flow.lastModified;
if (!(flow.lastModified instanceof SynchronizedBlock)
|| flow.lastModified.outer == null)
return false;
SequentialBlock sequBlock =
(SequentialBlock) synBlock.outer;
/* If the program is well formed, the following succeed */
SynchronizedBlock synBlock = (SynchronizedBlock) flow.lastModified;
try {
SequentialBlock sequBlock = (SequentialBlock) synBlock.outer;
ComplexExpression monenter = (ComplexExpression)
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
@ -47,18 +50,21 @@ public class CompleteSynchronized implements Transformation {
|| ((LocalLoadOperator) monenter.getSubExpressions()[0]).
getLocalInfo() != synBlock.local.getLocalInfo())
return false;
} catch (ClassCastException ex) {
return false;
} catch (NullPointerException ex) {
return false;
}
if (jode.Decompiler.isVerbose)
System.err.print("f");
System.err.print('s');
synBlock.isEntered = true;
synBlock.replace(synBlock.outer, synBlock);
/* Is there another expression? */
if (synBlock.outer == null)
return false;
Expression object;
try {
SequentialBlock sequBlock =
@ -75,8 +81,6 @@ public class CompleteSynchronized implements Transformation {
} catch (ClassCastException ex) {
return true;
} catch (NullPointerException ex) {
return true;
}
synBlock.object = object;

@ -106,7 +106,7 @@ public class CreateExpression implements Transformation {
return false;
}
if(jode.Decompiler.isVerbose)
System.err.print("x");
System.err.print('x');
((InstructionContainer) flow.lastModified).setInstruction
(new ComplexExpression(op, exprs));

@ -30,32 +30,33 @@ public class CreateForInitializer implements Transformation {
*/
public boolean transform(FlowBlock flow) {
LoopBlock forBlock;
Instruction initializer;
try {
forBlock = (LoopBlock) flow.lastModified;
if (!(flow.lastModified instanceof LoopBlock)
|| flow.lastModified.outer == null)
return false;
if (forBlock.type != forBlock.FOR || forBlock.init != null)
return false;
LoopBlock forBlock = (LoopBlock) flow.lastModified;
if (forBlock.type != forBlock.FOR || forBlock.init != null)
return false;
/* The following succeed, with high probability */
Instruction initializer;
try {
SequentialBlock sequBlock =
(SequentialBlock) forBlock.outer;
initializer =
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (!(initializer instanceof Expression)
|| !( ((Expression)initializer).getOperator()
instanceof StoreInstruction))
if (!( ((Expression)initializer).getOperator()
instanceof StoreInstruction))
return false;
} catch (ClassCastException ex) {
return false;
} catch (NullPointerException ex) {
return false;
}
if (jode.Decompiler.isVerbose)
System.err.print("f");
System.err.print('f');
forBlock.init = initializer;
forBlock.replace(forBlock.outer, forBlock);

@ -61,28 +61,31 @@ public class CreateIfThenElseOperator implements Transformation {
*/
public boolean createFunny(FlowBlock flow) {
Expression[] e = new Expression[3];
IfThenElseBlock ifBlock;
try {
ConditionalBlock conditional =
(ConditionalBlock) flow.lastModified;
if (!(flow.lastModified instanceof ConditionalBlock))
return false;
if (!(conditional.trueBlock instanceof EmptyBlock)
|| conditional.trueBlock.jump == null
|| conditional.jump == null)
return false;
ConditionalBlock conditional = (ConditionalBlock) flow.lastModified;
CompareUnaryOperator compare =
(CompareUnaryOperator) conditional.getInstruction();
if (!(conditional.trueBlock instanceof EmptyBlock)
|| conditional.trueBlock.jump == null
|| conditional.jump == null
|| !(conditional.getInstruction() instanceof CompareUnaryOperator))
return false;
FlowBlock trueDestination;
if (compare.getOperatorIndex() == compare.EQUALS_OP)
trueDestination = conditional.jump.destination;
else if (compare.getOperatorIndex() == compare.NOTEQUALS_OP)
trueDestination = conditional.trueBlock.jump.destination;
else
return false;
CompareUnaryOperator compare =
(CompareUnaryOperator) conditional.getInstruction();
FlowBlock trueDestination;
if (compare.getOperatorIndex() == compare.EQUALS_OP)
trueDestination = conditional.jump.destination;
else if (compare.getOperatorIndex() == compare.NOTEQUALS_OP)
trueDestination = conditional.trueBlock.jump.destination;
else
return false;
Expression[] e = new Expression[3];
IfThenElseBlock ifBlock;
try {
SequentialBlock sequBlock =
(SequentialBlock) conditional.outer;
@ -129,9 +132,11 @@ public class CreateIfThenElseOperator implements Transformation {
return false;
Expression cond = (Expression) condBlock.getInstruction();
flow.removeSuccessor(condBlock.trueBlock.jump);
condBlock.trueBlock.removeJump();
pushBlock.setInstruction(cond);
pushBlock.replace(sequBlock, pushBlock);
e[i+1] = cond;
}
} catch (ClassCastException ex) {
@ -141,7 +146,7 @@ public class CreateIfThenElseOperator implements Transformation {
}
if (jode.Decompiler.isVerbose)
System.err.print("?");
System.err.print('?');
IfThenElseOperator iteo = new IfThenElseOperator
(e[1].getType().intersection(e[2].getType()));
@ -170,6 +175,7 @@ public class CreateIfThenElseOperator implements Transformation {
*/
public boolean create(FlowBlock flow) {
Expression e[] = new Expression[3];
InstructionBlock thenBlock;
try {
InstructionBlock elseBlock = (InstructionBlock) flow.lastModified;
@ -181,7 +187,7 @@ public class CreateIfThenElseOperator implements Transformation {
if (ifBlock.elseBlock != null)
return false;
InstructionBlock thenBlock = (InstructionBlock) ifBlock.thenBlock;
thenBlock = (InstructionBlock) ifBlock.thenBlock;
if (thenBlock.jump.destination != elseBlock.jump.destination)
return false;
@ -194,7 +200,6 @@ public class CreateIfThenElseOperator implements Transformation {
return false;
e[0] = (Expression) ifBlock.cond;
thenBlock.removeJump();
} catch (ClassCastException ex) {
return false;
} catch (NullPointerException ex) {
@ -202,7 +207,10 @@ public class CreateIfThenElseOperator implements Transformation {
}
if (jode.Decompiler.isVerbose)
System.err.print("?");
System.err.print('?');
flow.removeSuccessor(thenBlock.jump);
thenBlock.removeJump();
IfThenElseOperator iteo = new IfThenElseOperator
(e[1].getType().intersection(e[2].getType()));

File diff suppressed because it is too large Load Diff

@ -185,7 +185,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
writer.untab();
if (type == DOWHILE)
writer.println((needBrace?"} ": "")+
"while ("+cond.simplify().toString()+")");
"while ("+cond.simplify().toString()+");");
else if (needBrace)
writer.println("}");
}
@ -223,16 +223,16 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
/**
* Replace all breaks to this block with a continue to this block.
*/
public void replaceBreakContinue() {
public void replaceBreakContinue(BreakableBlock block) {
java.util.Stack todo = new java.util.Stack();
todo.push(this);
todo.push(block);
while (!todo.isEmpty()) {
StructuredBlock[] subs =
((StructuredBlock)todo.pop()).getSubBlocks();
for (int i=0; i<subs.length; i++) {
if (subs[i] instanceof BreakBlock) {
BreakBlock breakblk = (BreakBlock) subs[i];
if (breakblk.breaksBlock == this) {
if (breakblk.breaksBlock == block) {
new ContinueBlock(this, breakblk.label != null)
.replace(breakblk, null);
}

@ -69,11 +69,8 @@ public class RemoveEmpty implements Transformation {
StructuredBlock block = lastBlock.outer.getSubBlocks()[0];
block.replace(block.outer, block);
if (block.jump == null)
/*XXX can this happen */
if (lastBlock.jump != null)
block.moveJump(lastBlock.jump);
else
lastBlock.removeJump();
flow.lastModified = block;
return true;
}

@ -44,6 +44,13 @@ public class SequentialBlock extends StructuredBlock {
sb.setFlowBlock(flowBlock);
}
public void checkConsistent() {
super.checkConsistent();
if (subBlocks[0].jump != null
|| (jump != null && subBlocks[1].jump != null))
throw new jode.AssertError("Inconsistency");
}
/**
* Returns the block where the control will normally flow to, when
* the given sub block is finished (<em>not</em> ignoring the jump

@ -19,6 +19,7 @@
package jode.flow;
import jode.TabbedPrintWriter;
import jode.AssertError;
import jode.LocalInfo;
/**
@ -181,12 +182,11 @@ public abstract class StructuredBlock {
}
/**
* Removes the jump. This does also update the successors vector
* of the flow block. */
* Removes the jump. This does not update the successors vector
* of the flow block, you have to do it yourself. */
public void removeJump() {
if (jump != null) {
jump.prev = null;
flowBlock.removeSuccessor(jump);
jump = null;
}
}
@ -262,7 +262,8 @@ public abstract class StructuredBlock {
* @param jump The jump that should be moved, may be null.
*/
public void moveJump(Jump jump) {
removeJump();
if (this.jump != null)
throw new AssertError("overriding with moveJump()");
this.jump = jump;
if (jump != null) {
jump.prev.jump = null;
@ -282,6 +283,31 @@ public abstract class StructuredBlock {
return sequBlock;
}
/**
* Removes this block, or replaces it with an EmptyBlock.
*/
public void removeBlock() {
if (outer instanceof SequentialBlock) {
if (outer.getSubBlocks()[1] == this) {
if (jump != null)
outer.getSubBlocks()[0].moveJump(jump);
outer.getSubBlocks()[0].replace(outer, null);
return;
} else if (outer.outer instanceof SequentialBlock) {
if (jump != null)
outer.outer.getSubBlocks()[0].moveJump(jump);
outer.getSubBlocks()[1].replace(outer, null);
return;
}
}
EmptyBlock eb = new EmptyBlock();
eb.moveJump(jump);
eb.replace(this, null);
}
/**
* Determines if there is a sub block, that flows through to the end
* of this block. If this returns true, you know that jump is null.
@ -340,16 +366,14 @@ public abstract class StructuredBlock {
for (int i=0; i<subs.length; i++) {
if (subs[i].outer != this ||
subs[i].flowBlock != flowBlock) {
throw new RuntimeException("Inconsistency");
throw new AssertError("Inconsistency");
}
subs[i].checkConsistent();
}
if (jump != null &&
(jump.prev != this ||
!flowBlock.successors.contains(jump) ||
!jump.destination.predecessors.contains(flowBlock))) {
throw new RuntimeException("Inconsistency");
}
if (jump != null
&& !((java.util.Stack)
flowBlock.successors.get(jump.destination)).contains(jump))
throw new AssertError("Inconsistency");
}
/**

@ -80,18 +80,15 @@ public class SynchronizedBlock extends StructuredBlock {
public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException
{
boolean needsBrace = bodyBlock.needsBraces();
if (!isEntered)
writer.print("/* missing monitorenter */");
writer.println("synchronized ("
+ (object != null
? object.simplify().toString()
: local.getName()) + ")"
+ (needsBrace ? " {" :""));
: local.getName()) + ") {");
writer.tab();
bodyBlock.dumpSource(writer);
writer.untab();
if (needsBrace)
writer.println("}");
writer.println("}");
}
}

Loading…
Cancel
Save