Class OperandStackStateGenerators

java.lang.Object
com.offbynull.coroutines.instrumenter.OperandStackStateGenerators

final class OperandStackStateGenerators extends Object
Utility class to generate bytecode instructions that save/load the operand stack.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OperandStackStateGenerators

      private OperandStackStateGenerators()
  • Method Details

    • 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 calling loadOperandStack(markerType, storageVars, frame, 0, 0, frame.getStackSize()).
      Parameters:
      markerType - debug marker type
      storageVars - variables to load operand stack from
      frame - 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:
      NullPointerException - if any argument is null
    • 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 type
      storageVars - variables to load operand stack from
      frame - execution frame at the instruction where the operand stack is to be loaded
      storageStackStartIdx - stack position where storageVars starts from
      storageStackLoadIdx - stack position where loading should start from
      count - number of stack items to load
      Returns:
      instructions to load the operand stack from the specified storage variables
      Throws:
      NullPointerException - if any argument is null
      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 before storageStackStartIdx), or if you're trying to load too many items on the stack (such that it goes past frame.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 calling saveOperandStack(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 type
      storageVars - variables to store operand stack in to
      frame - 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:
      NullPointerException - if any argument is null
    • 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 type
      storageVars - variables to store operand stack in to
      frame - execution frame at the instruction where the operand stack is to be saved
      count - number of items to store from the stack
      Returns:
      instructions to save the operand stack to the storage variables
      Throws:
      NullPointerException - if any argument is null
      IllegalArgumentException - if size is larger than the number of items in the stack at frame (or is negative), or if count is larger than top (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 for
      offset - the position within the operand stack to start calculating
      length - the number of stack items to include in calculation
      Returns:
      size required by each storage array
      Throws:
      NullPointerException - if any argument is null
      IllegalArgumentException - if any numeric argument is negative, or if offset + length is larger than the size of the operand stack