Example usage for org.objectweb.asm.commons Method getName

List of usage examples for org.objectweb.asm.commons Method getName

Introduction

In this page you can find the example usage for org.objectweb.asm.commons Method getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the method described by this object.

Usage

From source file:org.glowroot.agent.weaving.WeavingMethodVisitor.java

License:Apache License

private void invokeOnBefore(Advice advice, @Nullable Integer travelerLocal) {
    Method onBeforeAdvice = advice.onBeforeAdvice();
    if (onBeforeAdvice == null) {
        return;/*from  w  ww. ja v a  2 s  .  c o m*/
    }
    Integer enabledLocal = enabledLocals.get(advice);
    Label onBeforeBlockEnd = null;
    if (enabledLocal != null) {
        onBeforeBlockEnd = new Label();
        loadLocal(enabledLocal);
        visitJumpInsn(IFEQ, onBeforeBlockEnd);
    }
    loadMethodParameters(advice.onBeforeParameters(), 0, -1, advice.adviceType(), OnBefore.class, false);
    visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onBeforeAdvice.getName(),
            onBeforeAdvice.getDescriptor(), false);
    if (travelerLocal != null) {
        storeLocal(travelerLocal);
    }
    String nestingGroup = advice.pointcut().nestingGroup();
    if (advice.hasBindOptionalThreadContext() && !nestingGroup.isEmpty()) {
        // need to check if transaction was just started in @OnBefore and update its
        // currentNestingGroupId

        Integer prevNestingGroupIdLocal = prevNestingGroupIdLocals.get(advice);
        checkNotNull(prevNestingGroupIdLocal);
        loadLocal(prevNestingGroupIdLocal);
        visitIntInsn(BIPUSH, -1);
        Label label = new Label();
        visitJumpInsn(IF_ICMPNE, label);
        // the only reason prevNestingGroupId is -1 here is because no thread context at the
        // start of the method
        checkNotNull(threadContextLocal);
        loadLocal(threadContextLocal);
        visitMethodInsn(INVOKEINTERFACE, threadContextPlusType.getInternalName(), "getCurrentNestingGroupId",
                "()I", true);
        storeLocal(prevNestingGroupIdLocal);
        loadLocal(threadContextLocal);
        int nestingGroupId = getNestingGroupId(nestingGroup);
        visitIntInsn(BIPUSH, nestingGroupId);
        visitMethodInsn(INVOKEINTERFACE, threadContextPlusType.getInternalName(), "setCurrentNestingGroupId",
                "(I)V", true);
        visitLabel(label);
    }
    if (onBeforeBlockEnd != null) {
        visitLabel(onBeforeBlockEnd);
    }
}

From source file:org.glowroot.agent.weaving.WeavingMethodVisitor.java

License:Apache License

private void weaveOnReturnAdvice(int opcode, Advice advice, Method onReturnAdvice) {
    boolean leaveReturnValueOnStack = onReturnAdvice.getReturnType().getSort() == Type.VOID;
    if (onReturnAdvice.getArgumentTypes().length > 0) {
        // @BindReturn must be the first argument to @OnReturn (if present)
        int startIndex = 0;
        AdviceParameter parameter = advice.onReturnParameters().get(0);
        switch (parameter.kind()) {
        case RETURN:
            loadNonOptionalReturnValue(opcode, parameter, leaveReturnValueOnStack);
            startIndex = 1;/*from   ww w  .j a v a  2s .com*/
            break;
        case OPTIONAL_RETURN:
            loadOptionalReturnValue(opcode, leaveReturnValueOnStack);
            startIndex = 1;
            break;
        default:
            // first argument is not @BindReturn
            break;
        }
        loadMethodParameters(advice.onReturnParameters(), startIndex, travelerLocals.get(advice),
                advice.adviceType(), OnReturn.class, true);
    }
    visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onReturnAdvice.getName(),
            onReturnAdvice.getDescriptor(), false);
}

From source file:org.glowroot.agent.weaving.WeavingMethodVisitor.java

License:Apache License

private void visitOnThrowAdvice(Advice advice) {
    Method onThrowAdvice = advice.onThrowAdvice();
    if (onThrowAdvice == null) {
        return;//from  w  w  w.ja  va 2  s. co  m
    }
    Integer enabledLocal = enabledLocals.get(advice);
    Label onThrowBlockEnd = null;
    if (enabledLocal != null) {
        onThrowBlockEnd = new Label();
        loadLocal(enabledLocal);
        visitJumpInsn(IFEQ, onThrowBlockEnd);
    }
    if (onThrowAdvice.getArgumentTypes().length == 0) {
        visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onThrowAdvice.getName(),
                onThrowAdvice.getDescriptor(), false);
    } else {
        int startIndex = 0;
        if (advice.onThrowParameters().get(0).kind() == ParameterKind.THROWABLE) {
            // @BindThrowable must be the first argument to @OnThrow (if present)
            visitInsn(DUP);
            startIndex++;
        }
        loadMethodParameters(advice.onThrowParameters(), startIndex, travelerLocals.get(advice),
                advice.adviceType(), OnThrow.class, true);
        visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onThrowAdvice.getName(),
                onThrowAdvice.getDescriptor(), false);
    }
    if (onThrowBlockEnd != null) {
        visitLabel(onThrowBlockEnd);
    }
}

From source file:org.glowroot.agent.weaving.WeavingMethodVisitor.java

License:Apache License

private void visitOnAfterAdvice(Advice advice) {
    Method onAfterAdvice = advice.onAfterAdvice();
    if (onAfterAdvice == null) {
        return;//w  w w.  j  a va 2 s .com
    }
    Integer enabledLocal = enabledLocals.get(advice);
    Label onAfterBlockEnd = null;
    if (enabledLocal != null) {
        onAfterBlockEnd = new Label();
        loadLocal(enabledLocal);
        visitJumpInsn(IFEQ, onAfterBlockEnd);
    }
    loadMethodParameters(advice.onAfterParameters(), 0, travelerLocals.get(advice), advice.adviceType(),
            OnAfter.class, true);
    visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onAfterAdvice.getName(),
            onAfterAdvice.getDescriptor(), false);
    if (onAfterBlockEnd != null) {
        visitLabel(onAfterBlockEnd);
    }
}

From source file:org.glowroot.weaving.WeavingClassVisitor.java

License:Apache License

@RequiresNonNull("type")
private void addShim(ShimType shimType) {
    for (java.lang.reflect.Method reflectMethod : shimType.shimMethods()) {
        Method method = Method.getMethod(reflectMethod);
        Shim shim = reflectMethod.getAnnotation(Shim.class);
        checkNotNull(shim);/* w w  w  .java2 s .  c  om*/
        Method targetMethod = Method.getMethod(shim.value());
        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, method.getName(), method.getDescriptor(), null, null);
        checkNotNull(mv);
        mv.visitCode();
        int i = 0;
        mv.visitVarInsn(ALOAD, i++);
        for (Type argumentType : method.getArgumentTypes()) {
            mv.visitVarInsn(argumentType.getOpcode(ILOAD), i++);
        }
        mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), targetMethod.getName(),
                targetMethod.getDescriptor(), false);
        mv.visitInsn(method.getReturnType().getOpcode(IRETURN));
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
}

From source file:org.glowroot.weaving.WeavingMethodVisitor.java

License:Apache License

private void defineAndEvaluateEnabledLocalVar(Advice advice) {
    Integer enabledLocal = null;/*from   www . j ava  2 s.c  o  m*/
    Method isEnabledAdvice = advice.isEnabledAdvice();
    if (isEnabledAdvice != null) {
        loadMethodParameters(advice.isEnabledParameters(), 0, -1, advice.adviceType(), IsEnabled.class, false);
        visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), isEnabledAdvice.getName(),
                isEnabledAdvice.getDescriptor(), false);
        enabledLocal = newLocal(Type.BOOLEAN_TYPE);
        enabledLocals.put(advice, enabledLocal);
        storeLocal(enabledLocal);
    }
    if (advice.pointcut().ignoreSelfNested()) {
        // originalAdviceFlowLocal must be defined/initialized outside of any code branches
        // since it is referenced later on in resetAdviceFlowIfNecessary()
        int adviceFlowHolderLocal = newLocal(adviceFlowHolderType);
        adviceFlowHolderLocals.put(advice, adviceFlowHolderLocal);
        visitInsn(ACONST_NULL);
        storeLocal(adviceFlowHolderLocal);

        int originalAdviceFlowLocal = newLocal(Type.BOOLEAN_TYPE);
        originalAdviceFlowLocals.put(advice, originalAdviceFlowLocal);
        visitInsn(ICONST_0);
        storeLocal(originalAdviceFlowLocal);

        Label setAdviceFlowBlockEnd = new Label();
        if (enabledLocal != null) {
            loadLocal(enabledLocal);
            visitJumpInsn(IFEQ, setAdviceFlowBlockEnd);
        } else {
            enabledLocal = newLocal(Type.BOOLEAN_TYPE);
            enabledLocals.put(advice, enabledLocal);
            // temporary initial value to help with Java 7 stack frames
            visitInsn(ICONST_0);
            storeLocal(enabledLocal);
        }
        visitFieldInsn(GETSTATIC, advice.adviceType().getInternalName(), "glowroot$advice$flow$outer$holder",
                adviceFlowOuterHolderType.getDescriptor());
        visitMethodInsn(INVOKEVIRTUAL, adviceFlowOuterHolderType.getInternalName(), "getInnerHolder",
                "()" + adviceFlowHolderType.getDescriptor(), false);
        visitInsn(DUP);
        storeLocal(adviceFlowHolderLocal);
        visitMethodInsn(INVOKEVIRTUAL, adviceFlowHolderType.getInternalName(), "isTop", "()Z", false);
        Label isTopBlockStart = new Label();
        visitInsn(DUP);
        storeLocal(originalAdviceFlowLocal);
        visitJumpInsn(IFNE, isTopBlockStart);
        // !isTop()
        visitInsn(ICONST_0);
        storeLocal(enabledLocal);
        visitJumpInsn(GOTO, setAdviceFlowBlockEnd);
        // enabled
        visitLabel(isTopBlockStart);
        loadLocal(adviceFlowHolderLocal);
        visitInsn(ICONST_0);
        // note that setTop() is only called if enabled is true, so it only needs to be reset
        // at the end of the advice if enabled is true
        visitMethodInsn(INVOKEVIRTUAL, adviceFlowHolderType.getInternalName(), "setTop", "(Z)V", false);
        visitInsn(ICONST_1);
        storeLocal(enabledLocal);
        visitLabel(setAdviceFlowBlockEnd);
    }
}

From source file:org.glowroot.weaving.WeavingMethodVisitor.java

License:Apache License

private void invokeOnBefore(Advice advice, @Nullable Integer travelerLocal) {
    Method onBeforeAdvice = advice.onBeforeAdvice();
    if (onBeforeAdvice == null) {
        return;// w  w  w. jav  a 2 s .  c  o  m
    }
    Integer enabledLocal = enabledLocals.get(advice);
    Label onBeforeBlockEnd = null;
    if (enabledLocal != null) {
        onBeforeBlockEnd = new Label();
        loadLocal(enabledLocal);
        visitJumpInsn(IFEQ, onBeforeBlockEnd);
    }
    loadMethodParameters(advice.onBeforeParameters(), 0, -1, advice.adviceType(), OnBefore.class, false);
    visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onBeforeAdvice.getName(),
            onBeforeAdvice.getDescriptor(), false);
    if (travelerLocal != null) {
        storeLocal(travelerLocal);
    }
    if (onBeforeBlockEnd != null) {
        visitLabel(onBeforeBlockEnd);
    }
}

From source file:org.glowroot.weaving.WeavingMethodVisitor.java

License:Apache License

private void visitOnThrowAdvice() {
    for (Advice advice : Lists.reverse(advisors)) {
        Method onThrowAdvice = advice.onThrowAdvice();
        if (onThrowAdvice == null) {
            continue;
        }//w  ww.  j a  va  2s. c o  m
        Integer enabledLocal = enabledLocals.get(advice);
        Label onThrowBlockEnd = null;
        if (enabledLocal != null) {
            onThrowBlockEnd = new Label();
            loadLocal(enabledLocal);
            visitJumpInsn(IFEQ, onThrowBlockEnd);
        }
        if (onThrowAdvice.getArgumentTypes().length == 0) {
            visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onThrowAdvice.getName(),
                    onThrowAdvice.getDescriptor(), false);
        } else {
            int startIndex = 0;
            if (advice.onThrowParameters().get(0).kind() == ParameterKind.THROWABLE) {
                // @BindThrowable must be the first argument to @OnThrow (if present)
                visitInsn(DUP);
                startIndex++;
            }
            loadMethodParameters(advice.onThrowParameters(), startIndex, travelerLocals.get(advice),
                    advice.adviceType(), OnThrow.class, true);
            visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onThrowAdvice.getName(),
                    onThrowAdvice.getDescriptor(), false);
        }
        if (onThrowBlockEnd != null) {
            visitLabel(onThrowBlockEnd);
        }
    }
}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates an invoke method instruction.
 *
 * @param opcode the instruction's opcode.
 * @param type the class in which the method is defined.
 * @param method the method to be invoked.
 *//*from ww w  . jav  a  2 s .  c  o m*/
private void invokeInsn(final int opcode, final Type type, final Method method) {
    String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName();
    visitMethodInsn(opcode, owner, method.getName(), method.getDescriptor());
}

From source file:org.kjots.json.object.ClassVisitor.java

License:Apache License

/**
 * Visit a method./*from   w w  w .  j av  a2s . c  o m*/
 * <p>
 * This is a convenience method that is equivalent to the following:
 * <pre>
 *   visitMethod(access, method.getName(), method.getDescriptor(), signature, exceptions))
 * </pre>
 * <p>
 * This method will add the given method to set of implemented methods.
 *
 * @param access The access flags.
 * @param method The method.
 * @param signature The signature.
 * @param exceptions The exception.
 * @return The method visitor.
 * @see org.objectweb.asm.ClassVisitor#visitMethod(int, String, String, String, String[])
 */
public MethodVisitor visitMethod(int access, Method method, String signature, String[] exceptions) {
    MethodVisitor methodVisitor = new MethodVisitor(this.asmClassVisitor.visitMethod(access, method.getName(),
            method.getDescriptor(), signature, exceptions));

    this.implementedMethods.add(method);

    return methodVisitor;
}