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:bytecode.MethodImporter.java
License:Apache License
/** * Imports variable load and store operations, as well as RET?!? * * @param opcode Opcode./*from w w w .j a v a 2 s.co m*/ * @param var Variable index. */ @Override public void visitVarInsn(final int opcode, final int var) { switch (opcode) { case Opcodes.ILOAD: createVarRead(var, Type.INT); break; case Opcodes.LLOAD: createVarRead(var, Type.LONG); break; case Opcodes.FLOAD: createVarRead(var, Type.FLOAT); break; case Opcodes.DLOAD: createVarRead(var, Type.DOUBLE); break; case Opcodes.ALOAD: createVarRead(var, Type.getFreshRef()); break; case Opcodes.ISTORE: createVarWrite(var, Type.INT); break; case Opcodes.LSTORE: createVarWrite(var, Type.LONG); break; case Opcodes.FSTORE: createVarWrite(var, Type.FLOAT); break; case Opcodes.DSTORE: createVarWrite(var, Type.DOUBLE); break; case Opcodes.ASTORE: createVarWrite(var, Type.getFreshRef()); break; // TODO: RET (paired with JSR) case Opcodes.RET: throw new RuntimeException("visitVarInsn: RET"); } }
From source file:com.codename1.tools.translator.bytecodes.VarOp.java
License:Open Source License
@Override public void appendInstruction(StringBuilder b) { b.append(" "); switch (opcode) { case Opcodes.ILOAD: b.append("(*SP).type = CN1_TYPE_INT; /* ILOAD */ \n" + " (*SP).data.i = ilocals_"); b.append(var); b.append("_; \n SP++;\n"); return;/*from w ww .jav a 2 s . c om*/ case Opcodes.LLOAD: b.append("BC_LLOAD("); break; case Opcodes.FLOAD: b.append("BC_FLOAD("); break; case Opcodes.DLOAD: b.append("BC_DLOAD("); break; case Opcodes.ALOAD: b.append("BC_ALOAD("); break; case Opcodes.ISTORE: b.append("BC_ISTORE("); break; case Opcodes.LSTORE: b.append("BC_LSTORE("); break; case Opcodes.FSTORE: b.append("BC_FSTORE("); break; case Opcodes.DSTORE: b.append("BC_DSTORE("); break; case Opcodes.ASTORE: b.append("BC_ASTORE("); break; case Opcodes.RET: b.append("/* RET TODO */"); //b.append("goto label_"); //b.append(var); //b.append("; /* RET */\n"); return; case Opcodes.SIPUSH: case Opcodes.BIPUSH: b.append("PUSH_INT("); break; case Opcodes.NEWARRAY: switch (var) { case 4: // boolean b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BOOLEAN, sizeof(JAVA_ARRAY_BOOLEAN), 1));\n"); break; case 5: // char b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_CHAR, sizeof(JAVA_ARRAY_CHAR), 1));\n"); break; case 6: // float b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_FLOAT, sizeof(JAVA_ARRAY_FLOAT), 1));\n"); break; case 7: // double b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_DOUBLE, sizeof(JAVA_ARRAY_DOUBLE), 1));\n"); break; case 8: // byte b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BYTE, sizeof(JAVA_ARRAY_BYTE), 1));\n"); break; case 9: // short b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_SHORT, sizeof(JAVA_ARRAY_SHORT), 1));\n"); break; case 10: // int b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_INT, sizeof(JAVA_ARRAY_INT), 1));\n"); break; case 11: // long b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_LONG, sizeof(JAVA_ARRAY_LONG), 1));\n"); break; } return; default: throw new RuntimeException("Missing opcode: " + opcode); } b.append(var); b.append(");\n"); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: push(InferredType.INT);// w ww . jav a 2 s . c o m break; case Opcodes.LLOAD: push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.FLOAD: push(InferredType.FLOAT); break; case Opcodes.DLOAD: push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.ALOAD: push(getLocalVariableType(var)); break; case Opcodes.ISTORE: case Opcodes.FSTORE: case Opcodes.ASTORE: { InferredType type = pop(); setLocalVariableTypes(var, type); break; } case Opcodes.LSTORE: case Opcodes.DSTORE: { InferredType type = pop(2); setLocalVariableTypes(var, type); setLocalVariableTypes(var + 1, InferredType.TOP); break; } case Opcodes.RET: throw new RuntimeException("The instruction RET is not supported"); default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitVarInsn(opcode, var); }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitVarInsn(final int opcode, final int var) { switch (opcode) { case Opcodes.ILOAD: load(var, JavaType.INT); break;/* w w w .j ava2 s . c o m*/ case Opcodes.LLOAD: load(var, JavaType.LONG); break; case Opcodes.FLOAD: load(var, JavaType.FLOAT); break; case Opcodes.DLOAD: load(var, JavaType.DOUBLE); break; case Opcodes.ALOAD: load(var, JavaType.OBJECT); break; case Opcodes.ISTORE: store(var, JavaType.INT); break; case Opcodes.LSTORE: store(var, JavaType.LONG); break; case Opcodes.FSTORE: store(var, JavaType.FLOAT); break; case Opcodes.DSTORE: store(var, JavaType.DOUBLE); break; case Opcodes.ASTORE: store(var, JavaType.OBJECT); break; case Opcodes.RET: recorder.add(new Runnable() { public void run() { block.addOp(new RetSub(lineNumber)); } }); break; default: throw new UnsupportedOperationException("opcode: " + opcode); } }
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: case Opcodes.LLOAD: case Opcodes.FLOAD: case Opcodes.DLOAD: case Opcodes.ALOAD: stack.add(registers.get(Integer.valueOf(var))); break;//from w w w . j ava 2 s .c o m case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: registers.put(Integer.valueOf(var), stack.remove(stack.size() - 1)); break; case Opcodes.RET: //nop - a fudge break; } }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitVarInsn(int opcode, int var) { if (_me != null) { if (var == 0) { _exprStack.push(_me);//from w w w . j a v a 2 s . c o m return; } var--; } Class<?> type; switch (opcode) { case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: case Opcodes.RET: default: throw notLambda(opcode); case Opcodes.ILOAD: type = Integer.TYPE; break; case Opcodes.LLOAD: type = Long.TYPE; break; case Opcodes.FLOAD: type = Float.TYPE; break; case Opcodes.DLOAD: type = Double.TYPE; break; case Opcodes.ALOAD: type = _argTypes[var]; break; } _exprStack.push(Expression.parameter(type, var)); }
From source file:de.codesourcery.asm.controlflow.ControlFlowAnalyzer.java
License:Apache License
@SuppressWarnings("unchecked") public ControlFlowGraph analyze(String owner, final MethodNode mn) throws AnalyzerException { // line numbers with associated block // initially we'll create one block per line and merge adjacent ones later if control flow permits it final Map<Integer, IBlock> blocks = new HashMap<>(); final ListIterator<AbstractInsnNode> it = mn.instructions.iterator(); IBlock currentLine = null;//from www .ja v a 2s. c o m Object previousMetadata = null; IBlock previous = null; final IBlock methodExit = new MethodExit(); for (int instrCounter = 0; it.hasNext(); instrCounter++) { final AbstractInsnNode instruction = it.next(); currentLine = getBlockForInstruction(instrCounter, blocks); if (previous != null) { previous.addSuccessor(currentLine, EdgeType.REGULAR, previousMetadata); currentLine.addRegularPredecessor(previous); previousMetadata = null; } IBlock nextPrevious = currentLine; switch (instruction.getType()) { case AbstractInsnNode.LOOKUPSWITCH_INSN: LookupSwitchInsnNode lookup = (LookupSwitchInsnNode) instruction; // add edge for default handler if (lookup.dflt != null) { final IBlock target = getBlockForInstruction(lookup.dflt, mn, blocks); target.addRegularPredecessor(currentLine); currentLine.addRegularSuccessor(target); } @SuppressWarnings("cast") final Iterator<Integer> keys = (Iterator<Integer>) lookup.keys.iterator(); for (LabelNode ln : (List<LabelNode>) lookup.labels) { final IBlock target = getBlockForInstruction(ln, mn, blocks); final Integer key = keys.next(); target.addPredecessor(currentLine, EdgeType.LOOKUP_SWITCH, key); currentLine.addSuccessor(target, EdgeType.LOOKUP_SWITCH, key); } nextPrevious = null; break; case AbstractInsnNode.TABLESWITCH_INSN: TableSwitchInsnNode tblSwitch = (TableSwitchInsnNode) instruction; // add edge for default handler if (tblSwitch.dflt != null) { final IBlock target = getBlockForInstruction(tblSwitch.dflt, mn, blocks); target.addRegularPredecessor(currentLine); currentLine.addRegularSuccessor(target); } int currentKey = tblSwitch.min; for (LabelNode ln : (List<LabelNode>) tblSwitch.labels) { final IBlock target = getBlockForInstruction(ln, mn, blocks); target.addPredecessor(currentLine, EdgeType.TABLE_SWITCH, currentKey); currentLine.addSuccessor(target, EdgeType.TABLE_SWITCH, currentKey); currentKey++; } nextPrevious = null; break; case AbstractInsnNode.INSN: if (instruction.getOpcode() == Opcodes.RETURN || instruction.getOpcode() == Opcodes.IRETURN) /* method exit */ { currentLine.addRegularSuccessor(methodExit); methodExit.addRegularPredecessor(currentLine); nextPrevious = null; } else if (instruction.getOpcode() == Opcodes.ATHROW || instruction.getOpcode() == Opcodes.RET) { nextPrevious = null; } break; case AbstractInsnNode.JUMP_INSN: /* jump */ final JumpInsnNode jmp = (JumpInsnNode) instruction; final LabelNode label = jmp.label; final int target = mn.instructions.indexOf(label); final boolean isConditional = ASMUtil.isConditionalJump(instruction); if (isConditional) { // label edges of conditional jump instructions with "true" and "false previousMetadata = "false"; } final IBlock targetBlock = getBlockForInstruction(target, blocks); targetBlock.addRegularPredecessor(currentLine); // create edge from current block to jump target currentLine.addSuccessor(targetBlock, EdgeType.REGULAR, isConditional ? "true" : null); if (instruction.getOpcode() == Opcodes.GOTO) { nextPrevious = null; } break; } // link last instruction with method_exit block if (!it.hasNext()) { currentLine.addRegularSuccessor(methodExit); methodExit.addRegularPredecessor(currentLine); } previous = nextPrevious; } // try/catch blocks need special treatment because // they are not represented as opcodes for (TryCatchBlockNode node : (List<TryCatchBlockNode>) mn.tryCatchBlocks) { final LabelNode startLabel = node.start; final int startTarget = mn.instructions.indexOf(startLabel); final LabelNode endLabel = node.end; final int endTarget = mn.instructions.indexOf(endLabel); final int handlerTarget = mn.instructions.indexOf(node.handler); IBlock handler = getBlockForInstruction(node.handler, mn, blocks); for (int i = startTarget; i <= endTarget; i++) { if (i != handlerTarget) { getBlockForInstruction(i, blocks).addExceptionHandler(handler, node.type); } } } // merge adjacent instructions final Set<Integer> linesBeforeMerge = new HashSet<>(); for (IBlock block : blocks.values()) { linesBeforeMerge.addAll(block.getInstructionNums()); } final List<IBlock> result = mergeBlocks(blocks, mn); if (debug) { System.out.println("################ Control-blocks merged ################"); } // sanity check final Set<Integer> linesAfterMerge = new HashSet<>(); for (IBlock block : result) { linesAfterMerge.addAll(block.getInstructionNums()); if (debug) { System.out.println("-----"); System.out.println(block + " has " + block.getByteCodeInstructionCount(mn) + " instructions."); System.out.println(block.disassemble(mn, false, true)); } for (Edge e : block.getEdges()) { if (!result.contains(e.src) && e.src != methodExit) { throw new RuntimeException(e + " has src that is not in result list?"); } if (!result.contains(e.dst) && e.dst != methodExit) { throw new RuntimeException(e + " has destination that is not in result list?"); } } } if (!linesBeforeMerge.equals(linesAfterMerge)) { throw new RuntimeException("Internal error, line count mismatch before/after control block merge: \n\n" + linesBeforeMerge + "\n\n" + linesAfterMerge); } // add starting block and link it with block that contains the lowest instruction number MethodEntry methodEntry = new MethodEntry(); int lowest = Integer.MAX_VALUE; for (Integer i : blocks.keySet()) { if (i < lowest) { lowest = i; } } final IBlock firstBlock = blocks.get(lowest); if (firstBlock.hasRegularPredecessor()) { throw new IllegalStateException(firstBlock + " that constrains first instruction has a predecessor?"); } methodEntry.addRegularSuccessor(firstBlock); firstBlock.addRegularPredecessor(methodEntry); result.add(0, methodEntry); // add end block to results result.add(methodExit);//owner+"#"+ ControlFlowGraph cfg = new ControlFlowGraph(mn, result); System.out.println("CFGMAP:" + formatname(owner) + "#" + cfg.getMethod().name); graphmap.put(formatname(owner) + "#" + cfg.getMethod().name, cfg); return cfg; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.VarInstruction.java
License:Open Source License
public VarInstruction(final ReadMethod readMethod, final int opcode, final int lineNumber, final int localVarIndex) { super(readMethod, opcode, lineNumber); assert opcode == Opcodes.ILOAD || opcode == Opcodes.LLOAD || opcode == Opcodes.FLOAD || opcode == Opcodes.DLOAD || opcode == Opcodes.ALOAD || opcode == Opcodes.ISTORE || opcode == Opcodes.LSTORE || opcode == Opcodes.FSTORE || opcode == Opcodes.DSTORE || opcode == Opcodes.ASTORE || opcode == Opcodes.RET; this.localVarIndex = localVarIndex; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.VarInstruction.java
License:Open Source License
private VarInstruction(final ReadMethod readMethod, final int lineNumber, final int opcode, final int localVarIndex, final int index) { super(readMethod, opcode, lineNumber, index); assert opcode == Opcodes.ILOAD || opcode == Opcodes.LLOAD || opcode == Opcodes.FLOAD || opcode == Opcodes.DLOAD || opcode == Opcodes.ALOAD || opcode == Opcodes.ISTORE || opcode == Opcodes.LSTORE || opcode == Opcodes.FSTORE || opcode == Opcodes.DSTORE || opcode == Opcodes.ASTORE || opcode == Opcodes.RET; this.localVarIndex = localVarIndex; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.VarInstruction.java
License:Open Source License
@Override public String toString() { String instruction;//from www . j av a 2 s.c om switch (getOpcode()) { case Opcodes.ILOAD: instruction = "ILOAD"; break; case Opcodes.LLOAD: instruction = "LLOAD"; break; case Opcodes.FLOAD: instruction = "FLOAD"; break; case Opcodes.DLOAD: instruction = "DLOAD"; break; case Opcodes.ALOAD: instruction = "ALOAD"; break; case Opcodes.ISTORE: instruction = "ISTORE"; break; case Opcodes.LSTORE: instruction = "LSTORE"; break; case Opcodes.FSTORE: instruction = "FSTORE"; break; case Opcodes.DSTORE: instruction = "DSTORE"; break; case Opcodes.ASTORE: instruction = "ASTORE"; break; case Opcodes.RET: instruction = "RET"; break; default: instruction = "-ERROR-"; } return new StringBuilder(instruction.length() + 11).append(instruction).append(' ') .append(this.localVarIndex).toString(); }