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


Java GeneratorAdapter.visitCode方法代碼示例

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


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

示例1: establishCallback

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public static void establishCallback(ClassNode cn, MethodNode mn) {
    if (!mn.desc.startsWith("()")) {
        MethodNode blank = new MethodNode();
        Method method = new Method(mn.name, mn.desc);
        GeneratorAdapter adapter = new GeneratorAdapter(mn.access, method, blank);
        adapter.visitCode();
        adapter.push(cn.name + "." + mn.name + "  " + mn.desc);
        adapter.loadArgArray();
        adapter.invokeStatic(Type.getType(CallFactory.class), new Method("testInvoke",
                "(Ljava/lang/String;[Ljava/lang/Object;)V"));
        for (AbstractInsnNode ain : mn.instructions.toArray()) {
            if (ain instanceof VarInsnNode) {
                mn.instructions.insertBefore(ain, blank.instructions);
                return;
            }
        }
    }
}
 
開發者ID:disassemble-io,項目名稱:agent-callback,代碼行數:19,代碼來源:CallFactory.java

示例2: emitMethods

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
protected void emitMethods(ClassVisitor cv){
	//override of invoke/doInvoke for each method
	for(ISeq s = RT.seq(methods); s != null; s = s.next())
		{
		ObjMethod method = (ObjMethod) s.first();
		method.emit(this, cv);
		}

	if(isVariadic())
		{
		GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
		                                            Method.getMethod("int getRequiredArity()"),
		                                            null,
		                                            null,
		                                            cv);
		gen.visitCode();
		gen.push(variadicMethod.reqParms.count());
		gen.returnValue();
		gen.endMethod();
		}
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:22,代碼來源:Compiler.java

示例3: generateFailedMethod

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null -> fail")
static void generateFailedMethod(ClassVisitor cv, Method interfaceMethod, String errorMessage) {
    String methodName = interfaceMethod.getName();
    String methodDescriptor = Type.getMethodDescriptor(interfaceMethod);
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDescriptor);
    adapter.visitCode();

    /* Throw exception */
    adapter.throwException(Type.getType(RuntimeException.class), errorMessage);

    /* End method generation */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:15,代碼來源:MethodGenerator.java

示例4: doEmit

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void doEmit(ObjExpr fn, ClassVisitor cv){
	Method m = new Method(getMethodName(), getReturnType(), getArgTypes());

	GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
	                                            m,
	                                            null,
	                                            //todo don't hardwire this
	                                            EXCEPTION_TYPES,
	                                            cv);
	gen.visitCode();

	Label loopLabel = gen.mark();
	gen.visitLineNumber(line, loopLabel);
	try
		{
		Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));

		body.emit(C.RETURN, fn, gen);
		Label end = gen.mark();

		gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
		for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
			{
			LocalBinding lb = (LocalBinding) lbs.first();
			gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
			}
		}
	finally
		{
		Var.popThreadBindings();
		}

	gen.returnValue();
	//gen.visitMaxs(1, 1);
	gen.endMethod();
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:37,代碼來源:Compiler.java

示例5: emit

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emit(ObjExpr fn, ClassVisitor cv){
	Method m = new Method(getMethodName(), getReturnType(), getArgTypes());

	GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
	                                            m,
	                                            null,
	                                            //todo don't hardwire this
	                                            EXCEPTION_TYPES,
	                                            cv);
	gen.visitCode();

	Label loopLabel = gen.mark();
	gen.visitLineNumber(line, loopLabel);
	try
		{
		Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));

		body.emit(C.RETURN, fn, gen);
		Label end = gen.mark();
		gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
		for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
			{
			LocalBinding lb = (LocalBinding) lbs.first();
			gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
			}
		}
	finally
		{
		Var.popThreadBindings();
		}

	gen.returnValue();
	//gen.visitMaxs(1, 1);
	gen.endMethod();
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:36,代碼來源:Compiler.java

示例6: generateMethodProxy

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, null, null, _, _ -> fail")
static void generateMethodProxy(ClassVisitor cv, Method interfaceMethod,
                                Type reflectorClass, Type targetClass, Type interfaceClass,
                                String targetMethodName, Type[] targetParameters, Type targetReturnType,
                                int flags, int mhIndex) {
    String methodName = interfaceMethod.getName();
    String methodDesc = Type.getMethodDescriptor(interfaceMethod);
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
    adapter.visitCode();

    /* Load MethodHandle, if required */
    loadMH(adapter, reflectorClass, flags, mhIndex);

    /* Load instance, if required */
    loadInstance(adapter, reflectorClass, targetClass, flags);

    /* Load method parameters into stack */
    loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
        /* Build MethodHandle descriptor (invokeExact is polymorphic) */
        String mhDescriptor = convertDesc(targetParameters,
                ((flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetReturnType : OBJECT),
                (flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT) : null);

        /* Select right MethodHandle invoker */
        String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";

        /* Invoke MethodHandle */
        mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
    } else {
        /* Figure out what opcode to use */
        int opCode = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ?
                ((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEINTERFACE : INVOKESTATIC)
                :
                ((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEVIRTUAL : INVOKESTATIC);

        /* Build descriptor & select target class */
        String targetDescriptor = convertDesc(targetParameters, targetReturnType, null);
        String targetName = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ? interfaceClass.getInternalName() : targetClass.getInternalName();

        /* Invoke method */
        adapter.visitMethodInsn(opCode, targetName, targetMethodName, targetDescriptor, (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0);
    }

    /* Return */
    handleReturn(adapter, interfaceMethod, targetReturnType);
    adapter.returnValue();

    /* End method */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:54,代碼來源:MethodGenerator.java

示例7: generateConstructorProxy

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, _, _ -> fail")
static void generateConstructorProxy(ClassVisitor cv, Method interfaceMethod,
                                     Type reflectorClass, Type targetClass,
                                     Type[] targetParameters,
                                     int flags, int mhIndex) {
    String methodName = interfaceMethod.getName();
    String methodDesc = Type.getMethodDescriptor(interfaceMethod);
    String targetClassName = targetClass.getInternalName();
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
    adapter.visitCode();

    /* Load MethodHandle, if required */
    loadMH(adapter, reflectorClass, flags, mhIndex);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) == 0) {
        adapter.visitTypeInsn(NEW, targetClassName);
        adapter.visitInsn(DUP);
    }

    /* Load method parameters into stack */
    loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.RETURN_TYPE_PUBLIC) != 0);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
        /* Build MethodHandle descriptor */
        String mhDescriptor = convertDesc(targetParameters,
                (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT, null);

        /* Select right MethodHandle invoker */
        String mhInvoker = (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";

        /* Invoke MethodHandle */
        mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
    } else {
        /* Build target descriptor */
        String targetDesc = convertDesc(targetParameters, Type.VOID_TYPE, null);

        /* Invoke constructor */
        adapter.visitMethodInsn(INVOKESPECIAL, targetClassName, "<init>", targetDesc, false);
    }

    /* Return */
    handleReturn(adapter, interfaceMethod, (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT);
    adapter.returnValue();

    /* End method */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:49,代碼來源:MethodGenerator.java

示例8: generateFieldReadMethod

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldReadMethod(ClassVisitor cv, Method interfaceMethod,
                                    Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
                                    int flags, int mhIndex) {
    String methodName = interfaceMethod.getName();
    String methodDesc = Type.getMethodDescriptor(interfaceMethod);
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
    adapter.visitCode();

    /* Load MethodHandle, if required */
    loadMH(adapter, reflectorClass, flags, mhIndex);

    /* Load instance, if required */
    loadInstance(adapter, reflectorClass, targetClass, flags);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
        /* Build MethodHandle descriptor */
        String mhDescriptor = newDescriptor()
                .accepts((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor() : "")
                .returns(fieldType.getDescriptor())
                .toString();

        /* Select right MethodHandle invoker */
        String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";

        /* Invoke MethodHandle */
        adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
    } else {
        if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
            adapter.getField(targetClass, fieldName, fieldType);
        else
            adapter.getStatic(targetClass, fieldName, fieldType);
    }

    /* Return */
    handleReturn(adapter, interfaceMethod, fieldType);
    adapter.returnValue();

    /* End method */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:43,代碼來源:MethodGenerator.java

示例9: generateFieldWriteMethod

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldWriteMethod(ClassVisitor cv, Method interfaceMethod,
                                     Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
                                     int flags, int mhIndex) {
    String methodName = interfaceMethod.getName();
    String methodDesc = Type.getMethodDescriptor(interfaceMethod);
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
    adapter.visitCode();

    /* Load MethodHandle, if required */
    loadMH(adapter, reflectorClass, flags, mhIndex);

    /* Load instance, if required */
    loadInstance(adapter, reflectorClass, targetClass, flags);

    /* Load method parameter into stack */
    adapter.loadArg(0);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
        /* Build MethodHandle descriptor */
        String mhDescriptor = newDescriptor()
                .accepts(((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ?
                        ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor(): "")
                        + fieldType.getDescriptor())
                .toString();

        /* Select right MethodHandle invoker */
        String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";

        /* Invoke MethodHandle */
        adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
    } else {
        if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
            adapter.putField(targetClass, fieldName, fieldType);
        else
            adapter.putStatic(targetClass, fieldName, fieldType);
    }

    /* Return */
    adapter.returnValue();

    /* End method */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:46,代碼來源:MethodGenerator.java


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