List of usage examples for org.objectweb.asm Opcodes DRETURN
int DRETURN
To view the source code for org.objectweb.asm Opcodes DRETURN.
Click Source Link
From source file:com.offbynull.coroutines.instrumenter.ContinuationGenerators.java
License:Open Source License
/** * Generates instructions that returns a dummy value. Return values are as follows: * <ul>//from w w w . j a v a 2 s. co m * <li>void -> no value</li> * <li>boolean -> false</li> * <li>byte/short/char/int -> 0</li> * <li>long -> 0L</li> * <li>float -> 0.0f</li> * <li>double -> 0.0</li> * <li>Object -> null</li> * </ul> * * @param returnType return type of the method this generated bytecode is for * @return instructions to return a dummy value * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code returnType}'s sort is of {@link Type#METHOD} */ private static InsnList returnDummy(Type returnType) { Validate.notNull(returnType); Validate.isTrue(returnType.getSort() != Type.METHOD); InsnList ret = new InsnList(); switch (returnType.getSort()) { case Type.VOID: ret.add(new InsnNode(Opcodes.RETURN)); break; case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: ret.add(new InsnNode(Opcodes.ICONST_0)); ret.add(new InsnNode(Opcodes.IRETURN)); break; case Type.LONG: ret.add(new InsnNode(Opcodes.LCONST_0)); ret.add(new InsnNode(Opcodes.LRETURN)); break; case Type.FLOAT: ret.add(new InsnNode(Opcodes.FCONST_0)); ret.add(new InsnNode(Opcodes.FRETURN)); break; case Type.DOUBLE: ret.add(new InsnNode(Opcodes.DCONST_0)); ret.add(new InsnNode(Opcodes.DRETURN)); break; case Type.OBJECT: case Type.ARRAY: ret.add(new InsnNode(Opcodes.ACONST_NULL)); ret.add(new InsnNode(Opcodes.ARETURN)); break; default: throw new IllegalStateException(); } return ret; }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.Inlining.java
License:Open Source License
public static List<Insn> convertInsns(MethodInsn mi, List<Insn> insns, int[] args, int _index, Label end) { List<Insn> result = new ArrayList<Insn>(); HashMap labels = new HashMap(); int index = _index; for (Insn i : insns) { if (i.isExpanded()) { MethodInsn expanded = (MethodInsn) i; // This use of end should be OK because all returns should have been removed when inlined before. // What could go wrong? result.addAll(convertInsns(expanded, expanded.inlineExpansionInsns, args, _index, end)); } else if (i instanceof SingleInsn) { SingleInsn si = (SingleInsn) i; switch (si.opcode) { case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: case Opcodes.RETURN: result.add(new JumpInsn("RETURN->GOTO", Opcodes.GOTO, end, newIndex(mi, index++))); break; default: result.add(i.copy(newIndex(mi, index++))); }//ww w . j av a2 s .co m } else if (i instanceof VarInsn) { VarInsn vi = (VarInsn) i; switch (vi.opcode) { case Opcodes.ILOAD: case Opcodes.LLOAD: case Opcodes.FLOAD: case Opcodes.DLOAD: case Opcodes.ALOAD: case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: VarInsn newVarInsn = new VarInsn(vi.name, vi.opcode, args[vi.var], newIndex(mi, index++)); result.add(newVarInsn); break; default: result.add(i.copy(newIndex(mi, index++))); } } else if (i instanceof VisitMaxs) { } else if (i instanceof VisitEnd) { } else if (i instanceof VisitCode) { } else if (i instanceof VisitFrame) { } else if (i instanceof LabelInsn) { LabelInsn li = (LabelInsn) i; if (labels.containsKey(li.label)) result.add(new LabelInsn(li.name, (Label) labels.get(li.label), newIndex(mi, index++))); else { Label l = new Label(); labels.put(li.label, l); result.add(new LabelInsn(li.name, l, newIndex(mi, index++))); } } else if (i instanceof JumpInsn) { JumpInsn ji = (JumpInsn) i; if (labels.containsKey(ji.label)) result.add( new JumpInsn(ji.name, ji.opcode, (Label) labels.get(ji.label), newIndex(mi, index++))); else { Label l = new Label(); labels.put(ji.label, l); result.add(new JumpInsn(ji.name, ji.opcode, l, newIndex(mi, index++))); } } else if (i instanceof VisitLineNumberInsn) { VisitLineNumberInsn vlni = (VisitLineNumberInsn) i; if (labels.containsKey(vlni.start)) result.add(new VisitLineNumberInsn(vlni.name, vlni.line, (Label) labels.get(vlni.start), newIndex(mi, index++))); else { Label l = new Label(); labels.put(vlni.start, l); result.add(new VisitLineNumberInsn(vlni.name, vlni.line, l, newIndex(mi, index++))); } } else if (i instanceof LocalVariableInsn) { LocalVariableInsn lvi = (LocalVariableInsn) i; if (labels.containsKey(lvi.start) && labels.containsKey(lvi.end)) { result.add(new LocalVariableInsn(lvi.name, lvi._name, lvi.desc, lvi.sig, (Label) labels.get(lvi.start), (Label) labels.get(lvi.end), args[lvi._index], newIndex(mi, index++))); } else throw new RuntimeException("NYI"); } else if (i instanceof TryCatchBlock) { TryCatchBlock tcb = (TryCatchBlock) i; if (labels.containsKey(tcb.start) && labels.containsKey(tcb.end) && labels.containsKey(tcb.handler)) { result.add( new TryCatchBlock(tcb.name, (Label) labels.get(tcb.start), (Label) labels.get(tcb.end), (Label) labels.get(tcb.handler), tcb.type, newIndex(mi, index++))); } else if (!labels.containsKey(tcb.start) && !labels.containsKey(tcb.end) && !labels.containsKey(tcb.handler)) { Label s = new Label(); Label e = new Label(); Label h = new Label(); labels.put(tcb.start, s); labels.put(tcb.end, e); labels.put(tcb.handler, h); result.add(new TryCatchBlock(tcb.name, s, e, h, tcb.type, newIndex(mi, index++))); } else throw new RuntimeException("NYI"); // Need to add TableSwitch, LookupSwitch } else { result.add(i.copy(newIndex(mi, index++))); } } return result; }
From source file:com.sun.tdk.jcov.instrument.StaticInvokeMethodAdapter.java
License:Open Source License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.IRETURN: case Opcodes.FRETURN: case Opcodes.ARETURN: case Opcodes.LRETURN: case Opcodes.DRETURN: case Opcodes.RETURN: if (params.isInnerInvacationsOff() && Utils.isAdvanceStaticInstrAllowed(className, methName/*"<init>"*/)) { if (!methName.equals("<clinit>")) { int id = 0; super.visitLdcInsn(id); super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected", "(I)V"); } else { super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "leaveClinit", "()V"); }//from w w w . j av a2 s .c om } break; default: break; } super.visitInsn(opcode); }
From source file:com.taobao.profile.instrument.ProfMethodAdapter.java
License:Open Source License
public void visitInsn(int inst) { switch (inst) { case Opcodes.ARETURN: case Opcodes.DRETURN: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.RETURN: case Opcodes.ATHROW: this.visitLdcInsn(mMethodId); this.visitMethodInsn(INVOKESTATIC, "com/taobao/profile/Profiler", "End", "(I)V"); break;//from ww w .j a va 2 s .c o m default: break; } super.visitInsn(inst); }
From source file:com.triage.bytecodemaster.GroovyShardTransformer.java
protected boolean isReturnOpCode(int opCode) { return opCode == Opcodes.ARETURN || opCode == Opcodes.LRETURN || opCode == Opcodes.IRETURN || opCode == Opcodes.DRETURN || opCode == Opcodes.FRETURN || opCode == Opcodes.RETURN; }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitInsn(int opcode) { Expression e;/*from ww w . ja va 2s . co m*/ Expression first; Expression second; switch (opcode) { case Opcodes.ARRAYLENGTH: e = Expression.arrayLength(_exprStack.pop()); break; case Opcodes.ACONST_NULL: e = Expression.constant(null, Object.class); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.arrayIndex(second, first); break; case Opcodes.DCONST_0: e = Expression.constant(0d, Double.TYPE); break; case Opcodes.DCONST_1: e = Expression.constant(1d, Double.TYPE); break; case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.FCONST_0: e = Expression.constant(0f, Float.TYPE); break; case Opcodes.FCONST_1: e = Expression.constant(1f, Float.TYPE); break; case Opcodes.FCONST_2: e = Expression.constant(2f, Float.TYPE); break; case Opcodes.ICONST_M1: e = Expression.constant(-1, Integer.TYPE); break; case Opcodes.ICONST_0: e = Expression.constant(0, Integer.TYPE); break; case Opcodes.ICONST_1: e = Expression.constant(1, Integer.TYPE); break; case Opcodes.ICONST_2: e = Expression.constant(2, Integer.TYPE); break; case Opcodes.ICONST_3: e = Expression.constant(3, Integer.TYPE); break; case Opcodes.ICONST_4: e = Expression.constant(4, Integer.TYPE); break; case Opcodes.ICONST_5: e = Expression.constant(5, Integer.TYPE); break; case Opcodes.LCONST_0: e = Expression.constant(0l, Long.TYPE); break; case Opcodes.LCONST_1: e = Expression.constant(1l, Long.TYPE); break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.add(second, first); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.multiply(second, first); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.divide(second, first); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.modulo(second, first); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: first = _exprStack.pop(); e = Expression.negate(first); break; case Opcodes.ISHL: case Opcodes.LSHL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.leftShift(second, first); break; case Opcodes.ISHR: case Opcodes.LSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IUSHR: case Opcodes.LUSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IAND: case Opcodes.LAND: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseAnd(second, first); break; case Opcodes.IOR: case Opcodes.LOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseOr(second, first); break; case Opcodes.IXOR: case Opcodes.LXOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.exclusiveOr(second, first); break; case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup2[opcode - Opcodes.I2B]); break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.I2L + 1]); break; case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: int l2l = opcode > Opcodes.L2I ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.L2I + l2l]); break; case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: int f2f = opcode == Opcodes.F2D ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.F2I + f2f]); break; case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.D2I]); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: go(null); return; case Opcodes.SWAP: first = _exprStack.pop(); second = _exprStack.pop(); _exprStack.push(first); _exprStack.push(second); case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: // our stack is not divided to words int base = (opcode - Opcodes.DUP) % 3; base++; dup(_exprStack, base, base - 1); return; case Opcodes.NOP: return; case Opcodes.RETURN: default: throw notLambda(opcode); } _exprStack.push(e); }
From source file:de.tuberlin.uebb.jbop.optimizer.array.FieldArrayValueInlinerTest.java
License:Open Source License
/** * Tests that FieldArrayValueInliner is working correctly. * //from w w w. j a va2 s .c o m * @throws Exception * the exception */ @Test public void testFieldArrayValueInliner() throws Exception { // INIT final String owner = "de.tuberlin.uebb.jbop.optimizer.array.FieldArrayValueTestClass"; final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).// addField("doubleArray1", "[D").withAnnotation(ImmutableArray.class).initArrayWith(1.0, 2.0, 3.0).// addField("doubleArray2", "[D").withAnnotation(ImmutableArray.class).initArrayWith(4.0, 5.0, 6.0).// addMethod("sumArrayValues", "()D").withAnnotation(Optimizable.class).// loadFieldArrayValue("doubleArray1", 0).// 4 -> 1 loadFieldArrayValue("doubleArray2", 0).// 4 -> 1 addInsn(new InsnNode(Opcodes.DADD)).// 1 loadFieldArrayValue("doubleArray1", 1).// 4 -> 1 loadFieldArrayValue("doubleArray2", 1).// 4 -> 1 addInsn(new InsnNode(Opcodes.DADD)).// 1 addInsn(new InsnNode(Opcodes.DADD)).// 1 loadFieldArrayValue("doubleArray1", 2).// 4 -> 1 loadFieldArrayValue("doubleArray2", 2).// 4 -> 1 addInsn(new InsnNode(Opcodes.DADD)).// 1 addInsn(new InsnNode(Opcodes.DADD)).// 1 addInsn(new InsnNode(Opcodes.DRETURN));// 1 // final FieldArrayValueInliner inliner = new FieldArrayValueInliner(); inliner.setClassNode(builder.getClassNode()); inliner.setInputObject(builder.instance()); final MethodNode method = builder.getMethod("sumArrayValues"); assertEquals(30, method.instructions.size()); // RUN STEP 1 final InsnList optimized = inliner.optimize(method.instructions, method); // ASSERT STEP 1 assertEquals(12, optimized.size()); // first value pair AbstractInsnNode currentNode = optimized.getFirst(); assertEquals(1.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); currentNode = currentNode.getNext(); assertEquals(4.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); currentNode = currentNode.getNext(); // second value pair currentNode = currentNode.getNext(); assertEquals(2.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); currentNode = currentNode.getNext(); assertEquals(5.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); currentNode = currentNode.getNext(); currentNode = currentNode.getNext(); // third value pair currentNode = currentNode.getNext(); assertEquals(3.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); currentNode = currentNode.getNext(); assertEquals(6.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001); // RUN STEP 3 final InsnList optimized3 = inliner.optimize(method.instructions, method); // ASSERT STEP 3 assertEquals(12, optimized3.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueInlinerTest.java
License:Open Source License
/** * Tests that LocalArrayValueInliner is working correctly. * /* w w w. j a v a2s . com*/ * @throws Exception * the exception */ @Test public void testLocalArrayValueInliner() throws Exception { // INIT final String owner = "de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueTestClass"; final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).// addField("doubleArray", "[[D").// withAnnotation(ImmutableArray.class).// withModifiers(Opcodes.ACC_PRIVATE, Opcodes.ACC_FINAL).// initArray(2, 2).// initMultiArrayWith(1.0, 0, 0).// initMultiArrayWith(2.0, 0, 1).// initMultiArrayWith(3.0, 1, 0).// initMultiArrayWith(4.0, 1, 1).// addMethod("getArrayValue", "()D").withAnnotation(Optimizable.class).// addGetClassField("doubleArray").// 2 -> 2 addInsn(new InsnNode(Opcodes.ICONST_0)).// 1 -> 1 addInsn(new InsnNode(Opcodes.AALOAD)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ASTORE, 2)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ALOAD, 2)).// 1 -> 0| addInsn(new InsnNode(Opcodes.ICONST_1)).// 1 -> 0| addInsn(new InsnNode(Opcodes.DALOAD)).// 1 -> 0| 1 addInsn(new InsnNode(Opcodes.DRETURN));// 1 -> 1 // 14 -> 12 final LocalArrayValueInliner inliner = new LocalArrayValueInliner(); inliner.setInputObject(builder.toClass().instance()); // RUN STEP 1 final MethodNode method = builder.getMethod("getArrayValue"); assertEquals(9, method.instructions.size()); final InsnList optimized = inliner.optimize(method.instructions, method); // ASSERT STEP 1 assertEquals(7, optimized.size()); assertEquals(2.0, NodeHelper.getNumberValue(optimized.get(5)).doubleValue(), .0001); // RUN STEP 2 final InsnList optimized2 = inliner.optimize(method.instructions, method); // ASSERT STEP 2 assertEquals(7, optimized2.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
private Type getTypeIfSimpleType(final AbstractInsnNode node) { final int opcode = node.getOpcode(); if ((opcode == Opcodes.ILOAD) || (opcode == Opcodes.ISTORE) || (opcode == Opcodes.IRETURN)) { return Type.INT_TYPE; }/* w w w . jav a 2s.c o m*/ if ((opcode == Opcodes.FLOAD) || (opcode == Opcodes.FSTORE) || (opcode == Opcodes.FRETURN)) { return Type.FLOAT_TYPE; } if ((opcode == Opcodes.LLOAD) || (opcode == Opcodes.LSTORE) || (opcode == Opcodes.LRETURN)) { return Type.LONG_TYPE; } if ((opcode == Opcodes.DLOAD) || (opcode == Opcodes.DSTORE) || (opcode == Opcodes.DRETURN)) { return Type.DOUBLE_TYPE; } return null; }
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 . ja v a2 s.c om*/ 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); }