List of usage examples for org.objectweb.asm Opcodes IRETURN
int IRETURN
To view the source code for org.objectweb.asm Opcodes IRETURN.
Click Source Link
From source file:io.awacs.plugin.springmvc.ServiceWrapper.java
License:Apache License
/** * origin method: (XXX)X//from ww w. j av a 2s.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 ww w. j av a 2 s . c o m * 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
/** * ??//from ww w .jav a 2 s. c om * 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.OControllerClassVisitor.java
License:Apache License
/** * Generates this code:/* ww w . j av a 2 s . co m*/ * * public boolean _asActionIsDefined(String name) { * if(_asActions.containsKey(name)) * return true; * return false; * } */ public void createActionIsDefinedMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asActionIsDefined", "(Ljava/lang/String;)Z", null, null); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); mv.visitLabel(l0); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "containsKey", "(Ljava/lang/Object;)Z", true); mv.visitJumpInsn(Opcodes.IFEQ, l1); mv.visitLabel(l2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(l3); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l3, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l3, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:jasy.lang.ASMCompiler.java
private static boolean isReturn(int opcode) { switch (opcode) { case Opcodes.ARETURN: case Opcodes.DRETURN: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.RET: case Opcodes.RETURN: return true; }/*w w w .j av a2 s. c o m*/ return false; }
From source file:jasy.lang.ASMCompiler.java
private static int getReturn(Class<?> type) { String typeDescriptor = Type.getDescriptor(type); switch (typeDescriptor) { case "V": return Opcodes.RETURN; case "J": return Opcodes.LRETURN; case "D": return Opcodes.DRETURN; case "F": return Opcodes.FRETURN; case "I": case "Z": case "B": case "C": case "S": return Opcodes.IRETURN; default://w ww.java2 s . c o m return Opcodes.ARETURN; } }
From source file:jerl.bcm.inj.InjectionMethodAdapter.java
License:Apache License
@Override public void visitInsn(int opcode) { incByteCodeCounter();/*w w w . j a v a2s . co m*/ if (opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) { for (int i = 0; i < exitInjections.size(); i++) { InjectionMethodExit ime = (InjectionMethodExit) exitInjections.elementAt(i); ime.inject(mv); if (isDebugMode) { System.out.println("\t**Inject: " + ime); } } } mv.visitInsn(opcode); }
From source file:jp.co.dgic.testing.common.virtualmock.asm.AbstractAsmMethodVisitor.java
License:Open Source License
protected int getReturnOpcodeByType(Type type) { if (type.equals(Type.BOOLEAN_TYPE)) return Opcodes.IRETURN; if (type.equals(Type.BYTE_TYPE)) return Opcodes.IRETURN; if (type.equals(Type.CHAR_TYPE)) return Opcodes.IRETURN; if (type.equals(Type.SHORT_TYPE)) return Opcodes.IRETURN; if (type.equals(Type.INT_TYPE)) return Opcodes.IRETURN; if (type.equals(Type.LONG_TYPE)) return Opcodes.LRETURN; if (type.equals(Type.DOUBLE_TYPE)) return Opcodes.DRETURN; if (type.equals(Type.FLOAT_TYPE)) return Opcodes.FRETURN; return Opcodes.ARETURN; }
From source file:jpcsp.Allegrex.compiler.CodeBlock.java
License:Open Source License
private void addNonStaticMethods(CompilerContext context, ClassVisitor cv) { MethodVisitor mv;// ww w . j a v a2s. c o m // public int exec(int returnAddress, int alternativeReturnAddress, boolean isJump) throws Exception; mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getExecMethodName(), context.getExecMethodDesc(), null, exceptions); mv.visitCode(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, getClassName(), context.getStaticExecMethodName(), context.getStaticExecMethodDesc()); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // private static IExecutable e; FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, context.getReplaceFieldName(), executableDescriptor, null, null); fv.visitEnd(); // public void setExecutable(IExecutable e); mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getReplaceMethodName(), context.getReplaceMethodDesc(), null, exceptions); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTSTATIC, getClassName(), context.getReplaceFieldName(), executableDescriptor); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 2); mv.visitEnd(); // public IExecutable getExecutable(); mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getGetMethodName(), context.getGetMethodDesc(), null, exceptions); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, getClassName(), context.getReplaceFieldName(), executableDescriptor); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
public void visitJump() { flushInstructionCount(true, false); checkSync(); endMethod(); mv.visitInsn(Opcodes.IRETURN); }