public final class Locals
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static int |
computeFrameSize(org.objectweb.asm.tree.FrameNode frameNode)
Compute the size required to accomodate the entries described by the
supplied frame node
|
static java.util.List<org.objectweb.asm.tree.LocalVariableNode> |
generateLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
Use ASM Analyzer to generate the local variable table for the specified
method
|
static java.lang.String |
getFrameTypeName(java.lang.Object frameEntry)
Debug function to return printable name of a frame entry
|
static java.util.List<org.objectweb.asm.tree.LocalVariableNode> |
getGeneratedLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
Gets the generated the local variable table for the specified method.
|
static org.objectweb.asm.tree.LocalVariableNode[] |
getLocalsAt(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode node)
Attempts to identify available locals at an arbitrary point in the
bytecode specified by node.
|
static org.objectweb.asm.tree.LocalVariableNode |
getLocalVariableAt(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode node,
int var)
Attempts to locate the appropriate entry in the local variable table for
the specified local variable index at the location specified by node.
|
static java.util.List<org.objectweb.asm.tree.LocalVariableNode> |
getLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
Fetches or generates the local variable table for the specified method.
|
static void |
loadLocals(org.objectweb.asm.Type[] locals,
org.objectweb.asm.tree.InsnList insns,
int pos,
int limit)
Injects appropriate LOAD opcodes into the supplied InsnList for each
entry in the supplied locals array starting at pos
|
public static void loadLocals(org.objectweb.asm.Type[] locals,
org.objectweb.asm.tree.InsnList insns,
int pos,
int limit)
locals - Local types (can contain nulls for uninitialised, TOP, or
RETURN values in locals)insns - Instruction List to inject intopos - Start positionlimit - maximum number of locals to consumepublic static org.objectweb.asm.tree.LocalVariableNode[] getLocalsAt(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode node)
Attempts to identify available locals at an arbitrary point in the bytecode specified by node.
This method builds an approximate view of the locals available at an arbitrary point in the bytecode by examining the following features in the bytecode:
Inference proceeds by walking the bytecode from the start of the method looking for stack frames and STORE opcodes. When either of these is encountered, an attempt is made to cross-reference the values in the stack map or STORE opcode with the value in the local variable table which covers the code range. Stack map frames overwrite the entire simulated local variable table with their own value types, STORE opcodes overwrite only the local slot to which they pertain. Values in the simulated locals array are spaced according to their size (unlike the representation in FrameNode) and this TOP, NULL and UNINTITIALIZED_THIS opcodes will be represented as null values in the simulated frame.
This code does not currently simulate the prescribed JVM behaviour where overwriting the second slot of a DOUBLE or LONG actually invalidates the DOUBLE or LONG stored in the previous location, so we have to hope (for now) that this behaviour isn't emitted by the compiler or any upstream transformers. I may have to re-think this strategy if this situation is encountered in the wild.
classNode - ClassNode containing the method, used to initialise the
implicit "this" reference in simple methods with no stack framesmethod - MethodNode to explorenode - Node indicating the position at which to determine the locals
state. The locals will be enumerated UP TO the specified node, so
bear in mind that if the specified node is itself a STORE opcode,
then we will be looking at the state of the locals PRIOR to its
invocationpublic static org.objectweb.asm.tree.LocalVariableNode getLocalVariableAt(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode node,
int var)
classNode - Containing classmethod - Methodnode - Instruction defining the location to get the local variable
table atvar - Local variable indexpublic static java.util.List<org.objectweb.asm.tree.LocalVariableNode> getLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
classNode - Containing classmethod - Methodpublic static java.util.List<org.objectweb.asm.tree.LocalVariableNode> getGeneratedLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
classNode - Containing classmethod - Methodpublic static java.util.List<org.objectweb.asm.tree.LocalVariableNode> generateLocalVariableTable(org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
classNode - Containing classmethod - Methodpublic static int computeFrameSize(org.objectweb.asm.tree.FrameNode frameNode)
frameNode - frame node with locals to computepublic static java.lang.String getFrameTypeName(java.lang.Object frameEntry)
frameEntry - Frame entry