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


Java GeneratorAdapter.visitJumpInsn方法代碼示例

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


在下文中一共展示了GeneratorAdapter.visitJumpInsn方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: doEmit

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUnboxed){
	Label nullLabel = gen.newLabel();
	Label falseLabel = gen.newLabel();
	Label endLabel = gen.newLabel();

	gen.visitLineNumber(line, gen.mark());

	if(testExpr instanceof StaticMethodExpr && ((StaticMethodExpr)testExpr).canEmitIntrinsicPredicate())
		{
		((StaticMethodExpr) testExpr).emitIntrinsicPredicate(C.EXPRESSION, objx, gen, falseLabel);
		}
	else if(maybePrimitiveType(testExpr) == boolean.class)
		{
		((MaybePrimitiveExpr) testExpr).emitUnboxed(C.EXPRESSION, objx, gen);
		gen.ifZCmp(gen.EQ, falseLabel);
		}
	else
		{
		testExpr.emit(C.EXPRESSION, objx, gen);
		gen.dup();
		gen.ifNull(nullLabel);
		gen.getStatic(BOOLEAN_OBJECT_TYPE, "FALSE", BOOLEAN_OBJECT_TYPE);
		gen.visitJumpInsn(IF_ACMPEQ, falseLabel);
		}
	if(emitUnboxed)
		((MaybePrimitiveExpr)thenExpr).emitUnboxed(context, objx, gen);
	else
		thenExpr.emit(context, objx, gen);
	gen.goTo(endLabel);
	gen.mark(nullLabel);
	gen.pop();
	gen.mark(falseLabel);
	if(emitUnboxed)
		((MaybePrimitiveExpr)elseExpr).emitUnboxed(context, objx, gen);
	else
		elseExpr.emit(context, objx, gen);
	gen.mark(endLabel);
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:39,代碼來源:Compiler.java

示例6: emit

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
    Label endLabel = gen.newLabel();
    Label faultLabel = gen.newLabel();

    gen.visitLineNumber(line, gen.mark());
    gen.getStatic(objx.objtype, objx.thunkNameStatic(siteIndex),ObjExpr.ILOOKUP_THUNK_TYPE);
    gen.dup();  //thunk, thunk
    target.emit(C.EXPRESSION, objx, gen); //thunk,thunk,target
    gen.visitLineNumber(line, gen.mark());
    gen.dupX2();                          //target,thunk,thunk,target
    gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, Method.getMethod("Object get(Object)")); //target,thunk,result
    gen.dupX2();                          //result,target,thunk,result
    gen.visitJumpInsn(IF_ACMPEQ, faultLabel); //result,target
    gen.pop();                                //result
    gen.goTo(endLabel);

    gen.mark(faultLabel);    //result,target
    gen.swap();              //target,result
    gen.pop();               //target
 gen.dup();               //target,target
    gen.getStatic(objx.objtype, objx.siteNameStatic(siteIndex),ObjExpr.KEYWORD_LOOKUPSITE_TYPE);  //target,target,site
    gen.swap();              //target,site,target
    gen.invokeInterface(ObjExpr.ILOOKUP_SITE_TYPE,
                        Method.getMethod("clojure.lang.ILookupThunk fault(Object)"));    //target,new-thunk
 gen.dup();   //target,new-thunk,new-thunk
 gen.putStatic(objx.objtype, objx.thunkNameStatic(siteIndex),ObjExpr.ILOOKUP_THUNK_TYPE);  //target,new-thunk
 gen.swap();              //new-thunk,target
 gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, Method.getMethod("Object get(Object)")); //result

    gen.mark(endLabel);
    if(context == C.STATEMENT)
        gen.pop();
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:34,代碼來源:Compiler.java

示例7: emitThenForHashes

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private void emitThenForHashes(ObjExpr objx, GeneratorAdapter gen, Expr test, Expr then, Label defaultLabel, boolean emitUnboxed){
    expr.emit(C.EXPRESSION, objx, gen);
    test.emit(C.EXPRESSION, objx, gen);
    if(testType == hashIdentityKey)
        {
        gen.visitJumpInsn(IF_ACMPNE, defaultLabel);
        }
    else
        {
        gen.invokeStatic(UTIL_TYPE, equivMethod);
        gen.ifZCmp(GeneratorAdapter.EQ, defaultLabel);
        }
    emitExpr(objx, gen, then, emitUnboxed);
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:15,代碼來源:Compiler.java

示例8: 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

示例9: emitProto

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emitProto(C context, ObjExpr objx, GeneratorAdapter gen){
	Label onLabel = gen.newLabel();
	Label callLabel = gen.newLabel();
	Label endLabel = gen.newLabel();

	Var v = ((VarExpr)fexpr).var;

	Expr e = (Expr) args.nth(0);
	e.emit(C.EXPRESSION, objx, gen);
	gen.dup(); //target, target
	gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class
	gen.getStatic(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target,class,cached-class
	gen.visitJumpInsn(IF_ACMPEQ, callLabel); //target
	if(protocolOn != null)
		{
		gen.dup(); //target, target			
		gen.instanceOf(Type.getType(protocolOn));
		gen.ifZCmp(GeneratorAdapter.NE, onLabel);
		}

	gen.dup(); //target, target
	gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class
	gen.putStatic(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target

	gen.mark(callLabel); //target
	objx.emitVar(gen, v);
	gen.invokeVirtual(VAR_TYPE, Method.getMethod("Object getRawRoot()")); //target, proto-fn
	gen.swap();
	emitArgsAndCall(1, context,objx,gen);
	gen.goTo(endLabel);

	gen.mark(onLabel); //target
	if(protocolOn != null)
		{
		MethodExpr.emitTypedArgs(objx, gen, onMethod.getParameterTypes(), RT.subvec(args,1,args.count()));
		if(context == C.RETURN)
			{
			ObjMethod method = (ObjMethod) METHOD.deref();
			method.emitClearLocals(gen);
			}
		Method m = new Method(onMethod.getName(), Type.getReturnType(onMethod), Type.getArgumentTypes(onMethod));
		gen.invokeInterface(Type.getType(protocolOn), m);
		HostExpr.emitBoxReturn(objx, gen, onMethod.getReturnType());
		}
	gen.mark(endLabel);
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:47,代碼來源:Compiler.java


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