Example usage for org.objectweb.asm MethodVisitor visitLdcInsn

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

Introduction

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

Prototype

public void visitLdcInsn(final Object value) 

Source Link

Document

Visits a LDC instruction.

Usage

From source file:org.codehaus.aspectwerkz.transform.inlining.AsmHelper.java

License:Open Source License

/**
 * Adds a string and inserts null if the string is null.
 *
 * @param cv/*from w w w  . j ava 2 s.  co  m*/
 * @param value
 */
public static void addNullableString(final MethodVisitor cv, final String value) {
    if (value == null) {
        cv.visitInsn(ACONST_NULL);
    } else {
        cv.visitLdcInsn(value);
    }
}

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

License:Open Source License

/**
 * Creates the static initialization method (not clinit) for the join point.
 *//*w ww .j av a2 s .  co m*/
private void createStaticInitializer() {
    MethodVisitor cv = m_cw.visitMethod(ACC_STATIC | ACC_PUBLIC, STATIC_INITIALIZATION_METHOD_NAME,
            NO_PARAM_RETURN_VOID_SIGNATURE, null, null);

    Label tryLabel = new Label();
    cv.visitLabel(tryLabel);
    cv.visitLdcInsn(m_calleeClassName.replace('/', '.'));
    cv.visitMethodInsn(INVOKESTATIC, CLASS_CLASS, FOR_NAME_METHOD_NAME, FOR_NAME_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);

    cv.visitLdcInsn(m_callerClassName.replace('/', '.'));
    cv.visitMethodInsn(INVOKESTATIC, CLASS_CLASS, FOR_NAME_METHOD_NAME, FOR_NAME_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, THIS_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);

    Label finallyLabel = new Label();
    cv.visitLabel(finallyLabel);

    Label gotoFinallyLabel = new Label();
    cv.visitJumpInsn(GOTO, gotoFinallyLabel);

    Label catchLabel = new Label();
    cv.visitLabel(catchLabel);
    cv.visitVarInsn(ASTORE, 0);

    cv.visitVarInsn(ALOAD, 0);
    cv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V");

    cv.visitTypeInsn(NEW, RUNTIME_EXCEPTION_CLASS_NAME);
    cv.visitInsn(DUP);
    cv.visitLdcInsn("could not load target class using Class.forName() in generated join point base class "
            + m_joinPointClassName);

    cv.visitMethodInsn(INVOKESPECIAL, RUNTIME_EXCEPTION_CLASS_NAME, INIT_METHOD_NAME,
            RUNTIME_EXCEPTION_INIT_METHOD_SIGNATURE);

    cv.visitInsn(ATHROW);
    cv.visitLabel(gotoFinallyLabel);

    // create the enclosing static joinpoint
    createEnclosingStaticJoinPoint(cv);

    // create the metadata map
    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(PUTSTATIC, m_joinPointClassName, META_DATA_FIELD_NAME, MAP_CLASS_SIGNATURE);

    // create the Signature instance
    createSignature(cv);

    // create the static JoinPoint instance
    cv.visitTypeInsn(NEW, m_joinPointClassName);
    cv.visitInsn(DUP);
    cv.visitMethodInsn(INVOKESPECIAL, m_joinPointClassName, INIT_METHOD_NAME, NO_PARAM_RETURN_VOID_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, OPTIMIZED_JOIN_POINT_INSTANCE_FIELD_NAME,
            L + m_joinPointClassName + SEMICOLON);

    // ensure aspect factories are all loaded
    for (int i = 0; i < m_aspectInfos.length; i++) {
        AspectInfo m_aspectInfo = m_aspectInfos[i];

        cv.visitLdcInsn(m_aspectInfo.getAspectFactoryClassName());
        cv.visitLdcInsn(m_aspectInfo.getAspectDefinition().getSystemDefinition().getUuid());
        cv.visitLdcInsn(m_aspectInfo.getAspectClassName());
        cv.visitLdcInsn(m_aspectInfo.getAspectQualifiedName());
        AsmHelper.loadStringConstant(cv, m_aspectInfo.getAspectDefinition().getContainerClassName());
        //TODO AVF do it once per aspect def
        StringBuffer sb = new StringBuffer();
        boolean hasOne = false;
        boolean isFirst = true;
        for (Iterator iterator = m_aspectInfo.getAspectDefinition().getParameters().entrySet()
                .iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            if (!isFirst) {
                sb.append(DELIMITER);
            }
            isFirst = false;
            hasOne = true;
            sb.append(entry.getKey()).append(DELIMITER).append(entry.getValue());
        }
        if (hasOne) {
            cv.visitLdcInsn(sb.toString());
        } else {
            cv.visitInsn(ACONST_NULL);
        }
        cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, THIS_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);
        cv.visitMethodInsn(INVOKEVIRTUAL, CLASS_CLASS, GETCLASSLOADER_METHOD_NAME,
                CLASS_CLASS_GETCLASSLOADER_METHOD_SIGNATURE);
        cv.visitLdcInsn(m_aspectInfo.getDeploymentModel().toString());
        cv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(AspectFactoryManager.class), "loadAspectFactory",
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)V");
    }

    // create and initialize the aspect fields
    for (int i = 0; i < m_aspectInfos.length; i++) {
        m_aspectInfos[i].getAspectModel().createAndStoreStaticAspectInstantiation(m_cw, cv, m_aspectInfos[i],
                m_joinPointClassName);
    }

    cv.visitInsn(RETURN);
    cv.visitTryCatchBlock(tryLabel, finallyLabel, catchLabel, CLASS_NOT_FOUND_EXCEPTION_CLASS_NAME);
    cv.visitMaxs(0, 0);
}

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

License:Open Source License

/**
 * Add and initialize the static field for enclosing joint point static part
 *
 * @param cv// www.  j  a v a  2 s.  co  m
 */
private void createEnclosingStaticJoinPoint(MethodVisitor cv) {
    cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, THIS_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);
    cv.visitLdcInsn(m_callerMethodName);
    cv.visitLdcInsn(m_callerMethodDesc);

    cv.visitMethodInsn(INVOKESTATIC, SIGNATURE_FACTORY_CLASS, NEW_ENCLOSING_SJP_METHOD_NAME,
            NEW_ENCLOSING_SJP_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, ENCLOSING_SJP_FIELD_NAME,
            ENCLOSING_SJP_FIELD_CLASS_SIGNATURE);
}

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

License:Open Source License

/**
 * Handle the around interceptor init.//  w  w w . j  a va2 s  .c om
 *
 * @param cv
 * @param joinPointInstanceIndex
 * @param advisableIndex
 */
private void initializeAroundInterceptors(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int advisableIndex) {
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, advisableIndex);
    cv.visitTypeInsn(CHECKCAST, ADVISABLE_CLASS_NAME);
    cv.visitLdcInsn(new Integer(m_joinPointClassName.hashCode()));
    cv.visitMethodInsn(INVOKEINTERFACE, ADVISABLE_CLASS_NAME, GET_AROUND_ADVICE_METHOD_NAME,
            GET_AROUND_ADVICE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, AROUND_INTERCEPTORS_FIELD_NAME,
            AROUND_ADVICE_ARRAY_CLASS_SIGNATURE);

    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AROUND_INTERCEPTORS_FIELD_NAME,
            AROUND_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitInsn(ARRAYLENGTH);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, NR_OF_AROUND_INTERCEPTORS_FIELD_NAME, I);
}

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

License:Open Source License

/**
 * Handle the before interceptor init.//from   ww  w. java 2  s  .  c  om
 *
 * @param cv
 * @param joinPointInstanceIndex
 * @param advisableIndex
 */
private void initializeBeforeInterceptors(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int advisableIndex) {
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, advisableIndex);
    cv.visitTypeInsn(CHECKCAST, ADVISABLE_CLASS_NAME);
    cv.visitLdcInsn(new Integer(m_joinPointClassName.hashCode()));
    cv.visitMethodInsn(INVOKEINTERFACE, ADVISABLE_CLASS_NAME, GET_BEFORE_ADVICE_METHOD_NAME,
            GET_BEFORE_ADVICE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, BEFORE_INTERCEPTORS_FIELD_NAME,
            BEFORE_ADVICE_ARRAY_CLASS_SIGNATURE);

    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, BEFORE_INTERCEPTORS_FIELD_NAME,
            BEFORE_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitInsn(ARRAYLENGTH);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, NR_OF_BEFORE_INTERCEPTORS_FIELD_NAME, I);
}

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

License:Open Source License

/**
 * Handle the after finally interceptor init.
 *
 * @param cv//  w  w w .java2 s . co  m
 * @param joinPointInstanceIndex
 * @param advisableIndex
 */
private void initializeAfterInterceptors(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int advisableIndex) {
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, advisableIndex);
    cv.visitTypeInsn(CHECKCAST, ADVISABLE_CLASS_NAME);
    cv.visitLdcInsn(new Integer(m_joinPointClassName.hashCode()));
    cv.visitMethodInsn(INVOKEINTERFACE, ADVISABLE_CLASS_NAME, GET_AFTER_ADVICE_METHOD_NAME,
            GET_AFTER_ADVICE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, AFTER_INTERCEPTORS_FIELD_NAME,
            AFTER_ADVICE_ARRAY_CLASS_SIGNATURE);

    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_INTERCEPTORS_FIELD_NAME,
            AFTER_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitInsn(ARRAYLENGTH);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, NR_OF_AFTER_INTERCEPTORS_FIELD_NAME, I);
}

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

License:Open Source License

/**
 * Handle the after returning interceptor init.
 *
 * @param cv//w  w  w  . ja  va2s . com
 * @param joinPointInstanceIndex
 * @param advisableIndex
 */
private void initializeAfterReturningInterceptors(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int advisableIndex) {
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, advisableIndex);
    cv.visitTypeInsn(CHECKCAST, ADVISABLE_CLASS_NAME);
    cv.visitLdcInsn(new Integer(m_joinPointClassName.hashCode()));
    cv.visitMethodInsn(INVOKEINTERFACE, ADVISABLE_CLASS_NAME, GET_AFTER_RETURNING_ADVICE_METHOD_NAME,
            GET_AFTER_RETURNING_ADVICE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, AFTER_RETURNING_INTERCEPTORS_FIELD_NAME,
            AFTER_RETURNING_ADVICE_ARRAY_CLASS_SIGNATURE);

    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_RETURNING_INTERCEPTORS_FIELD_NAME,
            AFTER_RETURNING_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitInsn(ARRAYLENGTH);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, NR_OF_AFTER_RETURNING_INTERCEPTORS_FIELD_NAME, I);
}

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

License:Open Source License

/**
 * Handle the after throwing interceptor init.
 *
 * @param cv//from www.j ava 2  s  .c o  m
 * @param joinPointInstanceIndex
 * @param advisableIndex
 */
private void initializeAfterThrowingInterceptors(final MethodVisitor cv, final int joinPointInstanceIndex,
        final int advisableIndex) {
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, advisableIndex);
    cv.visitTypeInsn(CHECKCAST, ADVISABLE_CLASS_NAME);
    cv.visitLdcInsn(new Integer(m_joinPointClassName.hashCode()));
    cv.visitMethodInsn(INVOKEINTERFACE, ADVISABLE_CLASS_NAME, GET_AFTER_THROWING_ADVICE_METHOD_NAME,
            GET_AFTER_THROWING_ADVICE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, AFTER_THROWING_INTERCEPTORS_FIELD_NAME,
            AFTER_THROWING_ADVICE_ARRAY_CLASS_SIGNATURE);

    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitVarInsn(ALOAD, joinPointInstanceIndex);
    cv.visitFieldInsn(GETFIELD, m_joinPointClassName, AFTER_THROWING_INTERCEPTORS_FIELD_NAME,
            AFTER_THROWING_ADVICE_ARRAY_CLASS_SIGNATURE);
    cv.visitInsn(ARRAYLENGTH);
    cv.visitFieldInsn(PUTFIELD, m_joinPointClassName, NR_OF_AFTER_THROWING_INTERCEPTORS_FIELD_NAME, I);
}

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

License:Open Source License

/**
 * Creates the signature for the join point.
 * <p/>//from w ww .  j av  a  2s  .  co m
 * FIXME signature field should NOT be of type Signature but of the specific type (update all refs as well)
 *
 * @param cv
 */
protected void createSignature(final MethodVisitor cv) {
    cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);
    cv.visitLdcInsn(new Integer(m_joinPointHash));

    cv.visitMethodInsn(INVOKESTATIC, SIGNATURE_FACTORY_CLASS, NEW_CONSTRUCTOR_SIGNATURE_METHOD_NAME,
            NEW_CONSTRUCTOR_SIGNATURE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME,
            CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE);
}

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

License:Open Source License

/**
 * Creates the signature for the join point.
 * <p/>/*  w ww .  j  a v  a2 s.c o m*/
 * FIXME signature field should NOT be of type Signature but of the specific type (update all refs as well)
 *
 * @param cv
 */
protected void createSignature(final MethodVisitor cv) {
    cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);
    cv.visitLdcInsn(new Integer(m_joinPointHash));

    cv.visitMethodInsn(INVOKESTATIC, SIGNATURE_FACTORY_CLASS, NEW_FIELD_SIGNATURE_METHOD_NAME,
            NEW_FIELD_SIGNATURE_METHOD_SIGNATURE);
    cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME,
            FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE);
}