00001 package gov.nasa.arc.ase.jpf.jvm.bytecode;
00002
00003 import gov.nasa.arc.ase.jpf.InternalErrorException;
00004 import de.fub.bytecode.classfile.ConstantPool;
00005 import de.fub.bytecode.generic.InstructionHandle;
00006 import gov.nasa.arc.ase.jpf.jvm.MethodInfo;
00007 import gov.nasa.arc.ase.jpf.jvm.ThreadInfo;
00008 import gov.nasa.arc.ase.jpf.jvm.SystemState;
00009 import gov.nasa.arc.ase.jpf.jvm.KernelState;
00010 import gov.nasa.arc.ase.util.Debug;
00011
00012
00013
00014
00015 import java.util.List;
00016 import java.util.ArrayList;
00017
00018
00019 import gov.nasa.arc.ase.jpf.jvm.VirtualMachine;
00020
00021
00022 public abstract class Instruction {
00023 protected static List Unimplemented = new ArrayList();
00024 protected int position;
00025 protected int offset;
00026 protected MethodInfo mi;
00027 protected String asString;
00028
00029 protected boolean isObservable;
00030
00031 public static Instruction create(InstructionHandle h, int o, MethodInfo m, ConstantPool cp) {
00032 Instruction i = null;
00033 String name = null;
00034 try {
00035 name = h.getInstruction().getClass().getName();
00036 if(!name.startsWith("de.fub.bytecode.generic.")) {
00037 Debug.println(Debug.ERROR, "panic: instruction not in the right package");
00038 Debug.println(Debug.ERROR, "Quitting...");
00039 throw new InternalErrorException("");
00040 }
00041 name = "gov.nasa.arc.ase.jpf.jvm.bytecode." + name.substring(24);
00042 Class clazz = Class.forName(name);
00043
00044 i = (gov.nasa.arc.ase.jpf.jvm.bytecode.Instruction)clazz.newInstance();
00045 i.init(h, o, m, cp);
00046 } catch(ClassNotFoundException e) {
00047 if(!Unimplemented.contains(name)) {
00048 Unimplemented.add(name);
00049 Debug.println(Debug.WARNING,"warning: unimplemented bytecode instruction: " +
00050 name.substring(34));
00051 }
00052 } catch(Exception e) {
00053 throw new InternalErrorException("creation of instruction " +
00054 name.substring(34) + " failed");
00055 }
00056
00057 return i;
00058 }
00059 public boolean examine(SystemState ss, KernelState ks, ThreadInfo th) {
00060 return false;
00061 }
00062 public abstract Instruction execute(SystemState ss, KernelState ks, ThreadInfo th);
00063 public Instruction getNext() {
00064 return mi.getInstruction(offset+1);
00065 }
00066 public int getOffset() {
00067 return offset;
00068 }
00069 public int getPosition() {
00070 return position;
00071 }
00072 protected void init(InstructionHandle h, int o, MethodInfo m, ConstantPool cp) {
00073 position = h.getPosition();
00074 offset = o;
00075 mi = m;
00076 asString = h.getInstruction().toString(cp);
00077 setPeer(h.getInstruction(), cp);
00078
00079 isObservable = VirtualMachine.observablePositions.contains(mi.getCompleteName() + ":" + position);
00080
00081 }
00082 public boolean isExecutable(SystemState ss, KernelState ks, ThreadInfo th) {
00083 return true;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 public boolean isObservable() {
00106 return isObservable;
00107 }
00108 public void setObservable() {
00109 isObservable = true;
00110 }
00111
00112
00113 protected abstract void setPeer(de.fub.bytecode.generic.Instruction i, ConstantPool cp);
00114 public String toString() {
00115 return asString;
00116 }
00117 }