Search in sources :

Example 1 with InterceptorType

use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType in project pinpoint by naver.

the class ASMMethodVariables method initInterceptorLocalVariables.

public boolean initInterceptorLocalVariables(final InsnList instructions, final int interceptorId, final InterceptorDefinition interceptorDefinition, final int apiId) {
    if (this.initializedInterceptorLocalVariables) {
        return false;
    }
    this.initializedInterceptorLocalVariables = true;
    // find enter & exit instruction.
    if (isConstructor()) {
        this.enterInsnNode = findInitConstructorInstruction();
    } else {
        this.enterInsnNode = methodNode.instructions.getFirst();
    }
    if (this.enterInsnNode == null) {
        throw new IllegalStateException("not found enter code. " + declaringClassInternalName + "/" + methodNode.name + methodNode.desc);
    }
    this.exitInsnNode = methodNode.instructions.getLast();
    // setup interceptor variables start/end label.
    this.methodNode.instructions.insertBefore(this.enterInsnNode, this.interceptorVariableStartLabelNode);
    this.methodNode.instructions.insert(this.exitInsnNode, this.interceptorVariableEndLabelNode);
    // initialize interceptor variable.
    initInterceptorVar(instructions, interceptorId);
    // initialize argument variable.
    final InterceptorType interceptorType = interceptorDefinition.getInterceptorType();
    if (interceptorType == InterceptorType.ARRAY_ARGS) {
        // Object target, Object[] args
        initArgsVar(instructions);
    } else if (interceptorType == InterceptorType.STATIC) {
        // Object target, String declaringClassInternalName, String methodName, String parameterDescription, Object[] args
        initClassNameVar(instructions);
        initMethodNameVar(instructions);
        initParameterDescriptionVar(instructions);
        initArgsVar(instructions);
    } else if (interceptorType == InterceptorType.API_ID_AWARE) {
        // Object target, int apiId, Object[] args
        initApiIdVar(apiId, instructions);
        initArgsVar(instructions);
    } else if (interceptorType == InterceptorType.BASIC) {
        int interceptorMethodParameterCount = getInterceptorParameterCount(interceptorDefinition);
        final int methodParameterCount = this.argumentTypes.length;
        final int argumentCount = Math.min(methodParameterCount, interceptorMethodParameterCount);
        for (int i = 1; i <= argumentCount; i++) {
            // Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4
            if (i == 1) {
                initArg0Var(instructions);
            } else if (i == 2) {
                initArg1Var(instructions);
            } else if (i == 3) {
                initArg2Var(instructions);
            } else if (i == 4) {
                initArg3Var(instructions);
            } else if (i == 5) {
                initArg4Var(instructions);
            }
        }
    }
    return true;
}
Also used : InterceptorType(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType)

Example 2 with InterceptorType

use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType in project pinpoint by naver.

the class ASMMethodVariables method loadInterceptorLocalVariables.

public void loadInterceptorLocalVariables(final InsnList instructions, final InterceptorDefinition interceptorDefinition, final boolean after) {
    assertInitializedInterceptorLocalVariables();
    loadVar(instructions, this.interceptorVarIndex);
    instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(interceptorDefinition.getInterceptorBaseClass())));
    // target(this) object.
    loadThis(instructions);
    final InterceptorType interceptorType = interceptorDefinition.getInterceptorType();
    if (interceptorType == InterceptorType.ARRAY_ARGS) {
        // Object target, Object[] args
        loadVar(instructions, this.argsVarIndex);
    } else if (interceptorType == InterceptorType.STATIC) {
        // Object target, String declaringClassInternalName, String methodName, String parameterDescription, Object[] args
        loadVar(instructions, this.classNameVarIndex);
        loadVar(instructions, this.methodNameVarIndex);
        loadVar(instructions, this.parameterDescriptionVarIndex);
        loadVar(instructions, this.argsVarIndex);
    } else if (interceptorType == InterceptorType.API_ID_AWARE) {
        // Object target, int apiId, Object[] args
        loadInt(instructions, this.apiIdVarIndex);
        loadVar(instructions, this.argsVarIndex);
    } else if (interceptorType == InterceptorType.BASIC) {
        int interceptorMethodParameterCount = getInterceptorParameterCount(interceptorDefinition);
        int argumentCount = Math.min(this.argumentTypes.length, interceptorMethodParameterCount);
        int i = 1;
        for (; i <= argumentCount; i++) {
            // Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4
            if (i == 1)
                loadVar(instructions, this.arg0VarIndex);
            else if (i == 2)
                loadVar(instructions, this.arg1VarIndex);
            else if (i == 3)
                loadVar(instructions, this.arg2VarIndex);
            else if (i == 4)
                loadVar(instructions, this.arg3VarIndex);
            else if (i == 5)
                loadVar(instructions, this.arg4VarIndex);
            else
                loadNull(instructions);
        }
        for (; i <= interceptorMethodParameterCount; i++) {
            loadNull(instructions);
        }
    }
    if (after) {
        loadVar(instructions, this.resultVarIndex);
        loadVar(instructions, this.throwableVarIndex);
    }
}
Also used : TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) InterceptorType(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType)

Aggregations

InterceptorType (com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType)2 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)1