List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:hellfirepvp.astralsorcery.core.patch.helper.PatchModifyAttributes.java
License:Open Source License
@Override public void patch(ClassNode cn) { MethodNode mn = getMethod(cn, "getAttributeModifiers", "func_111283_C", "(Lnet/minecraft/inventory/EntityEquipmentSlot;)Lcom/google/common/collect/Multimap;"); InsnList list = new InsnList(); list.add(new VarInsnNode(Opcodes.ALOAD, 0)); list.add(new VarInsnNode(Opcodes.ALOAD, 1)); list.add(new VarInsnNode(Opcodes.ALOAD, 2)); list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "hellfirepvp/astralsorcery/common/util/SwordSharpenHelper", "applySharpenModifier", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/inventory/EntityEquipmentSlot;Lcom/google/common/collect/Multimap;)V", false));//from ww w. j av a2 s . co m mn.instructions.insert(mn.instructions.getLast().getPrevious().getPrevious(), list); }
From source file:ht.misc.injectsocks.InjectSockstTransformerImpl.java
License:Apache License
public byte[] inject(byte[] classfileBuffer) { try {/*from ww w. jav a 2 s . c o m*/ ClassReader cr = new ClassReader(classfileBuffer); ClassNode cn = new ClassNode(); cr.accept(cn, 0); ArrayList<AbstractInsnNode> injectPos = new ArrayList<AbstractInsnNode>(); @SuppressWarnings("unchecked") List<MethodNode> methods = (List<MethodNode>) cn.methods; for (int i = 0; i < methods.size(); ++i) { MethodNode method = methods.get(i); InsnList instructions = method.instructions; if (instructions.size() <= 0) continue; //System.out.println("Method: "+method.name+" "); for (int j = 0; j < instructions.size(); ++j) { AbstractInsnNode insn = (AbstractInsnNode) instructions.get(j); //System.out.println("\tInsn: opc="+OpcodeUtil.getOpcode(insn.getOpcode())+", type="+insn.getType()); if (insn.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode min = (MethodInsnNode) insn; //System.out.printf("\t\towner=%s, name=%s, desc=%s\n", min.owner, min.name, min.desc); if (min.owner.equals("java/net/Socket") && min.name.equals("<init>") && min.desc.equals("()V")) { min.desc = "(Ljava/net/Proxy;)V"; injectPos.add(min); } } } for (int k = 0; k < injectPos.size(); k++) { AbstractInsnNode pos = injectPos.get(k); MethodInsnNode newMin = new MethodInsnNode(Opcodes.INVOKESTATIC, "ht/misc/injectsocks/ProxyManager", "getProxy", "()Ljava/net/Proxy;", false); instructions.insertBefore(pos, newMin); } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cn.accept(cw); byte[] injectedClassfileBuffer = cw.toByteArray(); System.out.printf("INFO: classfileBuffer.legnth=%d, injectedClassfileBuffer.length=%d\n", classfileBuffer.length, injectedClassfileBuffer.length); return injectedClassfileBuffer; } catch (Throwable e) { e.printStackTrace(); return classfileBuffer; } }
From source file:instrumentation.InstrumentationMethodAdapter.java
License:Open Source License
private void insertCode(int opcode, String type) { mv.visitInsn(Opcodes.DUP);// ww w .ja va2 s.co m mv.visitIntInsn(Opcodes.BIPUSH, opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "dimmunix/TrackDelegate", "track" + type, "(Ljava/lang/Object;B)V"); addedInstructions += 2; }
From source file:io.awacs.plugin.springmvc.ServiceWrapper.java
License:Apache License
/** * origin method: (XXX)X//from w ww. j av a2s .c o m * <p> * proxy method: (XXXLjavax/servlet/http/HttpServletRequest;)X * req -> localIndex - 1 * * @param cn * @param origin * @return */ private MethodNode doProxy(ClassNode cn, MethodNode origin) { MethodNode newNode = copyMethod(origin); //move annotations hideAnnotations(origin); LabelNode l0 = new LabelNode(); LabelNode l1 = new LabelNode(); LabelNode l2 = new LabelNode(); String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1); int localIndex = copyParameters(origin, newNode, l0, l2); newNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception")); //localIndex -> elapsedTime newNode.localVariables.add(new LocalVariableNode("elapsedTime", "J", null, l0, l1, localIndex)); // newNode.instructions.add(l0); // long elapsedTime = System.currentTimeMillis(); newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J")); newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex)); int paramCount = getParamCount(origin.desc, origin.access); //load? for (int i = 0; i < paramCount; i++) { LocalVariableNode node = (LocalVariableNode) newNode.localVariables.get(i); switch (node.desc) { case "J": newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, node.index)); break; case "D": newNode.instructions.add(new VarInsnNode(Opcodes.DLOAD, node.index)); break; case "F": newNode.instructions.add(new VarInsnNode(Opcodes.FLOAD, node.index)); break; case "I": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "S": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "Z": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "B": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; case "C": newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index)); break; default: newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, node.index)); break; } } // newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, cn.name, origin.name, origin.desc)); // newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J")); newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex)); newNode.instructions.add(new InsnNode(Opcodes.LSUB)); newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex)); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1)); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;")); //? newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex)); //SpringmvcPlugin.incrAccess(uri, elapsedTime); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrAccess", "(Ljava/lang/String;J)V")); // newNode.instructions.add(l1); switch (returnType) { case "J": newNode.instructions.add(new InsnNode(Opcodes.LRETURN)); break; case "D": newNode.instructions.add(new InsnNode(Opcodes.DRETURN)); break; case "F": newNode.instructions.add(new InsnNode(Opcodes.FRETURN)); break; case "I": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "S": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "C": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "B": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "Z": newNode.instructions.add(new InsnNode(Opcodes.IRETURN)); break; default: newNode.instructions.add(new InsnNode(Opcodes.ARETURN)); break; } newNode.instructions.add(l2); newNode.instructions .add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" })); newNode.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex)); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1)); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;")); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex)); newNode.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrFailure", "(Ljava/lang/String;Ljava/lang/Throwable;)V")); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex)); newNode.instructions.add(new InsnNode(Opcodes.ATHROW)); newNode.maxLocals = origin.maxLocals + 3; newNode.maxStack = Math.max(localIndex + 2, 6); return newNode; }
From source file:io.awacs.plugin.stacktrace.ClassTransformer.java
License:Apache License
/** * ?/*from w w w . j av a 2 s .c om*/ * 1?try catch? try{ * 2???? io.awacs.plugin.stacktrace.StackFrames.init(); * 3???? io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,0); * 4? Object val = methodName_origin_className(args); * 5????? io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,1); * 5??? List list = io.awacs.plugin.stacktrace.StackFrames.dump(); * 7????? io.awacs.plugin.stacktrace.StackTracePlugin.incrAccess(list); * 8? return val; * }catch(java.lang.Exception e){ * 9?? io.awacs.plugin.stacktrace.StackTracePlugin.incrFailure(e); * 10? throw e; * } */ private void transformTerminatedMethod(MethodNode origin, MethodNode proxy, ClassNode owner) { LabelNode l0 = new LabelNode(); LabelNode l1 = new LabelNode(); LabelNode l2 = new LabelNode(); //try catch? proxy.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception")); proxy.instructions.add(l0); //? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "init", "()V", false)); proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", "."))); proxy.instructions.add(new LdcInsnNode(proxy.name)); proxy.instructions.add(new LdcInsnNode(0)); // proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); int varIndex = 0;//??? //???,????this? if ((proxy.access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) { proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); varIndex = 1; } List<String> parameters = resolveParameters(proxy.desc); //??? for (String param : parameters) { VarInsnNode insnNode; switch (param) { case "J": insnNode = new VarInsnNode(Opcodes.LLOAD, varIndex); varIndex += 2; break; case "D": insnNode = new VarInsnNode(Opcodes.DLOAD, varIndex); varIndex += 2; break; case "F": insnNode = new VarInsnNode(Opcodes.FLOAD, varIndex++); break; case "I": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "S": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "Z": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "B": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; case "C": insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++); break; default: insnNode = new VarInsnNode(Opcodes.ALOAD, varIndex++); break; } proxy.instructions.add(insnNode); } // if ((origin.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) proxy.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner.name, origin.name, origin.desc, false)); else proxy.instructions .add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, owner.name, origin.name, origin.desc, false)); proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", "."))); proxy.instructions.add(new LdcInsnNode(proxy.name)); proxy.instructions.add(new LdcInsnNode(1)); //? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); //?? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "dump", "()Ljava/util/List;", false)); //??? proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackTracePlugin", "incrAccess", "(Ljava/util/List;)V", false)); proxy.instructions.add(l1); // String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1); switch (returnType) { case "J": proxy.instructions.add(new InsnNode(Opcodes.LRETURN)); break; case "D": proxy.instructions.add(new InsnNode(Opcodes.DRETURN)); break; case "F": proxy.instructions.add(new InsnNode(Opcodes.FRETURN)); break; case "I": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "S": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "C": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "B": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "Z": proxy.instructions.add(new InsnNode(Opcodes.IRETURN)); break; case "V": proxy.instructions.add(new InsnNode(Opcodes.RETURN)); break; default: proxy.instructions.add(new InsnNode(Opcodes.ARETURN)); break; } proxy.instructions.add(l2); //? proxy.instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" })); proxy.instructions.add(new VarInsnNode(Opcodes.ASTORE, varIndex)); proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex)); proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackTracePlugin", "incrFailure", "(Ljava/lang/Throwable;)V", false)); proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex)); proxy.instructions.add(new InsnNode(Opcodes.ATHROW)); proxy.maxLocals = varIndex + 1; proxy.maxStack = Math.max(varIndex, 5); }
From source file:io.awacs.plugin.stacktrace.ClassTransformer.java
License:Apache License
/** * ??// ww w .j a v a2s . c o m * 1?StackFrames.push(0)??? * 2???this??? * 3?StackFrames.push(1)??? * 4?? */ private void transformPlainMethod(MethodNode mn, ClassNode cn) { InsnList before = new InsnList(); before.add(new LdcInsnNode(cn.name.replaceAll("/", "."))); before.add(new LdcInsnNode(mn.name)); before.add(new LdcInsnNode(0)); before.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); InsnList end = new InsnList(); end.add(new LdcInsnNode(cn.name.replaceAll("/", "."))); end.add(new LdcInsnNode(mn.name)); end.add(new LdcInsnNode(1)); end.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames", "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false)); List<AbstractInsnNode> insts = new LinkedList<>(); for (int i = 0; i < mn.instructions.size(); i++) { int opcode = mn.instructions.get(i).getOpcode(); if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) { insts.add(mn.instructions.get(i)); } } if (!insts.isEmpty()) { mn.instructions.insert(before); for (AbstractInsnNode node : insts) { mn.instructions.insertBefore(node, end); } } mn.maxStack = mn.maxStack + 5; }
From source file:io.syncframework.optimizer.OControllerStaticMethodVisitor.java
License:Apache License
public void visitInsn(int opcode) { if (opcode != Opcodes.RETURN) { mv.visitInsn(opcode);//from w w w .ja v a 2s . com return; } Label start = new Label(); Label l1 = new Label(); Label l2 = new Label(); Label interceptorsLabel = new Label(); mv.visitCode(); mv.visitTryCatchBlock(start, l1, l2, "java/lang/Throwable"); /* * _asActions = new HashMap<String,Boolean>(); */ { mv.visitLabel(start); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;"); } /* * _asActions.put("main", true); * _asActions.put("action1", true); */ for (String name : reflector.getActions().keySet()) { Label l = new Label(); mv.visitLabel(l); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitInsn(Opcodes.ICONST_1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } /* * _asInterceptors = new HashMap<String,Class<?>[]>() */ { Label l = new Label(); mv.visitLabel(l); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asInterceptors", "Ljava/util/Map;"); } /* * List<Class<?>> l = new ArrayList<Class<?>>(); */ mv.visitLabel(interceptorsLabel); mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); mv.visitVarInsn(Opcodes.ASTORE, 0); for (String name : reflector.getActions().keySet()) { Class<?> interceptors[] = reflector.getInterceptors().get(name); if (interceptors == null || interceptors.length == 0) continue; /* * l.clear(); */ Label l01 = new Label(); mv.visitLabel(l01); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "clear", "()V", true); for (Class<?> interceptor : interceptors) { /* * l.add(LoginInterceptor.class); */ Label l02 = new Label(); mv.visitLabel(l02); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitLdcInsn(Type.getType(interceptor)); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); } /* * _asInterceptors.put("upload", l.toArray(new Class[0])); */ Label l03 = new Label(); mv.visitLabel(l03); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asInterceptors", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_0); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", true); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } /* * _asParameters = new HashMap<String,Class<?>>() */ { Label l = new Label(); mv.visitLabel(l); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asParameters", "Ljava/util/Map;"); } /* * _asParameters.put("name", Type.class); */ for (String name : reflector.getParameters().keySet()) { Label l = new Label(); mv.visitLabel(l); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitLdcInsn(Type.getType(reflector.getParameters().get(name))); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } /* * _asConverters = new HashMap<String,Class<?>>() */ { Label l = new Label(); mv.visitLabel(l); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asConverters", "Ljava/util/Map;"); } /* * _asConverters.put("name", Type.class); */ for (String name : reflector.getParameters().keySet()) { if (reflector.getConverters().get(name) != null) { Class<?> converter = reflector.getConverters().get(name); Label l = new Label(); mv.visitLabel(l); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitLdcInsn(Type.getType(converter)); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } } /* * } * catch(Throwable t) { * throw t; * } */ Label throwableStart = new Label(); Label throwableEnd = new Label(); mv.visitLabel(l1); mv.visitJumpInsn(Opcodes.GOTO, throwableEnd); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(Opcodes.ASTORE, 0); mv.visitLabel(throwableStart); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(throwableEnd); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.RETURN); mv.visitLocalVariable("l", "Ljava/util/List;", null, interceptorsLabel, l1, 0); mv.visitLocalVariable("t", "Ljava/lang/Throwable;", null, throwableStart, throwableEnd, 0); }
From source file:jaspex.speculation.SpeculativeClassLoader.java
License:Open Source License
public void execute(StringList args) throws Throwable { Log.info("JaSPEx SpeculativeClassLoader (Start time: {}, Args: '{}')", new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date()), args.join(" ")); if (Options.JAR) { File jar = new File(args.pollFirst()); addToClasspath(jar);// w w w.j a v a 2 s . c o m JarFile jarFile = new JarFile(jar); String mainClass = jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS); jarFile.close(); args.addFirst(mainClass); } // Infelizmente no podemos usar reflection para invocar mtodos dentro do // runWithContinuationSupport, portanto abusamos do codegen para obter um // objecto callable que chame o main Type codegenType = CodegenHelper .methodToCodegenType(new InvokedMethod(Opcodes.INVOKESTATIC, Type.fromCommon(args.pollFirst()), "main$speculative", "(" + Type.STRING.toArray().bytecodeName() + ")V")); final Callable c = (Callable) loadClass(codegenType.commonName(), true).getConstructor(String[].class) .newInstance((Object) args.toArray()); // Passamos o objecto que quando invocado chama o main para o ContSpeculationControl ContSpeculationControl.bootstrapMain(c); }
From source file:javaone2015.con7442.indyprotector.MethodIndyProtector.java
License:Apache License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { boolean isStatic = (opcode == Opcodes.INVOKESTATIC); String newSig = isStatic ? desc : desc.replace("(", "(Ljava/lang/Object;"); Type origReturnType = Type.getReturnType(newSig); Type[] args = Type.getArgumentTypes(newSig); for (int i = 0; i < args.length; i++) { args[i] = genericType(args[i]);/* w ww .j a va 2 s. c o m*/ } newSig = Type.getMethodDescriptor(origReturnType, args); switch (opcode) { case INVOKESTATIC: // invokestatic opcode case INVOKEVIRTUAL: // invokevirtual opcode case INVOKEINTERFACE: // invokeinterface opcode mv.visitInvokeDynamicInsn(String.valueOf(rnd.nextInt()), newSig, bootstrapMethodHandle, opcode, owner.replaceAll("/", "."), name, desc); if (origReturnType.getSort() == Type.ARRAY) { mv.visitTypeInsn(Opcodes.CHECKCAST, origReturnType.getInternalName()); } break; default: mv.visitMethodInsn(opcode, owner, name, desc, itf); } }
From source file:jerl.bcm.inj.impl.InjectCollection.java
License:Apache License
public void injectSystemOutCurThread(MethodVisitor mv, String str) { mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn(str);// www . j ava 2 s .co m mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V"); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Thread", "currentThread", "()Ljava/lang/Thread;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V"); }