當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。