00001 package gov.nasa.arc.ase.jpf.jvm;
00002
00003 import de.fub.bytecode.*;
00004 import de.fub.bytecode.classfile.*;
00005 import gov.nasa.arc.ase.jpf.*;
00006 import gov.nasa.arc.ase.util.Debug;
00007 import java.util.*;
00008
00009 public class JPFVM {
00010 private static JPFVM jpfvm = null;
00011 private Hashtable loadedClasses = new Hashtable();
00012 private int nLoadedClasses = 0;
00013
00014 public JPFVM() {
00015 setJPFVM(this);
00016 }
00017
00018 public int countLoadedClasses() {
00019 return nLoadedClasses;
00020 }
00021 public ClassInfo getClass(String name) {
00022 if (isLoaded(name)) return getLoadedClass(name);
00023
00024 JavaClass jc = loadClassData(name);
00025 ClassInfo ci = new ClassInfo(jc);
00026 nLoadedClasses++;
00027 loadedClasses.put(name, ci);
00028
00029 return ci;
00030 }
00031 public static JPFVM getJPFVM() {
00032 if(jpfvm == null) {
00033 Debug.println(Debug.ERROR, "No JPFVM singleton created");
00034 System.exit(1);
00035 }
00036
00037 return jpfvm;
00038 }
00039
00040 public ClassInfo getLoadedClass(String name) {
00041 return (ClassInfo)loadedClasses.get(name);
00042 }
00043
00044 public boolean isLoaded(String name) {
00045 return loadedClasses.containsKey(name);
00046 }
00047
00048 public JavaClass loadClassData(String name) {
00049 JavaClass jc = null;
00050 if ((jc = Repository.lookupClass(name)) == null) {
00051 Debug.println(Debug.ERROR, "Could not load class: " + name);
00052 System.exit(1);
00053 }
00054
00055 return jc;
00056 }
00057 private static void setJPFVM(JPFVM j) {
00058 jpfvm = j;
00059 }
00060 }