Example usage for org.objectweb.asm MethodVisitor visitJumpInsn

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

Introduction

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

Prototype

public void visitJumpInsn(final int opcode, final Label label) 

Source Link

Document

Visits a jump instruction.

Usage

From source file:org.apache.tuscany.sca.interfacedef.java.jaxws.BaseBeanGenerator.java

License:Apache License

protected void decalreCollectionGetter(ClassWriter cw, String classDescriptor, String classSignature,
        String propName, String propClassSignature, String propTypeSignature, String collectionImplClass) {
    String getterName = "get" + capitalize(propName);
    String fieldName = getFieldName(propName);
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, getterName, "()" + propClassSignature,
            propTypeSignature == null ? null : "()" + propTypeSignature, null);
    mv.visitCode();// w w  w  .j av a  2 s . c  o  m
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(63, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, classDescriptor, fieldName, propClassSignature);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(64, l2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, collectionImplClass);
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, collectionImplClass, "<init>", "()V");
    mv.visitFieldInsn(PUTFIELD, classDescriptor, fieldName, propClassSignature);
    mv.visitLabel(l1);
    mv.visitLineNumber(66, l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, classDescriptor, fieldName, propClassSignature);
    mv.visitInsn(ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", classSignature, null, l0, l3, 0);
    mv.visitMaxs(3, 1);
    mv.visitEnd();
}

From source file:org.ballerinalang.nativeimpl.jvm.methodvisitor.VisitJumpInsn.java

License:Open Source License

public static void visitJumpInsn(Strand strand, ObjectValue oMv, long opcode, ObjectValue oLabel) {
    MethodVisitor mv = ASMUtil.getRefArgumentNativeData(oMv);

    Label label = ASMUtil.getRefArgumentNativeData(oLabel);
    mv.visitJumpInsn((int) opcode, label);
}

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. jav a 2  s  .co  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;/*  w w w  .j  a  va 2s  .  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//from w  ww .ja  v a 2s. c  o  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 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
 *//*from  w  w  w  .  j  a  v  a 2s .  c  om*/
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.chromium.bytecode.CustomResourcesClassAdapter.java

License:Open Source License

/**
 * Generates://  ww  w  .j av a2 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:/* ww w .  j  a  v  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://from ww  w. ja v  a  2 s .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.codehaus.aspectwerkz.aspect.container.LazyPerXFactoryCompiler.java

License:Open Source License

protected void createAspectOf() {
    m_cw.visitField(ACC_PRIVATE + ACC_STATIC, FACTORY_ASPECTS_FIELD_NAME, MAP_CLASS_SIGNATURE, null, null);

    m_clinit.visitTypeInsn(NEW, "java/util/WeakHashMap");
    m_clinit.visitInsn(DUP);/*  w  w w  . j  av  a  2  s.co  m*/
    m_clinit.visitMethodInsn(INVOKESPECIAL, "java/util/WeakHashMap", INIT_METHOD_NAME,
            NO_PARAM_RETURN_VOID_SIGNATURE);
    m_clinit.visitFieldInsn(PUTSTATIC, m_aspectFactoryClassName, FACTORY_ASPECTS_FIELD_NAME,
            MAP_CLASS_SIGNATURE);

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

    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_ASPECTS_FIELD_NAME, MAP_CLASS_SIGNATURE);
    cv.visitVarInsn(ALOAD, 0);//Class
    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);
    if (m_hasAspectContainer) {
        cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_CONTAINER_FIELD_NAME,
                ASPECT_CONTAINER_CLASS_SIGNATURE);
        cv.visitMethodInsn(INVOKEINTERFACE, ASPECT_CONTAINER_CLASS_NAME, ASPECT_CONTAINER_ASPECTOF_METHOD_NAME,
                "(" + getXSignature() + ")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.visitVarInsn(ASTORE, 2);
    cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName, FACTORY_ASPECTS_FIELD_NAME, MAP_CLASS_SIGNATURE);
    cv.visitVarInsn(ALOAD, 0);
    cv.visitVarInsn(ALOAD, 2);
    cv.visitMethodInsn(INVOKEINTERFACE, MAP_CLASS_NAME, "put",
            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
    cv.visitVarInsn(ALOAD, 2);
    cv.visitInsn(ARETURN);

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