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


Java MethodVisitor.visitMethodInsn方法代碼示例

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


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

示例1: invoke_methodhandle

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
public Container invoke_methodhandle(TMethodHandle mh_type) throws CompileException {
  MethodVisitor mv = getClosestFunContext().getMethodVisitor();

  Container loaded_obj = null;

  LOG.debug("Method Handle Call : " + mh_type);

  FuncSignatureDesc funcsig = mh_type.getFuncSignatureDesc();
  Debug.assertion(funcsig != null, "fucsig should be valid");

  LOG.info("INVOKEVIRTUAL java/lang/invoke/MethodHandle/invoke");
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", funcsig.getMthdDscStr(),
      false);

  AbsType rettype = funcsig.getReturnType();
  Debug.assertion(rettype != null, "rettype should be valid");

  loaded_obj = new Container("anonymous", Container.FORM_OPSTACK_VAR, true, false);
  loaded_obj.initializeType(rettype);
  return loaded_obj;
}
 
開發者ID:Samsung,項目名稱:MeziLang,代碼行數:22,代碼來源:ASTCompileVisitor.java

示例2: loadDataItem

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void loadDataItem(MethodVisitor mv, int var, Class<?> type) throws CompilerException {
    if(type != TemplateData.class) {
        throw new CompilerException("Can't parse a data item that is not a template data");
    }

    if(!vars.isEmpty()) {
        // TODO
        // d = new ScopedData(data, d);
        mv.visitTypeInsn(NEW, SCOPED_DATA.getInternalName());
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, vars.getLast());
        mv.visitVarInsn(ALOAD, var);
        mv.visitMethodInsn(INVOKESPECIAL, SCOPED_DATA.getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, DATA, DATA), false);
        mv.visitVarInsn(ASTORE, var);
    }

    vars.add(var);
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:21,代碼來源:SimpleDataManager.java

示例3: hookMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
/**
 * (none-javadoc)
 *
 * @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("lookup".equals(name) && desc.startsWith("(Ljava/lang/String;)")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodExit(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    mv.visitVarInsn(ALOAD, 2);
                    mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/ProxyDirContextHook", "checkResourceCacheEntry",
                            "(Ljava/lang/Object;)V", false);
                }
                super.onMethodExit(opcode);
            }

        };
    }
    return mv;
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:24,代碼來源:ProxyDirContextHook.java

示例4: generateUpdateMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateUpdateMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String argsClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "update", "()Lio/primeval/reflex/arguments/Arguments;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, argsClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, argsClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:26,代碼來源:MethodArgumentssUpdaterGenerator.java

示例5: insertStringGetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void insertStringGetter(MethodVisitor mv, int var, String key, boolean escaped) throws CompilerException {
    Class<?> type = insertGetter(mv, var, key, true).clazz;

    // String.valueOf(...)
    if(type.isPrimitive()) {
        mv.visitMethodInsn(INVOKESTATIC, STRING.getInternalName(), "valueOf",
                Type.getMethodDescriptor(STRING, Type.getType(type)), false);
    } else if(!String.class.isAssignableFrom(type)) {
        mv.visitMethodInsn(INVOKESTATIC, STRING.getInternalName(), "valueOf",
                Type.getMethodDescriptor(STRING, OBJECT), false);
    }

    // TemplateUtils.escapeString(...)
    if(escaped) {
        mv.visitMethodInsn(INVOKESTATIC, UTILS.getInternalName(), "escapeString",
                Type.getMethodDescriptor(STRING, STRING), false);
    }
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:20,代碼來源:ClassDataManager.java

示例6: generateClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static byte[] generateClass(Class<? extends TileEntity> baseClass, String className, String contentId)
{
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(baseClass), null);

    // Constructor
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(contentId);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(baseClass), "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();

    return cw.toByteArray();
}
 
開發者ID:cubex2,項目名稱:customstuff4,代碼行數:17,代碼來源:TileEntityRegistry.java

示例7: apply

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void apply(MethodVisitor mv) {
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "insertToDB", "(Lcom/lhh/lkdb/ILKDBModel;)Z", false);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:MeetYouDevs,項目名稱:LKDBHelper-ORM-Android,代碼行數:9,代碼來源:InsertToDBApply.java

示例8: insertNewInstance

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
static void insertNewInstance(ClassWriter cw, String classNameInternal) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newInstance", "()Ljava/lang/Object;", null, null);
	mv.visitCode();
	mv.visitTypeInsn(NEW, classNameInternal);
	mv.visitInsn(DUP);
	mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "()V");
	mv.visitInsn(ARETURN);
	mv.visitMaxs(2, 1);
	mv.visitEnd();
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:12,代碼來源:ConstructorAccess.java

示例9: apply

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void apply(MethodVisitor mv) {
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "updateToDBWithTableName", "(Lcom/lhh/lkdb/ILKDBModel;Ljava/lang/String;Ljava/lang/Object;)Z", false);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(3, 3);
    mv.visitEnd();
}
 
開發者ID:MeetYouDevs,項目名稱:LKDBHelper-ORM-Android,代碼行數:11,代碼來源:UpdateToDBWithTableNameApply.java

示例10: throwExceptionBecauseCalledOnItself

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void throwExceptionBecauseCalledOnItself(MethodVisitor methodVisitor) {
    String exceptionInternalName = Type.getInternalName(UnsupportedOperationException.class);
    methodVisitor.visitTypeInsn(NEW, exceptionInternalName);
    methodVisitor.visitInsn(DUP);
    putConstantOnStack(methodVisitor, "Calling setters of a managed type on itself is not allowed");

    String constructorDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, STRING_TYPE);
    methodVisitor.visitMethodInsn(INVOKESPECIAL, exceptionInternalName, CONSTRUCTOR_NAME, constructorDescriptor, false);
    methodVisitor.visitInsn(ATHROW);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:11,代碼來源:ManagedProxyClassGenerator.java

示例11: createDoubleObj

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void createDoubleObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Double");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.DLOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Double", "<init>", "(D)V");
    mv.visitInsn(Opcodes.AASTORE);
}
 
開發者ID:Meituan-Dianping,項目名稱:Robust,代碼行數:8,代碼來源:RobustAsmUtils.java

示例12: apply

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void apply(MethodVisitor mv) {
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "insertWhenNotExists", "(Lcom/lhh/lkdb/ILKDBModel;)Z", false);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:MeetYouDevs,項目名稱:LKDBHelper-ORM-Android,代碼行數:9,代碼來源:InsertWhenNotExistsApply.java

示例13: buildClosureClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void buildClosureClass(TContext closure_ctx) throws CompileException {
  Debug.assertion(closure_ctx instanceof TContextClosure, "closure_ctx should be closure ctx");

  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  ((TContextClosure) closure_ctx).setClassWriter(cw);

  cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, closure_ctx.getName(), null, "java/lang/Object", null);

  // default constructor
  MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
  mv.visitCode();

  LOG.info("ALOAD 0 for this");
  LOG.info("INVOKESPECIAL java/lang/Object");

  mv.visitVarInsn(Opcodes.ALOAD, 0); // this
  mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
  if (Debug.enable_compile_debug_print) {
    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn(closure_ctx.getName() + " was instantiated");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
  }
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(0, 0);
  mv.visitEnd();
  // end default constructor

  TContext parent_ctx = (TContext) closure_ctx.getOwnerType();
  Debug.assertion(parent_ctx != null, "parent_ctx should be valid");

  // add closure class member field
  Container var_cont = null;
  AbsType var_type = null;

  LinkedList<Container> var_list = closure_ctx.get_childvar_list();
  int var_size = var_list.size();
  Container closure_member_var = null;

  for (int i = 0; i < var_size; i++) {
    closure_member_var = var_list.get(i);
    var_cont = closure_member_var.getClosureOrgFuncvarContainer();

    Debug.assertion(var_cont != null, "var_cont should be valid");
    // Debug.assertion(var_cont.isForm(Container.FORM_FUNSTACK_VAR), "var_cont
    // should be stack variable");
    Debug.assertion(var_cont.isTypeInitialized(), "var_cont type should be initialized");

    if (var_cont.isForm(Container.FORM_FUNSTACK_VAR)) {
      // only assigned stack variable will be copied
      if (var_cont.isAssigned()) {
        LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
        var_type = var_cont.getType();
        cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
      }
    } else if (var_cont.isForm(Container.FORM_OBJMEMBER_VAR)) {
      LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
      var_type = var_cont.getType();
      cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
    } else {
      throw new CompileException("Invalid var_cont form(" + var_cont + ")");
    }

  }

}
 
開發者ID:Samsung,項目名稱:MeziLang,代碼行數:66,代碼來源:ASTCompileVisitor.java

示例14: insertGetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private MemberType insertGetter(MethodVisitor mv, Class<?> clazz, int var, String key, boolean basicType) {
    Member[] members = findPath(clazz, key);
    if(members == null || members.length == 0) {
        return null;
    }

    mv.visitVarInsn(ALOAD, var);

    for(int i = 0; i < members.length; i++) {
        Member member = members[i];
        boolean last = i == members.length - 1;

        if(member instanceof Method) {

            Method method = (Method)member;
            Class<?> returnClass = method.getReturnType();
            Class<?> declaringClass = method.getDeclaringClass();
            Type returnType = Type.getType(returnClass);

            boolean itf = declaringClass.isInterface();
            mv.visitMethodInsn(itf ? INVOKEINTERFACE : INVOKEVIRTUAL, Type.getInternalName(declaringClass),
                    method.getName(), Type.getMethodDescriptor(returnType), itf);

            if(last) {
                return basicType ? new MemberType(returnClass, returnType) : new MemberType(method, returnType);
            }

        } else if(member instanceof Field) {

            Field field = (Field)member;
            Class<?> fieldClass = field.getType();
            Type fieldType = Type.getType(fieldClass);

            mv.visitFieldInsn(GETFIELD, Type.getInternalName(field.getDeclaringClass()),
                    field.getName(), fieldType.getDescriptor());

            if(last) {
                return basicType ? new MemberType(fieldClass, fieldType) : new MemberType(field, fieldType);
            }

        }
    }

    // The code should never reach here
    return null;
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:47,代碼來源:ClassDataManager.java

示例15: findClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (name.equals(POISON_IMPL_NAME)) {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, POISON_IMPL_NAME.replace('.', '/'), null, Type.getInternalName(Pill.class), null);
        // constructor
        MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        constructor.visitCode();
        constructor.visitVarInsn(Opcodes.ALOAD, 0);
        constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Pill.class), "<init>", "()V", false);
        constructor.visitInsn(Opcodes.RETURN);
        constructor.visitMaxs(0, 0);
        constructor.visitEnd();

        MethodVisitor setList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setField", "()V", null, null);
        setList.visitCode();
        setList.visitVarInsn(Opcodes.ALOAD, 0);
        setList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        setList.visitInsn(Opcodes.DUP);
        setList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        setList.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(Pill.class), "field", Type.getDescriptor(TestInterface.class));
        setList.visitInsn(Opcodes.RETURN);
        setList.visitMaxs(0, 0);
        setList.visitEnd();

        MethodVisitor setStaticList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setStaticField", "()V", null, null);
        setStaticList.visitCode();
        setStaticList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        setStaticList.visitInsn(Opcodes.DUP);
        setStaticList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        setStaticList.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(Pill.class), "staticField", Type.getDescriptor(TestInterface.class));
        setStaticList.visitInsn(Opcodes.RETURN);
        setStaticList.visitMaxs(0, 0);
        setStaticList.visitEnd();

        MethodVisitor callMe = cw.visitMethod(Opcodes.ACC_PUBLIC, "callMe", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(CallBack.class)), null, null);
        callMe.visitCode();
        callMe.visitVarInsn(Opcodes.ALOAD, 1);
        callMe.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        callMe.visitInsn(Opcodes.DUP);
        callMe.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        callMe.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(CallBack.class), "callBack", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(TestInterface.class)), true);
        callMe.visitInsn(Opcodes.IRETURN);
        callMe.visitMaxs(0, 0);
        callMe.visitEnd();

        MethodVisitor getList = cw.visitMethod(Opcodes.ACC_PUBLIC, "get", Type.getMethodDescriptor(Type.getType(TestInterface.class)), null, null);
        getList.visitCode();
        getList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        getList.visitInsn(Opcodes.DUP);
        getList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        getList.visitInsn(Opcodes.ARETURN);
        getList.visitMaxs(0, 0);
        getList.visitEnd();

        cw.visitEnd();

        byte[] bytes = cw.toByteArray();
        return defineClass(name, bytes, 0, bytes.length);
    }
    return super.findClass(name);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:64,代碼來源:UntrustedInterfaces.java


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