List of usage examples for org.objectweb.asm Opcodes RETURN
int RETURN
To view the source code for org.objectweb.asm Opcodes RETURN.
Click Source Link
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateCallAllBindingsCallInOrgMethod.java
License:Open Source License
protected InsnList getReturnInsn(Type returnType) { InsnList instructions = new InsnList(); switch (returnType.getSort()) { case Type.VOID: instructions.add(new InsnNode(Opcodes.RETURN)); break;//from w w w . java 2s .c o m case Type.ARRAY: case Type.OBJECT: instructions.add(new InsnNode(Opcodes.ACONST_NULL)); instructions.add(new InsnNode(Opcodes.ARETURN)); break; case Type.BOOLEAN: case Type.CHAR: case Type.BYTE: case Type.INT: case Type.SHORT: case Type.LONG: instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.IRETURN)); break; case Type.DOUBLE: instructions.add(new InsnNode(Opcodes.DCONST_0)); instructions.add(new InsnNode(Opcodes.DRETURN)); break; case Type.FLOAT: instructions.add(new InsnNode(Opcodes.FCONST_0)); instructions.add(new InsnNode(Opcodes.FRETURN)); break; } return instructions; }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
/** * <p>//from ww w. ja v a2 s.com * isReturn * </p> * * @return a boolean. */ public boolean isReturn() { switch (asmNode.getOpcode()) { case Opcodes.RETURN: case Opcodes.ARETURN: case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.DRETURN: case Opcodes.FRETURN: return true; default: return false; } }
From source file:org.evosuite.instrumentation.coverage.LCSAJsInstrumentation.java
License:Open Source License
/** {@inheritDoc} */ @SuppressWarnings("unchecked") //using external lib @Override// w w w . j ava 2 s . c om public void analyze(ClassLoader classLoader, MethodNode mn, String className, String methodName, int access) { Queue<LCSAJ> lcsaj_queue = new LinkedList<LCSAJ>(); HashSet<Integer> targets_reached = new HashSet<Integer>(); AbstractInsnNode start = mn.instructions.getFirst(); int startID = 0; // TODO: This should replace the hack below if (methodName.startsWith("<init>")) { Iterator<AbstractInsnNode> j = mn.instructions.iterator(); boolean constructorInvoked = false; while (j.hasNext()) { AbstractInsnNode in = j.next(); startID++; if (!constructorInvoked) { if (in.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode cn = (MethodInsnNode) in; Collection<String> superClasses = DependencyAnalysis.getInheritanceTree() .getSuperclasses(className); superClasses.add(className); String classNameWithDots = ResourceList.getClassNameFromResourcePath(cn.owner); if (superClasses.contains(classNameWithDots)) { constructorInvoked = true; break; } } else { continue; } } } } /* if (methodName.startsWith("<init>")) { if (mn.instructions.size() >= 4) { start = mn.instructions.get(4); startID = 4; } } */ LCSAJ a = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader) .getInstruction(className, methodName, startID, start)); lcsaj_queue.add(a); targets_reached.add(0); ArrayList<TryCatchBlockNode> tc_blocks = (ArrayList<TryCatchBlockNode>) mn.tryCatchBlocks; for (TryCatchBlockNode t : tc_blocks) { LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader) .getInstruction(className, methodName, mn.instructions.indexOf(t.handler), t.handler)); lcsaj_queue.add(b); } while (!lcsaj_queue.isEmpty()) { LCSAJ currentLCSAJ = lcsaj_queue.poll(); int position = mn.instructions.indexOf(currentLCSAJ.getLastNodeAccessed()); // go to next bytecode instruction position++; if (position >= mn.instructions.size()) { // New LCSAJ for current + return LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ); continue; } AbstractInsnNode next = mn.instructions.get(position); currentLCSAJ.lookupInstruction(position, BytecodeInstructionPool.getInstance(classLoader) .getInstruction(className, methodName, position, next)); if (next instanceof JumpInsnNode) { JumpInsnNode jump = (JumpInsnNode) next; // New LCSAJ for current + jump to target LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ); LabelNode target = jump.label; int targetPosition = mn.instructions.indexOf(target); if (jump.getOpcode() != Opcodes.GOTO) { LCSAJ copy = new LCSAJ(currentLCSAJ); lcsaj_queue.add(copy); } if (!targets_reached.contains(targetPosition)) { LCSAJ c = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader) .getInstruction(className, methodName, targetPosition, target)); lcsaj_queue.add(c); targets_reached.add(targetPosition); } } else if (next instanceof TableSwitchInsnNode) { TableSwitchInsnNode tswitch = (TableSwitchInsnNode) next; List<LabelNode> allTargets = tswitch.labels; for (LabelNode target : allTargets) { int targetPosition = mn.instructions.indexOf(target); if (!targets_reached.contains(targetPosition)) { LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader) .getInstruction(className, methodName, targetPosition, target)); lcsaj_queue.add(b); targets_reached.add(targetPosition); } } } else if (next instanceof InsnNode) { InsnNode insn = (InsnNode) next; // New LCSAJ for current + throw / return if (insn.getOpcode() == Opcodes.ATHROW || insn.getOpcode() == Opcodes.RETURN || insn.getOpcode() == Opcodes.ARETURN || insn.getOpcode() == Opcodes.IRETURN || insn.getOpcode() == Opcodes.DRETURN || insn.getOpcode() == Opcodes.LRETURN || insn.getOpcode() == Opcodes.FRETURN) { LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ); } else lcsaj_queue.add(currentLCSAJ); } else lcsaj_queue.add(currentLCSAJ); } if (Properties.STRATEGY != Strategy.EVOSUITE) addInstrumentation(classLoader, mn, className, methodName); // if (Properties.WRITE_CFG) // for (LCSAJ l : LCSAJPool.getLCSAJs(className, methodName)) { // LCSAJGraph graph = new LCSAJGraph(l, false); // String graphDestination = "evosuite-graphs/LCSAJGraphs/" + className // + "/" + methodName; // File dir = new File(graphDestination); // if (dir.mkdirs()) // graph.generate(new File(graphDestination + "/LCSAJGraph no: " // + l.getID() + ".dot")); // else if (dir.exists()) // graph.generate(new File(graphDestination + "/LCSAJGraph no: " // + l.getID() + ".dot")); // } }
From source file:org.evosuite.instrumentation.CreateClassResetClassAdapter.java
License:Open Source License
private void createEmptyStaticReset() { logger.info("Creating brand-new static initializer in class {}", className); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, ClassResetter.STATIC_RESET, "()V", null, null); mv.visitCode();/* w ww . j a va 2 s . c om*/ for (StaticField staticField : static_fields) { if (!finalFields.contains(staticField.name)) { logger.info("Adding bytecode for initializing field {}", staticField.name); if (staticField.value != null) { mv.visitLdcInsn(staticField.value); } else { Type type = Type.getType(staticField.desc); switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: mv.visitInsn(Opcodes.ICONST_0); break; case Type.FLOAT: mv.visitInsn(Opcodes.FCONST_0); break; case Type.LONG: mv.visitInsn(Opcodes.LCONST_0); break; case Type.DOUBLE: mv.visitInsn(Opcodes.DCONST_0); break; case Type.ARRAY: case Type.OBJECT: mv.visitInsn(Opcodes.ACONST_NULL); break; } } mv.visitFieldInsn(Opcodes.PUTSTATIC, className, staticField.name, staticField.desc); } } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.evosuite.instrumentation.EndOfClassInitializerVisitor.java
License:Open Source License
private void createEmptyClassInit() { logger.info("Creating <clinit> in class " + className); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode();//w ww . ja v a 2 s.c o m String executionTracerClassName = ExecutionTracer.class.getName().replace('.', '/'); String executionTracerDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class)); String classNameWithDots = className.replace('/', '.'); mv.visitLdcInsn(classNameWithDots); mv.visitMethodInsn(INVOKESTATIC, executionTracerClassName, EXIT_CLASS_INIT, executionTracerDescriptor, false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.evosuite.instrumentation.ExitClassInitMethodAdapter.java
License:Open Source License
@Override public void visitInsn(int opcode) { if (opcode == Opcodes.RETURN && (methodName.equals("<clinit>"))) { String executionTracerClassName = ExecutionTracer.class.getName().replace('.', '/'); String executionTracerDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class)); String classNameWithDots = className.replace('/', '.'); super.visitLdcInsn(classNameWithDots); super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, EXIT_CLASS_INIT, executionTracerDescriptor, false); }/*from ww w .ja v a 2 s.c om*/ super.visitInsn(opcode); }
From source file:org.evosuite.instrumentation.ReturnValueAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override/*ww w .j av a 2 s. c om*/ 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.junit.TestSuiteWriter.java
License:Open Source License
private void testToBytecode(TestCase test, GeneratorAdapter mg, Map<Integer, Throwable> exceptions) { Map<Integer, Integer> locals = new HashMap<Integer, Integer>(); mg.visitAnnotation("Lorg/junit/Test;", true); int num = 0;//from w ww . ja v a2 s . c om for (StatementInterface statement : test) { logger.debug("Current statement: {}", statement.getCode()); statement.getBytecode(mg, locals, exceptions.get(num)); num++; } mg.visitInsn(Opcodes.RETURN); mg.endMethod(); }
From source file:org.evosuite.runtime.instrumentation.CreateClassResetClassAdapter.java
License:Open Source License
/** * Creates an empty __STATIC_RESET method where no <clinit> was found. *///from www . java 2s. co m private void createEmptyStaticReset() { logger.info("Creating brand-new static initializer in class " + className); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, ClassResetter.STATIC_RESET, "()V", null, null); mv.visitCode(); for (StaticField staticField : static_fields) { if (!finalFields.contains(staticField.name) && !staticField.name.startsWith("__cobertura") && !staticField.name.startsWith("$jacoco") && !staticField.name.startsWith("$VRc") // Old // Emma ) { logger.info("Adding bytecode for initializing field " + staticField.name); if (staticField.value != null) { mv.visitLdcInsn(staticField.value); } else { Type type = Type.getType(staticField.desc); switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: mv.visitInsn(Opcodes.ICONST_0); break; case Type.FLOAT: mv.visitInsn(Opcodes.FCONST_0); break; case Type.LONG: mv.visitInsn(Opcodes.LCONST_0); break; case Type.DOUBLE: mv.visitInsn(Opcodes.DCONST_0); break; case Type.ARRAY: case Type.OBJECT: mv.visitInsn(Opcodes.ACONST_NULL); break; } } mv.visitFieldInsn(Opcodes.PUTSTATIC, className, staticField.name, staticField.desc); } } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.evosuite.runtime.instrumentation.RegisterObjectForDeterministicHashCodeVisitor.java
License:Open Source License
@Override public void visitInsn(int opcode) { // We don't use the AdviceAdapter here because this is not properly initialised if the constructor is // exited with an exception if (opcode == Opcodes.RETURN) { loadThis();//from w ww.ja va 2 s .c om invokeStatic(Type.getType(org.evosuite.runtime.System.class), Method.getMethod("void registerObjectForIdentityHashCode(Object)")); } super.visitInsn(opcode); }