1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.Config; 22 import gov.nasa.jpf.JPFException; 23 import gov.nasa.jpf.util.Debug; 24 25 26 29 public class StaticArea extends Area { 30 31 public static void init (Config config) { 32 StaticMap.init(); 33 } 34 35 38 public StaticArea (Config config, KernelState ks) { 39 super(ks, StaticElementInfo.storingDataLength); 40 } 41 42 public StaticArea (StaticArea sa) { 43 super(sa); 44 } 45 46 public boolean isStatic () { 47 return true; 48 } 49 50 public Object clone () { 51 return new StaticArea(this); 52 } 53 54 public boolean containsClass (String cname) { 55 return indexOf(cname) != -1; 56 } 57 58 public StaticElementInfo get (String cname) { 59 int index = indexOf(cname); 60 61 if (index == -1) { 62 newClass(ClassInfo.getClassInfo(cname)); 63 } 64 65 return (StaticElementInfo) get(indexOf(cname)); 66 } 67 68 71 public int indexOf (String cname) { 72 synchronized (StaticMap.class) { 73 if (!StaticMap.hasEntry(cname)) { 74 return -1; 75 } 76 77 int index = StaticMap.getEntry(cname); 78 79 if ((index >= 0) && (index < elements.length) && 80 (elements[index] != null)) { 81 return index; 82 } else { 83 return -1; 84 } 85 } 86 } 87 88 public void initializeClasses () { 89 int length = elements.length; 90 ThreadInfo th = ks.ss.getRunningThread(); 91 92 for (int i = 0; i < length; i++) { 93 if (elements[i] != null) { 94 StaticElementInfo ei = (StaticElementInfo) elements[i]; 95 ClassInfo ci = ei.getClassInfo(); 96 97 if (ei.classObjectRef == -1) { 98 ei.classObjectRef = ci.createClassObject(th, i); 100 } 101 102 ci.initializeClass(th); 103 } 104 } 105 } 106 107 public void log () { 108 Debug.println(Debug.MESSAGE, "SA"); 109 110 for (int i = 0; i < elements.length; i++) { 111 if (elements[i] != null) { 112 elements[i].log(); 113 } 114 } 115 } 116 117 public void markRoots () { 118 int length = elements.length; 119 120 for (int i = 0; i < length; i++) { 121 StaticElementInfo ei = (StaticElementInfo)elements[i]; 122 if (ei != null) { 123 ei.markStaticRoot(); 124 } 125 } 126 } 127 128 139 public int newClass (ClassInfo ci) { 140 int index = indexOf(ci.getName()); 141 142 if (index == -1) { 143 ClassInfo sci = ci.getSuperClass(); 145 146 if ((sci != null) && !containsClass(sci.getName())) { 147 newClass(sci); } 149 150 index = indexOf(ci.getName()); 151 if (index == -1) { 152 index = getNewIndexFor(ci.getName()); 153 154 ThreadInfo th = ks.ss.getRunningThread(); 155 int cref = ci.createClassObject(th, index); 156 StaticElementInfo ei = createElementInfo(ci, cref); 157 158 add(index, ei); 159 160 ci.initializeClass(th); } 162 } 163 164 return index; 165 } 166 167 ElementInfo createElementInfo () { 168 return new StaticElementInfo(); 169 } 170 171 int newUninitializedClass (ClassInfo ci) { 172 int index = getNewIndexFor(ci.getName()); 173 174 ThreadInfo th = ks.ss.getRunningThread(); 175 int cref = ci.createClassObject(th, index); 176 StaticElementInfo ei = createElementInfo(ci, cref); 177 178 add(index, ei); 179 180 return index; 181 } 182 183 StaticElementInfo createElementInfo (ClassInfo ci, int classObjRef) { 184 Fields f = ci.createStaticFields(this); 185 Monitor m = new Monitor(); 186 187 StaticElementInfo ei = new StaticElementInfo(f, m, classObjRef); 188 189 return ei; 190 } 191 192 196 int newStartupClass (ClassInfo ci) { 197 StaticElementInfo ei = createElementInfo(ci, -1); 198 int index = getNewIndexFor(ci.getName()); 199 200 add(index, ei); 201 202 return index; 203 } 204 205 private static int getNewIndexFor (String cname) { 206 return StaticMap.addEntry(cname); 207 } 208 } 209 | Popular Tags |