Class OperandStackStateGenerators
- java.lang.Object
-
- com.offbynull.coroutines.instrumenter.OperandStackStateGenerators
-
final class OperandStackStateGenerators extends java.lang.Object
Utility class to generate bytecode instructions that save/load the operand stack.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
OperandStackStateGenerators()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StorageSizes
computeSizes(org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int offset, int length)
Compute sizes required for the storage arrays that will contain the operand stack at this frame.static org.objectweb.asm.tree.InsnList
loadOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame)
Generates instructions to load the entire operand stack.static org.objectweb.asm.tree.InsnList
loadOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int storageStackStartIdx, int storageStackLoadIdx, int count)
Generates instructions to load a certain number of items to the top of the operand stack.static org.objectweb.asm.tree.InsnList
saveOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame)
Generates instructions to save the entire operand stack.static org.objectweb.asm.tree.InsnList
saveOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int count)
Generates instructions to save a certain number of items from the top of the operand stack.
-
-
-
Method Detail
-
loadOperandStack
public static org.objectweb.asm.tree.InsnList loadOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame)
Generates instructions to load the entire operand stack. Equivalent to callingloadOperandStack(markerType, storageVars, frame, 0, 0, frame.getStackSize())
.- Parameters:
markerType
- debug marker typestorageVars
- variables to load operand stack fromframe
- execution frame at the instruction where the operand stack is to be loaded- Returns:
- instructions to load the operand stack from the storage variables
- Throws:
java.lang.NullPointerException
- if any argument isnull
-
loadOperandStack
public static org.objectweb.asm.tree.InsnList loadOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int storageStackStartIdx, int storageStackLoadIdx, int count)
Generates instructions to load a certain number of items to the top of the operand stack.- Parameters:
markerType
- debug marker typestorageVars
- variables to load operand stack fromframe
- execution frame at the instruction where the operand stack is to be loadedstorageStackStartIdx
- stack position wherestorageVars
starts fromstorageStackLoadIdx
- stack position where loading should start fromcount
- number of stack items to load- Returns:
- instructions to load the operand stack from the specified storage variables
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- if any numeric argument is negative, or if you're trying to load stack items that aren't available in the storage vars (stack items beforestorageStackStartIdx
), or if you're trying to load too many items on the stack (such that it goes pastframe.getStackSize()
)
-
saveOperandStack
public static org.objectweb.asm.tree.InsnList saveOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame)
Generates instructions to save the entire operand stack. Equivalent to callingsaveOperandStack(markerType, storageVars, frame, frame.getStackSize())
.The instructions generated here expect the operand stack to be fully loaded. The stack items specified by
frame
must actually all be on the operand stack.REMEMBER: The items aren't returned to the operand stack after they've been saved (they have been popped off the stack). If you want them back on the operand stack, reload using
loadOperandStack(markerType, storageVars, frame)
.- Parameters:
markerType
- debug marker typestorageVars
- variables to store operand stack in toframe
- execution frame at the instruction where the operand stack is to be saved- Returns:
- instructions to save the operand stack to the storage variables
- Throws:
java.lang.NullPointerException
- if any argument isnull
-
saveOperandStack
public static org.objectweb.asm.tree.InsnList saveOperandStack(DebugGenerators.MarkerType markerType, StorageVariables storageVars, org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int count)
Generates instructions to save a certain number of items from the top of the operand stack.The instructions generated here expect the operand stack to be fully loaded. The stack items specified by
frame
must actually all be on the operand stack.REMEMBER: The items aren't returned to the operand stack after they've been saved (they have been popped off the stack). If you want them back on the operand stack, reload using
loadOperandStack(markerType, storageVars, frame, frame.getStackSize() - count, frame.getStackSize() - count, count)
.- Parameters:
markerType
- debug marker typestorageVars
- variables to store operand stack in toframe
- execution frame at the instruction where the operand stack is to be savedcount
- number of items to store from the stack- Returns:
- instructions to save the operand stack to the storage variables
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- ifsize
is larger than the number of items in the stack atframe
(or is negative), or ifcount
is larger thantop
(or is negative)
-
computeSizes
public static StorageSizes computeSizes(org.objectweb.asm.tree.analysis.Frame<org.objectweb.asm.tree.analysis.BasicValue> frame, int offset, int length)
Compute sizes required for the storage arrays that will contain the operand stack at this frame.- Parameters:
frame
- frame to compute foroffset
- the position within the operand stack to start calculatinglength
- the number of stack items to include in calculation- Returns:
- size required by each storage array
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- if any numeric argument is negative, or ifoffset + length
is larger than the size of the operand stack
-
-