Class BeforeStringInvoke


  • public class BeforeStringInvoke
    extends BeforeInvoke

    Like BeforeInvoke, this injection point searches for INVOKEVIRTUAL, INVOKESTATIC and INVOKESPECIAL opcodes matching its arguments and returns a list of insns immediately prior to matching instructions. This specialised version however only matches methods which accept a single string and return void, but allows the string itself to be matched as part of the search process. This is primarily used for matching particular invocations of Profiler::startSection with a specific argument. Note that because a string literal is required, this injection point can not be used to match invocations where the value being passed in is a variable.

    To be precise, this injection point matches invocations of the specified method which are preceded by an LDC instruction. The LDC instruction's payload can be specified with the ldc named argument (see below)

    The following parameters from At are accepted

    target
    A Target Selector which identifies the target method, the method must be specified with a signature which accepts a single string and returns void, eg. (Ljava/lang/String;)V
    ordinal
    The ordinal position of the method invocation to match. For example if the method is invoked 3 times and you want to match the 3rd then you can specify an ordinal of 2 (ordinals are zero-indexed). The default value is -1 which supresses ordinal matching
    named argument: ldc
    The value of the LDC node to look for prior to the method invocation

    Example:

       @At(value = "INVOKE_STRING",
          target="startSection(Ljava/lang/String;)V", args = { "ldc=root" })

    Notice the use of the named argument "ldc" which specifies the value of the target LDC node.

    Note that like all standard injection points, this class matches the insn itself, putting the injection point immediately before the access in question. Use shift specifier to adjust the matched opcode as necessary.

    • Method Detail

      • find

        public boolean find​(java.lang.String desc,
                            org.objectweb.asm.tree.InsnList insns,
                            java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)
        Description copied from class: InjectionPoint
        Find injection points in the supplied insn list
        Overrides:
        find in class BeforeInvoke
        Parameters:
        desc - Method descriptor, supplied to allow return types and arguments etc. to be determined
        insns - Insn list to search in, the strategy MUST ONLY add nodes from this list to the nodes collection
        nodes - Collection of nodes to populate. Injectors should NOT make any assumptions about the state of this collection and should only call the add() method
        Returns:
        true if one or more injection points were found
      • inspectInsn

        protected void inspectInsn​(java.lang.String desc,
                                   org.objectweb.asm.tree.InsnList insns,
                                   org.objectweb.asm.tree.AbstractInsnNode insn)
        Overrides:
        inspectInsn in class BeforeInvoke