Top Description Fields Constructors Methods
org.objectweb.asm.util

pack-priv Class CheckFrameAnalyzer<V extends org.objectweb.asm.tree.analysis.Value>

extends Analyzer<V extends Value>
Class Inheritance
Type Parameters
<V>
type of the Value used for the analysis.
Imports
java.util.Collections, .List, org.objectweb.asm.Opcodes, .Type, org.objectweb.asm.tree.AbstractInsnNode, .FrameNode, .InsnList, .InsnNode, .JumpInsnNode, .LabelNode, .LookupSwitchInsnNode, .MethodNode, .TableSwitchInsnNode, .TryCatchBlockNode, .TypeInsnNode, org.objectweb.asm.tree.analysis.Analyzer, .AnalyzerException, .Frame, .Interpreter, .Value

An Analyzer subclass which checks that methods provide stack map frames where expected (i.e. at jump target and after instructions without immediate successor), and that these stack map frames are valid (for the provided interpreter; they may still be invalid for the JVM, if the Interpreter uses a simplified type system compared to the JVM verifier). This is done in two steps:
Author
Eric Bruneton

Field Summary

Modifier and TypeField and Description
private int
currentLocals

The number of locals in the last stack map frame processed by expandFrame.

private InsnList
insnList

Hides org.objectweb.asm.tree.analysis.Analyzer.insnList.

The instructions of the currently analyzed method.
private final Interpreter<V>
interpreter

Hides org.objectweb.asm.tree.analysis.Analyzer.interpreter.

The interpreter to use to symbolically interpret the bytecode instructions.

Constructor Summary

AccessConstructor and Description
pack-priv
CheckFrameAnalyzer(final Interpreter<V> interpreter)

Method Summary

Modifier and TypeMethod and Description
private void
checkFrame(final int
an instruction index.
insnIndex
,
final Frame<V>
a frame. This frame is left unchanged by this method.
frame
,
final boolean
whether a frame must already exist or not in frames at 'insnIndex'.
requireFrame
)

Checks that the given frame is compatible with the frame at the given instruction index, if any.

private String

Returns:

an error message if the frames have incompatible sizes, or if a type in the source frame is not a sub type of the corresponding type in the destination frame. Returns null otherwise.
checkMerge
(final Frame<V>
a source frame. This frame is left unchanged by this method.
srcFrame
,
final Frame<V>
a destination frame. This frame is left unchanged by this method.
dstFrame
)

Checks that merging the two given frames would not produce any change, i.e. that the types in the source frame are sub types of the corresponding types in the destination frame.

private void
endControlFlow(final int
an instruction index.
insnIndex
)

Ends the control flow graph at the given instruction.

private Frame<V>

Returns:

the expanded version of 'frameNode'.
expandFrame
(final String
the internal name of the class to which 'frameNode' belongs.
owner
,
final Frame<V>
the frame before 'frameNode', in expanded form.
previousFrame
,
final FrameNode
a possibly compressed stack map frame.
frameNode
)

Returns the expanded representation of the given FrameNode.

private void
expandFrames(final String
the internal name of the class to which 'method' belongs.
owner
,
final MethodNode
the method whose frames must be expanded.
method
,
final Frame<V>
the implicit initial frame of 'method'.
initialFrame
)

Expands the FrameNode "instructions" of the given method into Frame objects and stores them at the corresponding indices of the frames array.

private boolean

Returns:

true if 'insnIndex' is followed by a JVM instruction or a by stack map frame.
hasNextJvmInsnOrFrame
(final int
an instruction index.
insnIndex
)

Returns true if the given instruction is followed by a JVM instruction or a by stack map frame.

protected void
init(final String
the internal name of the class to which the method belongs (see Type#getInternalName()).
owner
,
final MethodNode
the method to be analyzed.
method
)

Overrides org.objectweb.asm.tree.analysis.Analyzer.init.

Initializes this analyzer.
private static boolean

Returns:

true except for label, line number and stack map frame nodes.
isJvmInsnNode
(final AbstractInsnNode
an instruction node.
insnNode
)

Returns true if the given instruction node corresponds to a real JVM instruction.

private V

Returns:

a value that represents the given type.
newFrameValue
(final String
the internal name of the class to which 'frameNode' belongs.
owner
,
final FrameNode
the stack map frame to which 'type' belongs.
frameNode
,
final Object
an Integer, String or LabelNode object representing a primitive, reference or uninitialized a stack map frame type, respectively. See FrameNode.
type
)

Creates a new Value that represents the given stack map frame type.

Inherited from org.objectweb.asm.tree.analysis.Analyzer:
analyzeanalyzeAndComputeMaxsgetFramesgetHandlersnewControlFlowEdgenewControlFlowExceptionEdgenewControlFlowExceptionEdgenewFramenewFrame

Field Detail

currentLocalsback to summary
private int currentLocals

The number of locals in the last stack map frame processed by expandFrame. Long and double values are represented with two elements.

insnListback to summary
private InsnList insnList

Hides org.objectweb.asm.tree.analysis.Analyzer.insnList.

The instructions of the currently analyzed method.

interpreterback to summary
private final Interpreter<V> interpreter

Hides org.objectweb.asm.tree.analysis.Analyzer.interpreter.

The interpreter to use to symbolically interpret the bytecode instructions.

Constructor Detail

CheckFrameAnalyzerback to summary
pack-priv CheckFrameAnalyzer(final Interpreter<V> interpreter)

Method Detail

checkFrameback to summary
private void checkFrame(final int insnIndex, final Frame<V> frame, final boolean requireFrame) throws AnalyzerException

Checks that the given frame is compatible with the frame at the given instruction index, if any. If there is no frame at this instruction index and none is required, the frame at 'insnIndex' is set to the given frame. Otherwise, if the merge of the two frames is not equal to the current frame at 'insnIndex', an exception is thrown.

Parameters
insnIndex:int

an instruction index.

frame:Frame<V>

a frame. This frame is left unchanged by this method.

requireFrame:boolean

whether a frame must already exist or not in frames at 'insnIndex'.

Exceptions
AnalyzerException:
if the frames have incompatible sizes or if the frame at 'insnIndex' is missing (if required) or not compatible with 'frame'.
checkMergeback to summary
private String checkMerge(final Frame<V> srcFrame, final Frame<V> dstFrame)

Checks that merging the two given frames would not produce any change, i.e. that the types in the source frame are sub types of the corresponding types in the destination frame.

Parameters
srcFrame:Frame<V>

a source frame. This frame is left unchanged by this method.

dstFrame:Frame<V>

a destination frame. This frame is left unchanged by this method.

Returns:String

an error message if the frames have incompatible sizes, or if a type in the source frame is not a sub type of the corresponding type in the destination frame. Returns null otherwise.

endControlFlowback to summary
private void endControlFlow(final int insnIndex) throws AnalyzerException

Ends the control flow graph at the given instruction. This method checks that there is an existing frame for the next instruction, if any.

Parameters
insnIndex:int

an instruction index.

Exceptions
AnalyzerException:
if 'insnIndex' is not the last instruction and there is no frame at 'insnIndex' + 1 in getFrames.
expandFrameback to summary
private Frame<V> expandFrame(final String owner, final Frame<V> previousFrame, final FrameNode frameNode) throws AnalyzerException

Returns the expanded representation of the given FrameNode.

Parameters
owner:String

the internal name of the class to which 'frameNode' belongs.

previousFrame:Frame<V>

the frame before 'frameNode', in expanded form.

frameNode:FrameNode

a possibly compressed stack map frame.

Returns:Frame<V>

the expanded version of 'frameNode'.

Exceptions
AnalyzerException:
if 'frameNode' is invalid.
expandFramesback to summary
private void expandFrames(final String owner, final MethodNode method, final Frame<V> initialFrame) throws AnalyzerException

Expands the FrameNode "instructions" of the given method into Frame objects and stores them at the corresponding indices of the frames array. The expanded frames are also associated with the label and line number nodes immediately preceding each frame node.

Parameters
owner:String

the internal name of the class to which 'method' belongs.

method:MethodNode

the method whose frames must be expanded.

initialFrame:Frame<V>

the implicit initial frame of 'method'.

Exceptions
AnalyzerException:
if the stack map frames of 'method', i.e. its FrameNode "instructions", are invalid.
hasNextJvmInsnOrFrameback to summary
private boolean hasNextJvmInsnOrFrame(final int insnIndex)

Returns true if the given instruction is followed by a JVM instruction or a by stack map frame.

Parameters
insnIndex:int

an instruction index.

Returns:boolean

true if 'insnIndex' is followed by a JVM instruction or a by stack map frame.

initback to summary
protected void init(final String owner, final MethodNode method) throws AnalyzerException

Overrides org.objectweb.asm.tree.analysis.Analyzer.init.

Doc from org.objectweb.asm.tree.analysis.Analyzer.init.

Initializes this analyzer. This method is called just before the execution of control flow analysis loop in analyze. The default implementation of this method does nothing.

Parameters
owner:String

the internal name of the class to which the method belongs (see Type#getInternalName()).

method:MethodNode

the method to be analyzed.

Annotations
@Override
Exceptions
AnalyzerException:
if a problem occurs.
isJvmInsnNodeback to summary
private static boolean isJvmInsnNode(final AbstractInsnNode insnNode)

Returns true if the given instruction node corresponds to a real JVM instruction.

Parameters
insnNode:AbstractInsnNode

an instruction node.

Returns:boolean

true except for label, line number and stack map frame nodes.

newFrameValueback to summary
private V newFrameValue(final String owner, final FrameNode frameNode, final Object type) throws AnalyzerException

Creates a new Value that represents the given stack map frame type.

Parameters
owner:String

the internal name of the class to which 'frameNode' belongs.

frameNode:FrameNode

the stack map frame to which 'type' belongs.

type:Object

an Integer, String or LabelNode object representing a primitive, reference or uninitialized a stack map frame type, respectively. See FrameNode.

Returns:V

a value that represents the given type.

Exceptions
AnalyzerException:
if 'type' is an invalid stack map frame type.