Class BytecodeCreatorImpl
- java.lang.Object
-
- io.quarkus.gizmo.BytecodeCreatorImpl
-
- All Implemented Interfaces:
BytecodeCreator,java.lang.AutoCloseable
- Direct Known Subclasses:
AbstractSwitch,CatchBlockCreatorImpl,FunctionCreatorImpl.FunctionBytecodeCreator,IfThenElseImpl,LoopImpl,MethodCreatorImpl,TryBlockImpl
class BytecodeCreatorImpl extends java.lang.Object implements BytecodeCreator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classBytecodeCreatorImpl.AssignOperation(package private) static classBytecodeCreatorImpl.BlockOperation(package private) classBytecodeCreatorImpl.IfOperation(package private) classBytecodeCreatorImpl.InvokeOperation(package private) static classBytecodeCreatorImpl.JumpOperation(package private) classBytecodeCreatorImpl.NewInstanceOperation(package private) static classBytecodeCreatorImpl.Operation
-
Field Summary
Fields Modifier and Type Field Description private org.objectweb.asm.Labelbottomprivate static java.util.Map<java.lang.String,java.lang.String>boxingMapprivate static java.util.Map<java.lang.String,java.lang.String>boxingMethodMapprivate ResultHandlecachedTcclprivate static MethodDescriptorCL_FOR_NAMEprivate static booleanDEBUG_SCOPESprivate static java.lang.StringFUNCTIONprivate static java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger>functionCountersByClass(package private) static intMAX_STRING_LENGTHprivate MethodCreatorImplmethodprotected java.util.List<BytecodeCreatorImpl.Operation>operationsprivate BytecodeCreatorImplownerprivate static java.util.Set<java.lang.String>SAFE_CLASSES_TO_LOAD_AS_CONSTANTSprivate java.lang.StackTraceElement[]stackprivate static MethodDescriptorTHREAD_CURRENT_THREADprivate static MethodDescriptorTHREAD_GET_TCCLprivate org.objectweb.asm.Labeltop
-
Constructor Summary
Constructors Constructor Description BytecodeCreatorImpl(BytecodeCreatorImpl enclosing)BytecodeCreatorImpl(BytecodeCreatorImpl enclosing, boolean useThisMethod)BytecodeCreatorImpl(BytecodeCreatorImpl enclosing, MethodCreatorImpl methodCreator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResultHandleadd(ResultHandle a1, ResultHandle a2)Adds the two result handles together and returns the resultprotected intallocateLocalVariables(int localVarCount)private ResultHandleallocateResult(java.lang.String returnType)ResultHandlearrayLength(ResultHandle array)voidassign(AssignableResultHandle target, ResultHandle value)Assign the given value to the given assignable target.ResultHandlebitwiseAnd(ResultHandle a1, ResultHandle a2)Computes the bitwise AND of the two result handles and returns the resultResultHandlebitwiseOr(ResultHandle a1, ResultHandle a2)Computes the bitwise OR of the two result handles and returns the resultResultHandlebitwiseXor(ResultHandle a1, ResultHandle a2)Computes the bitwise XOR of the two result handles and returns the resultvoidbreakScope(BytecodeCreator scope)Go to the end of the given scope.ResultHandlecheckCast(ResultHandle resultHandle, java.lang.String castTarget)Perform a check cast operation which transforms the type of the given result handle.(package private) ResultHandle[]checkScope(ResultHandle[] handles)(package private) <R extends ResultHandle>
RcheckScope(R handle)ResultHandlecompareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)Compares twodoublevalues and pushes the resulting integer to the stack.ResultHandlecompareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)Compares twofloatvalues and pushes the resulting integer to the stack.ResultHandlecompareLong(ResultHandle value1, ResultHandle value2)Compares twolongvalues and pushes the resulting integer to the stack.voidcontinueScope(BytecodeCreator scope)Go to the top of the given scope.ResultHandleconvertPrimitive(ResultHandle value, java.lang.Class<?> conversionTarget)Converts givenvalue, which must be of a primitive type, to the givenconversionTarget, which must be a primitive type, using primitive conversions defined by the Java language specification.FunctionCreatorcreateFunction(java.lang.Class<?> functionalInterface)Creates an instance of a functional interface(package private) BytecodeCreatorImpl.OperationcreateNewInstanceOp(ResultHandle handle, MethodDescriptor descriptor, ResultHandle[] args)BytecodeCreatorcreateScope()Create a nested scope.AssignableResultHandlecreateVariable(java.lang.String typeDescr)Create a local variable which can be assigned within this scope.ResultHandledivide(ResultHandle a1, ResultHandle a2)Divides the first result handle by the second and returns the resultprivate intdoubleArithmeticOpcode(int intOpcode)private voiddumpScope(java.lang.StringBuilder builder)private ResultHandleemitBinaryArithmetic(int intOpcode, ResultHandle a1, ResultHandle a2)private ResultHandleemitCompare(int opcode, java.lang.String expectedType, ResultHandle value1, ResultHandle value2)private static voidemitLoadConstant(org.objectweb.asm.MethodVisitor methodVisitor, java.lang.Object constant)<E extends java.lang.Enum<E>>
Switch.EnumSwitch<E>enumSwitch(ResultHandle value, java.lang.Class<E> enumClass)Create a new switch construct for an enum constant.(package private) voidfindActiveResultHandles(java.util.Set<ResultHandle> handlesToAllocate)private intfloatArithmeticOpcode(int intOpcode)ForEachLoopforEach(ResultHandle iterable)Create a new for-each loop construct.(package private) org.objectweb.asm.LabelgetBottom()(package private) MethodCreatorImplgetMethod()ResultHandlegetMethodParam(int methodNo)(package private) BytecodeCreatorImplgetOwner()ResultHandlegetThis()(package private) org.objectweb.asm.LabelgetTop()BranchResultifFalse(ResultHandle resultHandle)An if statement.BranchResultifGreaterEqualZero(ResultHandle resultHandle)An if statement.BranchResultifGreaterThanZero(ResultHandle resultHandle)An if statement.BranchResultifIntegerEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerGreaterEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerGreaterThan(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerLessEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerLessThan(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifLessEqualZero(ResultHandle resultHandle)An if statement.BranchResultifLessThanZero(ResultHandle resultHandle)An if statement.BranchResultifNonZero(ResultHandle resultHandle)An if statement.BranchResultifNotNull(ResultHandle resultHandle)An if statement.BranchResultifNull(ResultHandle resultHandle)An if statement.BranchResultifReferencesEqual(ResultHandle ref1, ResultHandle ref2)An if statement.BranchResultifReferencesNotEqual(ResultHandle ref1, ResultHandle ref2)An if statement.IfThenElseifThenElse(ResultHandle value)Create a new if-then-else construct.BranchResultifTrue(ResultHandle resultHandle)An if statement.private BranchResultifValue(ResultHandle resultHandle, int opcode, java.lang.String opType)private BranchResultifValues(ResultHandle resultHandle1, ResultHandle resultHandle2, int opcode, java.lang.String opType)BranchResultifZero(ResultHandle resultHandle)An if statement.ResultHandleinstanceOf(ResultHandle resultHandle, java.lang.String castTarget)Checks if the given resultHandle is an instance of the target typeResultHandleinvokeInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)Invokes a interface method, and returns aResultHandlewith the result, or null if the method is void.ResultHandleinvokeSpecialInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)Invokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.ResultHandleinvokeSpecialMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)Invokes a special method, and returns aResultHandlewith the result, or null if the method is void.ResultHandleinvokeStaticInterfaceMethod(MethodDescriptor descriptor, ResultHandle... args)Invokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.ResultHandleinvokeStaticMethod(MethodDescriptor descriptor, ResultHandle... args)Invokes a static method, and returns aResultHandlewith the result, or null if the method is void.ResultHandleinvokeVirtualMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)Invokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.private booleanisNonPrimitiveSafeJavaClass(java.lang.String className)Returnstrueif the {@param className} is a non-primitive Java type that is guaranteed to be absolutely safe to load from a constant.booleanisScopedWithin(BytecodeCreator other)Determine if this bytecode creator is scoped within the given bytecode creator.(package private) voidjumpTo(BytecodeCreator scope)Go the the top of the given scope.ResultHandleload(boolean val)Returns aResultHandlerepresenting the specified valueResultHandleload(byte val)Returns aResultHandlerepresenting the specified valueResultHandleload(char val)Returns aResultHandlerepresenting the specified valueResultHandleload(double val)Returns aResultHandlerepresenting the specified valueResultHandleload(float val)Returns aResultHandlerepresenting the specified valueResultHandleload(int val)Returns aResultHandlerepresenting the specified valueResultHandleload(long val)Returns aResultHandlerepresenting the specified valueResultHandleload(short val)Returns aResultHandlerepresenting the specified valueResultHandleload(java.lang.String val)Implementation detail: when the string to be loaded is larger thanMAX_STRING_LENGTH, then aStringBuilderis used to construct the final String.ResultHandleloadClass(java.lang.String className)Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingBytecodeCreator.loadClassFromTCCL(String), as it can load classes that are not visible from the current class.private ResultHandleloadClass(java.lang.String className, boolean useTccl)private ResultHandleloadClassConstant(java.lang.String className)ResultHandleloadClassFromTCCL(java.lang.String className)Returns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.ResultHandleloadNull()Returns aResultHandlerepresentingnull}(package private) voidloadResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle, BytecodeCreatorImpl bc, java.lang.String expectedType)(package private) voidloadResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle, BytecodeCreatorImpl bc, java.lang.String expectedType, boolean dontCast)private intlongArithmeticOpcode(int intOpcode)private java.lang.Class<?>matchPossiblyPrimitive(java.lang.String className)ResultHandlemultiply(ResultHandle a1, ResultHandle a2)Multiplies the two result handles together and returns the resultResultHandlenewArray(java.lang.String type, ResultHandle length)ResultHandlenewInstance(MethodDescriptor descriptor, ResultHandle... args)Creates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the resultResultHandlereadArrayValue(ResultHandle array, ResultHandle index)ResultHandlereadInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance)Reads an instance field and returns aResultHandlerepresenting the result.ResultHandlereadStaticField(FieldDescriptor fieldDescriptor)Reads a static field and returns aResultHandlerepresenting the result.ResultHandleremainder(ResultHandle a1, ResultHandle a2)Computes the remainder after division of the first result handle by the second and returns the resultprivate ResultHandle[]requireNonNullHandles(ResultHandle[] handles)(package private) ResultHandle[]resolve(BytecodeCreator creator, ResultHandle... handles)(package private) ResultHandleresolve(ResultHandle handle)(package private) ResultHandle[]resolve(ResultHandle... handles)(package private) ResultHandleresolve(ResultHandle handle, BytecodeCreator creator)voidreturnValue(ResultHandle returnValue)Represents a return statement.(package private) static voidstoreResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle)Switch.StringSwitchstringSwitch(ResultHandle value)Create a new switch construct for a string value.ResultHandlesubtract(ResultHandle a1, ResultHandle a2)Subtracts the second result handle from the first result and returns the resultvoidthrowException(ResultHandle exception)Throws an exceptionTryBlocktryBlock()Add atryblock.WhileLoopwhileLoop(java.util.function.Function<BytecodeCreator,BranchResult> conditionFun)Create a new while loop statement.voidwriteArrayValue(ResultHandle array, ResultHandle index, ResultHandle value)voidwriteInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance, ResultHandle value)Writes the specified value to an instance fieldprotected voidwriteInteriorOperations(org.objectweb.asm.MethodVisitor visitor)protected voidwriteOperations(org.objectweb.asm.MethodVisitor visitor)voidwriteStaticField(FieldDescriptor fieldDescriptor, ResultHandle value)Writes the specified value to an static field-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.quarkus.gizmo.BytecodeCreator
breakScope, checkCast, close, continueScope, createVariable, increment, instanceOf, invokeInterfaceMethod, invokeSpecialInterfaceMethod, invokeSpecialMethod, invokeStaticInterfaceMethod, invokeStaticMethod, invokeVirtualMethod, load, loadClass, loadClass, loadClassFromTCCL, loadClassFromTCCL, marshalAsArray, newArray, newArray, newArray, newInstance, readArrayValue, readInstanceField, readStaticField, returnBoolean, returnInt, returnNull, returnVoid, throwException, throwException, writeArrayValue, writeInstanceField, writeStaticField
-
-
-
-
Field Detail
-
THREAD_CURRENT_THREAD
private static final MethodDescriptor THREAD_CURRENT_THREAD
-
THREAD_GET_TCCL
private static final MethodDescriptor THREAD_GET_TCCL
-
CL_FOR_NAME
private static final MethodDescriptor CL_FOR_NAME
-
DEBUG_SCOPES
private static final boolean DEBUG_SCOPES
-
functionCountersByClass
private static final java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> functionCountersByClass
-
FUNCTION
private static final java.lang.String FUNCTION
- See Also:
- Constant Field Values
-
SAFE_CLASSES_TO_LOAD_AS_CONSTANTS
private static final java.util.Set<java.lang.String> SAFE_CLASSES_TO_LOAD_AS_CONSTANTS
-
MAX_STRING_LENGTH
static final int MAX_STRING_LENGTH
- See Also:
- Constant Field Values
-
operations
protected final java.util.List<BytecodeCreatorImpl.Operation> operations
-
method
private final MethodCreatorImpl method
-
owner
private final BytecodeCreatorImpl owner
-
top
private final org.objectweb.asm.Label top
-
bottom
private final org.objectweb.asm.Label bottom
-
stack
private final java.lang.StackTraceElement[] stack
-
boxingMap
private static final java.util.Map<java.lang.String,java.lang.String> boxingMap
-
boxingMethodMap
private static final java.util.Map<java.lang.String,java.lang.String> boxingMethodMap
-
cachedTccl
private ResultHandle cachedTccl
-
-
Constructor Detail
-
BytecodeCreatorImpl
BytecodeCreatorImpl(BytecodeCreatorImpl enclosing, MethodCreatorImpl methodCreator)
-
BytecodeCreatorImpl
BytecodeCreatorImpl(BytecodeCreatorImpl enclosing, boolean useThisMethod)
-
BytecodeCreatorImpl
BytecodeCreatorImpl(BytecodeCreatorImpl enclosing)
-
-
Method Detail
-
getTop
org.objectweb.asm.Label getTop()
-
getBottom
org.objectweb.asm.Label getBottom()
-
getThis
public ResultHandle getThis()
- Specified by:
getThisin interfaceBytecodeCreator- Returns:
- A
ResultHandlethat represents the current object
-
invokeVirtualMethod
public ResultHandle invokeVirtualMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.- Specified by:
invokeVirtualMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeInterfaceMethod
public ResultHandle invokeInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a interface method, and returns aResultHandlewith the result, or null if the method is void.- Specified by:
invokeInterfaceMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticMethod
public ResultHandle invokeStaticMethod(MethodDescriptor descriptor, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a static method, and returns aResultHandlewith the result, or null if the method is void.- Specified by:
invokeStaticMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticInterfaceMethod
public ResultHandle invokeStaticInterfaceMethod(MethodDescriptor descriptor, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.- Specified by:
invokeStaticInterfaceMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialMethod
public ResultHandle invokeSpecialMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a special method, and returns aResultHandlewith the result, or null if the method is void.Special methods are constructor invocations, or invocations on a superclass method of the current class.
- Specified by:
invokeSpecialMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialInterfaceMethod
public ResultHandle invokeSpecialInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)
Description copied from interface:BytecodeCreatorInvokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.Special interface method invocations are invocations of a superinterface method of the current class.
- Specified by:
invokeSpecialInterfaceMethodin interfaceBytecodeCreator- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
newInstance
public ResultHandle newInstance(MethodDescriptor descriptor, ResultHandle... args)
Description copied from interface:BytecodeCreatorCreates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the result- Specified by:
newInstancein interfaceBytecodeCreator- Parameters:
descriptor- The constructor descriptorargs- The constructor parameters- Returns:
- The new instance
-
newArray
public ResultHandle newArray(java.lang.String type, ResultHandle length)
- Specified by:
newArrayin interfaceBytecodeCreator
-
load
public ResultHandle load(java.lang.String val)
Implementation detail: when the string to be loaded is larger thanMAX_STRING_LENGTH, then aStringBuilderis used to construct the final String. This is done because strings constants cannot be larger thanMAX_STRING_LENGTH.- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(byte val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(short val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(char val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(int val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(long val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(float val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(double val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
public ResultHandle load(boolean val)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified value- Specified by:
loadin interfaceBytecodeCreator- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
loadClass
public ResultHandle loadClass(java.lang.String className)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingBytecodeCreator.loadClassFromTCCL(String), as it can load classes that are not visible from the current class. This method should only be used if you are sure that the class being loaded will be accessible from the generated bytecode.- Specified by:
loadClassin interfaceBytecodeCreator- Parameters:
className- The class name- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClassFromTCCL
public ResultHandle loadClassFromTCCL(java.lang.String className)
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.- Specified by:
loadClassFromTCCLin interfaceBytecodeCreator- Parameters:
className- The class name- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClass
private ResultHandle loadClass(java.lang.String className, boolean useTccl)
-
loadClassConstant
private ResultHandle loadClassConstant(java.lang.String className)
-
matchPossiblyPrimitive
private java.lang.Class<?> matchPossiblyPrimitive(java.lang.String className)
-
isNonPrimitiveSafeJavaClass
private boolean isNonPrimitiveSafeJavaClass(java.lang.String className)
Returnstrueif the {@param className} is a non-primitive Java type that is guaranteed to be absolutely safe to load from a constant.Note that it's not safe to load all JDK classes using this, see this for an example.
-
loadNull
public ResultHandle loadNull()
Description copied from interface:BytecodeCreatorReturns aResultHandlerepresentingnull}- Specified by:
loadNullin interfaceBytecodeCreator- Returns:
- A
ResultHandlerepresentingnull}
-
writeInstanceField
public void writeInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance, ResultHandle value)
Description copied from interface:BytecodeCreatorWrites the specified value to an instance field- Specified by:
writeInstanceFieldin interfaceBytecodeCreator- Parameters:
fieldDescriptor- The field to write toinstance- AResultHandlerepresenting the instance that contains the fieldvalue- AResultHandlerepresenting the value
-
readInstanceField
public ResultHandle readInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance)
Description copied from interface:BytecodeCreatorReads an instance field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Specified by:
readInstanceFieldin interfaceBytecodeCreator- Parameters:
fieldDescriptor- The field to read frominstance- AResultHandlerepresenting the instance that contains the field- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
writeStaticField
public void writeStaticField(FieldDescriptor fieldDescriptor, ResultHandle value)
Description copied from interface:BytecodeCreatorWrites the specified value to an static field- Specified by:
writeStaticFieldin interfaceBytecodeCreator- Parameters:
fieldDescriptor- The field to write tovalue- AResultHandlerepresenting the value
-
readStaticField
public ResultHandle readStaticField(FieldDescriptor fieldDescriptor)
Description copied from interface:BytecodeCreatorReads a static field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Specified by:
readStaticFieldin interfaceBytecodeCreator- Parameters:
fieldDescriptor- The field to read from- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
arrayLength
public ResultHandle arrayLength(ResultHandle array)
- Specified by:
arrayLengthin interfaceBytecodeCreator
-
readArrayValue
public ResultHandle readArrayValue(ResultHandle array, ResultHandle index)
- Specified by:
readArrayValuein interfaceBytecodeCreator
-
writeArrayValue
public void writeArrayValue(ResultHandle array, ResultHandle index, ResultHandle value)
- Specified by:
writeArrayValuein interfaceBytecodeCreator
-
createVariable
public AssignableResultHandle createVariable(java.lang.String typeDescr)
Description copied from interface:BytecodeCreatorCreate a local variable which can be assigned within this scope.- Specified by:
createVariablein interfaceBytecodeCreator- Parameters:
typeDescr- the type descriptor of the variable's type (must not benull)- Returns:
- the assignable local variable (not
null)
-
assign
public void assign(AssignableResultHandle target, ResultHandle value)
Description copied from interface:BytecodeCreatorAssign the given value to the given assignable target.- Specified by:
assignin interfaceBytecodeCreator- Parameters:
target- the assignment target (must not benull)value- the value to assign (must not benull)
-
checkCast
public ResultHandle checkCast(ResultHandle resultHandle, java.lang.String castTarget)
Description copied from interface:BytecodeCreatorPerform a check cast operation which transforms the type of the given result handle.- Specified by:
checkCastin interfaceBytecodeCreator- Parameters:
resultHandle- the result handlecastTarget- the cast target type descriptor- Returns:
- a new result handle with updated type
-
convertPrimitive
public ResultHandle convertPrimitive(ResultHandle value, java.lang.Class<?> conversionTarget)
Description copied from interface:BytecodeCreatorConverts givenvalue, which must be of a primitive type, to the givenconversionTarget, which must be a primitive type, using primitive conversions defined by the Java language specification.Returns
valuedirectly when its static type is the same asconversionTarget.Throws an exception if any of the arguments is
null. Throws an exception when the static type ofvalueis not a primitive type or whenconversionTargetis not a primitive type. Throws an exception if no primitive conversion exists from the type ofvalueto theconversionTarget. (Note that "throws an exception" in this paragraph does not mean that a bytecode sequence for throwing an exception is emitted; instead, the methodconvertPrimitivethrows an exception directly and eagerly.)- Specified by:
convertPrimitivein interfaceBytecodeCreator- Parameters:
value- the value to be convertedconversionTarget- the primitive type to which thevalueshould be converted- Returns:
- the converted value
-
isScopedWithin
public boolean isScopedWithin(BytecodeCreator other)
Description copied from interface:BytecodeCreatorDetermine if this bytecode creator is scoped within the given bytecode creator.- Specified by:
isScopedWithinin interfaceBytecodeCreator- Parameters:
other- the other bytecode creator- Returns:
trueif this bytecode creator is scoped within the given creator,falseotherwise
-
continueScope
public void continueScope(BytecodeCreator scope)
Description copied from interface:BytecodeCreatorGo to the top of the given scope.- Specified by:
continueScopein interfaceBytecodeCreator- Parameters:
scope- the scope to continue
-
breakScope
public void breakScope(BytecodeCreator scope)
Description copied from interface:BytecodeCreatorGo to the end of the given scope.- Specified by:
breakScopein interfaceBytecodeCreator- Parameters:
scope- the scope to break out of
-
createScope
public BytecodeCreator createScope()
Description copied from interface:BytecodeCreatorCreate a nested scope. Bytecode added to the nested scope will be inserted at this point of the enclosing scope.- Specified by:
createScopein interfaceBytecodeCreator- Returns:
- the nested scope
-
jumpTo
void jumpTo(BytecodeCreator scope)
Go the the top of the given scope. UnlikecontinueScope(BytecodeCreator)this method does not verify if this bytecode creator is scoped within the given bytecode creator.- Parameters:
scope-
-
storeResultHandle
static void storeResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle)
-
loadResultHandle
void loadResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle, BytecodeCreatorImpl bc, java.lang.String expectedType)
-
loadResultHandle
void loadResultHandle(org.objectweb.asm.MethodVisitor methodVisitor, ResultHandle handle, BytecodeCreatorImpl bc, java.lang.String expectedType, boolean dontCast)
-
emitLoadConstant
private static void emitLoadConstant(org.objectweb.asm.MethodVisitor methodVisitor, java.lang.Object constant)
-
tryBlock
public TryBlock tryBlock()
Description copied from interface:BytecodeCreatorAdd atryblock.- Specified by:
tryBlockin interfaceBytecodeCreator- Returns:
- the
tryblock
-
compareLong
public ResultHandle compareLong(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorCompares twolongvalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typelong.- Specified by:
compareLongin interfaceBytecodeCreator- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to compare- Returns:
- the comparison result
-
compareFloat
public ResultHandle compareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
Description copied from interface:BytecodeCreatorCompares twofloatvalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typefloat.If one of the values is NaN, the result is 1 if
nanComparesAsGreateris true and -1 if not.- Specified by:
compareFloatin interfaceBytecodeCreator- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to comparenanComparesAsGreater- whether presence of NaN should result in "greater"- Returns:
- the comparison result
-
compareDouble
public ResultHandle compareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
Description copied from interface:BytecodeCreatorCompares twodoublevalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typedouble.If one of the values is NaN, the result is 1 if
nanComparesAsGreateris true and -1 if not.- Specified by:
compareDoublein interfaceBytecodeCreator- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to comparenanComparesAsGreater- whether presence of NaN should result in "greater"- Returns:
- the comparison result
-
emitCompare
private ResultHandle emitCompare(int opcode, java.lang.String expectedType, ResultHandle value1, ResultHandle value2)
-
ifNonZero
public BranchResult ifNonZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type or boolean. If this value is true or non-zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifNonZeroin interfaceBytecodeCreator- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifNull
public BranchResult ifNull(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement. If the value isnulltheBranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifNullin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifZero
public BranchResult ifZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type or boolean. If this value is false or zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifZeroin interfaceBytecodeCreator- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifTrue
public BranchResult ifTrue(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement. An alias forBytecodeCreator.ifNonZero(ResultHandle).- Specified by:
ifTruein interfaceBytecodeCreator- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifFalse
public BranchResult ifFalse(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement. An alias forBytecodeCreator.ifZero(ResultHandle).- Specified by:
ifFalsein interfaceBytecodeCreator- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifNotNull
public BranchResult ifNotNull(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement. If the value is notnulltheBranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifNotNullin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifGreaterThanZero
public BranchResult ifGreaterThanZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type. If this value is greater than zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifGreaterThanZeroin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifGreaterEqualZero
public BranchResult ifGreaterEqualZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type. If this value is greater or equals to zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifGreaterEqualZeroin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifLessThanZero
public BranchResult ifLessThanZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type. If this value is lower than zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifLessThanZeroin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifLessEqualZero
public BranchResult ifLessEqualZero(ResultHandle resultHandle)
Description copied from interface:BytecodeCreatorAn if statement.resultHandle must be an integer type. If this value is lower or equals to zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifLessEqualZeroin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifIntegerEqual
public BranchResult ifIntegerEqual(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorAn if statement.Values must be integer types. If value1 is equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifIntegerEqualin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifIntegerGreaterThan
public BranchResult ifIntegerGreaterThan(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorAn if statement.Values must be integer types. If value1 is greater than value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifIntegerGreaterThanin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifIntegerGreaterEqual
public BranchResult ifIntegerGreaterEqual(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorAn if statement.Values must be integer types. If value1 is greater or equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifIntegerGreaterEqualin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifIntegerLessThan
public BranchResult ifIntegerLessThan(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorAn if statement.Values must be integer types. If value1 is less than value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifIntegerLessThanin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
instanceOf
public ResultHandle instanceOf(ResultHandle resultHandle, java.lang.String castTarget)
Description copied from interface:BytecodeCreatorChecks if the given resultHandle is an instance of the target type- Specified by:
instanceOfin interfaceBytecodeCreator- Parameters:
resultHandle- the result handlecastTarget- the cast target class- Returns:
- a boolean result handle with the result of the instanceof call
-
ifIntegerLessEqual
public BranchResult ifIntegerLessEqual(ResultHandle value1, ResultHandle value2)
Description copied from interface:BytecodeCreatorAn if statement.Values must be integer types. If value1 is less or equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifIntegerLessEqualin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifReferencesEqual
public BranchResult ifReferencesEqual(ResultHandle ref1, ResultHandle ref2)
Description copied from interface:BytecodeCreatorAn if statement.If references are equal (object identity) the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Specified by:
ifReferencesEqualin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifReferencesNotEqual
public BranchResult ifReferencesNotEqual(ResultHandle ref1, ResultHandle ref2)
Description copied from interface:BytecodeCreatorAn if statement.If references are not equal (as in object identity) the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.This method is dual to
BytecodeCreator.ifReferencesEqual(ResultHandle, ResultHandle)and can be used to emit bytecode that is closer to what javac emits, when useful.- Specified by:
ifReferencesNotEqualin interfaceBytecodeCreator- Returns:
- The branch result that is used to build the if statement
-
ifThenElse
public IfThenElse ifThenElse(ResultHandle value)
Description copied from interface:BytecodeCreatorCreate a new if-then-else construct.The
IfThenElse.then()block is executed if the condition result handle evaluates totrue.- Specified by:
ifThenElsein interfaceBytecodeCreator- Returns:
- the if-then-else construct
-
getMethodParam
public ResultHandle getMethodParam(int methodNo)
- Specified by:
getMethodParamin interfaceBytecodeCreator- Parameters:
methodNo- The method parameter number, zero indexed- Returns:
- A
ResultHandlerepresenting the parameter
-
createFunction
public FunctionCreator createFunction(java.lang.Class<?> functionalInterface)
Description copied from interface:BytecodeCreatorCreates an instance of a functional interfaceThe resulting
FunctionCreatorcan be used to both define the functions bytecode, and to get aResultHandlethat represents the instance of the function.- Specified by:
createFunctionin interfaceBytecodeCreator- Parameters:
functionalInterface- A functional interface- Returns:
- The function builder
-
returnValue
public void returnValue(ResultHandle returnValue)
Description copied from interface:BytecodeCreatorRepresents a return statement. If this is a void method the return value must be null, otherwise it must be aResultHandleof the correct type which will be returned from the method.- Specified by:
returnValuein interfaceBytecodeCreator- Parameters:
returnValue- The value to return
-
throwException
public void throwException(ResultHandle exception)
Description copied from interface:BytecodeCreatorThrows an exception- Specified by:
throwExceptionin interfaceBytecodeCreator- Parameters:
exception- A result handle representing the exception to throw
-
whileLoop
public WhileLoop whileLoop(java.util.function.Function<BytecodeCreator,BranchResult> conditionFun)
Description copied from interface:BytecodeCreatorCreate a new while loop statement.- Specified by:
whileLoopin interfaceBytecodeCreator- Parameters:
conditionFun- A function used to create the condition. The true branch continues executing the block and the false branch terminates the statement.- Returns:
- the while loop statement
-
forEach
public ForEachLoop forEach(ResultHandle iterable)
Description copied from interface:BytecodeCreatorCreate a new for-each loop construct.- Specified by:
forEachin interfaceBytecodeCreator- Returns:
- the for-each construct
-
add
public ResultHandle add(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorAdds the two result handles together and returns the result- Specified by:
addin interfaceBytecodeCreator- Parameters:
a1- The first number, aka the augenda2- The second number, aka the addend- Returns:
- The result
-
subtract
public ResultHandle subtract(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorSubtracts the second result handle from the first result and returns the result- Specified by:
subtractin interfaceBytecodeCreator- Parameters:
a1- The first number, aka the minuenda2- The second number, aka the subtrahend- Returns:
- The result
-
multiply
public ResultHandle multiply(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorMultiplies the two result handles together and returns the result- Specified by:
multiplyin interfaceBytecodeCreator- Parameters:
a1- The first number, aka the multipliera2- The second number, aka the multiplicand- Returns:
- The result
-
divide
public ResultHandle divide(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorDivides the first result handle by the second and returns the result- Specified by:
dividein interfaceBytecodeCreator- Parameters:
a1- The first number, aka the numeratora2- The second number, aka the denominator- Returns:
- The result
-
remainder
public ResultHandle remainder(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorComputes the remainder after division of the first result handle by the second and returns the result- Specified by:
remainderin interfaceBytecodeCreator- Parameters:
a1- The first number, aka the numeratora2- The second number, aka the denominator- Returns:
- The result
-
bitwiseAnd
public ResultHandle bitwiseAnd(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorComputes the bitwise AND of the two result handles and returns the result- Specified by:
bitwiseAndin interfaceBytecodeCreator- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
bitwiseOr
public ResultHandle bitwiseOr(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorComputes the bitwise OR of the two result handles and returns the result- Specified by:
bitwiseOrin interfaceBytecodeCreator- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
bitwiseXor
public ResultHandle bitwiseXor(ResultHandle a1, ResultHandle a2)
Description copied from interface:BytecodeCreatorComputes the bitwise XOR of the two result handles and returns the result- Specified by:
bitwiseXorin interfaceBytecodeCreator- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
stringSwitch
public Switch.StringSwitch stringSwitch(ResultHandle value)
Description copied from interface:BytecodeCreatorCreate a new switch construct for a string value.- Specified by:
stringSwitchin interfaceBytecodeCreator- Parameters:
value- The string value to switch on- Returns:
- the switch construct
-
enumSwitch
public <E extends java.lang.Enum<E>> Switch.EnumSwitch<E> enumSwitch(ResultHandle value, java.lang.Class<E> enumClass)
Description copied from interface:BytecodeCreatorCreate a new switch construct for an enum constant.- Specified by:
enumSwitchin interfaceBytecodeCreator- Parameters:
value- The enum constant to switch on- Returns:
- the switch construct
-
emitBinaryArithmetic
private ResultHandle emitBinaryArithmetic(int intOpcode, ResultHandle a1, ResultHandle a2)
-
longArithmeticOpcode
private int longArithmeticOpcode(int intOpcode)
-
floatArithmeticOpcode
private int floatArithmeticOpcode(int intOpcode)
-
doubleArithmeticOpcode
private int doubleArithmeticOpcode(int intOpcode)
-
allocateResult
private ResultHandle allocateResult(java.lang.String returnType)
-
allocateLocalVariables
protected int allocateLocalVariables(int localVarCount)
-
findActiveResultHandles
void findActiveResultHandles(java.util.Set<ResultHandle> handlesToAllocate)
-
writeOperations
protected void writeOperations(org.objectweb.asm.MethodVisitor visitor)
-
writeInteriorOperations
protected void writeInteriorOperations(org.objectweb.asm.MethodVisitor visitor)
-
checkScope
<R extends ResultHandle> R checkScope(R handle)
-
dumpScope
private void dumpScope(java.lang.StringBuilder builder)
-
checkScope
ResultHandle[] checkScope(ResultHandle[] handles)
-
resolve
final ResultHandle resolve(ResultHandle handle)
-
resolve
ResultHandle resolve(ResultHandle handle, BytecodeCreator creator)
-
resolve
ResultHandle[] resolve(BytecodeCreator creator, ResultHandle... handles)
-
resolve
final ResultHandle[] resolve(ResultHandle... handles)
-
getMethod
MethodCreatorImpl getMethod()
-
getOwner
BytecodeCreatorImpl getOwner()
-
ifValue
private BranchResult ifValue(ResultHandle resultHandle, int opcode, java.lang.String opType)
-
ifValues
private BranchResult ifValues(ResultHandle resultHandle1, ResultHandle resultHandle2, int opcode, java.lang.String opType)
-
requireNonNullHandles
private ResultHandle[] requireNonNullHandles(ResultHandle[] handles)
-
createNewInstanceOp
BytecodeCreatorImpl.Operation createNewInstanceOp(ResultHandle handle, MethodDescriptor descriptor, ResultHandle[] args)
-
-