private static boolean isGetClassInvocation(final Instruction p) { return p != null && p.getOpCode() == OpCode.INVOKEVIRTUAL && p.<MethodReference>getOperand(0).getParameters().isEmpty() && StringUtilities.equals(p.<MethodReference>getOperand(0).getName(), "getClass"); }
public static Instruction reverseLoadOrStore(final Instruction instruction) { VerifyArgument.notNull(instruction, "instruction"); final OpCode oldCode = instruction.getOpCode(); final OpCode newCode; if (oldCode.isStore()) { newCode = OpCode.valueOf(oldCode.name().replace("STORE", "LOAD")); } else if (oldCode.isLoad()) { newCode = OpCode.valueOf(oldCode.name().replace("LOAD", "STORE")); } else { throw new IllegalArgumentException("Instruction is neither a load nor store: " + instruction.getOpCode()); } if (instruction.getOperandCount() == 1) { return new Instruction(newCode, instruction.getOperand(0)); } return new Instruction(newCode); } }
public static boolean isThrower(MethodDefinition md) { MethodBody body = md.getBody(); if(body == null) return false; for(Instruction inst : body.getInstructions()) { if(inst.hasLabel() || inst.getOpCode() == OpCode.RETURN || inst.getOpCode() == OpCode.ARETURN) return false; if(inst.getOpCode() == OpCode.ATHROW) return true; } // Actually should not go here for valid bytecode return false; }
void registerJump(Instruction instr) { if(instr.getOperandCount() == 1 && instr.getOperand(0) instanceof Instruction) { seenLabels.add(instr.getOperand(0)); } }
private static boolean isNarrower(final InstructionBlock block, final InstructionBlock anchor) { if (block == null || anchor == null) { return false; } final Instruction start = block.getFirstInstruction(); final Instruction anchorStart = anchor.getFirstInstruction(); final Instruction end = block.getLastInstruction(); final Instruction anchorEnd = anchor.getLastInstruction(); if (start.getOffset() > anchorStart.getOffset()) { return end.getOffset() < anchorEnd.getEndOffset(); } return start.getOffset() == anchorStart.getOffset() && end.getOffset() < anchorEnd.getOffset(); }
instruction = Instruction.create(op); break; instruction = Instruction.create(op, BuiltinTypes.fromPrimitiveTypeCode(b.readUnsignedByte())); break; instruction = Instruction.create(op, _scope.lookupType(typeToken)); break; instruction = Instruction.create(op, _scope.lookupType(b.readUnsignedShort()), b.readUnsignedByte()); break; instruction = Instruction.create(op, _scope.lookupDynamicCallSite(b.readUnsignedShort())); b.readUnsignedByte(); b.readUnsignedByte(); instruction = Instruction.create(op, _scope.lookupMethod(b.readUnsignedShort())); instruction = Instruction.create(op, _scope.lookupField(b.readUnsignedShort())); break; instruction = new Instruction(op); if (!target.hasLabel()) { target.setLabel(new Label(targetOffset)); instruction.setOperand(target); instruction.setOperand(instruction);
final Instruction copy = new Instruction(instruction.getOffset(), instruction.getOpCode()); if (instruction.getOperandCount() > 1) { final Object[] operands = new Object[instruction.getOperandCount()]; operands[i] = instruction.getOperand(i); copy.setOperand(operands); copy.setOperand(instruction.getOperand(0)); copy.setLabel(instruction.getLabel()); if (!instruction.hasOperand()) { continue; final Object operand = instruction.getOperand(0); instruction.setOperand(mappedInstruction(oldToNew, (Instruction) operand)); newOperand.setHighValue(oldOperand.getHighValue()); instruction.setOperand(newOperand);
@SuppressWarnings("ConstantConditions") private void remapJumps(final Map<Instruction, Instruction> remappedJumps) { for (final Instruction instruction : _instructions) { if (instruction.hasLabel()) { instruction.getLabel().setIndex(instruction.getOffset()); if (instruction.getOperandCount() == 0) { continue; final Object operand = instruction.getOperand(0); instruction.setOpCode(OpCode.NOP); instruction.setOperand(null); instruction.setOperand(newTarget); if (!newTarget.hasLabel()) { newTarget.setLabel(new com.strobel.assembler.metadata.Label(newTarget.getOffset())); final Instruction newDefault = mappedInstruction(remappedJumps, oldDefault); if (newDefault != null && !newDefault.hasLabel()) { newDefault.setLabel(new com.strobel.assembler.metadata.Label(newDefault.getOffset())); if (!newTarget.hasLabel()) { newTarget.setLabel(new com.strobel.assembler.metadata.Label(newTarget.getOffset())); instruction.setOperand(newOperand);
if (finallyTail.getEnd().getOpCode().isReturn() || finallyTail.getEnd().getOpCode().isThrow()) { if (last.getOpCode() == OpCode.GOTO || last.getOpCode() == OpCode.GOTO_W) { tryNext = true; if (tail.getOpCode().isUnconditionalBranch()) { switch (tail.getOpCode()) { case GOTO: case GOTO_W: case DRETURN: case ARETURN: if (finallyTail.getEnd().getOpCode().getFlowControl() != FlowControl.Return) { tail = previous(tail); startingPoints.add(Pair.create(last, tail.getNext())); if (last.getOpCode() == OpCode.JSR) { (lastInTry.getOpCode() == OpCode.GOTO || lastInTry.getOpCode() == OpCode.GOTO_W)) { final Instruction target = lastInTry.getOperand(0); if (target.getOpCode() == OpCode.JSR && target.getOperand(0) == last.getOperand(0)) { target.setOpCode(OpCode.NOP); target.setOperand(null);
final int lineNumber = _lineNumbers[instruction.getOffset()]; _currentOffset = instruction.getOffset(); _output.writeLabel(String.format("%1$8d", instruction.getOffset())); _output.write(": "); instruction.accept(this); printOpCode(instruction.getOpCode()); for (int i = 0; i < instruction.getOperandCount(); i++) { final Object operand = instruction.getOperand(i);
public static Instruction create(final OpCode opCode, final FieldReference field) { VerifyArgument.notNull(opCode, "opCode"); if (!checkOperand(opCode.getOperandType(), field)) { throw new IllegalArgumentException(String.format("Invalid operand for OpCode %s.", opCode)); } return new Instruction(opCode, field); }
public static void writeInstruction(final ITextOutput writer, final Instruction instruction) { VerifyArgument.notNull(writer, "writer"); VerifyArgument.notNull(instruction, "instruction"); writer.writeDefinition(offsetToString(instruction.getOffset()), instruction); writer.write(": "); writer.writeReference(instruction.getOpCode().name(), instruction.getOpCode()); if (instruction.hasOperand()) { writer.write(' '); writeOperandList(writer, instruction); } }
public void accept(final InstructionVisitor visitor) { if (hasLabel()) { visitor.visitLabel(_label); case TypeReference: case TypeReferenceU1: visitor.visitType(_opCode, (TypeReference) getOperand(0)); break; visitor.visitVariable( _opCode, this.<VariableReference>getOperand(0), this.<Number>getOperand(1).intValue() ); break;
public static FrameValue makeUninitializedReference(final Instruction newInstruction) { VerifyArgument.notNull(newInstruction, "newInstruction"); if (newInstruction.getOpCode() != OpCode.NEW) { throw new IllegalArgumentException("Parameter must be a NEW instruction."); } return new FrameValue(FrameValueType.Uninitialized, newInstruction); }
public static Instruction create(final OpCode opCode, final VariableReference variable) { VerifyArgument.notNull(opCode, "opCode"); if (opCode.getOperandType() != OperandType.Local) { throw new IllegalArgumentException(String.format("Invalid operand for OpCode %s.", opCode)); } return new Instruction(opCode, variable); }
final InstructionBlock h2 = o._handlerBlock; result = h1.getFirstInstruction().compareTo(h2.getFirstInstruction()); final InstructionBlock t2 = o._tryBlock; result = t1.getFirstInstruction().compareTo(t2.getFirstInstruction()); result = t2.getLastInstruction().compareTo(t1.getLastInstruction()); return h2.getLastInstruction().compareTo(h1.getLastInstruction());
public static void writeEndOffsetReference(final ITextOutput writer, final Instruction instruction) { VerifyArgument.notNull(writer, "writer"); writer.writeLabel(offsetToString(instruction.getEndOffset())); }
instruction = Instruction.create(op); break; instruction = Instruction.create(op, BuiltinTypes.fromPrimitiveTypeCode(b.readUnsignedByte())); break; instruction = Instruction.create(op, _scope.lookupType(typeToken)); break; instruction = Instruction.create(op, _scope.lookupType(b.readUnsignedShort()), b.readUnsignedByte()); break; instruction = Instruction.create(op, _scope.lookupDynamicCallSite(b.readUnsignedShort())); b.readUnsignedByte(); b.readUnsignedByte(); instruction = Instruction.create(op, _scope.lookupMethod(b.readUnsignedShort())); instruction = Instruction.create(op, _scope.lookupField(b.readUnsignedShort())); break; instruction = new Instruction(op); if (!target.hasLabel()) { target.setLabel(new Label(targetOffset)); instruction.setOperand(target); instruction.setOperand(instruction);
final Instruction copy = new Instruction(instruction.getOffset(), instruction.getOpCode()); if (instruction.getOperandCount() > 1) { final Object[] operands = new Object[instruction.getOperandCount()]; operands[i] = instruction.getOperand(i); copy.setOperand(operands); copy.setOperand(instruction.getOperand(0)); copy.setLabel(instruction.getLabel()); if (!instruction.hasOperand()) { continue; final Object operand = instruction.getOperand(0); instruction.setOperand(mappedInstruction(oldToNew, (Instruction) operand)); newOperand.setHighValue(oldOperand.getHighValue()); instruction.setOperand(newOperand);