Example usage for org.objectweb.asm MethodVisitor visitLabel

List of usage examples for org.objectweb.asm MethodVisitor visitLabel

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitLabel.

Prototype

public void visitLabel(final Label label) 

Source Link

Document

Visits a label.

Usage

From source file:org.codehaus.aspectwerkz.transform.inlining.compiler.AbstractJoinPointCompiler.java

License:Open Source License

/**
 * Creates invocations fo the after finally interceptors.
 *
 * @param cv/*from w w  w .ja v a2s  . com*/
 * @param joinPointInstanceIndex
 * @param registerDepth
 */
private void createAfterInterceptorInvocations(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int registerDepth) {
    final int loopIndex = registerDepth + 1;
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, NR_OF_AFTER_INTERCEPTORS_FIELD_NAME, I);
    cv.visitInsn(ICONST_1);
    cv.visitInsn(ISUB);
    cv.visitVarInsn(ISTORE, loopIndex);
    Label loopLabel1 = new Label();
    cv.visitLabel(loopLabel1);
    cv.visitVarInsn(ILOAD, loopIndex);
    Label loopLabel2 = new Label();
    cv.visitJumpInsn(IFLT, loopLabel2);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_INTERCEPTORS_FIELD_NAME,
            AFTER_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitVarInsn(ILOAD, loopIndex);
    cv.visitInsn(AALOAD);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitMethodInsn(INVOKEINTERFACE, AFTER_ADVICE_CLASS_NAME, INTERCEPT_INVOKE_METHOD_NAME,
            AFTER_ADVICE_INVOKE_METHOD_SIGNATURE);
    cv.visitIincInsn(loopIndex, -1);
    cv.visitJumpInsn(GOTO, loopLabel1);
    cv.visitLabel(loopLabel2);
}

From source file:org.codehaus.aspectwerkz.transform.inlining.compiler.AbstractJoinPointCompiler.java

License:Open Source License

/**
 * Creates invocations fo the after returning interceptors.
 *
 * @param cv//from  w w  w.  jav  a  2s .  c  o  m
 * @param joinPointInstanceIndex
 * @param returnValueInstanceIndex
 */
private void createAfterReturningInterceptorInvocations(final MethodVisitor cv,
        final int joinPointInstanceIndex, final int returnValueInstanceIndex) {
    final int loopIndex = returnValueInstanceIndex + 1;
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, NR_OF_AFTER_RETURNING_INTERCEPTORS_FIELD_NAME, I);
    cv.visitInsn(ICONST_1);
    cv.visitInsn(ISUB);
    cv.visitVarInsn(ISTORE, loopIndex);
    Label loopLabel1 = new Label();
    cv.visitLabel(loopLabel1);
    cv.visitVarInsn(ILOAD, loopIndex);
    Label loopLabel2 = new Label();
    cv.visitJumpInsn(IFLT, loopLabel2);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_RETURNING_INTERCEPTORS_FIELD_NAME,
            AFTER_RETURNING_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitVarInsn(ILOAD, loopIndex);
    cv.visitInsn(AALOAD);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, returnValueInstanceIndex);
    cv.visitMethodInsn(INVOKEINTERFACE, AFTER_RETURNING_ADVICE_CLASS_NAME, INTERCEPT_INVOKE_METHOD_NAME,
            AFTER_RETURNING_ADVICE_INVOKE_METHOD_SIGNATURE);
    cv.visitIincInsn(loopIndex, -1);
    cv.visitJumpInsn(GOTO, loopLabel1);
    cv.visitLabel(loopLabel2);
}

From source file:org.codehaus.aspectwerkz.transform.inlining.compiler.AbstractJoinPointCompiler.java

License:Open Source License

/**
 * Creates invocations fo the after returning interceptors.
 *
 * @param cv//from  w ww  .j a  v a2 s  .  c  o m
 * @param joinPointInstanceIndex
 * @param exceptionInstanceIndex
 */
private void createAfterThrowingInterceptorInvocations(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int exceptionInstanceIndex) {
    final int loopIndex = exceptionInstanceIndex + 1;
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, NR_OF_AFTER_THROWING_INTERCEPTORS_FIELD_NAME, I);
    cv.visitInsn(ICONST_1);
    cv.visitInsn(ISUB);
    cv.visitVarInsn(ISTORE, loopIndex);
    Label loopLabel1 = new Label();
    cv.visitLabel(loopLabel1);
    cv.visitVarInsn(ILOAD, loopIndex);
    Label loopLabel2 = new Label();
    cv.visitJumpInsn(IFLT, loopLabel2);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_THROWING_INTERCEPTORS_FIELD_NAME,
            AFTER_THROWING_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitVarInsn(ILOAD, loopIndex);
    cv.visitInsn(AALOAD);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, exceptionInstanceIndex);
    cv.visitMethodInsn(INVOKEINTERFACE, AFTER_THROWING_ADVICE_CLASS_NAME, INTERCEPT_INVOKE_METHOD_NAME,
            AFTER_THROWING_ADVICE_INVOKE_METHOD_SIGNATURE);
    cv.visitIincInsn(loopIndex, -1);
    cv.visitJumpInsn(GOTO, loopLabel1);
    cv.visitLabel(loopLabel2);
}

From source file:org.codehaus.aspectwerkz.transform.inlining.compiler.AspectWerkzAspectModel.java

License:Open Source License

/**
 * Initializes instance level aspects, retrieves them from the target instance through the
 * <code>HasInstanceLevelAspect</code> interfaces.
 * <p/>//  w  ww  .  ja  v a2s . c  o m
 * Use by 'perInstance', 'perThis' and 'perTarget' deployment models.
 *
 * @param cv
 * @param aspectInfo
 * @param input
 */
public void createAndStoreRuntimeAspectInstantiation(final MethodVisitor cv, final CompilerInput input,
        final AspectInfo aspectInfo) {
    // gen code: if (Aspects.hasAspect(...) { aspectField = (<TYPE>)((HasInstanceLocalAspect)CALLER).aw$getAspect(className, qualifiedName, containerClassName) }
    if (DeploymentModel.PER_INSTANCE.equals(aspectInfo.getDeploymentModel())) {//TODO && callerIndex >= 0
        //storeAspectInstance(cv, input, aspectInfo, input.callerIndex);
    } else if (DeploymentModel.PER_THIS.equals(aspectInfo.getDeploymentModel()) && input.callerIndex >= 0) {
        Label hasAspectCheck = pushPerXCondition(cv, input.callerIndex, aspectInfo);
        storeAspectInstance(cv, input, aspectInfo, input.callerIndex);
        cv.visitLabel(hasAspectCheck);
    } else if (DeploymentModel.PER_TARGET.equals(aspectInfo.getDeploymentModel()) && input.calleeIndex >= 0) {
        Label hasAspectCheck = pushPerXCondition(cv, input.calleeIndex, aspectInfo);
        storeAspectInstance(cv, input, aspectInfo, input.calleeIndex);
        cv.visitLabel(hasAspectCheck);
    }

    if (aspectInfo.getDeploymentModel() == DeploymentModel.PER_INSTANCE) {//TODO refactor with previous if block
        // gen code: aspectField = (<TYPE>)((HasInstanceLocalAspect)CALLER).aw$getAspect(className, qualifiedName, containerClassName)
        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        if (input.callerIndex >= 0) {
            cv.visitVarInsn(ALOAD, input.callerIndex);
        } else {
            // caller instance not available - skipping
            //TODO clean up should not occur
        }
        cv.visitMethodInsn(INVOKESTATIC, aspectInfo.getAspectFactoryClassName(), "aspectOf",
                "(Ljava/lang/Object;)" + aspectInfo.getAspectClassSignature());
        //            cv.visitLdcInsn(aspectInfo.getAspectClassName().replace('/', '.'));
        //            cv.visitLdcInsn(aspectInfo.getAspectQualifiedName());
        //            AsmHelper.loadStringConstant(cv, aspectInfo.getAspectDefinition().getContainerClassName());
        //            cv.visitMethodInsn(
        //                    INVOKEINTERFACE,
        //                    HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME,
        //                    INSTANCE_LEVEL_GETASPECT_METHOD_NAME,
        //                    INSTANCE_LEVEL_GETASPECT_METHOD_SIGNATURE
        //            );
        //            cv.visitTypeInsn(CHECKCAST, aspectInfo.getAspectClassName());
        cv.visitFieldInsn(PUTFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
    }
}

From source file:org.codehaus.aspectwerkz.transform.inlining.compiler.AspectWerkzAspectModel.java

License:Open Source License

/**
 * Load aspect instance on stack/*from  w w w  .j a v  a 2  s . c o m*/
 *
 * @param cv
 * @param input
 * @param aspectInfo
 */
public void loadAspect(final MethodVisitor cv, final CompilerInput input, final AspectInfo aspectInfo) {
    DeploymentModel deploymentModel = aspectInfo.getDeploymentModel();
    if (DeploymentModel.PER_JVM.equals(deploymentModel) || DeploymentModel.PER_CLASS.equals(deploymentModel)) {
        cv.visitFieldInsn(GETSTATIC, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
    } else if (DeploymentModel.PER_INSTANCE.equals(deploymentModel)) {
        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        cv.visitFieldInsn(GETFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
    } else if (DeploymentModel.PER_THIS.equals(deploymentModel)) {
        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        cv.visitFieldInsn(GETFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());

        //FIXME see FIXME on aspect instantion
        Label nullCheck = new Label();
        cv.visitJumpInsn(IFNONNULL, nullCheck);
        storeAspectInstance(cv, input, aspectInfo, input.callerIndex);
        cv.visitLabel(nullCheck);

        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        cv.visitFieldInsn(GETFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
    } else if (DeploymentModel.PER_TARGET.equals(deploymentModel)) {
        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        cv.visitFieldInsn(GETFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
        //FIXME see FIXME on aspect instantion

        Label nullCheck = new Label();
        cv.visitJumpInsn(IFNONNULL, nullCheck);
        storeAspectInstance(cv, input, aspectInfo, input.calleeIndex);
        cv.visitLabel(nullCheck);

        AbstractJoinPointCompiler.loadJoinPointInstance(cv, input);
        cv.visitFieldInsn(GETFIELD, input.joinPointClassName, aspectInfo.getAspectFieldName(),
                aspectInfo.getAspectClassSignature());
    } else {
        throw new DefinitionException("deployment model [" + deploymentModel + "] is not supported");
    }
}

From source file:org.codehaus.aspectwerkz.transform.inlining.weaver.InstanceLevelAspectVisitor.java

License:Open Source License

/**
 * Adds the getAspect(..) method to the target class.
 *
 * @param name the class name of the target class
 *//*from   ww w  .j ava  2 s  . c o m*/
private void addGetAspectMethod(final String name) {
    MethodVisitor cv = super.visitMethod(ACC_PUBLIC + ACC_SYNTHETIC, INSTANCE_LEVEL_GETASPECT_METHOD_NAME,
            INSTANCE_LEVEL_GETASPECT_METHOD_SIGNATURE, null, null);

    cv.visitVarInsn(ALOAD, 0);
    cv.visitFieldInsn(GETFIELD, name, INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
            INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE);
    //--
    cv.visitInsn(DUP);
    Label ifMapNonNull = new Label();
    cv.visitJumpInsn(IFNONNULL, ifMapNonNull);
    cv.visitInsn(ACONST_NULL);
    cv.visitInsn(ARETURN);
    cv.visitLabel(ifMapNonNull);

    //        // if == null, field = new HashMap()
    //        Label ifFieldNullNotLabel = new Label();
    //        cv.visitJumpInsn(IFNONNULL, ifFieldNullNotLabel);
    //        cv.visitVarInsn(ALOAD, 0);
    //        cv.visitTypeInsn(NEW, HASH_MAP_CLASS_NAME);
    //        cv.visitInsn(DUP);
    //        cv.visitMethodInsn(
    //                INVOKESPECIAL,
    //                HASH_MAP_CLASS_NAME,
    //                INIT_METHOD_NAME,
    //                NO_PARAM_RETURN_VOID_SIGNATURE
    //        );
    //        cv.visitFieldInsn(
    //                PUTFIELD,
    //                name,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE
    //        );
    //        cv.visitLabel(ifFieldNullNotLabel);
    //
    //        cv.visitVarInsn(ALOAD, 0);
    //        cv.visitFieldInsn(
    //                GETFIELD,
    //                name,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE
    //        );
    //
    //        cv.visitVarInsn(ALOAD, 2);//qName
    //        cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, GET_METHOD_NAME, GET_METHOD_SIGNATURE);
    //        cv.visitVarInsn(ASTORE, 4);
    //        cv.visitVarInsn(ALOAD, 4);
    //        Label ifNullNotLabel = new Label();
    //        cv.visitJumpInsn(IFNONNULL, ifNullNotLabel);
    //        cv.visitVarInsn(ALOAD, 2);//qName
    //        cv.visitVarInsn(ALOAD, 3);//containerClassName
    //        cv.visitVarInsn(ALOAD, 0);//this (perInstance)
    //        cv.visitMethodInsn(
    //                INVOKESTATIC,
    //                ASPECTS_CLASS_NAME,
    //                ASPECT_OF_METHOD_NAME,
    //                ASPECT_OF_PER_INSTANCE_METHOD_SIGNATURE
    //        );
    //        cv.visitVarInsn(ASTORE, 4);
    //cv.visitVarInsn(ALOAD, 0);
    //--
    cv.visitVarInsn(ALOAD, 1);
    cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, GET_METHOD_NAME, GET_METHOD_SIGNATURE);
    //--
    //        cv.visitFieldInsn(
    //                GETFIELD,
    //                name,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
    //                INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE
    //        );
    cv.visitInsn(ARETURN);
    //        cv.visitVarInsn(ALOAD, 2);
    //        cv.visitVarInsn(ALOAD, 4);
    //        cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, PUT_METHOD_NAME, PUT_METHOD_SIGNATURE);
    //        cv.visitInsn(POP);
    //        cv.visitLabel(ifNullNotLabel);
    //        cv.visitVarInsn(ALOAD, 4);
    //        cv.visitInsn(ARETURN);
    cv.visitMaxs(0, 0);

    m_ctx.markAsAdvised();
    m_isAdvised = true;
}

From source file:org.codehaus.aspectwerkz.transform.inlining.weaver.InstanceLevelAspectVisitor.java

License:Open Source License

private void addHasAspectMethod(String mapFieldName) {
    MethodVisitor cv = super.visitMethod(ACC_PUBLIC + ACC_SYNTHETIC, INSTANCE_LEVEL_HASASPECT_METHOD_NAME,
            INSTANCE_LEVEL_HASASPECT_METHOD_SIGNATURE, null, null);

    cv.visitVarInsn(ALOAD, 0);//from  w w w.  ja v  a 2  s  . c  o m
    cv.visitFieldInsn(GETFIELD, mapFieldName, INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
            INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE);
    cv.visitInsn(DUP);
    Label ifMapNonNull = new Label();
    cv.visitJumpInsn(IFNONNULL, ifMapNonNull);
    cv.visitInsn(ICONST_0);
    cv.visitInsn(IRETURN);
    cv.visitLabel(ifMapNonNull);
    cv.visitVarInsn(ALOAD, 1);
    cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, "containsKey", "(Ljava/lang/Object;)Z");
    //cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, GET_METHOD_NAME, GET_METHOD_SIGNATURE);
    //
    //        Label ifNullLabel = new Label();
    //        cv.visitJumpInsn(IFNULL, ifNullLabel);
    //        cv.visitInsn(ICONST_1);
    //        cv.visitInsn(IRETURN);
    //        cv.visitLabel(ifNullLabel);
    //        cv.visitInsn(ICONST_0);
    cv.visitInsn(IRETURN);
    cv.visitMaxs(0, 0);

    m_ctx.markAsAdvised();
    m_isAdvised = true;
}

From source file:org.codehaus.aspectwerkz.transform.inlining.weaver.InstanceLevelAspectVisitor.java

License:Open Source License

private void addBindAspectMethod(final String name) {
    MethodVisitor cv = super.visitMethod(ACC_PUBLIC + ACC_SYNTHETIC, INSTANCE_LEVEL_BINDASPECT_METHOD_NAME,
            INSTANCE_LEVEL_BINDASPECT_METHOD_SIGNATURE, null, null);

    cv.visitVarInsn(ALOAD, 0);//from   ww  w .  j  av  a 2 s.co m
    cv.visitFieldInsn(GETFIELD, name, INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
            INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE);
    // if == null, field = new HashMap()
    Label ifFieldNullNotLabel = new Label();
    cv.visitJumpInsn(IFNONNULL, ifFieldNullNotLabel);
    cv.visitVarInsn(ALOAD, 0);
    cv.visitTypeInsn(NEW, HASH_MAP_CLASS_NAME);
    cv.visitInsn(DUP);
    cv.visitMethodInsn(INVOKESPECIAL, HASH_MAP_CLASS_NAME, INIT_METHOD_NAME, NO_PARAM_RETURN_VOID_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, name, INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
            INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE);
    cv.visitLabel(ifFieldNullNotLabel);

    cv.visitVarInsn(ALOAD, 0);
    cv.visitFieldInsn(GETFIELD, name, INSTANCE_LEVEL_ASPECT_MAP_FIELD_NAME,
            INSTANCE_LEVEL_ASPECT_MAP_FIELD_SIGNATURE);
    cv.visitVarInsn(ALOAD, 1);
    cv.visitVarInsn(ALOAD, 2);
    cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, PUT_METHOD_NAME, PUT_METHOD_SIGNATURE);
    cv.visitVarInsn(ALOAD, 2);
    cv.visitInsn(ARETURN);
}

From source file:org.codehaus.groovy.classgen.asm.AssertionWriter.java

License:Apache License

public void writeAssertStatement(AssertStatement statement) {
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack operandStack = controller.getOperandStack();

    // don't rewrite assertions with message
    boolean rewriteAssert = isNull(statement.getMessageExpression());
    AssertionTracker oldTracker = assertionTracker;
    Janitor janitor = new Janitor();
    final Label tryStart = new Label();
    if (rewriteAssert) {
        assertionTracker = new AssertionTracker();
        try {//w ww.  ja v a  2  s  .  c  o  m
            // because source position seems to be more reliable for statements
            // than for expressions, we get the source text for the whole statement
            assertionTracker.sourceText = new SourceText(statement, controller.getSourceUnit(), janitor);
            mv.visitTypeInsn(NEW, "org/codehaus/groovy/runtime/powerassert/ValueRecorder");
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/powerassert/ValueRecorder", "<init>",
                    "()V", false);
            //TODO: maybe use more specialized type here
            controller.getOperandStack().push(ClassHelper.OBJECT_TYPE);
            assertionTracker.recorderIndex = controller.getCompileStack().defineTemporaryVariable("recorder",
                    true);
            mv.visitLabel(tryStart);
        } catch (SourceTextNotAvailableException e) {
            // set assertionTracker to null to deactivate AssertionWriter#record calls
            assertionTracker = null;
            // don't rewrite assertions w/o source text
            rewriteAssert = false;
        }
    }

    statement.getBooleanExpression().visit(controller.getAcg());

    Label exceptionThrower = operandStack.jump(IFEQ);

    // do nothing, but clear the value recorder
    if (rewriteAssert) {
        //clean up assertion recorder
        mv.visitVarInsn(ALOAD, assertionTracker.recorderIndex);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/codehaus/groovy/runtime/powerassert/ValueRecorder", "clear",
                "()V", false);
    }
    Label afterAssert = new Label();
    mv.visitJumpInsn(GOTO, afterAssert);
    mv.visitLabel(exceptionThrower);

    if (rewriteAssert) {
        mv.visitLdcInsn(assertionTracker.sourceText.getNormalizedText());
        mv.visitVarInsn(ALOAD, assertionTracker.recorderIndex);
        mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/powerassert/AssertionRenderer", "render",
                "(Ljava/lang/String;Lorg/codehaus/groovy/runtime/powerassert/ValueRecorder;)Ljava/lang/String;",
                false);
    } else {
        writeSourcelessAssertText(statement);
    }
    operandStack.push(ClassHelper.STRING_TYPE);
    AssertionTracker savedTracker = assertionTracker;
    assertionTracker = null;

    // now the optional exception expression
    statement.getMessageExpression().visit(controller.getAcg());
    operandStack.box();
    assertFailedMethod.call(mv);
    operandStack.remove(2); // assertFailed called static with 2 arguments 

    if (rewriteAssert) {
        final Label tryEnd = new Label();
        mv.visitLabel(tryEnd);
        mv.visitJumpInsn(GOTO, afterAssert);
        // finally block to clean assertion recorder
        final Label catchAny = new Label();
        mv.visitLabel(catchAny);
        mv.visitVarInsn(ALOAD, savedTracker.recorderIndex);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/codehaus/groovy/runtime/powerassert/ValueRecorder", "clear",
                "()V", false);
        mv.visitInsn(ATHROW);
        // add catch any block to exception table
        controller.getCompileStack().addExceptionBlock(tryStart, tryEnd, catchAny, null);
    }

    mv.visitLabel(afterAssert);
    if (rewriteAssert) {
        controller.getCompileStack().removeVar(savedTracker.recorderIndex);
    }
    assertionTracker = oldTracker;
    // close possibly open file handles from getting a sample for 
    // power asserts
    janitor.cleanup();
}

From source file:org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.java

License:Apache License

private void evaluateLogicalAndExpression(BinaryExpression expression) {
    MethodVisitor mv = controller.getMethodVisitor();
    AsmClassGenerator acg = controller.getAcg();
    OperandStack operandStack = controller.getOperandStack();

    expression.getLeftExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    Label falseCase = operandStack.jump(IFEQ);

    expression.getRightExpression().visit(acg);
    operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
    operandStack.jump(IFEQ, falseCase);/*from   ww w . j a va  2  s  . c  o m*/

    ConstantExpression.PRIM_TRUE.visit(acg);
    Label trueCase = new Label();
    mv.visitJumpInsn(GOTO, trueCase);

    mv.visitLabel(falseCase);
    ConstantExpression.PRIM_FALSE.visit(acg);

    mv.visitLabel(trueCase);
    operandStack.remove(1); // have to remove 1 because of the GOTO
}