List of usage examples for org.objectweb.asm MethodVisitor visitLdcInsn
public void visitLdcInsn(final Object value)
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates _asActions() method as following: * // www . ja v a2s . com * if(name.equals("upload")) * return upload(); * else if(name.equals("save")) * return save(); * else if(name.equals("main")) * return main(); * else if(name.equals("redir")) * return redir(); * else * throw new RuntimeException("no action named "+name); */ private void createActionMethod() { StringBuilder sb = new StringBuilder(); sb.append("(").append(Type.getType(String.class)).append(")").append(Type.getType(Result.class)); String desc = sb.toString(); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asAction", desc, null, null); Label start = new Label(); Label next = new Label(); Label variable = new Label(); boolean first = true; for (String name : reflector.getActions().keySet()) { Label l0 = null; Label l1 = new Label(); if (first) { l0 = new Label(); first = false; } else { l0 = next; next = new Label(); } mv.visitLabel(l0); if (!first) { mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(name); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); mv.visitJumpInsn(Opcodes.IFEQ, next); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), name, "()" + Type.getType(Result.class), false); mv.visitInsn(Opcodes.ARETURN); } mv.visitLabel(next); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(Opcodes.NEW, "java/lang/NoSuchMethodException"); mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("no @Action named "); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/NoSuchMethodException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(variable); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, start, next, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, start, next, 1); mv.visitMaxs(5, 2); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates the _asParameter() getter as * //ww w. j a v a 2s . c o m * public Object _asParameter(String name) { * if(name.equals("name")) * return getName(); * if(name.equals("date")) * return getDate(); * ... * return null; * } */ private void createParametersGetterMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asParameter", "(Ljava/lang/String;)Ljava/lang/Object;", null, null); Label start = new Label(); Label next = new Label(); Label variable = new Label(); boolean first = true; for (String name : reflector.getParameters().keySet()) { Label l0 = null; Label l1 = new Label(); if (first) { l0 = new Label(); first = false; } else { l0 = next; next = new Label(); } mv.visitLabel(l0); if (!first) mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(name); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); mv.visitJumpInsn(Opcodes.IFEQ, next); String methodGetterName = reflector.getGetters().get(name).getName(); String methodGetterDesc = "()" + Type.getDescriptor(reflector.getParameters().get(name)); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), methodGetterName, methodGetterDesc, false); mv.visitInsn(Opcodes.ARETURN); } mv.visitLabel(next); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(variable); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, start, variable, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, start, variable, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Creates the code as://from w w w. j ava 2s . co m * * public void _asParameter(String name, Object value) { * if(name.equals("name") { * setName((String)value); * return; * } * if(name.equals("date") { * setDate((Date)value); * return; * } * ... * return; * } */ private void createParametersSetterMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asParameter", "(Ljava/lang/String;Ljava/lang/Object;)V", null, null); Label start = new Label(); Label next = new Label(); Label variable = new Label(); boolean first = true; for (String name : reflector.getParameters().keySet()) { Label l0 = null; Label l1 = new Label(); Label l2 = new Label(); if (first) { l0 = new Label(); first = false; } else { l0 = next; next = new Label(); } mv.visitLabel(l0); if (!first) mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(name); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); mv.visitJumpInsn(Opcodes.IFEQ, next); Class<?> parameterType = reflector.getParameters().get(name); String setterMethodName = reflector.getSetters().get(name).getName(); String setterMethodDesc = "(" + Type.getDescriptor(parameterType) + ")V"; mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(parameterType)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), setterMethodName, setterMethodDesc, false); mv.visitLabel(l2); mv.visitInsn(Opcodes.RETURN); } mv.visitLabel(next); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(variable); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, start, next, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, start, next, 1); mv.visitLocalVariable("value", "Ljava/lang/Object;", null, start, next, 2); mv.visitMaxs(2, 3); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates the _asUrl() method with using a constant string * public String _asUrl() { return "/*"; } */// w w w . j a va2s. c o m public void createUrlMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asUrl", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(reflector.getUrl()); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLocalVariable("this", Type.getDescriptor(reflector.getClazz()), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:jaspex.speculation.runtime.CodegenHelper.java
License:Open Source License
public static byte[] generateClass(Type codegenType) { // Obter id a partir do tipo String name = codegenType.commonName(); name = name.replaceFirst(Matcher.quoteReplacement(CODEGEN_CLASS_PREFIX), ""); int id = Integer.parseInt(name.substring(0, name.indexOf("$"))); // Obter InvokedMethod InvokedMethod method = _idToMethodMap.get(id); Log.trace(color("[ CodeGen ]", "31") + " Generating wrapper for {}.{}{}", method.owner(), method.name(), method.desc());/*from w w w . j a v a 2 s . c om*/ UtilList<Type> arguments = method.argumentTypes(); if (!method.isStatic()) arguments.addFirst(method.owner()); String argumentsDesc = ""; for (Type type : arguments) argumentsDesc += type.bytecodeName(); // Optimizao: Se mtodo for ()V e static, criamos um singleton apenas com o call, // e tornamos o constructor private para que a classe no seja instanciada // noutros locais boolean singletonMode = arguments.isEmpty(); // Criar classe ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(V1_6, ACC_PUBLIC | ACC_FINAL, codegenType.asmName(), null, CommonTypes.CALLABLE.asmName(), (Options.RVP ? new String[] { CommonTypes.PREDICTABLECALLABLE.asmName() } : null)); cw.visitSource(color("JaSPEx Generated Wrapper Class", "31"), null); // Criar fields para conter argumentos { int fieldPos = 0; for (Type t : arguments) { cw.visitField(ACC_PRIVATE + ACC_FINAL, "arg" + (fieldPos++), t.bytecodeName(), null, null); } } // Criar constructor { MethodVisitor mv = cw.visitMethod((singletonMode ? ACC_PRIVATE : ACC_PUBLIC), "<init>", "(" + argumentsDesc + ")V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, Type.OBJECT.asmName(), "<init>", "()V"); int localsPos = 0; int fieldPos = 0; for (Type t : arguments) { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(t.getLoadInsn(), localsPos + 1); mv.visitFieldInsn(PUTFIELD, codegenType.asmName(), "arg" + fieldPos++, t.bytecodeName()); localsPos += t.getNumberSlots(); } mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // Criar mtodo esttico como "bridge" para o constructor // A ideia deste mtodo resolver o problema de j termos os argumentos para a invocao na stack // quando descobrimos que queremos criar uma instncia desta classe. Assim, em vez de andar a // fazer swaps at colocarmos a instncia desta classe por baixo dos argumentos para o seu // construtor, chamamos este mtodo esttico para fazer esse trabalho por ns. // O que este mtodo basicamente: // public static codegenType newInstance(args) { return new codegenType(args); } if (!singletonMode) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "newInstance", "(" + argumentsDesc + ")" + codegenType.bytecodeName(), null, null); mv.visitCode(); mv.visitTypeInsn(NEW, codegenType.asmName()); mv.visitInsn(DUP); int localsPos = 0; for (Type t : arguments) { mv.visitVarInsn(t.getLoadInsn(), localsPos); localsPos += t.getNumberSlots(); } mv.visitMethodInsn(INVOKESPECIAL, codegenType.asmName(), "<init>", "(" + argumentsDesc + ")V"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // Criar mtodos call e call_nonspeculative for (String[] target : new String[][] { { "call", method.name() }, { "call_nonspeculative", method.name().replace("$speculative", "$non_speculative") } }) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, target[0], "()" + Type.OBJECT.bytecodeName(), null, null); mv.visitCode(); int fieldPos = 0; for (Type t : arguments) { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, codegenType.asmName(), "arg" + fieldPos++, t.bytecodeName()); } mv.visitMethodInsn(method.opcode() == INVOKESPECIAL ? INVOKEVIRTUAL : method.opcode(), method.owner().asmName(), target[1], method.desc()); if (method.returnType().equals(Type.PRIM_VOID)) { if (!jaspex.Options.FASTMODE) mv.visitLdcInsn("JASPEX VOID RETURN VALUE"); else mv.visitInsn(ACONST_NULL); } else if (method.returnType().isPrimitive()) boxWrap(method.returnType(), mv); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (singletonMode) { // Criar field com singleton cw.visitField(ACC_STATIC | ACC_FINAL | ACC_PUBLIC, "INSTANCE", codegenType.bytecodeName(), null, null); } if (Options.RVP) { // Field com previso cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, "PREDICTOR", CommonTypes.PREDICTOR.bytecodeName(), null, null); { // Mtodo de acesso previso MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "predict", "()" + Type.OBJECT.bytecodeName(), null, null); mv.visitCode(); if (method.returnType().equals(Type.PRIM_VOID)) { mv.visitTypeInsn(NEW, "java/lang/AssertionError"); mv.visitInsn(DUP); mv.visitLdcInsn("Asked for prediction for Void method"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/AssertionError", "<init>", "(Ljava/lang/Object;)V"); mv.visitInsn(ATHROW); } else { mv.visitFieldInsn(GETSTATIC, codegenType.asmName(), "PREDICTOR", CommonTypes.PREDICTOR.bytecodeName()); mv.visitMethodInsn(INVOKEVIRTUAL, CommonTypes.PREDICTOR.asmName(), "predict", "()" + Type.OBJECT.bytecodeName()); mv.visitInsn(ARETURN); } mv.visitMaxs(0, 0); mv.visitEnd(); } { // Mtodo de actualizao da previso MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "updatePrediction", "(" + Type.OBJECT.bytecodeName() + ")V", null, null); mv.visitCode(); if (!method.returnType().equals(Type.PRIM_VOID)) { mv.visitFieldInsn(GETSTATIC, codegenType.asmName(), "PREDICTOR", CommonTypes.PREDICTOR.bytecodeName()); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, CommonTypes.PREDICTOR.asmName(), "updatePrediction", "(" + Type.OBJECT.bytecodeName() + ")V"); } mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } } // Gerar clinit caso existam fields para inicializar if (singletonMode || Options.RVP) { // Adicionar static initializer MethodVisitor mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); if (singletonMode) { mv.visitTypeInsn(NEW, codegenType.asmName()); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, codegenType.asmName(), "<init>", "()V"); mv.visitFieldInsn(PUTSTATIC, codegenType.asmName(), "INSTANCE", codegenType.bytecodeName()); } if (Options.RVP) { mv.visitLdcInsn(method.returnType().bytecodeName()); mv.visitMethodInsn(INVOKESTATIC, CommonTypes.PREDICTORFACTORY.asmName(), "newPredictor", "(" + Type.STRING.bytecodeName() + ")" + CommonTypes.PREDICTOR.bytecodeName()); mv.visitFieldInsn(PUTSTATIC, codegenType.asmName(), "PREDICTOR", CommonTypes.PREDICTOR.bytecodeName()); } mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // Criar toString { Type sb = Type.fromClass(StringBuilder.class); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "toString", "()" + Type.STRING.bytecodeName(), null, null); mv.visitCode(); mv.visitTypeInsn(NEW, sb.asmName()); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, Type.OBJECT.asmName(), "toString", "()" + Type.STRING.bytecodeName()); mv.visitMethodInsn(INVOKESPECIAL, sb.asmName(), "<init>", "(" + Type.STRING.bytecodeName() + ")V"); mv.visitVarInsn(ASTORE, 1); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("{"); mv.visitMethodInsn(INVOKEVIRTUAL, sb.asmName(), "append", "(" + Type.STRING.bytecodeName() + ")" + sb.bytecodeName()); int fieldPos = 0; boolean first = true; for (Type t : arguments) { mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn((first ? "" : ", ") + "arg" + fieldPos + ": "); first = false; mv.visitMethodInsn(INVOKEVIRTUAL, sb.asmName(), "append", "(" + Type.STRING.bytecodeName() + ")" + sb.bytecodeName()); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, codegenType.asmName(), "arg" + fieldPos++, t.bytecodeName()); if (t.isPrimitive()) boxWrap(t, mv); mv.visitMethodInsn(INVOKESTATIC, Type.STRING.asmName(), "valueOf", "(" + Type.OBJECT.bytecodeName() + ")" + Type.STRING.bytecodeName()); mv.visitMethodInsn(INVOKEVIRTUAL, sb.asmName(), "append", "(" + Type.STRING.bytecodeName() + ")" + sb.bytecodeName()); } mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("} "); mv.visitMethodInsn(INVOKEVIRTUAL, sb.asmName(), "append", "(" + Type.STRING.bytecodeName() + ")" + sb.bytecodeName()); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, Type.OBJECT.asmName(), "toString", "()" + Type.STRING.bytecodeName()); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (Options.ALLOWDUMMYTX && SpeculationSkiplist.useDummyTransaction(method)) { Log.info("Setting isDummy transaction flag for " + method.owner().commonName() + "." + method.name()); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "useDummyTransaction", "()Z", null, null); mv.visitCode(); mv.visitInsn(ICONST_1); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); byte[] newClass = cw.toByteArray(); //if (speculation.SpeculativeClassLoader.PRINTCLASS) asmlib.Util.printClass(newClass); if (Options.WRITECLASS) { try { new java.io.File("output" + java.io.File.separatorChar).mkdir(); java.io.FileOutputStream fos = new java.io.FileOutputStream( "output" + java.io.File.separatorChar + codegenType.commonName() + ".class"); fos.write(newClass); fos.close(); } catch (java.io.FileNotFoundException e) { throw new Error(e); } catch (java.io.IOException e) { throw new Error(e); } } return newClass; }
From source file:javalin.expr.Exp.java
License:Open Source License
byte[] compile(final String name) { // class header final String[] itfs = { DoubleExpression.class.getName().replaceAll("\\.", "/") }; final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", itfs); // default public constructor MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitVarInsn(ALOAD, 0);/* ww w . jav a 2 s . c om*/ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // eval method mv = cw.visitMethod(ACC_PUBLIC, "eval", "(Ljava/util/Map;)D", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Double;>;)D", null); compile(mv); mv.visitInsn(DRETURN); // max stack and max locals automatically computed mv.visitMaxs(0, 0); mv.visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitLdcInsn(toString()); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); return cw.toByteArray(); }
From source file:javaone2015.con7442.indyprotector.BootstrapMethodGenerator.java
License:Apache License
/** * Generate bootstrap method//from www . ja v a 2 s . c om */ public void insertMethod(ClassVisitor target) { MethodVisitor mv = target.visitMethod(ACC_PRIVATE + ACC_STATIC, BSM_NAME, BSM_SIG, null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ASTORE, 7); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false); mv.visitVarInsn(ASTORE, 8); mv.visitLdcInsn(Type.getType(targetClassName)); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", "()Ljava/lang/ClassLoader;", false); mv.visitVarInsn(ASTORE, 9); mv.visitVarInsn(ALOAD, 6); mv.visitVarInsn(ALOAD, 9); mv.visitMethodInsn(INVOKESTATIC, "java/lang/invoke/MethodType", "fromMethodDescriptorString", "(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/invoke/MethodType;", false); mv.visitVarInsn(ASTORE, 10); mv.visitVarInsn(ILOAD, 3); Label l3 = new Label(); Label l4 = new Label(); Label l5 = new Label(); mv.visitTableSwitchInsn(182, 185, l4, new Label[] { l3, l4, l5, l3 }); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_FULL, 11, new Object[] { "java/lang/invoke/MethodHandles$Lookup", "java/lang/String", "java/lang/invoke/MethodType", Opcodes.INTEGER, "java/lang/String", "java/lang/String", "java/lang/String", "java/lang/invoke/MethodHandle", "java/lang/Class", "java/lang/ClassLoader", "java/lang/invoke/MethodType" }, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 8); mv.visitVarInsn(ALOAD, 5); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandles$Lookup", "findStatic", "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", false); mv.visitVarInsn(ASTORE, 7); Label l6 = new Label(); mv.visitJumpInsn(GOTO, l6); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 8); mv.visitVarInsn(ALOAD, 5); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandles$Lookup", "findVirtual", "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", false); mv.visitVarInsn(ASTORE, 7); mv.visitJumpInsn(GOTO, l6); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/BootstrapMethodError"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/BootstrapMethodError", "<init>", "()V", false); mv.visitInsn(ATHROW); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 7); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "asType", "(Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", false); mv.visitVarInsn(ASTORE, 7); mv.visitLabel(l1); Label l7 = new Label(); mv.visitJumpInsn(GOTO, l7); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, 8, new Object[] { "java/lang/invoke/MethodHandles$Lookup", "java/lang/String", "java/lang/invoke/MethodType", Opcodes.INTEGER, "java/lang/String", "java/lang/String", "java/lang/String", "java/lang/invoke/MethodHandle" }, 1, new Object[] { "java/lang/Exception" }); mv.visitVarInsn(ASTORE, 8); mv.visitTypeInsn(NEW, "java/lang/BootstrapMethodError"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/BootstrapMethodError", "<init>", "()V", false); mv.visitInsn(ATHROW); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/invoke/ConstantCallSite"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 7); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/invoke/ConstantCallSite", "<init>", "(Ljava/lang/invoke/MethodHandle;)V", false); mv.visitInsn(ARETURN); mv.visitMaxs(4, 11); mv.visitEnd(); }
From source file:jerl.bcm.inj.impl.InjectCollection.java
License:Apache License
public void injectIDRegistration(MethodVisitor mv, int id) { // TODO: change to correct call mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("entry: " + id); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); }
From source file:jerl.bcm.inj.impl.InjectCollection.java
License:Apache License
public void injectSystemOut(MethodVisitor mv, String str) { mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn(str); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); }
From source file:jerl.bcm.inj.impl.InjectCollection.java
License:Apache License
public void injectMemberFieldSystemOut(MethodVisitor mv, String clazz, String field, String type, String printType, String prefix, boolean isStatic) { mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn(prefix); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V"); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); if (isStatic) { mv.visitFieldInsn(Opcodes.GETSTATIC, clazz, field, type); } else {//from www .j a va 2 s .c o m mv.visitVarInsn(Opcodes.ALOAD, 0); // this mv.visitFieldInsn(Opcodes.GETFIELD, clazz, field, type); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(" + printType + ")V"); }