Example usage for org.objectweb.asm Opcodes F_SAME

List of usage examples for org.objectweb.asm Opcodes F_SAME

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes F_SAME.

Prototype

int F_SAME

To view the source code for org.objectweb.asm Opcodes F_SAME.

Click Source Link

Document

A compressed frame with exactly the same locals as the previous frame and with an empty stack.

Usage

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.EvaluatorVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if (!METHOD_IDENTIFIER.equals(new MethodIdentifier(name, desc, signature))) {
        return mv;
    }/* w w  w  . j a v a 2s  .c o  m*/
    if (mv != null) {
        return new MethodVisitor(Opcodes.ASM5, mv) {
            private FieldInsnNode fieldAccessNode = null;
            private List<AbstractInsnNode> instructionsAfterFieldAccess = new ArrayList<>();

            @Override
            public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                fieldAccessNode = new FieldInsnNode(opcode, owner, name, desc);
                instructionsAfterFieldAccess.clear();
            }

            @Override
            public void visitIincInsn(int var, int increment) {
                if (fieldAccessNode != null) {
                    instructionsAfterFieldAccess.add(new IincInsnNode(var, increment));
                }
                super.visitIincInsn(var, increment);
            }

            @Override
            public void visitInsn(int opcode) {
                if (fieldAccessNode != null) {
                    instructionsAfterFieldAccess.add(new InsnNode(opcode));
                }
                super.visitInsn(opcode);
            }

            @Override
            public void visitIntInsn(int opcode, int operand) {
                if (fieldAccessNode != null) {
                    instructionsAfterFieldAccess.add(new IntInsnNode(opcode, operand));
                }
                super.visitIntInsn(opcode, operand);
            }

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                mv.visitMethodInsn(opcode, owner, name, desc, itf);
                if (fieldAccessNode == null
                        || !METHOD_IDENTIFIER.equals(new MethodIdentifier(name, desc, signature))) {
                    return;
                }
                // Loads "this".
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                // Replays the field access instruction.
                fieldAccessNode.accept(mv);

                // Replays other instruction between the field access and the evaluator call.
                for (AbstractInsnNode instruction : instructionsAfterFieldAccess) {
                    instruction.accept(mv);
                }

                // Loads the result IPointable.
                mv.visitVarInsn(Opcodes.ALOAD, 2);

                // Invokes the null check method.
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, TYPECHECK_CLASS, IS_NULL, TYPECHECK_METHOD_DESC,
                        false);
                Label notNull = new Label();
                // Adds the if branch.
                mv.visitJumpInsn(Opcodes.IFEQ, notNull);
                mv.visitInsn(Opcodes.RETURN);
                mv.visitLabel(notNull);
                mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
            }
        };
    }
    return null;
}

From source file:org.apache.s4.core.gen.OverloadDispatcherGenerator.java

License:Apache License

private void generateEventDispatchMethod(ClassWriter cw, String dispatchMethodName,
        List<Hierarchy> eventHierarchies, String processEventMethodName) {
    MethodVisitor mv2 = cw.visitMethod(ACC_PUBLIC, dispatchMethodName,
            "(" + Type.getType(ProcessingElement.class).getDescriptor()
                    + Type.getType(Event.class).getDescriptor() + ")V",
            null, null);//  ww  w. j a  va2s.co m
    mv2.visitCode();
    Label l3 = new Label();
    mv2.visitLabel(l3);
    mv2.visitVarInsn(ALOAD, 1);
    mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(targetClass));
    mv2.visitVarInsn(ASTORE, 3);
    boolean first = true;
    Label aroundLabel = new Label();
    for (Hierarchy hierarchy : eventHierarchies) {
        if (first) {
            Label l4 = new Label();
            mv2.visitLabel(l4);
        }
        mv2.visitVarInsn(ALOAD, 2);
        mv2.visitTypeInsn(INSTANCEOF, Type.getInternalName(hierarchy.getTop()));

        Label l5 = new Label();
        mv2.visitJumpInsn(IFEQ, l5);

        Label l6 = new Label();
        mv2.visitLabel(l6);
        mv2.visitVarInsn(ALOAD, 3);
        mv2.visitVarInsn(ALOAD, 2);
        mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(hierarchy.getTop()));
        mv2.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(targetClass), processEventMethodName,
                "(" + Type.getDescriptor(hierarchy.getTop()) + ")V");
        mv2.visitJumpInsn(Opcodes.GOTO, aroundLabel);
        mv2.visitLabel(l5);

        if (first) {
            mv2.visitFrame(F_APPEND, 1, new Object[] { Type.getInternalName(targetClass) }, 0, null);
            first = false;
        } else {
            mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        }
    }
    addErrorLogStatement(mv2);
    if (eventHierarchies.size() > 0) {
        mv2.visitLabel(aroundLabel);
        mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    }
    mv2.visitInsn(RETURN);
    Label l8 = new Label();
    mv2.visitLabel(l8);
    mv2.visitLocalVariable("pe", Type.getDescriptor(ProcessingElement.class), null, l3, l8, 1);
    mv2.visitLocalVariable("event", Type.getDescriptor(Event.class), null, l3, l8, 2);
    mv2.visitLocalVariable("typedPE", Type.getDescriptor(targetClass), null, l3, l8, 3);
    mv2.visitMaxs(4, 4);
    mv2.visitEnd();
}

From source file:org.boretti.drools.integration.drools5.DroolsClassVisitor.java

License:Open Source License

@Override
public void visitEnd() {
    FieldVisitor fv = null;/*w  w  w. j  a v  a2 s. co  m*/
    if (isNeedChangeForBoth()) {
        fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor(), null,
                null);
        if (fv != null) {
            AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
            AnnotationVisitor value = av.visitArray("value");
            value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
            value.visitEnd();
            av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
            av.visitEnd();
            fv.visitEnd();
        }
    }
    if (isNeedChangeForField()) {
        fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_RULE,
                Type.getType(RuleBase.class).getDescriptor(), null, null);
        if (fv != null) {
            AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
            AnnotationVisitor value = av.visitArray("value");
            value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
            value.visitEnd();
            av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
            av.visitEnd();
            fv.visitEnd();
        }
        MethodVisitor mv = super.visitMethod(Opcodes.ACC_PRIVATE, DROOLS_METHOD_RUN, "()V", null, null);
        AnnotationVisitor av = mv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
        AnnotationVisitor value = av.visitArray("value");
        value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
        value.visitEnd();
        av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
        av.visitEnd();
        mv.visitCode();
        Label start = new Label();
        mv.visitLabel(start);
        Label doIt = new Label();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME,
                Type.BOOLEAN_TYPE.getDescriptor());
        mv.visitJumpInsn(Opcodes.IFEQ, doIt);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitLabel(doIt);
        mv.visitFrame(Opcodes.F_SAME, 1, new Object[] { Type.getObjectType(me).getInternalName() }, 0,
                new Object[] {});
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_RULE,
                Type.getType(RuleBase.class).getDescriptor());
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(RuleBase.class).getInternalName(),
                "newStatelessSession", "()Lorg/drools/StatelessSession;");
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn(FIELD_NAME_LOGGER);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(Object.class).getInternalName(), "getClass",
                "()Ljava/lang/Class;");
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(org.apache.log4j.Logger.class).getInternalName(),
                "getLogger", "(Ljava/lang/Class;)Lorg/apache/log4j/Logger;");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(),
                "setGlobal", "(Ljava/lang/String;Ljava/lang/Object;)V");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(),
                "execute", "(Ljava/lang/Object;)V");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitFieldInsn(Opcodes.PUTFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME,
                Type.BOOLEAN_TYPE.getDescriptor());
        mv.visitInsn(Opcodes.RETURN);
        Label end = new Label();
        mv.visitLabel(end);
        mv.visitLocalVariable("this", Type.getObjectType(me).getDescriptor(), null, start, end, 0);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    super.visitEnd();
}

From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java

License:Open Source License

/**
 * Generates:/*from   w  w  w .ja v  a 2  s.c  o  m*/
 *
 * <pre>
 * public Context createConfigurationContext(Configuration configuration) {
 *   // createConfigurationContext does not exist before API level 17.
 *   if (Build.VERSION.SDK_INT < 17) return null;
 *   if (!BuildHooksAndroid.isEnabled()) return super.createConfigurationContext(configuration);
 *   return BuildHooksAndroid.createConfigurationContext(
 *          super.createConfigurationContext(configuration));
 * }
 * </pre>
 * }
 */
private void delegateCreateConfigurationContext() {
    String methodName = "createConfigurationContext";
    String methodDescriptor = TypeUtils.getMethodDescriptor(CONTEXT, CONFIGURATION);
    MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
    mv.visitCode();
    mv.visitFieldInsn(GETSTATIC, "android/os/Build$VERSION", "SDK_INT", INT);
    mv.visitIntInsn(BIPUSH, 17);
    Label l0 = new Label();
    mv.visitJumpInsn(IF_ICMPGE, l0);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNE, l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false);
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName,
            TypeUtils.getMethodDescriptor(CONTEXT, CONTEXT), false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}

From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java

License:Open Source License

/**
 * Generates:// w  ww.j av a  2  s  .  c  o  m
 *
 * <pre>
 * public void setTheme(int theme) {
 *   if (!BuildHooksAndroid.isEnabled()) {
 *     super.setTheme(theme);
 *     return;
 *   }
 *   BuildHooksAndroid.setTheme(this, theme);
 * }
 * </pre>
 */
private void delegateSetTheme() {
    String methodName = "setTheme";
    String methodDescriptor = TypeUtils.getMethodDescriptor(VOID, INT);
    String buildHooksMethodDescriptor = TypeUtils.getMethodDescriptor(VOID, CONTEXT, INT);
    MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
    mv.visitCode();
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false);
    Label l0 = new Label();
    mv.visitJumpInsn(IFNE, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false);
    mv.visitInsn(RETURN);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, buildHooksMethodDescriptor, false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}

From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java

License:Open Source License

/**
 * Generates://  w  ww . j  av  a 2s.  c  o  m
 *
 * <pre>
 * public returnType methodName() {
 *   if (!BuildHooksAndroid.isEnabled()) return super.methodName();
 *   return BuildHooksAndroid.methodName(this);
 * }
 * </pre>
 */
private void delegateGet(String methodName, String returnType) {
    String getMethodDescriptor = TypeUtils.getMethodDescriptor(returnType);
    String buildHooksGetMethodDescriptor = TypeUtils.getMethodDescriptor(returnType, CONTEXT);
    MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, getMethodDescriptor, null, null);
    mv.visitCode();
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false);
    Label l0 = new Label();
    mv.visitJumpInsn(IFNE, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, getMethodDescriptor, false);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, buildHooksGetMethodDescriptor, false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:org.eclipse.core.databinding.pojo.bindable.internal.asm.ClassBindable.java

License:Open Source License

/**
 * Add the implementation of the _bindable_getPropertyChangeSupport method
 * to the class. The result is a method that looks as follows:
 * /*from  w  w w .  j a  v a 2s.  c  o  m*/
 * private PropertyChangeSupport _bindable_getPropertyChangeSupport() { if
 * (_bindable_propertyChangeSupport == null) {
 * this._bindable_propertyChangeSupport = new PropertyChangeSupport( this);
 * } return _bindable_propertyChangeSupport; }
 */
public void addGetPropertyChangeSupport() {

    // private PropertyChangeSupport _bindable_getPropertyChangeSupport()
    MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, PCS_GETTER, "()" + PCS_SIGNATURE, null, null);
    mv.visitCode();

    // if (_bindable_propertyChangeSupport == null)
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, PCS_FIELD, PCS_SIGNATURE);
    Label l0 = new Label();
    mv.visitJumpInsn(IFNONNULL, l0);

    // this._bindable_propertyChangeSupport = new PropertyChangeSupport(
    // this);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, PCS_SHORT_SIGNATURE);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, PCS_SHORT_SIGNATURE, "<init>", "(Ljava/lang/Object;)V");
    mv.visitFieldInsn(PUTFIELD, className, PCS_FIELD, PCS_SIGNATURE);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);

    // return _bindable_propertyChangeSupport;
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, PCS_FIELD, PCS_SIGNATURE);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(4, 1);

}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

/**
 *    public int myMethod(int i)//w  w  w  .  j  a  v a2s .  co  m
   {
 try
 {
    return _sw_prototype_original_myMethod(i)
 }
 finally
 {
    Capturer.enable();
 }
   }
        
 * @param classNode
 * @param className
 * @param methodNode
 */
@SuppressWarnings("unchecked")
private MethodNode wrapMethod(final ClassNode classNode, final String className, final MethodNode methodNode) {
    methodNode.maxStack += 4;

    // create wrapper for original method
    final MethodNode wrappingMethodNode = new MethodNode(methodNode.access, methodNode.name, methodNode.desc,
            methodNode.signature,
            (String[]) methodNode.exceptions.toArray(new String[methodNode.exceptions.size()]));
    wrappingMethodNode.maxStack = methodNode.maxStack;

    // assign annotations to wrapping method
    wrappingMethodNode.visibleAnnotations = methodNode.visibleAnnotations;
    wrappingMethodNode.visibleParameterAnnotations = methodNode.visibleParameterAnnotations;

    // remove annotations from wrapped method to avoid wrong behavior controlled by annotations
    methodNode.visibleAnnotations = null;
    methodNode.visibleParameterAnnotations = null;

    // rename original method
    methodNode.access = TransformerUtil.modifyVisibility(methodNode.access, Opcodes.ACC_PRIVATE);

    final LabelNode l0 = new LabelNode();
    final LabelNode l1 = new LabelNode();
    final LabelNode l2 = new LabelNode();

    final InsnList wInstructions = wrappingMethodNode.instructions;

    if ("<init>".equals(methodNode.name)) {
        // wrap a constructor 

        methodNode.name = WRAP_NAME_PREFIX + "init" + WRAP_NAME_PREFIX;

        // move call to other constructors to new method
        AbstractInsnNode ins = null;
        ListIterator<AbstractInsnNode> iter = methodNode.instructions.iterator();

        int numInvokeSpecials = 0; // number of invokespecial calls before actual constructor call

        while (iter.hasNext()) {
            ins = iter.next();
            iter.remove();
            wInstructions.add(ins);

            if (ins instanceof MethodInsnNode) {
                MethodInsnNode mins = (MethodInsnNode) ins;
                if (ins.getOpcode() == Opcodes.INVOKESPECIAL) {
                    if (mins.name.startsWith("<init>")) {
                        if (numInvokeSpecials == 0) {
                            break;
                        } else {
                            numInvokeSpecials--;
                        }
                    }
                }
            } else if (ins instanceof TypeInsnNode) {
                TypeInsnNode typeIns = (TypeInsnNode) ins;
                if (typeIns.getOpcode() == Opcodes.NEW || typeIns.getOpcode() == Opcodes.NEWARRAY) {
                    numInvokeSpecials++;
                }
            }
        }
    } else {
        methodNode.name = WRAP_NAME_PREFIX + methodNode.name;
    }

    int varReturnValue = 0;

    final Type returnType = Type.getReturnType(methodNode.desc);

    if (returnType.equals(Type.VOID_TYPE)) {
        wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l1, "java/lang/Throwable"));

    } else {

        wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Throwable"));

        //--- create "Object returnValue = null;"

        if (!TransformerUtil.isStatic(methodNode.access)) {
            // load "this"
            varReturnValue++;
        }

        // consider method arguments to find right variable index
        final Type[] argTypes = Type.getArgumentTypes(methodNode.desc);
        for (int i = 0; i < argTypes.length; i++) {
            varReturnValue++;

            // long/double take two registers
            if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) {
                varReturnValue++;
            }
        }

        // push NULL on the stack and initialize variable for return value for it
        wInstructions.add(new InsnNode(Opcodes.ACONST_NULL));
        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue));
    }

    int var = 0;

    // --- L0
    wInstructions.add(l0);

    wInstructions.add(this.addCaptureCall(TransformerUtil.isStatic(methodNode.access), className,
            wrappingMethodNode.name, wrappingMethodNode.desc, Type.getArgumentTypes(methodNode.desc)));

    // --- construct call to wrapped methode

    if (!TransformerUtil.isStatic(methodNode.access)) {
        // load "this" to call method
        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        var++;
    }

    final Type[] argTypes = Type.getArgumentTypes(methodNode.desc);
    for (int i = 0; i < argTypes.length; i++) {
        this.addLoadInsn(wInstructions, argTypes[i], var++);

        // long/double take two registers
        if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) {
            var++;
        }
    }

    if (TransformerUtil.isStatic(methodNode.access)) {
        wInstructions.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name, methodNode.name, methodNode.desc));
    } else {
        wInstructions.add(
                new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classNode.name, methodNode.name, methodNode.desc));
    }

    var++;

    if (returnType.equals(Type.VOID_TYPE)) {
        wInstructions.add(new JumpInsnNode(Opcodes.GOTO, l2));

        // --- L1

        wInstructions.add(l1);

        wInstructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }));

        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, -1);

        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var));
        wInstructions.add(new InsnNode(Opcodes.ATHROW));

        // FIXME <--- DUPLICATE CODE

        // --- L2

        wInstructions.add(l2);
        wInstructions.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, -1);

        wInstructions.add(new InsnNode(Opcodes.RETURN));
    } else {
        // construct store of the wrapped method call's result

        this.addBoxingStmt(wInstructions, returnType);

        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue));
        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, varReturnValue));

        this.addUnBoxingStmt(wInstructions, returnType);

        final int storeOpcode = returnType.getOpcode(Opcodes.ISTORE);
        wInstructions.add(new VarInsnNode(storeOpcode, ++var)); // might be only var

        // --- L1

        wInstructions.add(l1);

        this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue);

        // construct load of the wrapped method call's result
        int loadOpcode = returnType.getOpcode(Opcodes.ILOAD);
        wInstructions.add(new VarInsnNode(loadOpcode, var));

        // construct return of the wrapped method call's result
        this.addReturnInsn(wInstructions, returnType);

        //---- L2

        wInstructions.add(l2);

        wInstructions.add(
                new FrameNode(Opcodes.F_FULL, 2, new Object[] { className, this.getInternalName(returnType) },
                        1, new Object[] { "java/lang/Throwable" }));
        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue);

        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var));
        wInstructions.add(new InsnNode(Opcodes.ATHROW));
    }
    transformWrapperCalls(methodNode);
    return wrappingMethodNode;
}

From source file:org.glassfish.pfl.tf.tools.enhancer.SimpleMethodTracer.java

License:Open Source License

private String getFrameType(int type) {
    switch (type) {
    case Opcodes.F_APPEND:
        return "APPEND";
    case Opcodes.F_CHOP:
        return "CHOP";
    case Opcodes.F_FULL:
        return "FULL";
    case Opcodes.F_NEW:
        return "NEW";
    case Opcodes.F_SAME:
        return "SAME";
    case Opcodes.F_SAME1:
        return "SAME1";
    }//from   www .j  a va2  s.  c  o m
    return "BAD_FRAME_TYPE";
}

From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java

License:Open Source License

@Test(expected = IllegalArgumentException.class)
public void testVisitFrame_invalidType() {
    ProbeInserter pi = new ProbeInserter(0, "()V", actualVisitor, arrayStrategy);
    pi.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
}