edu.umd.cs.findbugs.ba.type

Class TypeFrameModelingVisitor

public class TypeFrameModelingVisitor extends AbstractFrameModelingVisitor<Type,TypeFrame> implements Constants, Debug

Visitor to model the effects of bytecode instructions on the types of the values (local and operand stack) in Java stack frames. This visitor does not verify that the types are sensible for the bytecodes executed. In other words, this isn't a bytecode verifier, although it wouldn't be too hard to turn it into something vaguely verifier-like.

Author: David Hovemeyer

See Also: TypeFrame TypeAnalysis

Constructor Summary
TypeFrameModelingVisitor(ConstantPoolGen cpg)
Constructor.
Method Summary
protected voidconsumeStack(Instruction ins)
Consume stack.
TypegetInstanceOfType()
Get the type of the most recent instanceof instruction modeled.
ValueNumbergetInstanceOfValueNumber()
Get the value number of the most recent instanceof instruction modeled.
shortgetLastOpcode()
Get the last opcode analyzed by this visitor.
booleanisInstanceOfFollowedByBranch()
Return whether an instanceof instruction was followed by a branch.
voidmodelFieldLoad(FieldInstruction obj)
protected voidpushReturnType(InvokeInstruction ins)
Helper for pushing the return type of an invoke instruction.
protected voidpushValue(Type type)
Work around some weirdness in BCEL (inherited from JVM Spec 1): BCEL considers long and double types to consume two slots on the stack.
voidsetFieldStoreTypeDatabase(FieldStoreTypeDatabase database)
Set the field store type database.
voidsetValueNumberDataflow(ValueNumberDataflow valueNumberDataflow)
Set ValueNumberDataflow for the method being analyzed.
voidstartBasicBlock()
This method must be called at the beginning of modeling a basic block in order to clear information cached for instanceof modeling.

Constructor Detail

TypeFrameModelingVisitor

public TypeFrameModelingVisitor(ConstantPoolGen cpg)
Constructor.

Parameters: cpg the ConstantPoolGen of the method whose instructions we are examining

Method Detail

consumeStack

protected void consumeStack(Instruction ins)
Consume stack. This is a convenience method for instructions where the types of popped operands can be ignored.

getInstanceOfType

public Type getInstanceOfType()
Get the type of the most recent instanceof instruction modeled. The TypeAnalysis may use this to get more precise types in the resulting frame.

Returns: the Type checked by the most recent instanceof instruction

getInstanceOfValueNumber

public ValueNumber getInstanceOfValueNumber()
Get the value number of the most recent instanceof instruction modeled. The TypeAnalysis may use this to get more precise types in the resulting frame.

Returns: the ValueNumber checked by the most recent instanceof instruction

getLastOpcode

public short getLastOpcode()
Get the last opcode analyzed by this visitor. The TypeAnalysis may use this to get more precise types in the resulting frame.

Returns: the last opcode analyzed by this visitor

isInstanceOfFollowedByBranch

public boolean isInstanceOfFollowedByBranch()
Return whether an instanceof instruction was followed by a branch. The TypeAnalysis may use this to get more precise types in the resulting frame.

Returns: true if an instanceof instruction was followed by a branch, false if not

modelFieldLoad

public void modelFieldLoad(FieldInstruction obj)

pushReturnType

protected void pushReturnType(InvokeInstruction ins)
Helper for pushing the return type of an invoke instruction.

pushValue

protected void pushValue(Type type)
Work around some weirdness in BCEL (inherited from JVM Spec 1): BCEL considers long and double types to consume two slots on the stack. This method ensures that we push two types for each double or long value.

setFieldStoreTypeDatabase

public void setFieldStoreTypeDatabase(FieldStoreTypeDatabase database)
Set the field store type database. We can use this to get more accurate types for values loaded from fields.

Parameters: database the FieldStoreTypeDatabase

setValueNumberDataflow

public void setValueNumberDataflow(ValueNumberDataflow valueNumberDataflow)
Set ValueNumberDataflow for the method being analyzed. This is optional; if set, we will use the information to more accurately model the effects of instanceof instructions.

Parameters: valueNumberDataflow the ValueNumberDataflow

startBasicBlock

public void startBasicBlock()
This method must be called at the beginning of modeling a basic block in order to clear information cached for instanceof modeling.
FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.