Simulatorpublic class Simulator extends Object Class which knows how to simulate the effects of executing bytecode.
Note: This class is not thread-safe. If multiple threads
need to use a single instance, they must synchronize access explicitly
between themselves. |
Fields Summary |
---|
private static final String | LOCAL_MISMATCH_ERRORnon-null; canned error message for local variable table mismatches | private final Machine | machinenon-null; machine to use when simulating | private final BytecodeArray | codenon-null; array of bytecode | private final LocalVariableList | localVariablesnon-null; local variable information | private final SimVisitor | visitornon-null; visitor instance to use |
Constructors Summary |
---|
public Simulator(Machine machine, ConcreteMethod method)Constructs an instance.
if (machine == null) {
throw new NullPointerException("machine == null");
}
if (method == null) {
throw new NullPointerException("method == null");
}
this.machine = machine;
this.code = method.getCode();
this.localVariables = method.getLocalVariables();
this.visitor = new SimVisitor();
|
Methods Summary |
---|
private static SimException | illegalTos()Constructs an "illegal top-of-stack" exception, for the stack
manipulation opcodes.
return new SimException("stack mismatch: illegal " +
"top-of-stack for opcode");
| public void | simulate(ByteBlock bb, Frame frame)Simulates the effect of executing the given basic block. This modifies
the passed-in frame to represent the end result.
int end = bb.getEnd();
visitor.setFrame(frame);
try {
for (int off = bb.getStart(); off < end; /*off*/) {
int length = code.parseInstruction(off, visitor);
visitor.setPreviousOffset(off);
off += length;
}
} catch (SimException ex) {
frame.annotate(ex);
throw ex;
}
| public int | simulate(int offset, Frame frame)Simulates the effect of the instruction at the given offset, by
making appropriate calls on the given frame.
visitor.setFrame(frame);
return code.parseInstruction(offset, visitor);
|
|