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

public Class CodeSizeEvaluator

extends MethodVisitor
implements Opcodes
Class Inheritance
All Implemented Interfaces
org.objectweb.asm.Opcodes
Imports
org.objectweb.asm.ConstantDynamic, .Handle, .Label, .MethodVisitor, .Opcodes

A MethodVisitor that approximates the size of the methods it visits.
Author
Eugene Kuleshov

Field Summary

Modifier and TypeField and Description
private int
maxSize

The maximum size in bytes of the visited method.

private int
minSize

The minimum size in bytes of the visited method.

Inherited from org.objectweb.asm.MethodVisitor:
apimv

Constructor Summary

AccessConstructor and Description
public
CodeSizeEvaluator(final MethodVisitor methodVisitor)

protected
CodeSizeEvaluator(final int api, final MethodVisitor methodVisitor)

Method Summary

Modifier and TypeMethod and Description
public int
public int
public void
visitFieldInsn(final int
the opcode of the type instruction to be visited. This opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
opcode
,
final String
the internal name of the field's owner class (see Type#getInternalName()).
owner
,
final String
the field's name.
name
,
final String
the field's descriptor (see Type).
descriptor
)

Overrides org.objectweb.asm.MethodVisitor.visitFieldInsn.

Visits a field instruction.
public void
visitIincInsn(final int
index of the local variable to be incremented.
varIndex
,
final int
amount to increment the local variable by.
increment
)

Overrides org.objectweb.asm.MethodVisitor.visitIincInsn.

Visits an IINC instruction.
public void
visitInsn(final int
the opcode of the instruction to be visited. This opcode is either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.
opcode
)

Overrides org.objectweb.asm.MethodVisitor.visitInsn.

Visits a zero operand instruction.
public void
visitIntInsn(final int
the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH or NEWARRAY.
opcode
,
final int
the operand of the instruction to be visited.
When opcode is BIPUSH, operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.
When opcode is SIPUSH, operand value should be between Short.MIN_VALUE and Short.MAX_VALUE.
When opcode is NEWARRAY, operand value should be one of Opcodes#T_BOOLEAN, Opcodes#T_CHAR, Opcodes#T_FLOAT, Opcodes#T_DOUBLE, Opcodes#T_BYTE, Opcodes#T_SHORT, Opcodes#T_INT or Opcodes#T_LONG.
operand
)

Overrides org.objectweb.asm.MethodVisitor.visitIntInsn.

Visits an instruction with a single int operand.
public void
visitInvokeDynamicInsn(final String
the method's name.
name
,
final String
the method's descriptor (see Type).
descriptor
,
final Handle
the bootstrap method.
bootstrapMethodHandle
,
final Object...
the bootstrap method constant arguments. Each argument must be an Integer, Float, Long, Double, String, Type, Handle or ConstantDynamic value. This method is allowed to modify the content of the array so a caller should expect that this array may change.
bootstrapMethodArguments
)

Overrides org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn.

Visits an invokedynamic instruction.
public void
visitJumpInsn(final int
the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
opcode
,
final Label
the operand of the instruction to be visited. This operand is a label that designates the instruction to which the jump instruction may jump.
label
)

Overrides org.objectweb.asm.MethodVisitor.visitJumpInsn.

Visits a jump instruction.
public void
visitLdcInsn(final Object
the constant to be loaded on the stack. This parameter must be a non null Integer, a Float, a Long, a Double, a String, a Type of OBJECT or ARRAY sort for .class constants, for classes whose version is 49, a Type of METHOD sort for MethodType, a Handle for MethodHandle constants, for classes whose version is 51 or a ConstantDynamic for a constant dynamic for classes whose version is 55.
value
)

Overrides org.objectweb.asm.MethodVisitor.visitLdcInsn.

Visits a LDC instruction.
public void
visitLookupSwitchInsn(final Label
beginning of the default handler block.
dflt
,
final int[]
the values of the keys.
keys
,
final Label[]
beginnings of the handler blocks. labels[i] is the beginning of the handler block for the keys[i] key.
labels
)

Overrides org.objectweb.asm.MethodVisitor.visitLookupSwitchInsn.

Visits a LOOKUPSWITCH instruction.
public void
visitMethodInsn(final int
the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
opcodeAndSource
,
final String
the internal name of the method's owner class (see Type#getInternalName()).
owner
,
final String
the method's name.
name
,
final String
the method's descriptor (see Type).
descriptor
,
final boolean
if the method's owner class is an interface.
isInterface
)

Overrides org.objectweb.asm.MethodVisitor.visitMethodInsn.

Visits a method instruction.
public void
visitMultiANewArrayInsn(final String
an array type descriptor (see Type).
descriptor
,
final int
the number of dimensions of the array to allocate.
numDimensions
)

Overrides org.objectweb.asm.MethodVisitor.visitMultiANewArrayInsn.

Visits a MULTIANEWARRAY instruction.
public void
visitTableSwitchInsn(final int
the minimum key value.
min
,
final int
the maximum key value.
max
,
final Label
beginning of the default handler block.
dflt
,
final Label...
beginnings of the handler blocks. labels[i] is the beginning of the handler block for the min + i key.
labels
)

Overrides org.objectweb.asm.MethodVisitor.visitTableSwitchInsn.

Visits a TABLESWITCH instruction.
public void
visitTypeInsn(final int
the opcode of the type instruction to be visited. This opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
opcode
,
final String
the operand of the instruction to be visited. This operand must be the internal name of an object or array class (see Type#getInternalName()).
type
)

Overrides org.objectweb.asm.MethodVisitor.visitTypeInsn.

Visits a type instruction.
public void
visitVarInsn(final int
the opcode of the local variable instruction to be visited. This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
opcode
,
final int
the operand of the instruction to be visited. This operand is the index of a local variable.
varIndex
)

Overrides org.objectweb.asm.MethodVisitor.visitVarInsn.

Visits a local variable instruction.
Inherited from org.objectweb.asm.MethodVisitor:
getDelegatevisitAnnotableParameterCountvisitAnnotationvisitAnnotationDefaultvisitAttributevisitCodevisitEndvisitFramevisitInsnAnnotationvisitLabelvisitLineNumbervisitLocalVariablevisitLocalVariableAnnotationvisitMaxsvisitMethodInsnvisitParametervisitParameterAnnotationvisitTryCatchAnnotationvisitTryCatchBlockvisitTypeAnnotation

Field Detail

maxSizeback to summary
private int maxSize

The maximum size in bytes of the visited method.

minSizeback to summary
private int minSize

The minimum size in bytes of the visited method.

Constructor Detail

CodeSizeEvaluatorback to summary
public CodeSizeEvaluator(final MethodVisitor methodVisitor)
CodeSizeEvaluatorback to summary
protected CodeSizeEvaluator(final int api, final MethodVisitor methodVisitor)

Method Detail

getMaxSizeback to summary
public int getMaxSize()
getMinSizeback to summary
public int getMinSize()
visitFieldInsnback to summary
public void visitFieldInsn(final int opcode, final String owner, final String name, final String descriptor)

Overrides org.objectweb.asm.MethodVisitor.visitFieldInsn.

Doc from org.objectweb.asm.MethodVisitor.visitFieldInsn.

Visits a field instruction. A field instruction is an instruction that loads or stores the value of a field of an object.

Parameters
opcode:int

the opcode of the type instruction to be visited. This opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.

owner:String

the internal name of the field's owner class (see Type#getInternalName()).

name:String

the field's name.

descriptor:String

the field's descriptor (see Type).

Annotations
@Override
visitIincInsnback to summary
public void visitIincInsn(final int varIndex, final int increment)

Overrides org.objectweb.asm.MethodVisitor.visitIincInsn.

Doc from org.objectweb.asm.MethodVisitor.visitIincInsn.

Visits an IINC instruction.

Parameters
varIndex:int

index of the local variable to be incremented.

increment:int

amount to increment the local variable by.

Annotations
@Override
visitInsnback to summary
public void visitInsn(final int opcode)

Overrides org.objectweb.asm.MethodVisitor.visitInsn.

Doc from org.objectweb.asm.MethodVisitor.visitInsn.

Visits a zero operand instruction.

Parameters
opcode:int

the opcode of the instruction to be visited. This opcode is either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.

Annotations
@Override
visitIntInsnback to summary
public void visitIntInsn(final int opcode, final int operand)

Overrides org.objectweb.asm.MethodVisitor.visitIntInsn.

Doc from org.objectweb.asm.MethodVisitor.visitIntInsn.

Visits an instruction with a single int operand.

Parameters
opcode:int

the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH or NEWARRAY.

operand:int

the operand of the instruction to be visited.
When opcode is BIPUSH, operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.
When opcode is SIPUSH, operand value should be between Short.MIN_VALUE and Short.MAX_VALUE.
When opcode is NEWARRAY, operand value should be one of Opcodes#T_BOOLEAN, Opcodes#T_CHAR, Opcodes#T_FLOAT, Opcodes#T_DOUBLE, Opcodes#T_BYTE, Opcodes#T_SHORT, Opcodes#T_INT or Opcodes#T_LONG.

Annotations
@Override
visitInvokeDynamicInsnback to summary
public void visitInvokeDynamicInsn(final String name, final String descriptor, final Handle bootstrapMethodHandle, final Object... bootstrapMethodArguments)

Overrides org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn.

Doc from org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn.

Visits an invokedynamic instruction.

Parameters
name:String

the method's name.

descriptor:String

the method's descriptor (see Type).

bootstrapMethodHandle:Handle

the bootstrap method.

bootstrapMethodArguments:Object[]

the bootstrap method constant arguments. Each argument must be an Integer, Float, Long, Double, String, Type, Handle or ConstantDynamic value. This method is allowed to modify the content of the array so a caller should expect that this array may change.

Annotations
@Override
visitJumpInsnback to summary
public void visitJumpInsn(final int opcode, final Label label)

Overrides org.objectweb.asm.MethodVisitor.visitJumpInsn.

Doc from org.objectweb.asm.MethodVisitor.visitJumpInsn.

Visits a jump instruction. A jump instruction is an instruction that may jump to another instruction.

Parameters
opcode:int

the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.

label:Label

the operand of the instruction to be visited. This operand is a label that designates the instruction to which the jump instruction may jump.

Annotations
@Override
visitLdcInsnback to summary
public void visitLdcInsn(final Object value)

Overrides org.objectweb.asm.MethodVisitor.visitLdcInsn.

Doc from org.objectweb.asm.MethodVisitor.visitLdcInsn.

Visits a LDC instruction. Note that new constant types may be added in future versions of the Java Virtual Machine. To easily detect new constant types, implementations of this method should check for unexpected constant types, like this:

if (cst instanceof Integer) {
    // ...
} else if (cst instanceof Float) {
    // ...
} else if (cst instanceof Long) {
    // ...
} else if (cst instanceof Double) {
    // ...
} else if (cst instanceof String) {
    // ...
} else if (cst instanceof Type) {
    int sort = ((Type) cst).getSort();
    if (sort == Type.OBJECT) {
        // ...
    } else if (sort == Type.ARRAY) {
        // ...
    } else if (sort == Type.METHOD) {
        // ...
    } else {
        // throw an exception
    }
} else if (cst instanceof Handle) {
    // ...
} else if (cst instanceof ConstantDynamic) {
    // ...
} else {
    // throw an exception
}
Parameters
value:Object

the constant to be loaded on the stack. This parameter must be a non null Integer, a Float, a Long, a Double, a String, a Type of OBJECT or ARRAY sort for .class constants, for classes whose version is 49, a Type of METHOD sort for MethodType, a Handle for MethodHandle constants, for classes whose version is 51 or a ConstantDynamic for a constant dynamic for classes whose version is 55.

Annotations
@Override
visitLookupSwitchInsnback to summary
public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels)

Overrides org.objectweb.asm.MethodVisitor.visitLookupSwitchInsn.

Doc from org.objectweb.asm.MethodVisitor.visitLookupSwitchInsn.

Visits a LOOKUPSWITCH instruction.

Parameters
dflt:Label

beginning of the default handler block.

keys:int[]

the values of the keys.

labels:Label[]

beginnings of the handler blocks. labels[i] is the beginning of the handler block for the keys[i] key.

Annotations
@Override
visitMethodInsnback to summary
public void visitMethodInsn(final int opcodeAndSource, final String owner, final String name, final String descriptor, final boolean isInterface)

Overrides org.objectweb.asm.MethodVisitor.visitMethodInsn.

Doc from org.objectweb.asm.MethodVisitor.visitMethodInsn.

Visits a method instruction. A method instruction is an instruction that invokes a method.

Parameters
opcodeAndSource:int

the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.

owner:String

the internal name of the method's owner class (see Type#getInternalName()).

name:String

the method's name.

descriptor:String

the method's descriptor (see Type).

isInterface:boolean

if the method's owner class is an interface.

Annotations
@Override
visitMultiANewArrayInsnback to summary
public void visitMultiANewArrayInsn(final String descriptor, final int numDimensions)

Overrides org.objectweb.asm.MethodVisitor.visitMultiANewArrayInsn.

Doc from org.objectweb.asm.MethodVisitor.visitMultiANewArrayInsn.

Visits a MULTIANEWARRAY instruction.

Parameters
descriptor:String

an array type descriptor (see Type).

numDimensions:int

the number of dimensions of the array to allocate.

Annotations
@Override
visitTableSwitchInsnback to summary
public void visitTableSwitchInsn(final int min, final int max, final Label dflt, final Label... labels)

Overrides org.objectweb.asm.MethodVisitor.visitTableSwitchInsn.

Doc from org.objectweb.asm.MethodVisitor.visitTableSwitchInsn.

Visits a TABLESWITCH instruction.

Parameters
min:int

the minimum key value.

max:int

the maximum key value.

dflt:Label

beginning of the default handler block.

labels:Label[]

beginnings of the handler blocks. labels[i] is the beginning of the handler block for the min + i key.

Annotations
@Override
visitTypeInsnback to summary
public void visitTypeInsn(final int opcode, final String type)

Overrides org.objectweb.asm.MethodVisitor.visitTypeInsn.

Doc from org.objectweb.asm.MethodVisitor.visitTypeInsn.

Visits a type instruction. A type instruction is an instruction that takes the internal name of a class as parameter (see Type#getInternalName()).

Parameters
opcode:int

the opcode of the type instruction to be visited. This opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.

type:String

the operand of the instruction to be visited. This operand must be the internal name of an object or array class (see Type#getInternalName()).

Annotations
@Override
visitVarInsnback to summary
public void visitVarInsn(final int opcode, final int varIndex)

Overrides org.objectweb.asm.MethodVisitor.visitVarInsn.

Doc from org.objectweb.asm.MethodVisitor.visitVarInsn.

Visits a local variable instruction. A local variable instruction is an instruction that loads or stores the value of a local variable.

Parameters
opcode:int

the opcode of the local variable instruction to be visited. This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.

varIndex:int

the operand of the instruction to be visited. This operand is the index of a local variable.

Annotations
@Override