Class ASMUtil
- java.lang.Object
-
- org.stianloader.micromixin.transform.internal.util.ASMUtil
-
@Internal public class ASMUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCALLBACK_INFO_DESCstatic java.lang.StringCALLBACK_INFO_NAMEstatic java.lang.StringCALLBACK_INFO_RETURNABLE_DESCstatic java.lang.StringCALLBACK_INFO_RETURNABLE_NAMEstatic intCI_LENstatic intCIR_LENstatic java.lang.StringCOMMON_CI_INSTANCE_ANNOT_DESCstatic java.lang.StringROLL_ANNOT_DESCstatic java.lang.StringUNROLL_ANNOT_DESC
-
Constructor Summary
Constructors Constructor Description ASMUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.objectweb.asm.tree.AbstractInsnNodeafterInstruction(org.objectweb.asm.tree.AbstractInsnNode insn)static voidcopyAnnotations(org.objectweb.asm.tree.MethodNode from, org.objectweb.asm.tree.MethodNode to)Copy all visible and invisible annotations from a method to a different method, excludingLocalVariableAnnotationNodes which will not be copied due to their reliance onLabelNode.static java.util.Collection<InjectionPointReference>enumerateTargets(java.util.Collection<MixinTargetSelector> selectors, java.util.Collection<SlicedInjectionPointSelector> ats, org.objectweb.asm.tree.ClassNode target, MixinStub mixinSource, org.objectweb.asm.tree.MethodNode injectMethodSource, int require, int expect, int allow, SimpleRemapper remapper, java.lang.StringBuilder sharedBuilder, MixinLoggingFacade logger)static intgetArgumentCount(java.lang.String methodDesc)Obtain the amount of arguments a method descriptor defines, irrespective of their size on the stack (so both int and long are counted as 1).static org.objectweb.asm.tree.FieldNodegetField(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)static intgetInitialFrameSize(org.objectweb.asm.tree.MethodNode method)static intgetInputOperandCount(org.objectweb.asm.tree.AbstractInsnNode insn)Obtain the amount of input operands of a given instruction, irrespective of how much space those input operands occupy on the operand stack.static java.util.List<java.lang.String>getInputOperandTypes(org.objectweb.asm.tree.AbstractInsnNode insn)Obtain the types of the input operands of a given instruction.static org.objectweb.asm.tree.LabelNodegetLabelNodeBefore(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.InsnList merge)static java.lang.StringgetLastType(java.lang.String methodDesc)static intgetLoadOpcode(int descReturnType)static intgetLoadOpcodeFromMethodDesc(java.lang.String methodDesc)static org.objectweb.asm.tree.MethodNodegetMethod(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)static org.objectweb.asm.tree.AbstractInsnNodegetNext(org.objectweb.asm.tree.AbstractInsnNode insn)static java.lang.StringgetRedirectHandlerSignature(org.objectweb.asm.tree.AbstractInsnNode insn)static intgetReturnComputationalType(java.lang.String methodDesc)static intgetReturnOpcode(int descReturnType)static intgetReturnOpcode(java.lang.String methodDesc)static java.lang.StringgetReturnType(java.lang.String methodDesc)Obtains the descriptor type returned by a method descriptor.static intgetShallowStashConfiguration(java.util.List<java.lang.String> headTypes, int uniformDepth)static intgetStoreOpcode(int descReturnType)static intgetStoreOpcodeFromMethodDesc(java.lang.String methodDesc)static java.lang.StringgetTargetDesc(org.objectweb.asm.tree.MethodNode method, java.lang.StringBuilder sharedBuilder)static booleanhasField(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)static booleanhasMethod(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)static booleanhasReducedAccess(int witnessAccess, int testAccess)static booleanisBetween(org.objectweb.asm.tree.AbstractInsnNode start, org.objectweb.asm.tree.AbstractInsnNode end, org.objectweb.asm.tree.AbstractInsnNode insn)static booleanisCategory2(int descType)static booleanisCategory2VarInsn(int opcode)static booleanisLoad(int opcode)static booleanisReturn(int opcode)static booleanisStore(int opcode)static intloadCallbackInfoInstance(org.objectweb.asm.tree.MethodNode injectTarget, org.objectweb.asm.tree.InsnList usageSiteOutput)Lazily allocates a sharedCallbackInfoorCallbackInfoCallbackInfoinstance for the given target method.static voidmoveStackHead(org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AbstractInsnNode beginMoveInsn, org.objectweb.asm.tree.AbstractInsnNode endRollbackInsn, java.util.List<java.lang.String> headTypes, int uniformDepth, org.objectweb.asm.tree.InsnList moveOut, org.objectweb.asm.tree.InsnList rollbackOut)Temporarily pop (or hide them deep in the stack) a given amount of operands.static intpopReturn(java.lang.String methodDesc)static org.objectweb.asm.tree.AbstractInsnNodeshiftInsn(org.objectweb.asm.tree.AbstractInsnNode insn, int offset)static inttoOperandDepth(java.util.List<java.lang.String> headTypes, int uniformDepth)static inttoUniformDepth(java.util.List<java.lang.String> headTypes, int operandDepth)
-
-
-
Field Detail
-
CALLBACK_INFO_DESC
public static final java.lang.String CALLBACK_INFO_DESC
- See Also:
- Constant Field Values
-
CALLBACK_INFO_NAME
public static final java.lang.String CALLBACK_INFO_NAME
- See Also:
- Constant Field Values
-
CALLBACK_INFO_RETURNABLE_DESC
public static final java.lang.String CALLBACK_INFO_RETURNABLE_DESC
- See Also:
- Constant Field Values
-
CALLBACK_INFO_RETURNABLE_NAME
public static final java.lang.String CALLBACK_INFO_RETURNABLE_NAME
- See Also:
- Constant Field Values
-
CI_LEN
public static final int CI_LEN
-
CIR_LEN
public static final int CIR_LEN
-
COMMON_CI_INSTANCE_ANNOT_DESC
public static final java.lang.String COMMON_CI_INSTANCE_ANNOT_DESC
- See Also:
- Constant Field Values
-
ROLL_ANNOT_DESC
public static final java.lang.String ROLL_ANNOT_DESC
- See Also:
- Constant Field Values
-
UNROLL_ANNOT_DESC
public static final java.lang.String UNROLL_ANNOT_DESC
- See Also:
- Constant Field Values
-
-
Method Detail
-
afterInstruction
@NotNull public static org.objectweb.asm.tree.AbstractInsnNode afterInstruction(@NotNull org.objectweb.asm.tree.AbstractInsnNode insn)
-
copyAnnotations
public static void copyAnnotations(@NotNull org.objectweb.asm.tree.MethodNode from, @NotNull org.objectweb.asm.tree.MethodNode to)Copy all visible and invisible annotations from a method to a different method, excludingLocalVariableAnnotationNodes which will not be copied due to their reliance onLabelNode.This method creates independently operating copies. That is, if the annotations in
fromwhere to be modified after invoking this method, the annotations intowill not be affected.This method will copy even when an annotation shouldn't be present more than once. Neither will this method honour Java 8's
Repeatable.value().- Parameters:
from- TheMethodNodeto copy the annotations from.to- TheMethodNodeto copy the annotations to.- Since:
- 0.8.0
-
enumerateTargets
@NotNull public static java.util.Collection<InjectionPointReference> enumerateTargets(@NotNull java.util.Collection<MixinTargetSelector> selectors, @NotNull java.util.Collection<SlicedInjectionPointSelector> ats, @NotNull org.objectweb.asm.tree.ClassNode target, @NotNull MixinStub mixinSource, @NotNull org.objectweb.asm.tree.MethodNode injectMethodSource, int require, int expect, int allow, @NotNull SimpleRemapper remapper, @NotNull java.lang.StringBuilder sharedBuilder, @NotNull MixinLoggingFacade logger)
-
getArgumentCount
public static int getArgumentCount(@NotNull java.lang.String methodDesc)Obtain the amount of arguments a method descriptor defines, irrespective of their size on the stack (so both int and long are counted as 1).- Parameters:
methodDesc- The method descriptor to use- Returns:
- The amount of arguments
-
getField
@Nullable public static org.objectweb.asm.tree.FieldNode getField(@NotNull org.objectweb.asm.tree.ClassNode node, @NotNull java.lang.String name, @NotNull java.lang.String desc)
-
getInitialFrameSize
public static int getInitialFrameSize(@NotNull org.objectweb.asm.tree.MethodNode method)
-
getInputOperandCount
public static int getInputOperandCount(@NotNull org.objectweb.asm.tree.AbstractInsnNode insn)Obtain the amount of input operands of a given instruction, irrespective of how much space those input operands occupy on the operand stack.- Parameters:
insn- The instruction to analyze- Returns:
- The amount of input operands
-
getInputOperandTypes
@NotNull public static java.util.List<java.lang.String> getInputOperandTypes(org.objectweb.asm.tree.AbstractInsnNode insn)
Obtain the types of the input operands of a given instruction. The returned list does not contain any null values, that is doubles are a single value within the return list.The values within the list are descriptor strings (e.g. Ljava/lang/Object;)
- Parameters:
insn- The instruction- Returns:
- The input operand types
-
getLabelNodeBefore
@NotNull public static org.objectweb.asm.tree.LabelNode getLabelNodeBefore(@NotNull org.objectweb.asm.tree.AbstractInsnNode insn, @NotNull org.objectweb.asm.tree.InsnList merge)
-
getLastType
@Nullable public static java.lang.String getLastType(@NotNull java.lang.String methodDesc)
-
getLoadOpcode
public static int getLoadOpcode(int descReturnType)
-
getLoadOpcodeFromMethodDesc
public static int getLoadOpcodeFromMethodDesc(@NotNull java.lang.String methodDesc)
-
getMethod
@Nullable public static org.objectweb.asm.tree.MethodNode getMethod(@NotNull org.objectweb.asm.tree.ClassNode node, @NotNull java.lang.String name, @NotNull java.lang.String desc)
-
getNext
@NotNull public static org.objectweb.asm.tree.AbstractInsnNode getNext(org.objectweb.asm.tree.AbstractInsnNode insn)
-
getRedirectHandlerSignature
@NotNull public static java.lang.String getRedirectHandlerSignature(@NotNull org.objectweb.asm.tree.AbstractInsnNode insn)
-
getReturnComputationalType
public static int getReturnComputationalType(@NotNull java.lang.String methodDesc)
-
getReturnOpcode
public static int getReturnOpcode(int descReturnType)
-
getReturnOpcode
public static int getReturnOpcode(@NotNull java.lang.String methodDesc)
-
getReturnType
@NotNull public static java.lang.String getReturnType(java.lang.String methodDesc)
Obtains the descriptor type returned by a method descriptor. Throws an arbitrary exception if the descriptor is not a method descriptor.- Parameters:
methodDesc- The method descriptor to get the return type of.- Returns:
- The returned type of the method
-
getShallowStashConfiguration
public static int getShallowStashConfiguration(java.util.List<java.lang.String> headTypes, int uniformDepth)
-
getStoreOpcode
public static int getStoreOpcode(int descReturnType)
-
getStoreOpcodeFromMethodDesc
public static int getStoreOpcodeFromMethodDesc(@NotNull java.lang.String methodDesc)
-
getTargetDesc
@NotNull public static java.lang.String getTargetDesc(@NotNull org.objectweb.asm.tree.MethodNode method, @NotNull java.lang.StringBuilder sharedBuilder)
-
hasField
public static boolean hasField(@NotNull org.objectweb.asm.tree.ClassNode node, @NotNull java.lang.String name, @NotNull java.lang.String desc)
-
hasMethod
public static boolean hasMethod(@NotNull org.objectweb.asm.tree.ClassNode node, @NotNull java.lang.String name, @NotNull java.lang.String desc)
-
hasReducedAccess
public static boolean hasReducedAccess(int witnessAccess, int testAccess)
-
isBetween
public static boolean isBetween(org.objectweb.asm.tree.AbstractInsnNode start, org.objectweb.asm.tree.AbstractInsnNode end, @NotNull org.objectweb.asm.tree.AbstractInsnNode insn)
-
isCategory2
public static boolean isCategory2(int descType)
-
isCategory2VarInsn
public static boolean isCategory2VarInsn(int opcode)
-
isLoad
public static boolean isLoad(int opcode)
-
isReturn
public static boolean isReturn(int opcode)
-
isStore
public static boolean isStore(int opcode)
-
loadCallbackInfoInstance
public static int loadCallbackInfoInstance(@NotNull org.objectweb.asm.tree.MethodNode injectTarget, @NotNull org.objectweb.asm.tree.InsnList usageSiteOutput)Lazily allocates a sharedCallbackInfoorCallbackInfoCallbackInfoinstance for the given target method. This method will try to aggressively reuse indices for theCallbackInfoorCallbackInfoCallbackInfo.The instance will be loaded onto the top of the stack within the provided usageSiteOutput
InsnList.This method mutates the injectTarget
MethodNode.The callback info will be cancellable.
- Parameters:
injectTarget- The method which is being injected into.usageSiteOutput- An instruction list where the allocation of the instance occurs in, if the allocation did not already occur.- Returns:
- The index from which the callback info instance can be loaded from afterwards.
- Since:
- 0.6.3
-
moveStackHead
public static void moveStackHead(org.objectweb.asm.tree.MethodNode method, @NotNull org.objectweb.asm.tree.AbstractInsnNode beginMoveInsn, @NotNull org.objectweb.asm.tree.AbstractInsnNode endRollbackInsn, @NotNull java.util.List<java.lang.String> headTypes, int uniformDepth, @NotNull org.objectweb.asm.tree.InsnList moveOut, @NotNull org.objectweb.asm.tree.InsnList rollbackOut)Temporarily pop (or hide them deep in the stack) a given amount of operands. This method will attempt to use as few additional local variables as possible, depending on the implementation this may be achieved via annotations or even stack analysis. The method's signature is made in a way to easily change the implementation as needed, so arguments that appear superfluous on the surface ought not be discarded.- Parameters:
method- The method where the instructions belong to. For locals analysis purposes only.beginMoveInsn- The instruction at which the stack has it's original contents. For locals analysis purposes only.endRollbackInsn- The instruction at which the stack should return to it's original constellation. No jump instruction which moves outside beginMoveInsn and this instruction may be between the two instructions. For locals analysis purposes only.headTypes- The type descriptors of the types on the top of the stack. There might be more types a bit more deeply hidden but they are not of relevance.uniformDepth- The amount of operands to pop - category 2 operands count as a single value. May not be larger than the size of headTypes .moveOut- Instructions which "store" the operands of the rollback operation are appended to this insn list.rollbackOut- Instructions which "load" the operands of the rollback operation are prepended (as perInsnList.insert(AbstractInsnNode)) to this insn list.
-
popReturn
public static int popReturn(@NotNull java.lang.String methodDesc)
-
shiftInsn
public static org.objectweb.asm.tree.AbstractInsnNode shiftInsn(org.objectweb.asm.tree.AbstractInsnNode insn, int offset)
-
toOperandDepth
public static int toOperandDepth(java.util.List<java.lang.String> headTypes, int uniformDepth)
-
toUniformDepth
public static int toUniformDepth(java.util.List<java.lang.String> headTypes, int operandDepth)
-
-