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:org.evosuite.instrumentation.ReturnValueAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w. j a v a 2s. c o m public void visitInsn(int opcode) { if (!methodName.equals("<clinit>")) { switch (opcode) { case Opcodes.IRETURN: callLogIReturn(); break; case Opcodes.ARETURN: callLogAReturn(); break; case Opcodes.ATHROW: break; case Opcodes.DRETURN: callLogDReturn(); break; case Opcodes.FRETURN: callLogFReturn(); break; case Opcodes.LRETURN: callLogLReturn(); break; case Opcodes.RETURN: break; default: break; } } super.visitInsn(opcode); }
From source file:org.evosuite.instrumentation.StringTransformation.java
License:Open Source License
/** * <p>//from w ww. j a va2 s . c o m * transformMethod * </p> * * @param mn * a {@link org.objectweb.asm.tree.MethodNode} object. * @return a boolean. */ public boolean transformMethod(MethodNode mn) { boolean changed = transformStrings(mn); if (changed) { try { mn.maxStack++; Analyzer a = new Analyzer(new StringBooleanInterpreter()); a.analyze(cn.name, mn); Frame[] frames = a.getFrames(); AbstractInsnNode node = mn.instructions.getFirst(); boolean done = false; while (!done) { if (node == mn.instructions.getLast()) done = true; AbstractInsnNode next = node.getNext(); int index = mn.instructions.indexOf(node); if (index >= frames.length) break; Frame current = frames[index]; if (current == null) break; int size = current.getStackSize(); if (node.getOpcode() == Opcodes.IFNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFNE -> IFGT"); branch.setOpcode(Opcodes.IFGT); // branch.setOpcode(Opcodes.IFGE); } } else if (node.getOpcode() == Opcodes.IFEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); branch.setOpcode(Opcodes.IFLE); // branch.setOpcode(Opcodes.IFNE); } } else if (node.getOpcode() == Opcodes.IF_ICMPEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IF_ICMPNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IRETURN) { if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE })); mn.instructions.insertBefore(node, n); } } node = next; } } catch (Exception e) { logger.warn("EXCEPTION DURING STRING TRANSFORMATION: {}", e); e.printStackTrace(); return changed; } } return changed; }
From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java
License:Open Source License
/** * This helper function determines whether the boolean on the stack at the * current position will be stored in a Boolean variable * /*from w w w. j av a 2 s . c o m*/ * @param position * @param mn * @return */ public boolean isBooleanAssignment(AbstractInsnNode position, MethodNode mn) { AbstractInsnNode node = position.getNext(); logger.info("Checking for ISTORE after boolean"); boolean done = false; while (!done) { if (node.getOpcode() == Opcodes.PUTFIELD || node.getOpcode() == Opcodes.PUTSTATIC) { // TODO: Check whether field is static logger.info("Checking field assignment"); FieldInsnNode fn = (FieldInsnNode) node; if (Type.getType(DescriptorMapping.getInstance().getFieldDesc(fn.owner, fn.name, fn.desc)) == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.ISTORE) { logger.info("Found ISTORE after boolean"); VarInsnNode vn = (VarInsnNode) node; // TODO: Check whether variable at this position is a boolean if (isBooleanVariable(vn.var, mn)) { logger.info("Assigning boolean to variable "); return true; } else { logger.info("Variable is not a bool"); return false; } } else if (node.getOpcode() == Opcodes.IRETURN) { logger.info("Checking return value of method " + cn.name + "." + mn.name); if (DescriptorMapping.getInstance().isTransformedOrBooleanMethod(cn.name, mn.name, mn.desc)) { logger.info("Method returns a bool"); return true; } else { logger.info("Method does not return a bool"); return false; } } else if (node.getOpcode() == Opcodes.BASTORE) { // We remove all bytes, so BASTORE is only used for booleans AbstractInsnNode start = position.getNext(); boolean reassignment = false; while (start != node) { if (node instanceof InsnNode) { reassignment = true; } start = start.getNext(); } logger.info("Possible assignment to array?"); if (reassignment) return false; else return true; } else if (node instanceof MethodInsnNode) { // if it is a boolean parameter of a converted method, then it needs to be converted // Problem: How do we know which parameter it represents? MethodInsnNode methodNode = (MethodInsnNode) node; String desc = DescriptorMapping.getInstance().getMethodDesc(methodNode.owner, methodNode.name, methodNode.desc); Type[] types = Type.getArgumentTypes(desc); if (types.length > 0 && types[types.length - 1] == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.GOTO || node.getOpcode() == Opcodes.ICONST_0 || node.getOpcode() == Opcodes.ICONST_1 || node.getOpcode() == -1) { logger.info("Continuing search"); // continue search } else if (!(node instanceof LineNumberNode || node instanceof FrameNode)) { logger.info("Search ended with opcode " + node.getOpcode()); return false; } if (node != mn.instructions.getLast()) node = node.getNext(); else done = true; } return false; }
From source file:org.evosuite.instrumentation.testability.StringTransformation.java
License:Open Source License
/** * <p>// w w w. j a va 2 s.co m * transformMethod * </p> * * @param mn * a {@link org.objectweb.asm.tree.MethodNode} object. * @return a boolean. */ public boolean transformMethod(MethodNode mn) { boolean changed = transformStrings(mn); if (changed) { try { mn.maxStack++; Analyzer a = new Analyzer(new StringBooleanInterpreter()); a.analyze(cn.name, mn); Frame[] frames = a.getFrames(); AbstractInsnNode node = mn.instructions.getFirst(); boolean done = false; while (!done) { if (node == mn.instructions.getLast()) done = true; AbstractInsnNode next = node.getNext(); int index = mn.instructions.indexOf(node); if (index >= frames.length) break; Frame current = frames[index]; if (current == null) break; int size = current.getStackSize(); if (node.getOpcode() == Opcodes.IFNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFNE -> IFGT"); branch.setOpcode(Opcodes.IFGT); } } else if (node.getOpcode() == Opcodes.IFEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); branch.setOpcode(Opcodes.IFLE); } } else if (node.getOpcode() == Opcodes.IF_ICMPEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IF_ICMPNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IRETURN) { if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }), false); mn.instructions.insertBefore(node, n); } } node = next; } } catch (Exception e) { logger.warn("EXCEPTION DURING STRING TRANSFORMATION: " + e); return changed; } } return changed; }
From source file:org.evosuite.instrumentation.testability.transformer.BooleanReturnTransformer.java
License:Open Source License
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { //String desc = DescriptorMapping.getInstance().getMethodDesc(className, mn.name, mn.desc); Type returnType = Type.getReturnType(mn.desc); if (!returnType.equals(Type.BOOLEAN_TYPE)) { return insnNode; }//from w w w . j a v a2 s. co m if (insnNode.getOpcode() == Opcodes.IRETURN) { BooleanTestabilityTransformation.logger.debug("Inserting conversion before IRETURN of " + this.booleanTestabilityTransformation.className + "." + mn.name); // If this function cannot be transformed, add a call to convert the value to a proper Boolean MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, n); } return insnNode; }
From source file:org.evosuite.testcarver.instrument.Instrumenter.java
License:Open Source License
private void addReturnInsn(final InsnList il, final Type type) { if (type.equals(Type.BOOLEAN_TYPE)) { il.add(new InsnNode(Opcodes.IRETURN)); } else if (type.equals(Type.CHAR_TYPE)) { il.add(new InsnNode(Opcodes.IRETURN)); } else if (type.equals(Type.BYTE_TYPE)) { il.add(new InsnNode(Opcodes.IRETURN)); } else if (type.equals(Type.SHORT_TYPE)) { il.add(new InsnNode(Opcodes.IRETURN)); } else if (type.equals(Type.INT_TYPE)) { il.add(new InsnNode(Opcodes.IRETURN)); } else if (type.equals(Type.FLOAT_TYPE)) { il.add(new InsnNode(Opcodes.FRETURN)); } else if (type.equals(Type.LONG_TYPE)) { il.add(new InsnNode(Opcodes.LRETURN)); } else if (type.equals(Type.DOUBLE_TYPE)) { il.add(new InsnNode(Opcodes.DRETURN)); } else {/* w ww . ja v a 2s . c o m*/ il.add(new InsnNode(Opcodes.ARETURN)); } }
From source file:org.fabric3.implementation.bytecode.proxy.common.ProxyFactoryImpl.java
License:Open Source License
private void writeReturn(Method method, Label endLabel, MethodVisitor mv) { Class<?> returnType = method.getReturnType(); if (Void.TYPE.equals(returnType)) { mv.visitInsn(Opcodes.POP);//from w w w.j a v a 2 s . c o m mv.visitLabel(endLabel); mv.visitInsn(RETURN); } else if (returnType.isPrimitive()) { if (Double.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Double"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.DRETURN); } else if (Long.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Long"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.LRETURN); } else if (Integer.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.IRETURN); } else if (Float.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Float"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.FRETURN); } else if (Short.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Short"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.IRETURN); } else if (Byte.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Byte"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.IRETURN); } else if (Boolean.TYPE.equals(returnType)) { mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); mv.visitLabel(endLabel); mv.visitInsn(Opcodes.IRETURN); } } else { String internalTypeName = Type.getInternalName(returnType); mv.visitTypeInsn(CHECKCAST, internalTypeName); mv.visitLabel(endLabel); mv.visitInsn(ARETURN); } }
From source file:org.formulacompiler.compiler.internal.bytecode.LinearizerCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = mv(); final Label outOfRange = mv.newLabel(); // range check row mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1);/*from w w w .ja v a 2s .c o m*/ mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(this.rows); mv.ifICmp(mv.GT, outOfRange); // range check col mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(this.cols); mv.ifICmp(mv.GT, outOfRange); // (<row> - 1) * <num_cols>) + (<col> - 1); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.push(this.cols); mv.visitInsn(Opcodes.IMUL); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(outOfRange); mv.throwException(ExpressionCompiler.FORMULA_ERROR_TYPE, "#VALUE/REF! because index is out of range in INDEX"); }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void storeFromXReturn(MethodVisitor mv, int returnOpcode, LocalVariableNode holder) { switch (returnOpcode) { case Opcodes.RETURN: // NOP/*from ww w .j a va 2s .c o m*/ break; case Opcodes.ARETURN: mv.visitVarInsn(Opcodes.ASTORE, holder.index); break; case Opcodes.IRETURN: mv.visitVarInsn(Opcodes.ISTORE, holder.index); break; case Opcodes.LRETURN: mv.visitVarInsn(Opcodes.LSTORE, holder.index); break; case Opcodes.FRETURN: mv.visitVarInsn(Opcodes.FSTORE, holder.index); break; case Opcodes.DRETURN: mv.visitVarInsn(Opcodes.DSTORE, holder.index); break; } }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void loadFromXReturn(MethodVisitor mv, int returnOpcode, LocalVariableNode holder) { switch (returnOpcode) { case Opcodes.RETURN: // NOP// w w w. j ava 2 s. c o m break; case Opcodes.ARETURN: mv.visitVarInsn(Opcodes.ALOAD, holder.index); break; case Opcodes.IRETURN: mv.visitVarInsn(Opcodes.ILOAD, holder.index); break; case Opcodes.LRETURN: mv.visitVarInsn(Opcodes.LLOAD, holder.index); break; case Opcodes.FRETURN: mv.visitVarInsn(Opcodes.FLOAD, holder.index); break; case Opcodes.DRETURN: mv.visitVarInsn(Opcodes.DLOAD, holder.index); break; } }