Java Code Examples for org.objectweb.asm.commons.GeneratorAdapter#visitFieldInsn()
The following examples show how to use
org.objectweb.asm.commons.GeneratorAdapter#visitFieldInsn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RobustAsmUtils.java From Robust with Apache License 2.0 | 5 votes |
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); }
Example 2
Source File: RobustAsmUtils.java From Robust with Apache License 2.0 | 5 votes |
/** * Pushes in the stack the value that should be redirected for the given local. */ protected static void redirectLocal(GeneratorAdapter mv, Type arg) { switch (arg.getDescriptor()) { case "Z": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;"); break; case "B": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;"); break; case "C": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;"); break; case "S": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;"); break; case "I": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;"); break; case "F": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;"); break; case "D": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;"); break; case "J": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;"); break; case "V": mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); break; default: mv.visitLdcInsn(Type.getType(arg.getDescriptor())); } }
Example 3
Source File: RobustAsmUtils.java From Robust with Apache License 2.0 | 4 votes |
/** * 插入代码 * * @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) { prepareMethodParameters(mv, className, args, returnType, isStatic, methodId); //开始调用 mv.visitMethodInsn(Opcodes.INVOKESTATIC, PROXYCLASSNAME, "proxy", "([Ljava/lang/Object;Ljava/lang/Object;" + REDIRECTCLASSNAME + "ZI[Ljava/lang/Class;Ljava/lang/Class;)Lcom/meituan/robust/PatchProxyResult;", false); int local = mv.newLocal(Type.getType("Lcom/meituan/robust/PatchProxyResult;")); mv.storeLocal(local); mv.loadLocal(local); mv.visitFieldInsn(Opcodes.GETFIELD, "com/meituan/robust/PatchProxyResult", "isSupported", "Z"); // if isSupported Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, l1); //判断是否有返回值,代码不同 if ("V".equals(returnType.getDescriptor())) { mv.visitInsn(Opcodes.RETURN); } else { mv.loadLocal(local); mv.visitFieldInsn(Opcodes.GETFIELD, "com/meituan/robust/PatchProxyResult", "result", "Ljava/lang/Object;"); //强制转化类型 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); }