Class ByteCodeUtility
- java.lang.Object
-
- org.glassfish.pfl.dynamic.codegen.impl.ByteCodeUtility
-
public final class ByteCodeUtility extends java.lang.ObjectClass that is responsible for low-level bytecode generation using ASM. It provides methods that directly generate bytecode in a MethodVisitor. This will often be accompanied by type analysis, such as in determining the correct sort of return instruction to use, or how to generate code for a constant.
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ByteCodeUtility(org.objectweb.asm.ClassWriter cw, ClassGeneratorImpl cg)ByteCodeUtility(org.objectweb.asm.ClassWriter cw, ClassGeneratorImpl cg, boolean debug, java.io.PrintStream ps)Construct an instance of ByteCodeUtility from an ASM ClassWriter and a codegen ClassGeneratorImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddField(FieldGenerator arg)voidcallEmitter(EmitterFactory.Emitter emitter)private voiddump()voidemitArrayStore()voidemitBinaryOperator(ExpressionFactory.BinaryOperatorExpression arg)private voidemitBooleanCodeForPrimitive(ExpressionFactory.BinaryOperatorExpression arg)private voidemitBooleanCodeForReference(ExpressionFactory.BinaryOperatorExpression arg)voidemitBranch(MyLabel target)voidemitCast(Type from, Type to)voidemitConditionalBranch(MyLabel falseBranch)voidemitConstantExpression(Type type, java.lang.Object value)voidemitConversion(Type from, Type to)voidemitDup()voidemitExceptionTableEntry(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, Type exceptionType)voidemitInstanceof(Type type)voidemitInvoke(Type type, java.lang.String name, Signature sig)Emit the appropriate non-static INVOKE instruction as follows: If type is an interface, emit INVOKEINTERFACE.voidemitJsr(org.objectweb.asm.Label label)voidemitLabel(Attribute<MyLabel> attr, Node node)private voidemitLineNumberTable(MethodGenerator mg)private voidemitLocalVariableTable(MethodGenerator mg)voidemitMethodEnd(MethodGenerator mg, org.objectweb.asm.Label returnLabel, Variable returnVariable, boolean dump)voidemitMethodStart(MethodGenerator mg)voidemitNewArrayCall(Type type)voidemitNewCall(Type type)Emit the NEW, DUP sequence required at the start of a new call.voidemitNewInvoke(Type type, Signature sig)Emit the INVOKESPECIAL instruction for calling a constructor with the given signature.voidemitPop()voidemitRet(Variable var)private voidemitReturn(Type returnType)voidemitSpecialInvoke(Type type, java.lang.String name, Signature sig)Emit the INVOKESPECIAL instruction for calling a method with the given signature.voidemitStaticInvoke(Type type, java.lang.String name, Signature sig)Emit a static INVOKE instruction.voidemitThisExpression()voidemitThrow()inttypeCode(Type type)
-
-
-
Field Detail
-
cw
private org.objectweb.asm.ClassWriter cw
-
mv
private org.objectweb.asm.MethodVisitor mv
-
debug
private boolean debug
-
ps
private java.io.PrintStream ps
-
methodName
private java.lang.String methodName
-
methodSignature
private java.lang.String methodSignature
-
typeIndex
private static java.util.Map<Type,java.lang.Integer> typeIndex
-
E_NOP
private static final EmitterFactory.Emitter E_NOP
-
E_I2B
private static final EmitterFactory.Emitter E_I2B
-
E_I2C
private static final EmitterFactory.Emitter E_I2C
-
E_I2S
private static final EmitterFactory.Emitter E_I2S
-
E_I2L
private static final EmitterFactory.Emitter E_I2L
-
E_I2F
private static final EmitterFactory.Emitter E_I2F
-
E_I2D
private static final EmitterFactory.Emitter E_I2D
-
E_L2I
private static final EmitterFactory.Emitter E_L2I
-
E_F2I
private static final EmitterFactory.Emitter E_F2I
-
E_D2I
private static final EmitterFactory.Emitter E_D2I
-
E_L2F
private static final EmitterFactory.Emitter E_L2F
-
E_L2D
private static final EmitterFactory.Emitter E_L2D
-
E_F2L
private static final EmitterFactory.Emitter E_F2L
-
E_D2L
private static final EmitterFactory.Emitter E_D2L
-
E_F2D
private static final EmitterFactory.Emitter E_F2D
-
E_D2F
private static final EmitterFactory.Emitter E_D2F
-
E_L2B
private static final EmitterFactory.Emitter E_L2B
-
E_F2B
private static final EmitterFactory.Emitter E_F2B
-
E_D2B
private static final EmitterFactory.Emitter E_D2B
-
E_L2S
private static final EmitterFactory.Emitter E_L2S
-
E_F2S
private static final EmitterFactory.Emitter E_F2S
-
E_D2S
private static final EmitterFactory.Emitter E_D2S
-
E_L2C
private static final EmitterFactory.Emitter E_L2C
-
E_F2C
private static final EmitterFactory.Emitter E_F2C
-
E_D2C
private static final EmitterFactory.Emitter E_D2C
-
numericConversions
EmitterFactory.Emitter[][] numericConversions
-
opInstructions
private static java.util.Map<ExpressionFactory.BinaryOperator,java.util.Map<Type,java.lang.Integer>> opInstructions
-
ifOpInstructions
private static java.util.Map<ExpressionFactory.BinaryOperator,java.lang.Integer> ifOpInstructions
-
-
Constructor Detail
-
ByteCodeUtility
public ByteCodeUtility(org.objectweb.asm.ClassWriter cw, ClassGeneratorImpl cg, boolean debug, java.io.PrintStream ps)Construct an instance of ByteCodeUtility from an ASM ClassWriter and a codegen ClassGeneratorImpl. If debug is true, debugText() can be called to get a text representation of the generated code for debugging purposes.
-
ByteCodeUtility
public ByteCodeUtility(org.objectweb.asm.ClassWriter cw, ClassGeneratorImpl cg)
-
-
Method Detail
-
addField
public void addField(FieldGenerator arg)
-
dump
private void dump()
-
emitMethodStart
public void emitMethodStart(MethodGenerator mg)
-
emitLineNumberTable
private void emitLineNumberTable(MethodGenerator mg)
-
emitLocalVariableTable
private void emitLocalVariableTable(MethodGenerator mg)
-
emitMethodEnd
public void emitMethodEnd(MethodGenerator mg, org.objectweb.asm.Label returnLabel, Variable returnVariable, boolean dump)
-
emitReturn
private void emitReturn(Type returnType)
-
emitRet
public void emitRet(Variable var)
-
emitConstantExpression
public void emitConstantExpression(Type type, java.lang.Object value)
-
emitThisExpression
public void emitThisExpression()
-
emitConditionalBranch
public void emitConditionalBranch(MyLabel falseBranch)
-
emitBranch
public void emitBranch(MyLabel target)
-
emitNewCall
public void emitNewCall(Type type)
Emit the NEW, DUP sequence required at the start of a new call.
-
emitInstanceof
public void emitInstanceof(Type type)
-
emitDup
public void emitDup()
-
emitArrayStore
public void emitArrayStore()
-
typeCode
public int typeCode(Type type)
-
emitNewArrayCall
public void emitNewArrayCall(Type type)
-
emitStaticInvoke
public void emitStaticInvoke(Type type, java.lang.String name, Signature sig)
Emit a static INVOKE instruction.
-
emitInvoke
public void emitInvoke(Type type, java.lang.String name, Signature sig)
Emit the appropriate non-static INVOKE instruction as follows:- If type is an interface, emit INVOKEINTERFACE.
- If name/sig has private access in type, emit INVOKESPECIAL. Note that the target must be "this" in this case.
- Otherwise emit INVOKEVIRTUAL.
-
emitNewInvoke
public void emitNewInvoke(Type type, Signature sig)
Emit the INVOKESPECIAL instruction for calling a constructor with the given signature. This is used for new Foo() calls, and for super() and this() calls at the start of a constructor.
-
emitSpecialInvoke
public void emitSpecialInvoke(Type type, java.lang.String name, Signature sig)
Emit the INVOKESPECIAL instruction for calling a method with the given signature. This is used for for super.name() and this.name() method calls.
-
emitThrow
public void emitThrow()
-
emitExceptionTableEntry
public void emitExceptionTableEntry(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, Type exceptionType)
-
emitJsr
public void emitJsr(org.objectweb.asm.Label label)
-
callEmitter
public void callEmitter(EmitterFactory.Emitter emitter)
-
emitPop
public void emitPop()
-
emitBooleanCodeForPrimitive
private void emitBooleanCodeForPrimitive(ExpressionFactory.BinaryOperatorExpression arg)
-
emitBooleanCodeForReference
private void emitBooleanCodeForReference(ExpressionFactory.BinaryOperatorExpression arg)
-
emitBinaryOperator
public void emitBinaryOperator(ExpressionFactory.BinaryOperatorExpression arg)
-
-