1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.JPFException; 22 23 31 public class StaticElementInfo extends ElementInfo { 32 static final int storingDataLength = ElementInfo.storingDataLength +1; 33 int classObjectRef = -1; 34 35 public StaticElementInfo () { 36 } 37 38 public StaticElementInfo (Fields f, Monitor m, int classObjRef) { 39 super(f, m); 40 classObjectRef = classObjRef; 41 } 42 43 protected FieldInfo getFieldInfo (String clsBase, String fname) { 44 ClassInfo ci = getClassInfo(); 45 FieldInfo fi = ci.getStaticField(clsBase, fname); 46 47 if (fi == null) { 48 throw new JPFException("class " + ci.getName() + 49 " has no static field " + fname); 50 } 51 return fi; 52 } 53 54 public int getNumberOfFields () { 55 return getClassInfo().getNumberOfStaticFields(); 56 } 57 58 public FieldInfo getFieldInfo (int fieldIndex) { 59 return getClassInfo().getStaticField(fieldIndex); 60 } 61 62 protected ElementInfo getElementInfo (ClassInfo ci) { 63 if (ci == getClassInfo()) { 64 return this; 65 } else { 66 return ((StaticArea)area).get( ci.getName()); 67 } 68 } 69 70 75 public int getStoringDataLength () { 76 return storingDataLength; 77 } 78 79 public void backtrackTo (ArrayOffset storing, Object backtrack) { 80 super.backtrackTo(storing, backtrack); 81 82 classObjectRef = storing.get(); 83 } 84 85 90 void markStaticRoot () { 91 94 DynamicArea heap = DynamicArea.getHeap(); 95 ClassInfo ci = getClassInfo(); 96 int n = ci.getNumberOfStaticFields(); 97 98 for (int i=0; i<n; i++) { 99 FieldInfo fi = ci.getStaticField(i); 100 if (fi.isReference()) { 101 heap.markStaticRoot(fields.getIntValue(fi.getStorageOffset())); 102 } 103 } 104 105 heap.markStaticRoot(classObjectRef); 107 } 108 109 public int storeDataTo (int[] buffer, int idx) { 110 idx += super.storeDataTo(buffer, idx); 111 112 buffer[idx] = classObjectRef; 113 114 return 3; 115 } 116 117 protected Ref getRef () { 118 return new ClassRef(getIndex()); 119 } 120 121 int getClassObjectRef () { 122 return classObjectRef; 123 } 124 125 public String toString() { 126 return getClassInfo().getName(); } 128 129 private void blowup () { 130 throw new JPFException("cannot access StaticElementInfo by index"); 131 } 132 } 133 134 | Popular Tags |