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


Java GeneratorAdapter.visitVarInsn方法代碼示例

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


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

示例1: loadVariableArray

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Given an array on the stack, it loads it with the values of the given variables stating at
 * offset.
 */
static void loadVariableArray(
         GeneratorAdapter mv,
         List<LocalVariable> variables, int offset) {
    // 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.
    for (int i = offset; i < variables.size(); i++) {
        LocalVariable variable = variables.get(i);
        // 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(i);
        // Pushes the appropriate local variable on the stack
        mv.visitVarInsn(variable.type.getOpcode(Opcodes.ILOAD), variable.var);
        // potentially box up intrinsic types.
        mv.box(variable.type);
        // store it in the array
        mv.arrayStore(Type.getType(Object.class));
    }
}
 
開發者ID:meili,項目名稱:Aceso,代碼行數:24,代碼來源:ByteCodeUtils.java

示例2: prepareMethodParameters

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private static void prepareMethodParameters(GeneratorAdapter mv, String className, List<Type> args, Type returnType, boolean isStatic, int methodId) {
    //第一個參數:new Object[]{...};,如果方法沒有參數直接傳入new Object[0]
    if (args.size() == 0) {
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    } else {
        createObjectArray(mv, args, isStatic);
    }

    //第二個參數:this,如果方法是static的話就直接傳入null
    if (isStatic) {
        mv.visitInsn(Opcodes.ACONST_NULL);
    } else {
        mv.visitVarInsn(Opcodes.ALOAD, 0);
    }

    //第三個參數:changeQuickRedirect
    mv.visitFieldInsn(Opcodes.GETSTATIC,
            className,
            REDIRECTFIELD_NAME,
            REDIRECTCLASSNAME);

    //第四個參數:false,標誌是否為static
    mv.visitInsn(isStatic ? Opcodes.ICONST_1 : Opcodes.ICONST_0);
    //第五個參數:
    mv.push(methodId);
    //第六個參數:參數class數組
    createClassArray(mv, args);
    //第七個參數:返回值類型class
    createReturnClass(mv, returnType);
}
 
開發者ID:Meituan-Dianping,項目名稱:Robust,代碼行數:32,代碼來源:RobustAsmUtils.java

示例3: emitUnboxedLocal

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private void emitUnboxedLocal(GeneratorAdapter gen, LocalBinding lb){
	int argoff = canBeDirect ?0:1;
	Class primc = lb.getPrimitiveType();
	if(closes.containsKey(lb))
		{
		gen.loadThis();
		gen.getField(objtype, lb.name, Type.getType(primc));
		}
	else if(lb.isArg)
		gen.loadArg(lb.idx-argoff);
	else
		gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), lb.idx);
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:14,代碼來源:Compiler.java

示例4: emitClearLocalsOld

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
void emitClearLocalsOld(GeneratorAdapter gen){
		for(int i=0;i<argLocals.count();i++)
			{
			LocalBinding lb = (LocalBinding) argLocals.nth(i);
			if(!localsUsedInCatchFinally.contains(lb.idx) && lb.getPrimitiveType() == null)
				{
				gen.visitInsn(Opcodes.ACONST_NULL);
				gen.storeArg(lb.idx - 1);
				}

			}
//		for(int i = 1; i < numParams() + 1; i++)
//			{
//			if(!localsUsedInCatchFinally.contains(i))
//				{
//				gen.visitInsn(Opcodes.ACONST_NULL);
//				gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
//				}
//			}
		for(int i = numParams() + 1; i < maxLocal + 1; i++)
			{
			if(!localsUsedInCatchFinally.contains(i))
				{
				LocalBinding b = (LocalBinding) RT.get(indexlocals, i);
				if(b == null || maybePrimitiveType(b.init) == null)
					{
					gen.visitInsn(Opcodes.ACONST_NULL);
					gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
					}
				}
			}
	}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:33,代碼來源:Compiler.java

示例5: redirectLocal

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Pushes in the stack the value that should be redirected for the given local.
 */
protected void redirectLocal(GeneratorAdapter mv, int local, Type arg) {
    mv.visitVarInsn(arg.getOpcode(Opcodes.ILOAD), local);
}
 
開發者ID:dodola,項目名稱:AnoleFix,代碼行數:7,代碼來源:Redirection.java

示例6: restore

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
protected void restore(GeneratorAdapter mv, List<Type> args) {
    // At this point, init$args has been called and the result Object is on the stack.
    // The value of that Object is Object[] with exactly n + 1 elements.
    // The first element is a string with the qualified name of the constructor to call.
    // The remaining elements are the constructtor arguments.

    // Create a new local that holds the result of init$args call.
    mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
    int constructorArgs = mv.newLocal(Type.getType("[Ljava/lang/Object;"));
    mv.storeLocal(constructorArgs);

    // Reinstate local values
    mv.loadLocal(locals);
    int stackIndex = 0;
    for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
        Type arg = args.get(arrayIndex);
        // Do not restore "this"
        if (arrayIndex > 0) {
            // duplicates the array
            mv.dup();
            // index in the array of objects to restore the boxed parameter.
            mv.push(arrayIndex);
            // get it from the array
            mv.arrayLoad(Type.getType(Object.class));
            // unbox the argument
            ByteCodeUtils.unbox(mv, arg);
            // restore the argument
            mv.visitVarInsn(arg.getOpcode(Opcodes.ISTORE), stackIndex);
        }
        // stack index must progress according to the parameter type we just processed.
        stackIndex += arg.getSize();
    }
    // pops the array
    mv.pop();

    // Push a null for the marker parameter.
    mv.loadLocal(constructorArgs);
    mv.visitInsn(Opcodes.ACONST_NULL);

    // Invoke the constructor
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, thisClassName, "<init>", DISPATCHING_THIS_SIGNATURE, false);

    mv.goTo(end.getLabel());
}
 
開發者ID:dodola,項目名稱:AnoleFix,代碼行數:46,代碼來源:ConstructorArgsRedirection.java

示例7: generateMethod

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * 生成方法
 * @param cw
 * @param method
 * @param exceptions
 * @param interfaceClazz
 */
private static ClassWriter generateMethod(ClassWriter cw,java.lang.reflect.Method method,Class<Prepared> prepared){
	
	org.objectweb.asm.commons.Method m = new org.objectweb.asm.commons.Method(method.getName(), Type.getMethodDescriptor(method));
	GeneratorAdapter mv = new GeneratorAdapter(ACC_PUBLIC, m, null, null,cw);

	mv.visitLdcInsn(method.getName()); // excute的第1參數
	mv.visitLdcInsn(Type.getType(method).getDescriptor()); // excute的第2參數
	
	//  excute的第3參數(是可變參數)
	Parameter[] parameters = method.getParameters();
	mv = setIn(mv, parameters); 

	// excute的第4個參數
	mv.visitVarInsn(ALOAD, 0);
	
	// 調用Prepared中的excute方法
	// INVOKESTATIC
	mv.visitMethodInsn(INVOKESTATIC, Type.getType(prepared).getInternalName(), "excute", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lorg/fastquery/core/Repository;)Ljava/lang/Object;", false);
	
	// 返回值處理
	String internalName  = Type.getInternalName(method.getReturnType());
	int sort = Type.getReturnType(method).getSort();
	if( sort == 0 ) { // 如果返回值是 Void
		mv.visitInsn(POP);
		mv.visitInsn(RETURN);
	} else if( (1 <= sort) && (sort <= 8)  ) { // 如果是基本類型 [1,8]
		Object[] objs = TypeUtil.getTypeInfo(Type.getReturnType(method).getDescriptor());
		String type = objs[0].toString();
		mv.visitTypeInsn(CHECKCAST, type);
		mv.visitMethodInsn(INVOKEVIRTUAL, type, objs[1].toString(), objs[2].toString(), false);
		// Integer.parseInt(objs[3].toString()) 比 Integer.valueOf(objs[3].toString()).intValue()更優.
		mv.visitInsn(Integer.parseInt(objs[3].toString()));
		
	} else { //sort==9 表述數組類型int[]或Integer[], srot=10表示包裝類型
		mv.visitTypeInsn(CHECKCAST, internalName);
		mv.visitInsn(ARETURN);
	}
	
	// mv.visitEnd()
	mv.endMethod();	
	return cw;
}
 
開發者ID:xixifeng,項目名稱:fastquery,代碼行數:50,代碼來源:AsmRepository.java


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