當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratorAdapter.visitLabel方法代碼示例

本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.visitLabel方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.visitLabel方法的具體用法?Java GeneratorAdapter.visitLabel怎麽用?Java GeneratorAdapter.visitLabel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.commons.GeneratorAdapter的用法示例。


在下文中一共展示了GeneratorAdapter.visitLabel方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitx

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (String string : strings) {
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
 
開發者ID:meili,項目名稱:Aceso,代碼行數:18,代碼來源:IntSwitch.java

示例2: redirect

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Adds the instructions to do a generic redirection.
 */
protected void redirect(GeneratorAdapter mv, int change) {
    // code to check if a new implementation of the current class is available.
    Label l0 = new Label();
    mv.loadLocal(change);
    mv.visitJumpInsn(Opcodes.IFNULL, l0);
    doRedirect(mv, change);

    // Return
    if (type == Type.VOID_TYPE) {
        mv.pop();
    } else {
        ByteCodeUtils.unbox(mv, type);
    }
    mv.returnValue();

    // jump label for classes without any new implementation, just invoke the original
    // method implementation.
    mv.visitLabel(l0);
}
 
開發者ID:meili,項目名稱:Aceso,代碼行數:23,代碼來源:Redirection.java

示例3: visitx

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Emit code for a string if-else block.
 *
 *     if (s.equals("collided_method1")) {
 *         visit(s);
 *     } else if (s.equals("collided_method2")) {
 *         visit(s);
 *     }
 *
 * In the most common case of just one string, this degenerates to:
 *
 *      visit(s)
 *
 */
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (int i = 0; i < strings.size(); ++i) {
        String string = strings.get(i);
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
 
開發者ID:dodola,項目名稱:AnoleFix,代碼行數:33,代碼來源:StringSwitch.java

示例4: redirect

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Adds the instructions to do a generic redirection.
 * <p/>
 * Note that the generated bytecode does not have a direct translation to code, but as an
 * example, the following code block gets inserted.
 * <code>
 * if ($change != null) {
 * $change.access$dispatch($name, new object[] { arg0, ... argsN })
 * $anyCodeInsertedbyRestore
 * }
 * $originalMethodBody
 * </code>
 *
 * @param mv     the method visitor to add the instructions to.
 * @param change the local variable containing the alternate implementation.
 * @param args   the type of the local variable that need to be forwarded.
 */
void redirect(GeneratorAdapter mv, int change, List<Type> args) {
    // code to check if a new implementation of the current class is available.
    Label l0 = new Label();
    mv.loadLocal(change);
    mv.visitJumpInsn(Opcodes.IFNULL, l0);
    mv.loadLocal(change);
    mv.push(name);

    // create an array of objects capable of containing all the parameters and optionally the "this"
    createLocals(mv, args);

    // we need to maintain the stack index when loading parameters from, as for long and double
    // values, it uses 2 stack elements, all others use only 1 stack element.
    int stackIndex = 0;
    for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
        Type arg = args.get(arrayIndex);
        // duplicate the array of objects reference, it will be used to store the value in.
        mv.dup();
        // index in the array of objects to store the boxed parameter.
        mv.push(arrayIndex);
        // Pushes the appropriate local variable on the stack
        redirectLocal(mv, stackIndex, arg);
        // potentially box up intrinsic types.
        mv.box(arg);
        mv.arrayStore(Type.getType(Object.class));
        // stack index must progress according to the parameter type we just processed.
        stackIndex += arg.getSize();
    }

    // now invoke the generic dispatch method.
    mv.invokeInterface(IncrementalVisitor.CHANGE_TYPE, Method.getMethod("Object access$dispatch(String, Object[])"));

    // Restore the state after the redirection
    restore(mv, args);
    // jump label for classes without any new implementation, just invoke the original
    // method implementation.
    mv.visitLabel(l0);
}
 
開發者ID:dodola,項目名稱:AnoleFix,代碼行數:56,代碼來源:Redirection.java

示例5: createInsertCode

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * 插入代碼
 *
 * @param mv
 * @param className
 * @param args
 * @param returnType
 * @param isStatic
 */
public static void createInsertCode(GeneratorAdapter mv, String className, List<Type> args, Type returnType, boolean isStatic, int methodId) {

    /**
     * 調用isSupport方法
     */
    prepareMethodParameters(mv, className, args, returnType, isStatic, methodId);
    //開始調用
    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            PROXYCLASSNAME,
            "isSupport",
            "([Ljava/lang/Object;Ljava/lang/Object;" + REDIRECTCLASSNAME + "ZI[Ljava/lang/Class;Ljava/lang/Class;)Z");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFEQ, l1);
    prepareMethodParameters(mv, className, args, returnType, isStatic, methodId);
    //開始調用
    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            PROXYCLASSNAME,
            "accessDispatch",
            "([Ljava/lang/Object;Ljava/lang/Object;" + REDIRECTCLASSNAME + "ZI[Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;");

    //判斷是否有返回值,代碼不同
    if ("V".equals(returnType.getDescriptor())) {
        mv.visitInsn(Opcodes.POP);
        mv.visitInsn(Opcodes.RETURN);
    } else {
        //強製轉化類型
        if (!castPrimateToObj(mv, returnType.getDescriptor())) {
            //這裏需要注意,如果是數組類型的直接使用即可,如果非數組類型,就得去除前綴了,還有最終是沒有結束符;
            //比如:Ljava/lang/String; ==》 java/lang/String
            String newTypeStr = null;
            int len = returnType.getDescriptor().length();
            if (returnType.getDescriptor().startsWith("[")) {
                newTypeStr = returnType.getDescriptor().substring(0, len);
            } else {
                newTypeStr = returnType.getDescriptor().substring(1, len - 1);
            }
            mv.visitTypeInsn(Opcodes.CHECKCAST, newTypeStr);
        }

        //這裏還需要做返回類型不同返回指令也不同
        mv.visitInsn(getReturnTypeCode(returnType.getDescriptor()));
    }

    mv.visitLabel(l1);
}
 
開發者ID:Meituan-Dianping,項目名稱:Robust,代碼行數:55,代碼來源:RobustAsmUtils.java


注:本文中的org.objectweb.asm.commons.GeneratorAdapter.visitLabel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。