/** * Get the number of bytes for which this local has a value in * the code byte array. */ public int getLength() { if (_end != null) return _end.getByteIndex() + _end.getLength() - _target.getByteIndex(); return _length; }
/** * Set the last {@link Instruction} for which this local is in scope. * The instruction must already be a part of the method. * WARNING: if this instruction is deleted, the results are undefined. */ public void setEnd(Instruction end) { if (end.getCode() != getCode()) throw new IllegalArgumentException("Instruction pointers and " + "targets must be part of the same code block."); _end = end; _length = -1; }
public void enterInstruction(Instruction obj) { _out.print(_prefix + obj.getByteIndex() + " " + obj.getName() + " "); }
int getLength() { return super.getLength() + 2; }
/** * Find the closest previous instruction from the current iterator * position that matches the given one, according to the * {@link Object#equals} methods of the instruction types. This allows * for matching based on template instructions, as the equals methods of * most instructions return true if the information for the given * instruction has not been filled in. If a match is found, the iterator * is placed before the matching Instruction. If no match is found, * moves the iterator to {@link #beforeFirst}. * * @return true if match found */ public boolean searchBackward(Instruction template) { if (template == null) return false; while (hasPrevious()) if (template.equalsInstruction(previous())) return true; return false; }
/** * Returns the byteIndex at which the target instruction can be found. * This call does not change the Target strategy. */ public int getByteIndex() { if (_target == null) return _byteIndex; return _target.getByteIndex(); }
private void readCode(DataInput in, int len) throws IOException { _head.next = _tail; _tail.prev = _head; _size = 0; _byteIndexesValid = true; beforeFirst(); Instruction ins; for (int byteIndex = 0; byteIndex < len;) { ins = createInstruction(in.readUnsignedByte()); _ci.addInternal(ins); ins.byteIndex = byteIndex; ins.read(in); byteIndex += ins.getLength(); } updateInstructionPointers(); beforeFirst(); // sanity check if (!_byteIndexesValid) throw new IllegalStateException(); }
/** * Return the logical number of stack positions changed by this * instruction. In other words, ignore weirdness with longs and doubles * taking two stack positions. */ public int getLogicalStackChange() { return getStackChange(); }
/** * Instructions are equal if their opcodes are the same. Subclasses * should override this method to perform a template comparison: * instructions should compare equal to other instructions of the same * type where the data is either the same or the data is unset. */ public boolean equalsInstruction(Instruction other) { if (other == this) return true; return other.getOpcode() == getOpcode(); }
public void set(Object obj) { if (obj == null) throw new NullPointerException("obj = null"); if (_last == null) throw new IllegalStateException(); Instruction ins = (Instruction) obj; ins.prev = _last.prev; ins.next = _last.next; ins.prev.next = ins; ins.next.prev = ins; replaceTarget(_last, ins); _last.invalidate(); if (_bn == _last) _bn = ins; _last = ins; invalidateByteIndexes(); }
public void acceptVisit(BCVisitor visit) { visit.enterCode(this); Instruction ins; for (CodeEntry entry = _head.next; entry != _tail; entry = entry.next) { ins = (Instruction) entry; visit.enterInstruction(ins); ins.acceptVisit(visit); visit.exitInstruction(ins); } for (Iterator i = _handlers.iterator(); i.hasNext();) ((ExceptionHandler) i.next()).acceptVisit(visit); visitAttributes(visit); visit.exitCode(this); }
case Constants.ARRAYLENGTH: case Constants.ATHROW: return new Instruction(this, opcode); case Constants.ACONSTNULL: case Constants.ICONSTM1:
int getLength() { return super.getLength() + 2; }
/** * Find the next instruction from the current iterator position that * matches the given one, according to the {@link Object#equals} methods of * the instruction types. This allows for matching based on template * instructions, as the equals methods of most instructions return * true if the information for the given instruction has not been filled * in. If a match is found, the iterator is placed after the matching * Instruction. If no match is found, moves the iterator to * {@link #afterLast}. * * @return true if match found */ public boolean searchForward(Instruction template) { if (template == null) return false; while (hasNext()) if (template.equalsInstruction(next())) return true; return false; }
/** * Returns the byteIndex at which the target instruction can be found. * This call does not change the Target strategy. */ public int getByteIndex() { if (_target == null) return _byteIndex; return _target.getByteIndex(); }
private void readCode(DataInput in, int len) throws IOException { _head.next = _tail; _tail.prev = _head; _size = 0; _byteIndexesValid = true; beforeFirst(); Instruction ins; for (int byteIndex = 0; byteIndex < len;) { ins = createInstruction(in.readUnsignedByte()); _ci.addInternal(ins); ins.byteIndex = byteIndex; ins.read(in); byteIndex += ins.getLength(); } updateInstructionPointers(); beforeFirst(); // sanity check if (!_byteIndexesValid) throw new IllegalStateException(); }