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.batoo.jpa.core.impl.instance.Enhancer.java

License:Open Source License

private static void createMethodCheck(final String enhancedClassName, final String descEnhancer,
        final ClassWriter cw) {
    final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PRIVATE, Enhancer.METHOD_ENHANCED_CHECK,
            Enhancer.makeDescription(Void.TYPE), null, null);
    mv.visitCode();//from  w  w  w. j  a v a  2 s.c  o m

    final Label lCheckInternal = new Label();
    final Label lCheckInitialized = new Label();
    final Label lReturn = new Label();
    final Label lFind = new Label();
    final Label lInitialized = new Label();
    final Label lChanged = new Label();
    final Label lOut = new Label();

    // if (!this.__enhanced__$$__internal) { return }
    mv.visitLabel(lCheckInternal);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL,
            Enhancer.DESCRIPTOR_BOOLEAN);
    mv.visitJumpInsn(Opcodes.IFEQ, lCheckInitialized);
    mv.visitInsn(Opcodes.RETURN);

    // if (!this.__enhanced__$$__initialized) {
    mv.visitLabel(lCheckInitialized);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED,
            Enhancer.DESCRIPTOR_BOOLEAN);
    mv.visitJumpInsn(Opcodes.IFNE, lChanged);

    //     if (this.__enhanced_$$__session == null)
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitJumpInsn(Opcodes.IFNONNULL, lFind);

    //         throw new PersistenceException("No session to initialize the instance");
    mv.visitTypeInsn(Opcodes.NEW, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION);
    mv.visitInsn(Opcodes.DUP);
    mv.visitLdcInsn("No session to initialize the instance");
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION,
            Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, String.class));
    mv.visitInsn(Opcodes.ATHROW);

    //       this.__enhanced_$$__session.getEntityManager().find(this.__enhanced_$$__type, this.__enhanced__$$__id);
    mv.visitLabel(lFind);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_SESSION, Enhancer.METHOD_GET_ENTITY_MANAGER,
            Enhancer.makeDescription(EntityManagerImpl.class));
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE,
            Enhancer.DESCRIPTOR_CLASS);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID,
            Enhancer.DESCRIPTOR_OBJECT);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_ENTITY_MANAGER, Enhancer.METHOD_FIND,
            Enhancer.makeDescription(Object.class, Class.class, Object.class));
    mv.visitInsn(Opcodes.POP);

    //   this.__enhanced__$$__initialized = true;
    mv.visitLabel(lInitialized);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED,
            Enhancer.DESCRIPTOR_BOOLEAN);

    // if (this.__enhanced_$$__session != null)
    mv.visitLabel(lChanged);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitJumpInsn(Opcodes.IFNULL, lReturn);

    //     this.__enhanced__$$__managedInstance.changed();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE,
            Enhancer.DESCRIPTOR_MANAGED_INSTANCE);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_MANAGED_INSTANCE, Enhancer.METHOD_CHANGED,
            Enhancer.makeDescription(Void.TYPE));

    // return;
    mv.visitLabel(lReturn);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitInsn(Opcodes.RETURN);

    mv.visitLabel(lOut);
    mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, lCheckInternal, lOut, 0);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

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

License:Open Source License

@Override
public void visitEnd() {
    FieldVisitor fv = null;//from w w w. j a va  2 s. c  o 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.cacheonix.impl.transformer.CacheonixMethodGenerator.java

License:LGPL

/**
 * Generates a new method body for implementing DataSource with the old name to look into the Cacheonix cache first
 * before calling the original method//  www.jav  a 2  s . co m
 *
 * @param cv                       ClassVisitor that this class delegates the calls to
 * @param className                Name of the class for which the method is being generated
 * @param access                   Method level access
 * @param desc                     Method descriptor
 * @param signature                Method signature
 * @param exceptions               Any exceptions that the method can throw
 * @param name                     original name of the method
 * @param newName                  the original method renamed to the format:orig$Cacheonix$methodName
 * @param metaData                 Annotation information for the method
 * @param cacheonixCacheFieldValue cacheName specified at the class level
 */
public static void generateCacheAddBody(final ClassVisitor cv, final String className, final int access,
        final String desc, final String signature, final String[] exceptions, final String name,
        final String newName, final MethodMetaData metaData, final String cacheonixCacheFieldValue) {

    final Type[] args = Type.getArgumentTypes(desc);
    final LocalStackUtil stackFrame = new LocalStackUtil(args);
    int expirationTime = CacheonixAnnotation.CACHEDATASOURCE_EXPIRATION_TIME_MILLIS_DEFAULT_VALUE;

    if (metaData.isAnnotationsPresent()) {
        final Object expTime = metaData.getAnnotationParameterValue(
                CacheonixAnnotation.CACHE_DATA_SOURCE_DESCRIPTOR,
                CacheonixAnnotation.CACHEDATASOURCE_EXPIRATION_TIME_MILLIS);
        if (expTime != null) {
            expirationTime = Integer.parseInt(expTime.toString());
        }
    }

    // Start
    final MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    mv.visitCode();

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

    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");

    final String classCan = 'L' + className + ';';

    mv.visitLdcInsn(Type.getType(classCan));
    mv.visitMethodInsn(INVOKESTATIC, "org/cacheonix/impl/util/logging/Logger", "getLogger",
            "(Ljava/lang/Class;)Lorg/cacheonix/impl/util/logging/Logger;");

    mv.visitVarInsn(ASTORE, stackFrame.getLogLocalStackPos());

    mv.visitInsn(ACONST_NULL);
    mv.visitVarInsn(ASTORE, stackFrame.getValObjLocalStackPos()); // val

    generateKeyAggregationSequence(mv, args, stackFrame, cacheonixCacheFieldValue,
            metaData.getMethodParamAnnotationInfo());

    mv.visitInsn(ACONST_NULL);
    mv.visitVarInsn(ASTORE, stackFrame.getCacheRefLocalStackPos()); // cache

    //      printingToSysout(mv, "!!!!!  G E N E R A T E D   !!!!!! '" + name + "' is Called");

    mv.visitLabel(l0);
    // Config file from annotation on Class level
    mv.visitFieldInsn(GETSTATIC, className, CacheonixClassAdapter.CACHEONIX_CONFIG_FILE_FIELD,
            "Ljava/lang/String;");

    mv.visitMethodInsn(INVOKESTATIC, "cacheonix/cache/CacheManager", "getInstance",
            "(Ljava/lang/String;)Lcacheonix/cache/CacheManager;");
    mv.visitVarInsn(ASTORE, stackFrame.getCacheManagerLocalStackPos()); // inst

    // CATCH Block
    mv.visitLabel(l1);
    final Label l3 = new Label();
    mv.visitJumpInsn(GOTO, l3);
    mv.visitLabel(l2);
    mv.visitVarInsn(ASTORE, stackFrame.getExceptionLocalStackPos()); // exception
    mv.visitInsn(ACONST_NULL);
    mv.visitVarInsn(ASTORE, stackFrame.getCacheManagerLocalStackPos()); // inst
    mv.visitVarInsn(ALOAD, stackFrame.getLogLocalStackPos()); // log
    mv.visitLdcInsn(">>>>> Exception getting CacheManager ");
    mv.visitVarInsn(ALOAD, stackFrame.getExceptionLocalStackPos()); // exception
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/cacheonix/impl/util/logging/Logger", "e",
            "(Ljava/lang/Object;Ljava/lang/Throwable;)V");
    // END OF TRY CACTCH

    mv.visitLabel(l3);

    //      printingToSysout(mv, "!!!!!  INST is NOT NULL   !!!!!! '" + name + "' is Called");

    mv.visitVarInsn(ALOAD, stackFrame.getCacheManagerLocalStackPos()); // inst
    final Label l4 = new Label();
    mv.visitJumpInsn(IFNULL, l4);
    mv.visitVarInsn(ALOAD, stackFrame.getCacheManagerLocalStackPos()); // inst

    mv.visitFieldInsn(GETSTATIC, className, CacheonixClassAdapter.CACHE_NAME_FIELD, "Ljava/lang/String;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "cacheonix/cache/CacheManager", "getCache",
            "(Ljava/lang/String;)Lcacheonix/cache/Cache;");

    mv.visitVarInsn(ASTORE, stackFrame.getCacheRefLocalStackPos()); // cache
    mv.visitVarInsn(ALOAD, stackFrame.getCacheRefLocalStackPos()); // cache
    mv.visitVarInsn(ALOAD, stackFrame.getKeyGenLocalStackPos()); // key
    mv.visitMethodInsn(INVOKEINTERFACE, "cacheonix/cache/Cache", "get",
            "(Ljava/lang/Object;)Ljava/lang/Object;");
    mv.visitVarInsn(ASTORE, stackFrame.getValObjLocalStackPos()); // val

    mv.visitVarInsn(ALOAD, stackFrame.getValObjLocalStackPos()); // val
    mv.visitJumpInsn(IFNONNULL, l4);

    //      printingToSysout(mv, "!!!!!  VALUE IN CACHE IS NULL   !!!!!! '" + name + "' is Called");

    generateMethodParameterLoadingSequence(mv, args);

    mv.visitMethodInsn(INVOKESPECIAL, className, newName, desc);

    mv.visitVarInsn(ASTORE, stackFrame.getValObjLocalStackPos()); // val
    mv.visitVarInsn(ALOAD, stackFrame.getCacheRefLocalStackPos()); // cache
    mv.visitVarInsn(ALOAD, stackFrame.getKeyGenLocalStackPos()); // key
    mv.visitVarInsn(ALOAD, stackFrame.getValObjLocalStackPos()); // val

    if (expirationTime == -1) {
        mv.visitMethodInsn(INVOKEINTERFACE, "cacheonix/cache/Cache", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
    } else {
        mv.visitLdcInsn(Long.valueOf(expirationTime));
        mv.visitMethodInsn(INVOKEINTERFACE, "cacheonix/cache/Cache", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;J)Ljava/lang/Object;");
    }

    mv.visitInsn(POP);

    mv.visitLabel(l4);

    mv.visitVarInsn(ALOAD, stackFrame.getValObjLocalStackPos()); // val

    // Return type
    final String retType = Type.getReturnType(desc).getInternalName();
    mv.visitTypeInsn(CHECKCAST, retType);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(6, 10);
    mv.visitEnd();

}

From source file:org.cacheonix.impl.transformer.CacheonixMethodGenerator.java

License:LGPL

/**
 * Generates the byte instructions for the Aggregate key generated to be used by the Cacheonix cache
 *
 * @param mv              MethodVisitor that writes byte instructions
 * @param types           array of Method arguments Types
 * @param stackFrame      Contains the offset for the local variables in the generated method
 * @param list/*from  w  w w. java 2s .c o m*/
 * @param strSyntheticKey
 */
private static void generateKeyAggregationSequence(final MethodVisitor mv, final Type[] types,
        final LocalStackUtil stackFrame, final String strSyntheticKey, final List<Integer> list) {

    final String strGeneratorKey = "org/cacheonix/impl/transformer/GeneratedKey";

    mv.visitTypeInsn(NEW, strGeneratorKey);

    mv.visitInsn(DUP);

    int keyElements = 1; //For Synthetic key
    keyElements += list.size();

    mv.visitIntInsn(BIPUSH, keyElements);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");

    //Add Synthetic key to the GeneratorKey
    mv.visitInsn(DUP);
    mv.visitIntInsn(BIPUSH, 0);

    final Type tpString = Type.getType(String.class);

    mv.visitLdcInsn(strSyntheticKey);

    // Call function
    String argDescriptor = getKeyGenArgumentDescrStr(tpString);
    mv.visitMethodInsn(INVOKESTATIC, strGeneratorKey, "addKeyElement", argDescriptor);
    // Push (store) result to the stack
    mv.visitInsn(AASTORE);

    for (int i = 0, j = 1; i < list.size(); ++i, ++j) {
        //Get the argument index which is marked with @CacheKey
        final int argTypeIndex = list.get(i).intValue();

        mv.visitInsn(DUP);
        mv.visitIntInsn(BIPUSH, j);

        final ByteInstruction bi = ByteInstruction.getByteInstructionAt(argTypeIndex, types);
        mv.visitVarInsn(bi.code, bi.stackIndex);

        // Call function
        argDescriptor = getKeyGenArgumentDescrStr(types[argTypeIndex]);
        mv.visitMethodInsn(INVOKESTATIC, strGeneratorKey, "addKeyElement", argDescriptor);
        // Push (store) result to the stack
        mv.visitInsn(AASTORE);
        // ---

    }

    // Call Constructor function with array of arguments
    mv.visitMethodInsn(INVOKESPECIAL, strGeneratorKey, "<init>", "([Ljava/lang/Object;)V");
    // Store new GeneratedKey to Local ()
    mv.visitVarInsn(ASTORE, stackFrame.getKeyGenLocalStackPos());

}

From source file:org.cacheonix.impl.transformer.CacheonixMethodGenerator.java

License:LGPL

/**
 * Generated the byte instructions to write the message to System out stream
 *
 * @param mv      Method Visitor that writes byte instructions
 * @param message message that needs to be written to the out stream
 *//*from w  ww.j a  va 2 s .  c  o m*/
public static void printingToSysout(final MethodVisitor mv, final String message) {

    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn(message);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
}

From source file:org.cacheonix.impl.transformer.CacheonixMethodGenerator.java

License:LGPL

/**
 * Generates a new method body for implementing CacheInvalidate with the old name to look into the Cacheonix cache
 * first before calling the original method
 *
 * @param cv                       ClassVisitor that this class delegates the calls to
 * @param className                Name of the class for which the method is being generated
 * @param access                   Method level access
 * @param desc                     Method descriptor
 * @param signature                Method signature
 * @param exceptions               Any exceptions that the method can throw
 * @param name                     original name of the method
 * @param newName                  the original method renamed to the format:orig$Cacheonix$methodName
 * @param metaData                 Annotation information for the method
 * @param cacheonixCacheFieldValue cacheName specified at the class level
 *///  w  w  w.j ava2 s  . c o  m
public static void generateCacheRemoveBody(final ClassVisitor cv, final String className, final int access,
        final String desc, final String signature, final String[] exceptions, final String name,
        final String newName, final MethodMetaData metaData, final String cacheonixCacheFieldValue) {

    final Type[] args = Type.getArgumentTypes(desc);
    final LocalStackUtil stackFrame = new LocalStackUtil(args);

    // Start
    final MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    mv.visitCode();

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

    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");

    final Label l3 = new Label();
    final Label l4 = new Label();
    final Label l5 = new Label();

    mv.visitTryCatchBlock(l3, l4, l5, "java/lang/Exception");

    final String classCan = 'L' + className + ';';

    mv.visitLdcInsn(Type.getType(classCan));
    mv.visitMethodInsn(INVOKESTATIC, "org/cacheonix/impl/util/logging/Logger", "getLogger",
            "(Ljava/lang/Class;)Lorg/cacheonix/impl/util/logging/Logger;");

    mv.visitVarInsn(ASTORE, stackFrame.getCILogLocalStackPos()); // Log
    mv.visitInsn(ACONST_NULL);
    mv.visitVarInsn(ASTORE, stackFrame.getCICacheManagerLocalStackPos()); // inst

    // try
    mv.visitLabel(l0);

    mv.visitFieldInsn(GETSTATIC, className, CacheonixClassAdapter.CACHEONIX_CONFIG_FILE_FIELD,
            "Ljava/lang/String;");
    mv.visitMethodInsn(INVOKESTATIC, "cacheonix/cache/CacheManager", "getInstance",
            "(Ljava/lang/String;)Lcacheonix/cache/CacheManager;");

    mv.visitVarInsn(ASTORE, stackFrame.getCICacheManagerLocalStackPos()); // inst
    // catch in
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, l3);
    // catch out
    mv.visitLabel(l2);
    mv.visitVarInsn(ASTORE, stackFrame.getCIExceptionLocalStackPos()); // Exception1
    mv.visitInsn(ACONST_NULL);
    mv.visitVarInsn(ASTORE, stackFrame.getCIExceptionLocalStackPos()); // inst <- null
    mv.visitVarInsn(ALOAD, stackFrame.getCILogLocalStackPos()); // Log
    mv.visitLdcInsn(">>>>> Exception getting CacheManager ");
    mv.visitVarInsn(ALOAD, stackFrame.getCIExceptionLocalStackPos()); // Exception
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/cacheonix/impl/util/logging/Logger", "e",
            "(Ljava/lang/Object;Ljava/lang/Throwable;)V");
    // END OF TRY CACTCH

    // try
    mv.visitLabel(l3);

    //        printingToSysout(mv, "!!!!!  INVALIDATE | INST is NOT NULL   !!!!!! '" + name + "' is Called");

    mv.visitVarInsn(ALOAD, stackFrame.getCICacheManagerLocalStackPos()); // inst
    final Label l6 = new Label();
    mv.visitJumpInsn(IFNULL, l6);

    // Key Loop
    generateKeyAggregationSequence(mv, args, stackFrame, cacheonixCacheFieldValue,
            metaData.getMethodParamAnnotationInfo());

    mv.visitVarInsn(ALOAD, stackFrame.getCICacheManagerLocalStackPos()); // inst

    mv.visitFieldInsn(GETSTATIC, className, CacheonixClassAdapter.CACHE_NAME_FIELD, "Ljava/lang/String;");

    mv.visitMethodInsn(INVOKEVIRTUAL, "cacheonix/cache/CacheManager", "getCache",
            "(Ljava/lang/String;)Lcacheonix/cache/Cache;");

    mv.visitVarInsn(ASTORE, stackFrame.getCICacheRefLocalStackPos()); // cache
    mv.visitVarInsn(ALOAD, stackFrame.getCICacheRefLocalStackPos()); // cache
    mv.visitJumpInsn(IFNULL, l6);
    mv.visitVarInsn(ALOAD, stackFrame.getCICacheRefLocalStackPos()); // cache
    mv.visitVarInsn(ALOAD, stackFrame.getCIKeyGenLocalStackPos()); // Key
    mv.visitMethodInsn(INVOKEINTERFACE, "cacheonix/cache/Cache", "remove",
            "(Ljava/lang/Object;)Ljava/lang/Object;");
    mv.visitInsn(POP); // Ignore result

    mv.visitLabel(l4);
    mv.visitJumpInsn(GOTO, l6);
    mv.visitLabel(l5);

    mv.visitVarInsn(ASTORE, stackFrame.getCIEExceptionLocalStackPos()); // EException
    mv.visitVarInsn(ALOAD, stackFrame.getCILogLocalStackPos()); // Log
    mv.visitLdcInsn(">>>>> Exception while removing key ");
    mv.visitVarInsn(ALOAD, stackFrame.getCIEExceptionLocalStackPos()); // EException
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/cacheonix/impl/util/logging/Logger", "e",
            "(Ljava/lang/Object;Ljava/lang/Throwable;)V");
    mv.visitLabel(l6);

    //
    generateMethodParameterLoadingSequence(mv, args);

    mv.visitMethodInsn(INVOKESPECIAL, className, newName, desc);

    //
    final int op = ByteInstruction.getReturnCode(desc);
    mv.visitInsn(op);
    mv.visitMaxs(6, 9);
    mv.visitEnd();

}

From source file:org.codehaus.aspectwerkz.aspect.container.PerCflowXAspectFactoryCompiler.java

License:Open Source License

/**
 * Overrides the aspectOf() method to not do lazy aspect instantiation since controlled by bind()/unbind()
 *///from w ww  .j  av a2 s. com
protected void createAspectOf() {
    m_cw.visitField(ACC_PRIVATE + ACC_STATIC, "ASPECTS", MAP_CLASS_SIGNATURE, null, null);

    m_clinit.visitTypeInsn(NEW, MAP_CLASS_NAME);
    m_clinit.visitInsn(DUP);
    m_clinit.visitMethodInsn(INVOKESPECIAL, "java/util/WeakHashMap", INIT_METHOD_NAME, "()V");
    m_clinit.visitFieldInsn(PUTSTATIC, m_aspectFactoryClassName, "ASPECTS", MAP_CLASS_SIGNATURE);

    MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, "aspectOf",
            "(" + getXSignature() + ")" + m_aspectClassSignature, null, null);

    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, "ASPECTS", MAP_CLASS_SIGNATURE);
    cv.visitVarInsn(ALOAD, 0);//Thread
    cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
    cv.visitVarInsn(ASTORE, 1);
    cv.visitVarInsn(ALOAD, 1);
    Label ifBound = new Label();
    cv.visitJumpInsn(IFNONNULL, ifBound);
    cv.visitTypeInsn(NEW, Type.getInternalName(NoAspectBoundException.class));
    cv.visitInsn(DUP);
    cv.visitLdcInsn("Not bound");
    cv.visitLdcInsn(m_aspectQualifiedName);
    cv.visitMethodInsn(INVOKESPECIAL, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME, INIT_METHOD_NAME,
            "(Ljava/lang/String;Ljava/lang/String;)V");
    cv.visitInsn(ATHROW);

    cv.visitLabel(ifBound);
    cv.visitVarInsn(ALOAD, 1);
    cv.visitTypeInsn(CHECKCAST, m_aspectClassName);
    cv.visitInsn(ARETURN);

    // create an implicit Thread.currentThread no arg aspectOf() method
    cv = m_cw.visitMethod(ACC_STATIC + ACC_PUBLIC + ACC_FINAL, "aspectOf", "()" + m_aspectClassSignature, null,
            null);
    cv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(Thread.class), "currentThread",
            "()Ljava/lang/Thread;");
    cv.visitMethodInsn(INVOKESTATIC, m_aspectFactoryClassName, "aspectOf",
            "(Ljava/lang/Thread;)" + getXSignature());
    cv.visitInsn(ARETURN);
    cv.visitMaxs(0, 0);
}

From source file:org.codehaus.aspectwerkz.aspect.container.PerObjectFactoryCompiler.java

License:Open Source License

protected void createAspectOf() {
    MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, FACTORY_ASPECTOF_METHOD_NAME,
            "(Ljava/lang/Object;)" + m_aspectClassSignature, null, null);

    // instanceOf check
    cv.visitVarInsn(ALOAD, 0);// object
    cv.visitTypeInsn(INSTANCEOF, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME);
    Label ifInstanceOf = new Label();
    cv.visitJumpInsn(IFNE, ifInstanceOf);
    cv.visitTypeInsn(NEW, Type.getInternalName(NoAspectBoundException.class));
    cv.visitInsn(DUP);/* w  w  w . j av a2 s. c o m*/
    cv.visitLdcInsn("Unimplemented interface");
    cv.visitLdcInsn(m_aspectQualifiedName);
    cv.visitMethodInsn(INVOKESPECIAL, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME, INIT_METHOD_NAME,
            "(Ljava/lang/String;Ljava/lang/String;)V");
    cv.visitInsn(ATHROW);
    cv.visitLabel(ifInstanceOf);

    cv.visitVarInsn(ALOAD, 0);
    cv.visitTypeInsn(CHECKCAST, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME);
    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_CLASS_FIELD_NAME, CLASS_CLASS_SIGNATURE);
    cv.visitMethodInsn(INVOKEINTERFACE, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME,
            INSTANCE_LEVEL_GETASPECT_METHOD_NAME, INSTANCE_LEVEL_GETASPECT_METHOD_SIGNATURE);
    cv.visitVarInsn(ASTORE, 1);
    cv.visitVarInsn(ALOAD, 1);
    Label ifBound = new Label();
    cv.visitJumpInsn(IFNONNULL, ifBound);
    cv.visitTypeInsn(NEW, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME);
    cv.visitInsn(DUP);
    cv.visitLdcInsn("Not bound");
    cv.visitLdcInsn(m_aspectQualifiedName);
    cv.visitMethodInsn(INVOKESPECIAL, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME, INIT_METHOD_NAME,
            "(Ljava/lang/String;Ljava/lang/String;)V");
    cv.visitInsn(ATHROW);

    cv.visitLabel(ifBound);
    cv.visitVarInsn(ALOAD, 1);
    cv.visitTypeInsn(CHECKCAST, m_aspectClassName);
    cv.visitInsn(ARETURN);
    cv.visitMaxs(0, 0);
}

From source file:org.codehaus.aspectwerkz.aspect.container.PerObjectFactoryCompiler.java

License:Open Source License

private void createBindMethod() {
    MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, "bind",
            "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);

    // instanceOf check
    cv.visitVarInsn(ALOAD, 0);// object
    cv.visitTypeInsn(INSTANCEOF, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME);
    Label ifInstanceOf = new Label();
    cv.visitJumpInsn(IFNE, ifInstanceOf);
    cv.visitTypeInsn(NEW, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME);
    cv.visitInsn(DUP);/*  w  w w.  jav a 2s .c  o m*/
    cv.visitLdcInsn("Unimplemented interface");
    cv.visitLdcInsn(m_aspectQualifiedName);
    cv.visitMethodInsn(INVOKESPECIAL, NO_ASPECT_BOUND_EXCEPTION_CLASS_NAME, INIT_METHOD_NAME,
            "(Ljava/lang/String;Ljava/lang/String;)V");
    cv.visitInsn(ATHROW);
    cv.visitLabel(ifInstanceOf);

    cv.visitVarInsn(ALOAD, 0);//object
    cv.visitTypeInsn(CHECKCAST, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME);
    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_CLASS_FIELD_NAME, CLASS_CLASS_SIGNATURE);
    cv.visitMethodInsn(INVOKEINTERFACE, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME,
            INSTANCE_LEVEL_GETASPECT_METHOD_NAME, INSTANCE_LEVEL_GETASPECT_METHOD_SIGNATURE);
    cv.visitVarInsn(ASTORE, 1);
    cv.visitVarInsn(ALOAD, 1);
    Label ifAlreadyBound = new Label();
    cv.visitJumpInsn(IFNONNULL, ifAlreadyBound);

    // target instance and arg0 for bind call
    cv.visitVarInsn(ALOAD, 0);//object
    cv.visitTypeInsn(CHECKCAST, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME);
    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_CLASS_FIELD_NAME, CLASS_CLASS_SIGNATURE);

    if (m_hasAspectContainer) {
        cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_CONTAINER_FIELD_NAME,
                ASPECT_CONTAINER_CLASS_SIGNATURE);
        cv.visitVarInsn(ALOAD, 0);//associated object
        cv.visitMethodInsn(INVOKEINTERFACE, ASPECT_CONTAINER_CLASS_NAME, ASPECT_CONTAINER_ASPECTOF_METHOD_NAME,
                "(Ljava/lang/Object;)Ljava/lang/Object;");
        cv.visitTypeInsn(CHECKCAST, m_aspectClassName);
    } else {
        cv.visitTypeInsn(NEW, m_aspectClassName);
        cv.visitInsn(DUP);
        cv.visitMethodInsn(INVOKESPECIAL, m_aspectClassName, INIT_METHOD_NAME, NO_PARAM_RETURN_VOID_SIGNATURE);
    }
    cv.visitMethodInsn(INVOKEINTERFACE, HAS_INSTANCE_LEVEL_ASPECT_INTERFACE_NAME,
            INSTANCE_LEVEL_BINDASPECT_METHOD_NAME, INSTANCE_LEVEL_BINDASPECT_METHOD_SIGNATURE);
    cv.visitInsn(ARETURN);

    cv.visitLabel(ifAlreadyBound);
    cv.visitVarInsn(ALOAD, 1);
    cv.visitInsn(ARETURN);

    cv.visitMaxs(0, 0);
}

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

License:Open Source License

/**
 * Push the string on the stack. Deal when case where string is null.
 * // ww  w .  j  a  va 2s.  c  om
 * @param cv
 * @param s
 */
public static void loadStringConstant(final MethodVisitor cv, final String s) {
    if (s != null) {
        cv.visitLdcInsn(s);
    } else {
        cv.visitInsn(ACONST_NULL);
    }
}