Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.flow
Class FlowBlock

java.lang.Object
  extended bynet.sf.jode.flow.FlowBlock

public class FlowBlock
extends java.lang.Object

A flow block is the structure of which the flow graph consists. A flow block contains structured code together with some conditional or unconditional jumps to the head of other flow blocks. We do a T1/T2 analysis to combine all flow blocks to a single. If the graph isn't reducible that doesn't work, but java can only produce reducible flow graphs. We don't use the notion of basic flow graphs. A flow block may be anything from a single bytecode opcode, to the whole method.


Field Summary
static FlowBlock END_OF_METHOD
           
 
Constructor Summary
FlowBlock(MethodAnalyzer method, int blockNr, FlowBlock lastFlow)
          The default constructor.
 
Method Summary
 void addStartPred()
          Mark the flow block as first flow block in a method.
 void analyze()
          The main analyzation.
 boolean analyze(int start, int end)
          The main analyzation.
 boolean analyzeSwitch(int start, int end)
          The switch analyzation.
 void appendBlock(StructuredBlock newBlock)
           
 void appendReadBlock(StructuredBlock newBlock, LocalInfo local)
           
 void appendWriteBlock(StructuredBlock newBlock, LocalInfo local)
           
 void checkConsistent()
          Checks if the FlowBlock and its StructuredBlocks are consistent.
 boolean doT1(int start, int end)
           
 boolean doT2(FlowBlock succ)
          Do a T2 transformation with succ if possible.
 void doTransformations()
           
 void dumpSource(TabbedPrintWriter writer)
          Print the source code for this structured block.
 StructuredBlock getBlock()
          Returns the structured block, that this flow block contains.
 int getBlockNr()
          Returns the block number, where the code in this flow block starts.
 Jump getJumps(FlowBlock dest)
           
 java.lang.String getLabel()
          Returns the label of this block and creates a new label, if there wasn't a label previously.
 int getNextBlockNr()
           
 java.util.Set getSuccessors()
           
 boolean hasNoJumps()
           
 void makeDeclaration(java.util.Set done)
          Make declarations.
 boolean mapStackToLocal()
          This is called after the analysis is completely done.
 void mapStackToLocal(VariableStack initialStack)
          This is called after the analysis is completely done.
 void mergeBlockNr(FlowBlock succ)
          Fixes the blockNr chained list, after merging this block with succ.
 void mergeEndBlock()
          Do a T2 transformation with the end_of_method block.
 void mergeParams(LocalInfo[] param)
          Merge the parameter locals with the in set of this flow block.
 void oldAppendBlock(StructuredBlock newBlock)
           
 void prependBlock(StructuredBlock insertBlock)
           
 Jump removeJumps(FlowBlock dest)
           
 void removeOnetimeLocals()
           
 void removePush()
           
 void removeStartPred()
           
 void removeSuccessor(Jump jump)
           
 Jump resolveSomeJumps(Jump jumps, FlowBlock succ)
          This method resolves some of the jumps to successor.
 void setSuccessors(FlowBlock[] succs)
           
 void simplify()
          Simplify this and all following flowblocks.
 java.lang.String toString()
           
 void updateInOutCatch(FlowBlock catchFlow)
          Updates the in/out-Vectors of the structured block of the successing flow block for a try catch block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

END_OF_METHOD

public static FlowBlock END_OF_METHOD
Constructor Detail

FlowBlock

public FlowBlock(MethodAnalyzer method,
                 int blockNr,
                 FlowBlock lastFlow)
The default constructor. Creates a new empty flowblock.

Method Detail

getNextBlockNr

public int getNextBlockNr()

hasNoJumps

public boolean hasNoJumps()

resolveSomeJumps

public Jump resolveSomeJumps(Jump jumps,
                             FlowBlock succ)
This method resolves some of the jumps to successor.

Parameters:
jumps - The list of jumps with that successor.
succ - The successing flow block.
Returns:
The remaining jumps, that couldn't be resolved.

mergeBlockNr

public void mergeBlockNr(FlowBlock succ)
Fixes the blockNr chained list, after merging this block with succ.


updateInOutCatch

public void updateInOutCatch(FlowBlock catchFlow)
Updates the in/out-Vectors of the structured block of the successing flow block for a try catch block. The main difference to updateInOut in FlowBlock is, that this function works, as if every instruction would have a jump. This is because every instruction can throw an exception and thus enter the catch block.
For example this code prints 0:
   int a=3;
   try {
     a = 5 / (a=0);
   } catch (DivideByZeroException ex) {
     System.out.println(a);
   }
 

Returns:
The variables that must be defined in this block.

checkConsistent

public void checkConsistent()
Checks if the FlowBlock and its StructuredBlocks are consistent. There are to many conditions to list them here, the best way is to read this function and all other checkConsistent functions.


prependBlock

public void prependBlock(StructuredBlock insertBlock)

appendReadBlock

public void appendReadBlock(StructuredBlock newBlock,
                            LocalInfo local)

appendWriteBlock

public void appendWriteBlock(StructuredBlock newBlock,
                             LocalInfo local)

appendBlock

public void appendBlock(StructuredBlock newBlock)

oldAppendBlock

public void oldAppendBlock(StructuredBlock newBlock)

setSuccessors

public void setSuccessors(FlowBlock[] succs)

doT2

public boolean doT2(FlowBlock succ)
Do a T2 transformation with succ if possible. It is possible, iff succ has exactly this block as predecessor.

Parameters:
succ - the successor block, must be a valid successor of this block, i.e. not null

mergeEndBlock

public void mergeEndBlock()
Do a T2 transformation with the end_of_method block.


doT1

public boolean doT1(int start,
                    int end)

doTransformations

public void doTransformations()

analyze

public void analyze()
The main analyzation. This calls doT1 and doT2 on apropriate regions until the whole function is transformed to a single block.


analyze

public boolean analyze(int start,
                       int end)
The main analyzation. This calls doT1 and doT2 on apropriate regions. Only blocks whose block number lies in the given block number range are considered.

Parameters:
start - the start of the block number range.
end - the end of the block number range.

analyzeSwitch

public boolean analyzeSwitch(int start,
                             int end)
The switch analyzation. This calls doSwitchT2 and doT1 on apropriate regions. Only blocks whose block number lies in the given block number range are considered and it is taken care of, that the switch is never left.

The current flow block must contain the switch block as lastModified.

Parameters:
start - the start of the block number range.
end - the end of the block number range.

addStartPred

public void addStartPred()
Mark the flow block as first flow block in a method.


removeStartPred

public void removeStartPred()

removeSuccessor

public void removeSuccessor(Jump jump)

getJumps

public Jump getJumps(FlowBlock dest)

removeJumps

public Jump removeJumps(FlowBlock dest)

getSuccessors

public java.util.Set getSuccessors()

mapStackToLocal

public final boolean mapStackToLocal()
This is called after the analysis is completely done. It will remove all PUSH/stack_i expressions, (if the bytecode is correct).

Returns:
true, if the stack mapping succeeded.

mapStackToLocal

public void mapStackToLocal(VariableStack initialStack)
This is called after the analysis is completely done. It will remove all PUSH/stack_i expressions, (if the bytecode is correct).

Parameters:
initialStack - the stackmap at begin of the flow block
Returns:
false if the bytecode isn't correct and stack mapping didn't worked.

removePush

public void removePush()

removeOnetimeLocals

public void removeOnetimeLocals()

mergeParams

public void mergeParams(LocalInfo[] param)
Merge the parameter locals with the in set of this flow block. This will also make a successive analysis to merge the gen/kill set of the jumps with the next flow block.


makeDeclaration

public void makeDeclaration(java.util.Set done)
Make declarations. It will determine, where in each block the variables and method scoped classes must be declared.


simplify

public void simplify()
Simplify this and all following flowblocks.


dumpSource

public void dumpSource(TabbedPrintWriter writer)
                throws java.io.IOException
Print the source code for this structured block. This handles everything that is unique for all structured blocks and calls dumpInstruction afterwards.

Parameters:
writer - The tabbed print writer, where we print to.
Throws:
java.io.IOException

getBlockNr

public int getBlockNr()
Returns the block number, where the code in this flow block starts.


getLabel

public java.lang.String getLabel()
Returns the label of this block and creates a new label, if there wasn't a label previously.


getBlock

public StructuredBlock getBlock()
Returns the structured block, that this flow block contains.


toString

public java.lang.String toString()

Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.