Class ArgumentTypeAnalyzer


  • public class ArgumentTypeAnalyzer
    extends Object
    Static helpers for classifying invoke-instruction arguments by how they are produced.
    • Constructor Detail

      • ArgumentTypeAnalyzer

        public ArgumentTypeAnalyzer()
    • Method Detail

      • isInvokeInstruction

        public static boolean isInvokeInstruction​(Instruction instr)
        Parameters:
        instr - the instruction to test
        Returns:
        true for any of the five invoke opcodes
      • getArgumentCount

        public static int getArgumentCount​(Instruction invokeInstr)
        Counts the declared arguments of an invoke, receiver excluded.
        Parameters:
        invokeInstr - the invoke instruction
        Returns:
        the argument count, 0 if the descriptor cannot be resolved
      • countDescriptorArguments

        public static int countDescriptorArguments​(String desc)
        Counts the parameters in a method descriptor, treating an array and its element as one parameter.
        Parameters:
        desc - the method descriptor
        Returns:
        the parameter count, 0 if the descriptor is null or does not start with '('
      • findArgumentProducer

        public static Instruction findArgumentProducer​(CodeWriter codeWriter,
                                                       int invokeIndex,
                                                       int argIndex,
                                                       int totalArgs,
                                                       Instruction invokeInstr)
        Walks backwards from an invoke, tracking stack depth, to find the instruction that pushed one of its arguments.
        Parameters:
        codeWriter - the body being scanned
        invokeIndex - index of the invoke instruction
        argIndex - the argument position to trace
        totalArgs - the invoke's argument count
        invokeInstr - the invoke instruction, used for slot widths
        Returns:
        the producing instruction, or null if none was reached
      • getDescriptor

        public static String getDescriptor​(Instruction invokeInstr)
        Reads the callee descriptor off an invoke; for invokedynamic the descriptor is cut out of the resolved call site signature.
        Parameters:
        invokeInstr - the invoke instruction
        Returns:
        the method descriptor, or null if the instruction is not an invoke
      • classifyInstruction

        public static ArgumentType classifyInstruction​(Instruction instr)
        Buckets a producing instruction into the argument kind a query matches on.
        Parameters:
        instr - the instruction that produced the value
        Returns:
        LITERAL, FIELD, LOCAL, CALL, DYNAMIC, or ANY when nothing matches