List of usage examples for org.objectweb.asm Opcodes RET
int RET
To view the source code for org.objectweb.asm Opcodes RET.
Click Source Link
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:// www. j a va 2s . c o m // 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.ControlFlowGraph.java
License:Open Source License
/** * Returns all <code>jsr</code> instructions that may end up in the given <code>ret</code> instructions. *///from w w w.j ava 2s . co m private static List<JumpInstruction> getJsrInstructions(VarInstruction retInstruction) { assert retInstruction.getOpcode() == Opcodes.RET; List<JumpInstruction> list = new ArrayList<JumpInstruction>(); for (AbstractInstruction instr : retInstruction.getMethod().getInstructions()) { if (instr.getOpcode() == Opcodes.JSR) { Queue<Instruction> queue = new UniqueQueue<Instruction>(); queue.add(((JumpInstruction) instr).getLabel()); while (!queue.isEmpty()) { Instruction instr2 = queue.poll(); if (instr2.getOpcode() == Opcodes.RET) { if (instr2 == retInstruction) { list.add((JumpInstruction) instr); } break; } queue.addAll(getSuccessors(instr)); } } } return list; }
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 va 2s .c om*/ // 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); }
From source file:de.unisb.cs.st.javaslicer.controlflowanalysis.ControlFlowGraph2.java
License:Open Source License
/** * Returns all <code>jsr</code> instructions that may end up in the given <code>ret</code> instructions. *//*w w w . jav a 2 s . c om*/ private List<JumpInstruction2> getJsrInstructions(VarInstruction retInstruction) { assert retInstruction.getOpcode() == Opcodes.RET; List<JumpInstruction2> list = new ArrayList<JumpInstruction2>(); for (AbstractInstruction instr : retInstruction.getMethod().getInstructions()) { if (instr.getOpcode() == Opcodes.JSR) { Queue<Instruction> queue = new UniqueQueue<Instruction>(); queue.add(((JumpInstruction2) instr).getLabel()); while (!queue.isEmpty()) { Instruction instr2 = queue.poll(); if (instr2.getOpcode() == Opcodes.RET) { if (instr2 == retInstruction) { list.add((JumpInstruction2) instr); } break; } queue.addAll(getSuccessors(instr)); } } } return list; }
From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java
License:Open Source License
private void generateMethodSkel(MethodVisitor cv, Method m, Variables var) { Class[] sig = m.getParameterTypes(); Label readArgs = new Label(); cv.visitLabel(readArgs);//from w ww .j a v a 2 s. c o m boolean needcastcheck = false; // ObjectInput in = call.getInputStream(); cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall")); cv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteCall.class), "getInputStream", Type.getMethodDescriptor(Type.getType(ObjectInput.class), new Type[] {})); cv.visitVarInsn(Opcodes.ASTORE, var.allocate("objectinput")); for (int i = 0; i < sig.length; i++) { // dup input stream cv.visitVarInsn(Opcodes.ALOAD, var.get("objectinput")); Class readCls = sig[i].isPrimitive() ? sig[i] : Object.class; // in.readFoo() cv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(ObjectInput.class), readMethod(sig[i]), Type.getMethodDescriptor(Type.getType(readCls), new Type[] {})); if (!sig[i].isPrimitive() && !sig[i].equals(Object.class)) { needcastcheck = true; cv.visitTypeInsn(Opcodes.CHECKCAST, typeArg(sig[i])); } // store arg in variable cv.visitVarInsn(storeOpcode(sig[i]), var.allocate(param(m, i), size(sig[i]))); } var.deallocate("objectinput"); Label doCall = new Label(); Label closeInput = new Label(); cv.visitJumpInsn(Opcodes.JSR, closeInput); cv.visitJumpInsn(Opcodes.GOTO, doCall); // throw new UnmarshalException Label handler = new Label(); cv.visitLabel(handler); cv.visitVarInsn(Opcodes.ASTORE, var.allocate("exception")); cv.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class)); cv.visitInsn(Opcodes.DUP); cv.visitLdcInsn("error unmarshalling arguments"); cv.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception")); cv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(UnmarshalException.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class), Type.getType(Exception.class) })); cv.visitVarInsn(Opcodes.ASTORE, var.allocate("toThrow")); cv.visitJumpInsn(Opcodes.JSR, closeInput); cv.visitVarInsn(Opcodes.ALOAD, var.get("toThrow")); cv.visitInsn(Opcodes.ATHROW); cv.visitTryCatchBlock(readArgs, handler, handler, Type.getInternalName(IOException.class)); if (needcastcheck) { cv.visitTryCatchBlock(readArgs, handler, handler, Type.getInternalName(ClassCastException.class)); } // finally block cv.visitLabel(closeInput); cv.visitVarInsn(Opcodes.ASTORE, var.allocate("retAddress")); cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall")); cv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteCall.class), "releaseInputStream", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {})); cv.visitVarInsn(Opcodes.RET, var.deallocate("retAddress")); var.deallocate("toThrow"); // do the call using args stored as variables cv.visitLabel(doCall); cv.visitVarInsn(Opcodes.ALOAD, var.get("remoteobj")); for (int i = 0; i < sig.length; i++) cv.visitVarInsn(loadOpcode(sig[i]), var.deallocate(param(m, i))); cv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(clazz), m.getName(), Type.getMethodDescriptor(m)); Class returntype = m.getReturnType(); if (!returntype.equals(Void.TYPE)) { cv.visitVarInsn(storeOpcode(returntype), var.allocate("result", size(returntype))); } // write result to result stream Label writeResult = new Label(); cv.visitLabel(writeResult); cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall")); cv.visitInsn(Opcodes.ICONST_1); cv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(RemoteCall.class), "getResultStream", Type.getMethodDescriptor(Type.getType(ObjectOutput.class), new Type[] { Type.BOOLEAN_TYPE })); if (!returntype.equals(Void.TYPE)) { // out.writeFoo(result) cv.visitVarInsn(loadOpcode(returntype), var.deallocate("result")); Class writeCls = returntype.isPrimitive() ? returntype : Object.class; cv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(ObjectOutput.class), writeMethod(returntype), Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(writeCls) })); } cv.visitInsn(Opcodes.RETURN); // throw new MarshalException Label marshalHandler = new Label(); cv.visitLabel(marshalHandler); cv.visitVarInsn(Opcodes.ASTORE, var.allocate("exception")); cv.visitTypeInsn(Opcodes.NEW, typeArg(MarshalException.class)); cv.visitInsn(Opcodes.DUP); cv.visitLdcInsn("error marshalling return"); cv.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception")); cv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(MarshalException.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class), Type.getType(Exception.class) })); cv.visitInsn(Opcodes.ATHROW); cv.visitTryCatchBlock(writeResult, marshalHandler, marshalHandler, Type.getInternalName(IOException.class)); }
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; }/*from w w w. ja va 2s .c o m*/ return false; }
From source file:net.cazzar.corelib.asm.MethodTransformer.java
License:Open Source License
private boolean isReturn(AbstractInsnNode node) { switch (node.getOpcode()) { case Opcodes.RET: case Opcodes.RETURN: case Opcodes.ARETURN: case Opcodes.DRETURN: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.LRETURN: return true; default://from ww w.j av a 2 s . c o m return false; } }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitVarInsn(final int opcode, final int var) { T t = null;/* w ww .java 2 s . c o m*/ switch (opcode) { /******** * LOAD * ********/ case Opcodes.ALOAD: t = T.REF; // fall through case Opcodes.DLOAD: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FLOAD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ILOAD: if (t == null) { t = T.AINT; } // fall through case Opcodes.LLOAD: if (t == null) { t = T.LONG; } add(new LOAD(this.ops.size(), opcode, this.line, t, var)); break; /********* * STORE * *********/ case Opcodes.ASTORE: t = T.AREF; // RET allowed too // fall through case Opcodes.DSTORE: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FSTORE: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ISTORE: if (t == null) { t = T.AINT; } // fall through case Opcodes.LSTORE: if (t == null) { t = T.LONG; } add(new STORE(this.ops.size(), opcode, this.line, t, var)); break; /******* * RET * *******/ case Opcodes.RET: { add(new RET(this.ops.size(), opcode, this.line, var)); break; } default: log.warn(getM() + ": Unknown var insn opcode '" + opcode + "'!"); } }
From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java
License:Open Source License
/** * Determine how many bytes the current instruction occupies together with * its operands/*from ww w. j ava2 s . co m*/ * * @return */ private int getBytecodeIncrement(AbstractInsnNode instructionNode) { int opcode = instructionNode.getOpcode(); switch (opcode) { case Opcodes.ALOAD: // index case Opcodes.ASTORE: // index case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.FLOAD: case Opcodes.FSTORE: case Opcodes.ILOAD: case Opcodes.ISTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: VarInsnNode varNode = (VarInsnNode) instructionNode; if (varNode.var > 3) return 1; else return 0; case Opcodes.BIPUSH: // byte case Opcodes.NEWARRAY: case Opcodes.RET: return 1; case Opcodes.LDC: LdcInsnNode ldcNode = (LdcInsnNode) instructionNode; if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long) return 2; // LDC2_W else return 1; case 19: //LDC_W case 20: //LDC2_W return 2; case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2 case Opcodes.CHECKCAST: // indexbyte1, indexbyte2 case Opcodes.GETFIELD: case Opcodes.GETSTATIC: case Opcodes.GOTO: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFNE: case Opcodes.IFEQ: case Opcodes.IFNONNULL: case Opcodes.IFNULL: case Opcodes.IINC: case Opcodes.INSTANCEOF: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: case Opcodes.JSR: case Opcodes.NEW: case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: case Opcodes.SIPUSH: // case Opcodes.LDC_W // case Opcodes.LDC2_W return 2; case Opcodes.MULTIANEWARRAY: return 3; case Opcodes.INVOKEDYNAMIC: case Opcodes.INVOKEINTERFACE: return 4; case Opcodes.LOOKUPSWITCH: case Opcodes.TABLESWITCH: // TODO: Could be more return 4; // case Opcodes.GOTO_W // case Opcodes.JSR_W } return 0; }
From source file:org.graalvm.compiler.replacements.test.DeoptimizeOnExceptionTest.java
License:Open Source License
private static byte[] makeClazz() { // Code generated the class below using asm. String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/'); final ClassWriter w = new ClassWriter(0); w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "t/TestJSR", null, "java/lang/Object", new String[] { "java/lang/Runnable" }); MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[] {}); mv.visitCode();// www. j a va 2s . c om mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(10, 10); mv.visitEnd(); mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null); mv.visitCode(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.JSR, l1); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ASTORE, 1); Label lElse = new Label(); Label lEnd = new Label(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNULL, lElse); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false); mv.visitJumpInsn(Opcodes.GOTO, lEnd); mv.visitLabel(lElse); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false); mv.visitLabel(lEnd); mv.visitVarInsn(Opcodes.RET, 1); mv.visitMaxs(10, 10); mv.visitEnd(); return w.toByteArray(); }