1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.JPFException; 22 import gov.nasa.jpf.util.HashData; 23 24 25 32 public abstract class Fields implements Cloneable { 33 static int FATTR_MASK = 0xffff; 35 36 protected final String type; 37 38 39 protected final ClassInfo ci; 40 41 42 protected int[] values; 43 44 protected Fields (String type, ClassInfo ci, int dataSize) { 45 this.type = type; 46 this.ci = ci; 47 48 values = new int[dataSize]; 49 } 50 51 56 public int getHeapSize () { 57 return values.length * 4; 58 } 59 60 64 public boolean hasRefField (int objRef) { 65 return ci.hasRefField( objRef, this); 66 } 67 68 71 public boolean isArray () { 72 return Types.getBaseType(type) == Types.T_ARRAY; 73 } 74 75 public boolean isReferenceArray () { 76 return false; 77 } 78 79 82 public ClassInfo getClassInfo () { 83 return ci; 84 } 85 86 public abstract FieldInfo getFieldInfo (String clsBase, String fname); 89 public abstract int getNumberOfFields (); 90 public abstract FieldInfo getFieldInfo (int fieldIndex); 92 93 public int getIntValue (int index) { 95 return values[index]; 96 } 97 98 public int getReferenceValue (int index) { 100 return values[index]; 101 } 102 103 public long getLongValue (int index) { 104 return Types.intsToLong(values[index + 1], values[index]); 105 } 106 107 public boolean getBooleanValue (int index) { 108 return Types.intToBoolean(values[index]); 109 } 110 111 public byte getByteValue (int index) { 112 return (byte) values[index]; 113 } 114 115 public char getCharValue (int index) { 116 return (char) values[index]; 117 } 118 119 public short getShortValue (int index) { 120 return (short) values[index]; 121 } 122 123 public void setReferenceValue (int index, int newValue) { 124 values[index] = newValue; 125 } 126 127 public void setIntValue (int index, int newValue) { 128 values[index] = newValue; 129 } 130 131 public void setLongValue (int index, long newValue) { 132 values[index++] = Types.hiLong(newValue); 133 values[index] = Types.loLong(newValue); 134 } 135 136 public void setDoubleValue (int index, double newValue) { 137 values[index++] = Types.hiDouble(newValue); 138 values[index] = Types.loDouble(newValue); 139 } 140 141 public void setFloatValue (int index, float newValue) { 142 values[index] = Types.floatToInt(newValue); 143 } 144 145 public float getFloatValue (int index) { 146 return Types.intToFloat(values[index]); 147 } 148 149 public double getDoubleValue (int index) { 150 return Types.intsToDouble( values[index+1], values[index]); 151 } 152 153 156 public String getType () { 157 return type; 158 } 159 160 163 public Object clone () { 164 Fields f; 165 166 try { 167 f = (Fields) super.clone(); 168 f.values = (int[]) values.clone(); 169 } catch (CloneNotSupportedException e) { 170 throw new InternalError (e.getMessage()); 171 } 172 173 return f; 174 } 175 176 179 public boolean equals (Object o) { 180 if (o == null) { 181 return false; 182 } 183 184 if (!(o instanceof Fields)) { 185 return false; 186 } 187 188 Fields f = (Fields) o; 189 190 if (!type.equals(f.type)) { 191 return false; 192 } 193 194 if (ci != f.ci) { 195 return false; 196 } 197 198 int[] v1 = values; 199 int[] v2 = f.values; 200 int l = v1.length; 201 202 if (l != v2.length) { 203 return false; 204 } 205 206 for (int i = 0; i < l; i++) { 207 if (v1[i] != v2[i]) { 208 return false; 209 } 210 } 211 212 return true; 213 } 214 215 218 public void hash (HashData hd) { 219 for (int i = 0, s = values.length; i < s; i++) { 220 hd.add(values[i]); 221 } 222 } 223 224 public int arrayLength () { 225 throw new JPFException ("attempt to get length of non-array: " + ci.getName()); 227 } 228 229 public boolean[] asBooleanArray () { 230 throw new JPFException( "not an array object: " + ci.getName()); 231 } 232 public byte[] asByteArray () { 233 throw new JPFException( "not an array object: " + ci.getName()); 234 } 235 public char[] asCharArray () { 236 throw new JPFException( "not an array object: " + ci.getName()); 237 } 238 public short[] asShortArray () { 239 throw new JPFException( "not an array object: " + ci.getName()); 240 } 241 public int[] asIntArray () { 242 throw new JPFException( "not an array object: " + ci.getName()); 243 } 244 public long[] asLongArray () { 245 throw new JPFException( "not an array object: " + ci.getName()); 246 } 247 public float[] asFloatArray () { 248 throw new JPFException( "not an array object: " + ci.getName()); 249 } 250 public double[] asDoubleArray () { 251 throw new JPFException( "not an array object: " + ci.getName()); 252 } 253 254 257 public int hashCode () { 258 HashData hd = new HashData(); 259 260 hash(hd); 261 262 return hd.getValue(); 263 } 264 265 268 public int size () { 269 return values.length; 270 } 271 272 public String toString () { 273 StringBuffer sb = new StringBuffer (); 274 sb.append("Fields("); 275 276 sb.append("type="); 277 sb.append(type); 278 sb.append(","); 279 280 sb.append("ci="); 281 sb.append(ci.getName()); 282 sb.append(","); 283 284 sb.append("values="); 285 sb.append('['); 286 287 for (int i = 0; i < values.length; i++) { 288 if (i != 0) { 289 sb.append(','); 290 } 291 292 sb.append(values[i]); 293 } 294 295 sb.append(']'); 296 sb.append(","); 297 298 sb.append(")"); 299 300 return sb.toString(); 301 } 302 303 protected abstract String getLogChar (); 304 } 305 306 307 308 309 | Popular Tags |