当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitIntInsn方法代码示例

本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitIntInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitIntInsn方法的具体用法?Java MethodVisitor.visitIntInsn怎么用?Java MethodVisitor.visitIntInsn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitIntInsn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeClinit

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeClinit(ClassWriter writer) {
    Map<String, int[]> styleables = symbols.getStyleables();
    MethodVisitor clinit = writer.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
    clinit.visitCode();

    for (Map.Entry<String, int[]> entry : styleables.entrySet()) {
        final String field = entry.getKey();
        final int[] value = entry.getValue();
        final int length = value.length;
        pushInt(clinit, length);
        clinit.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT);
        for (int i = 0; i < length; i++) {
            clinit.visitInsn(Opcodes.DUP);                  // dup
            pushInt(clinit, i);
            pushInt(clinit, value[i]);
            clinit.visitInsn(Opcodes.IASTORE);              // iastore
        }
        clinit.visitFieldInsn(Opcodes.PUTSTATIC, RSymbols.R_STYLEABLES_CLASS_NAME, field, "[I");
    }
    clinit.visitInsn(Opcodes.RETURN);
    clinit.visitMaxs(0, 0); // auto compute
    clinit.visitEnd();
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:24,代码来源:WriteStyleablesProcessor.java

示例2: ldcI

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void ldcI(MethodVisitor mv, int i) {
    /* Special opcodes for some integer constants */
    if (i >= -1 && i <= 5) {
        mv.visitInsn(Opcodes.ICONST_0 + i);
    } else {
        /* BIPUSH or SIPUSH if integer constant within certain limits */
        if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
            mv.visitIntInsn(Opcodes.BIPUSH, i);
        } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
            mv.visitIntInsn(Opcodes.SIPUSH, i);
        } else {
            /* Fallback to LDC */
            mv.visitLdcInsn(Integer.valueOf(i));
        }
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:17,代码来源:Util.java

示例3: visitZeroOperandInt

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * 
 * @param mv
 * @param i the int value
 */
public static void visitZeroOperandInt(MethodVisitor mv, int i) {
	if (i > 5) {
		mv.visitIntInsn(BIPUSH, i);
	} else {
		int opcode = NOP;
		switch (i) {
			case 0: opcode = ICONST_0; break;
			case 1: opcode = ICONST_1; break;
			case 2: opcode = ICONST_2; break;
			case 3: opcode = ICONST_3; break;
			case 4: opcode = ICONST_4; break;
			case 5: opcode = ICONST_5; break;
		}
		mv.visitInsn(opcode);
	}
}
 
开发者ID:Javalbert,项目名称:faster-than-reflection,代码行数:22,代码来源:AsmUtils.java

示例4: pushInt

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void pushInt(MethodVisitor mv, int i) {
    if (0 <= i && i <= 5) {
        mv.visitInsn(Opcodes.ICONST_0 + i); //  ICONST_0 ~ ICONST_5
    } else if (i <= Byte.MAX_VALUE) {
        mv.visitIntInsn(Opcodes.BIPUSH, i);
    } else if (i <= Short.MAX_VALUE) {
        mv.visitIntInsn(Opcodes.SIPUSH, i);
    } else {
        mv.visitLdcInsn(i);
    }
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:12,代码来源:ShrinkRClassVisitor.java

示例5: visitIntInsn

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void visitIntInsn(MethodVisitor mv, int i) {
    switch (i) {
    case -1:
        mv.visitInsn(ICONST_M1);
        break;
    case 0:
        mv.visitInsn(ICONST_0);
        break;
    case 1:
        mv.visitInsn(ICONST_1);
        break;
    case 2:
        mv.visitInsn(ICONST_2);
        break;
    case 3:
        mv.visitInsn(ICONST_3);
        break;
    case 4:
        mv.visitInsn(ICONST_4);
        break;
    case 5:
        mv.visitInsn(ICONST_5);
        break;

    default:
        mv.visitIntInsn(BIPUSH, i);
        break;
    }
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:30,代码来源:ProxyClassGenerator.java

示例6: accept

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
    mv.visitIntInsn(opcode, operand);
    acceptAnnotations(mv);
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:6,代码来源:IntInsnNode.java

示例7: putInt

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Puts an integer value onto stack using the best possible method
 *
 * @param m method visitor
 * @param i int to be put
 */
public static void putInt(final MethodVisitor m, final int i)
{
    if ((i >= -1) && (i <= 5))
    {
        switch (i)
        {
            case -1:
                m.visitInsn(Opcodes.ICONST_M1);
                break;
            case 0:
                m.visitInsn(Opcodes.ICONST_0);
                break;
            case 1:
                m.visitInsn(Opcodes.ICONST_1);
                break;
            case 2:
                m.visitInsn(Opcodes.ICONST_2);
                break;
            case 3:
                m.visitInsn(Opcodes.ICONST_3);
                break;
            case 4:
                m.visitInsn(Opcodes.ICONST_4);
                break;
            case 5:
                m.visitInsn(Opcodes.ICONST_5);
                break;
        }
    }
    else if ((i >= Byte.MIN_VALUE) && (i <= Byte.MAX_VALUE))
    {
        m.visitIntInsn(Opcodes.BIPUSH, i);
    }
    else if ((i >= Short.MIN_VALUE) && (i <= Short.MAX_VALUE))
    {
        m.visitIntInsn(Opcodes.SIPUSH, i);
    }
    else
    {
        m.visitLdcInsn(i);
    }
}
 
开发者ID:MrGregorix,项目名称:Gasket,代码行数:49,代码来源:AsmUtils.java

示例8: createObjectArray

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * 创建局部参数代码
 *
 * @param mv
 * @param paramsTypeClass
 * @param isStatic
 */
private static void createObjectArray(MethodVisitor mv, List<Type> paramsTypeClass, boolean isStatic) {
    //Opcodes.ICONST_0 ~ Opcodes.ICONST_5 这个指令范围
    int argsCount = paramsTypeClass.size();
    //声明 Object[argsCount];
    if (argsCount >= 6) {
        mv.visitIntInsn(Opcodes.BIPUSH, argsCount);
    } else {
        mv.visitInsn(Opcodes.ICONST_0 + argsCount);
    }
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");

    //如果是static方法,没有this隐含参数
    int loadIndex = (isStatic ? 0 : 1);

    //填充数组数据
    for (int i = 0; i < argsCount; i++) {
        mv.visitInsn(Opcodes.DUP);
        if (i <= 5) {
            mv.visitInsn(Opcodes.ICONST_0 + i);
        } else {
            mv.visitIntInsn(Opcodes.BIPUSH, i);
        }

        //这里又要做特殊处理,在实践过程中发现个问题:public void xxx(long a, boolean b, double c,int d)
        //当一个参数的前面一个参数是long或者是double类型的话,后面参数在使用LOAD指令,加载数据索引值要+1
        //个人猜想是和long,double是8个字节的问题有关系。这里做了处理
        //比如这里的参数:[a=LLOAD 1] [b=ILOAD 3] [c=DLOAD 4] [d=ILOAD 6];
        if (i >= 1) {
            //这里需要判断当前参数的前面一个参数的类型是什么
            if ("J".equals(paramsTypeClass.get(i - 1).getDescriptor()) || "D".equals(paramsTypeClass.get(i - 1).getDescriptor())) {
                //如果前面一个参数是long,double类型,load指令索引就要增加1
                loadIndex++;
            }
        }
        if (!createPrimateTypeObj(mv, loadIndex, paramsTypeClass.get(i).getDescriptor())) {
            mv.visitVarInsn(Opcodes.ALOAD, loadIndex);
            mv.visitInsn(Opcodes.AASTORE);
        }
        loadIndex++;
    }
}
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:49,代码来源:RobustAsmUtils.java

示例9: generateHashCodeMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateHashCodeMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null);
    mv.visitCode();

    // int result = 1;

    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitInsn(ICONST_1);
    mv.visitVarInsn(ISTORE, 1);

    for (Parameter param : parameters) {
        Class<?> type = param.getType();
        mv.visitIntInsn(BIPUSH, 31);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(IMUL);
        mv.visitVarInsn(ALOAD, 0);
        Type typeType = Type.getType(type);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), typeType.getDescriptor());
        if (type.isPrimitive()) {
            Class<?> boxed = BytecodeGenUtils.getBoxed(type);
            mv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(boxed), "hashCode",
                    Type.getMethodDescriptor(Type.INT_TYPE, typeType), false);

        } else {
            mv.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "hashCode", "(Ljava/lang/Object;)I", false);
        }
        mv.visitInsn(IADD);
        mv.visitVarInsn(ISTORE, 1);
    }

    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(IRETURN);
    Label l7 = new Label();
    mv.visitLabel(l7);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l7, 0);
    mv.visitLocalVariable("result", "I", null, l0, l7, 1);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:43,代码来源:MethodArgumentssUpdaterGenerator.java

示例10: getPatchFileContents

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] getPatchFileContents(
         ImmutableList<String> patchFileContents,  ImmutableList<Integer> patchIndexContents) {
    if (patchFileContents.size() != patchIndexContents.size()) {
        throw new GradleException("patchFileContents's size is "
                + patchFileContents.size() + ", but patchIndexContents's size is "
                + patchIndexContents.size() + ", please check the changed classes.");
    }
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
            IncrementalVisitor.APP_PATCHES_LOADER_IMPL, null,
            IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, null);

    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
                IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL,
                "<init>", "()V", false);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC,
                "getPatchedClasses", "()[Ljava/lang/String;", null, null);
        mv.visitCode();

        mv.visitIntInsn(Opcodes.SIPUSH, patchFileContents.size());
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
        for (int index = 0; index < patchFileContents.size(); index++) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitIntInsn(Opcodes.SIPUSH, index);
            mv.visitLdcInsn(patchFileContents.get(index));
            mv.visitInsn(Opcodes.AASTORE);
        }
        mv.visitInsn(Opcodes.ARETURN);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC,
                "getPatchedClassIndexes", "()[I", null, null);
        mv.visitCode();

        mv.visitIntInsn(Opcodes.SIPUSH, patchIndexContents.size());
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT);
        for (int index = 0; index < patchIndexContents.size(); index++) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitIntInsn(Opcodes.SIPUSH, index);
            mv.visitLdcInsn(patchIndexContents.get(index));
            mv.visitInsn(Opcodes.IASTORE);
        }
        mv.visitInsn(Opcodes.ARETURN);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();

}
 
开发者ID:meili,项目名称:Aceso,代码行数:65,代码来源:IncrementalTool.java


注:本文中的org.objectweb.asm.MethodVisitor.visitIntInsn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。