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:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java
License:Open Source License
/** * Tests that ForLoopUnroller is working correctly. * /* w ww.j a v a 2s .c o m*/ * Used is a loop of the kind: * * for(int i=0; i< 3; ++i) */ @Test public void testForLoopUnrollerStrictForward() { // INIT final LabelNode label1 = new LabelNode(); final LabelNode label2 = new LabelNode(); builder.addInsn(new InsnNode(Opcodes.ICONST_0)).// addInsn(new VarInsnNode(Opcodes.ISTORE, 1)).// addInsn(new JumpInsnNode(Opcodes.GOTO, label1)).// addInsn(label2).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new InsnNode(Opcodes.IADD)).// addInsn(new IincInsnNode(1, 1)).// addInsn(label1).// addInsn(NodeHelper.getInsnNodeFor(3)).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new JumpInsnNode(Opcodes.IF_ICMPLT, label2)).// addInsn(new InsnNode(Opcodes.RETURN)); // RUN assertEquals(13, method.instructions.size()); final InsnList optimized = optimizer.optimize(method.instructions, method); // ASSERT assertEquals(19, optimized.size()); int node = 0; for (int i = 0; i < 3; ++i) { assertEquals(i, NodeHelper.getNumberValue(optimized.get(node)).intValue()); node++; assertEquals(Opcodes.ISTORE, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.IADD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); // this is the SkipMarkNode node++; } }
From source file:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java
License:Open Source License
/** * Tests that ForLoopUnroller is working correctly. * //ww w . jav a 2s . c om * Used is a loop of the kind: * * for(int i=6; i> 0; i=i-2) */ @Test public void testForLoopUnrollerBackward() { // INIT final LabelNode label1 = new LabelNode(); final LabelNode label2 = new LabelNode(); builder.addInsn(NodeHelper.getInsnNodeFor(6)).// addInsn(new VarInsnNode(Opcodes.ISTORE, 1)).// addInsn(new JumpInsnNode(Opcodes.GOTO, label1)).// addInsn(label2).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new InsnNode(Opcodes.IADD)).// addInsn(new IincInsnNode(1, -2)).// addInsn(label1).// addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).// addInsn(new JumpInsnNode(Opcodes.IFGT, label2)).// addInsn(new InsnNode(Opcodes.RETURN)); // RUN assertEquals(12, method.instructions.size()); final InsnList optimized = optimizer.optimize(method.instructions, method); // ASSERT assertEquals(19, optimized.size()); int node = 0; for (int i = 6; i > 0; i -= 2) { assertEquals(i, NodeHelper.getNumberValue(optimized.get(node)).intValue()); node++; assertEquals(Opcodes.ISTORE, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.IADD, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; } }
From source file:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java
License:Open Source License
/** * Tests the Loopunroller for a loop with the test-instructions at the beginning. *//*ww w. ja va2 s .com*/ @Test public void testForLoopTypeTwo() { // INIT final LabelNode check = new LabelNode(); final LabelNode ende = new LabelNode(); builder.add(ICONST_0)// .add(ISTORE, 1)// .addInsn(check)// .add(ICONST_5)// .add(ILOAD, 1)// .add(IF_ICMPGT, ende)// .add(NOP)// .add(NOP)// .add(NOP)// .add(IINC, 1, 1)// .add(GOTO, check)// .addInsn(ende)// .add(NOP)// .addReturn(); // RUN assertEquals(14, method.instructions.size()); final InsnList optimized = optimizer.optimize(method.instructions, method); // ASSERT assertEquals(38, optimized.size()); // int node = 0; for (int i = 0; i < 6; ++i) { assertEquals(i, NodeHelper.getNumberValue(optimized.get(node)).intValue()); node++; assertEquals(Opcodes.ISTORE, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; } assertEquals(Opcodes.NOP, optimized.get(node).getOpcode()); node++; assertEquals(Opcodes.RETURN, optimized.get(node).getOpcode()); node++; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
private static boolean isStore(final AbstractInsnNode currentNode) { if (currentNode == null) { return false; }/* w ww . ja v a 2s .c om*/ if ((currentNode.getOpcode() >= Opcodes.ISTORE) && (currentNode.getOpcode() <= Opcodes.ASTORE)) { return true; } if ((currentNode.getOpcode() >= Opcodes.IRETURN) && (currentNode.getOpcode() <= Opcodes.RETURN)) { return true; } return false; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.BlockTest.java
License:Open Source License
/** * Tests the type erasure.//www . j ava2 s.c o m */ @Test public void testTypeErasure() { final InsnList list = new InsnList(); list.add(new InsnNode(Opcodes.ICONST_5)); list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT)); list.add(new VarInsnNode(Opcodes.ASTORE, 3)); list.add(new VarInsnNode(Opcodes.ILOAD, 1)); list.add(new VarInsnNode(Opcodes.ILOAD, 2)); list.add(new InsnNode(Opcodes.IADD)); list.add(new InsnNode(Opcodes.ICONST_0)); list.add(new VarInsnNode(Opcodes.ALOAD, 3)); list.add(new InsnNode(Opcodes.IASTORE)); list.add(new InsnNode(Opcodes.ICONST_5)); list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT)); list.add(new VarInsnNode(Opcodes.ASTORE, 4)); list.add(new VarInsnNode(Opcodes.ILOAD, 1)); list.add(new VarInsnNode(Opcodes.ILOAD, 2)); list.add(new InsnNode(Opcodes.IADD)); list.add(new InsnNode(Opcodes.ICONST_1)); final VarInsnNode insn = new VarInsnNode(Opcodes.ALOAD, 3); list.add(insn); list.add(new InsnNode(Opcodes.IASTORE)); list.add(new InsnNode(Opcodes.RETURN)); final ListIterator<AbstractInsnNode> iterator = list.iterator(); final Block block = new Block(1, new Type[] { Type.INT_TYPE, Type.INT_TYPE }, Type.INT_TYPE); while (iterator.hasNext()) { block.addInsn(iterator.next(), true); } final Type findType = block.findType(insn); assertEquals(Type.getType("[I"), findType); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.MethodSplitterTest.java
License:Open Source License
/** * Tests that methodSplitterArrayIsArgNoReturn() of the Testobject is working correctly. * //ww w . ja v a2s. com * @throws Exception * the exception */ @Test public void testMethodSplitterArrayIsArgNoReturn() throws Exception { // INIT classNode.name += "1"; method.desc = "([I)V"; fillArray().// arrayref addInsn(new InsnNode(Opcodes.RETURN)); // RUN final InsnList splitted = splitter.optimize(method.instructions, method); final List<MethodNode> additionalMethods = splitter.getAdditionalMethods(); // ASSERT // check methods assertFalse(additionalMethods.isEmpty()); for (int i = 0; i < additionalMethods.size(); ++i) { final MethodNode methodNode = additionalMethods.get(i); assertEquals("([I)V", methodNode.desc); } // check that the class is valid by instantiating it method.instructions = splitted; classNode.methods.addAll(additionalMethods); final Object instance = builder.toClass().instance(); // check method functionality final Method instanceMethod = instance.getClass().getMethod("testMethod", int[].class); instanceMethod.setAccessible(true); final int[] is = new int[arrayLength]; instanceMethod.invoke(instance, is); for (int i = 0; i < arrayLength; ++i) { assertEquals((i + 1) * 2, is[i]); } }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
public void visitInsn(int inst) { if (!methodName.equals("<clinit>") && instrumentReturns) { switch (inst) { case Opcodes.IRETURN: callLogIReturn();/*from w w w . j a v a 2 s.co m*/ callEnd(); break; case Opcodes.ARETURN: callLogAReturn(); callEnd(); break; case Opcodes.ATHROW: callEnd(); break; case Opcodes.DRETURN: callLogDReturn(); callEnd(); break; case Opcodes.FRETURN: callLogFReturn(); callEnd(); break; case Opcodes.LRETURN: callLogLReturn(); callEnd(); break; case Opcodes.RETURN: callEnd(); break; default: break; } } super.visitInsn(inst); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.SimpleInstruction.java
License:Open Source License
@Override public String toString() { switch (getOpcode()) { // the not interesting ones: case Opcodes.NOP: return "NOP"; // constants: case Opcodes.ACONST_NULL: return "ACONST_NULL"; case Opcodes.ICONST_M1: return "ICONST_M1"; case Opcodes.ICONST_0: return "ICONST_0"; case Opcodes.ICONST_1: return "ICONST_1"; case Opcodes.ICONST_2: return "ICONST_2"; case Opcodes.ICONST_3: return "ICONST_3"; case Opcodes.ICONST_4: return "ICONST_4"; case Opcodes.ICONST_5: return "ICONST_5"; case Opcodes.LCONST_0: return "LCONST_0"; case Opcodes.LCONST_1: return "LCONST_1"; case Opcodes.FCONST_0: return "FCONST_0"; case Opcodes.FCONST_1: return "FCONST_1"; case Opcodes.FCONST_2: return "FCONST_2"; case Opcodes.DCONST_0: return "DCONST_0"; case Opcodes.DCONST_1: return "DCONST_1"; // array load: case Opcodes.IALOAD: return "IALOAD"; case Opcodes.LALOAD: return "LALOAD"; case Opcodes.FALOAD: return "FALOAD"; case Opcodes.DALOAD: return "DALOAD"; case Opcodes.AALOAD: return "AALOAD"; case Opcodes.BALOAD: return "BALOAD"; case Opcodes.CALOAD: return "CALOAD"; case Opcodes.SALOAD: return "SALOAD"; // array store: case Opcodes.IASTORE: return "IASTORE"; case Opcodes.LASTORE: return "LASTORE"; case Opcodes.FASTORE: return "FASTORE"; case Opcodes.DASTORE: return "DASTORE"; case Opcodes.AASTORE: return "AASTORE"; case Opcodes.BASTORE: return "BASTORE"; case Opcodes.CASTORE: return "CASTORE"; case Opcodes.SASTORE: return "SASTORE"; // stack manipulation: case Opcodes.POP: return "POP"; case Opcodes.POP2: return "POP2"; case Opcodes.DUP: return "DUP"; case Opcodes.DUP_X1: return "DUP_X1"; case Opcodes.DUP_X2: return "DUP_X2"; case Opcodes.DUP2: return "DUP2"; case Opcodes.DUP2_X1: return "DUP2_X1"; case Opcodes.DUP2_X2: return "DUP2_X2"; case Opcodes.SWAP: return "SWAP"; // arithmetic: case Opcodes.IADD: return "IADD"; case Opcodes.LADD: return "LADD"; case Opcodes.FADD: return "FADD"; case Opcodes.DADD: return "DADD"; case Opcodes.ISUB: return "ISUB"; case Opcodes.LSUB: return "LSUB"; case Opcodes.FSUB: return "FSUB"; case Opcodes.DSUB: return "DSUB"; case Opcodes.IMUL: return "IMUL"; case Opcodes.LMUL: return "LMUL"; case Opcodes.FMUL: return "FMUL"; case Opcodes.DMUL: return "DMUL"; case Opcodes.IDIV: return "IDIV"; case Opcodes.LDIV: return "LDIV"; case Opcodes.FDIV: return "FDIV"; case Opcodes.DDIV: return "DDIV"; case Opcodes.IREM: return "IREM"; case Opcodes.LREM: return "LREM"; case Opcodes.FREM: return "FREM"; case Opcodes.DREM: return "DREM"; case Opcodes.INEG: return "INEG"; case Opcodes.LNEG: return "LNEG"; case Opcodes.FNEG: return "FNEG"; case Opcodes.DNEG: return "DNEG"; case Opcodes.ISHL: return "ISHL"; case Opcodes.LSHL: return "LSHL"; case Opcodes.ISHR: return "ISHR"; case Opcodes.LSHR: return "LSHR"; case Opcodes.IUSHR: return "IUSHR"; case Opcodes.LUSHR: return "LUSHR"; case Opcodes.IAND: return "IAND"; case Opcodes.LAND: return "LAND"; case Opcodes.IOR: return "IOR"; case Opcodes.LOR: return "LOR"; case Opcodes.IXOR: return "IXOR"; case Opcodes.LXOR: return "LXOR"; // type conversions: case Opcodes.I2L: return "I2L"; case Opcodes.I2F: return "I2F"; case Opcodes.I2D: return "I2D"; case Opcodes.L2I: return "L2I"; case Opcodes.L2F: return "L2F"; case Opcodes.L2D: return "L2D"; case Opcodes.F2I: return "F2I"; case Opcodes.F2L: return "F2L"; case Opcodes.F2D: return "F2D"; case Opcodes.D2I: return "D2I"; case Opcodes.D2L: return "D2L"; case Opcodes.D2F: return "D2F"; case Opcodes.I2B: return "I2B"; case Opcodes.I2C: return "I2C"; case Opcodes.I2S: return "I2S"; // comparison: case Opcodes.LCMP: return "LCMP"; case Opcodes.FCMPL: return "FCMPL"; case Opcodes.FCMPG: return "FCMPG"; case Opcodes.DCMPL: return "DCMPL"; case Opcodes.DCMPG: return "DCMPG"; // control-flow statements: case Opcodes.IRETURN: return "IRETURN"; case Opcodes.LRETURN: return "LRETURN"; case Opcodes.FRETURN: return "FRETURN"; case Opcodes.DRETURN: return "DRETURN"; case Opcodes.ARETURN: return "ARETURN"; case Opcodes.RETURN: return "RETURN"; // special things case Opcodes.ARRAYLENGTH: return "ARRAYLENGTH"; case Opcodes.ATHROW: return "ATHROW"; case Opcodes.MONITORENTER: return "MONITORENTER"; case Opcodes.MONITOREXIT: return "MONITOREXIT"; default:/*from ww w .j av a 2 s. co m*/ assert false; return "--ERROR--"; } }
From source file:de.unisb.cs.st.javaslicer.controlflowanalysis.ControlFlowGraph.java
License:Open Source License
private static Collection<Instruction> getSuccessors(Instruction instruction) { int opcode = instruction.getOpcode(); Instruction nextInstruction = instruction.getNext(); switch (instruction.getType()) { case JUMP://from w w w . j ava2s.com // GOTO and JSR are not conditional if (opcode == Opcodes.GOTO || opcode == Opcodes.JSR) { return Collections.singleton((Instruction) ((JumpInstruction) instruction).getLabel()); } assert nextInstruction != null; return Arrays.asList(((JumpInstruction) instruction).getLabel(), nextInstruction); case LOOKUPSWITCH: { LookupSwitchInstruction lsi = (LookupSwitchInstruction) instruction; Instruction[] successors = new AbstractInstruction[lsi.getHandlers().size() + 1]; successors[0] = lsi.getDefaultHandler(); int i = 1; for (LabelMarker lm : lsi.getHandlers().values()) successors[i++] = lm; return Arrays.asList(successors); } case TABLESWITCH: { TableSwitchInstruction tsi = (TableSwitchInstruction) instruction; Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length + 1]; successors[0] = tsi.getDefaultHandler(); System.arraycopy(tsi.getHandlers(), 0, successors, 1, tsi.getHandlers().length); return Arrays.asList(successors); } case SIMPLE: switch (opcode) { case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: case Opcodes.RETURN: return Collections.emptySet(); default: break; } break; case VAR: if (opcode == Opcodes.RET) { List<JumpInstruction> callingInstructions = getJsrInstructions((VarInstruction) instruction); Instruction[] successors = new AbstractInstruction[callingInstructions.size()]; int i = 0; for (JumpInstruction instr : callingInstructions) successors[i++] = instr.getNext(); return Arrays.asList(successors); } break; case LABEL: if (instruction == instruction.getMethod().getAbnormalTerminationLabel()) return Collections.emptySet(); break; default: break; } assert nextInstruction != null; return Collections.singleton(nextInstruction); }
From source file:de.unisb.cs.st.javaslicer.controlflowanalysis.ControlFlowGraph2.java
License:Open Source License
public Collection<Instruction> getSuccessors(Instruction instruction) { int opcode = instruction.getOpcode(); // index??? getnextindex+1? Instruction nextInstruction = instruction.getNext(); switch (instruction.getType()) { case JUMP:/*from ww w . j a v a2 s . c o m*/ // GOTO and JSR are not conditional // ???? if (opcode == Opcodes.GOTO || opcode == Opcodes.JSR) { List<AbstractInstruction> instrs = this.method.instructions; Iterator<AbstractInstruction> iter = instrs.iterator(); Instruction temp = null; while (iter.hasNext()) { temp = iter.next(); if (temp.getIndex() == ((JumpInstruction2) instruction).getTarget()) break; } return Collections.singleton(temp); } assert nextInstruction != null; // ?nextInstruction, ?label! List<AbstractInstruction> instrs = this.method.instructions; Iterator<AbstractInstruction> iter = instrs.iterator(); Instruction temp = null; while (iter.hasNext()) { temp = iter.next(); if (temp.getIndex() == ((JumpInstruction2) instruction).getTarget()) break; } return Arrays.asList(temp, nextInstruction); // switch case LOOKUPSWITCH: { LookupSwitchInstruction2 lsi = (LookupSwitchInstruction2) instruction; List<AbstractInstruction> instrs4 = this.method.instructions; List<AbstractInstruction> instrs5 = this.method.instructions; Iterator<AbstractInstruction> iter4 = instrs4.iterator(); Instruction temp2 = null; Instruction[] successors = new AbstractInstruction[lsi.getHandlers().size() + 1]; // find the default while (iter4.hasNext()) { temp2 = iter4.next(); if (temp2.getIndex() == lsi.getDefaultHandler()) { successors[0] = temp2; break; } } // find the handlers int index = 0; for (Integer lm : lsi.getHandlers().values()) { Iterator<AbstractInstruction> iter5 = instrs5.iterator(); while (iter5.hasNext()) { temp2 = iter5.next(); if (temp2.getIndex() == lm) { successors[index + 1] = temp2; index++; break; } } } return Arrays.asList(successors); } // switch ? case TABLESWITCH: { TableSwitchInstruction2 tsi = (TableSwitchInstruction2) instruction; List<AbstractInstruction> instrs2 = this.method.instructions; List<AbstractInstruction> instrs3 = this.method.instructions; Iterator<AbstractInstruction> iter2 = instrs2.iterator(); //Iterator<AbstractInstruction> iter3=instrs3.iterator(); Instruction temp2 = null; Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length + 1]; // get the default target while (iter2.hasNext()) { temp2 = iter2.next(); if (tsi.getDefaultHandler() == temp2.getIndex()) { successors[0] = temp2; break; } } // get the target from min to max! for (int i = 0; i < tsi.getHandlers().length; i++) { Iterator<AbstractInstruction> iter3 = instrs3.iterator(); while (iter3.hasNext()) { temp2 = iter3.next(); if (temp2.getIndex() == (tsi.getHandlers()[i])) { successors[i + 1] = temp2; break; } } } return Arrays.asList(successors); /* TableSwitchInstruction tsi = (TableSwitchInstruction) instruction; Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length+1]; successors[0] = tsi.getDefaultHandler(); System.arraycopy(tsi.getHandlers(), 0, successors, 1, tsi.getHandlers().length); return Arrays.asList(successors);*/ } // ???return??nextInstruction! case SIMPLE: switch (opcode) { case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: case Opcodes.RETURN: return Collections.emptySet(); default: break; } break; // ??ret case VAR: if (opcode == Opcodes.RET) { List<JumpInstruction2> callingInstructions = getJsrInstructions((VarInstruction) instruction); Instruction[] successors = new AbstractInstruction[callingInstructions.size()]; int i = 0; for (JumpInstruction2 instr : callingInstructions) successors[i++] = instr.getNext(); return Arrays.asList(successors); } break; // label abnormalTermination?nextInstruction! case LABEL: if (instruction == instruction.getMethod().getAbnormalTerminationLabel()) return Collections.emptySet(); break; default: break; } // ?index+1?? assert nextInstruction != null; return Collections.singleton(nextInstruction); }