Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Fields.java

00001 package gov.nasa.arc.ase.jpf.jvm;
00002 
00003 import de.fub.bytecode.*;
00004 import de.fub.bytecode.classfile.*;
00005 import de.fub.bytecode.generic.*;
00006 import gov.nasa.arc.ase.jpf.*;
00007 import gov.nasa.arc.ase.util.Debug;
00008 import gov.nasa.arc.ase.util.HashData;
00009 import gov.nasa.arc.ase.util.PoolObject;
00010 import java.io.*;
00011 import java.util.*;
00012 // ifdef RACE
00013 import gov.nasa.arc.ase.jpf.jvm.runtime.*;
00014 //#endif RACE
00015 
00016 public class Fields extends PoolObject {
00017   private ClassInfo ci;
00018   private long[] variables;
00019 // ifdef MARK_N_SWEEP
00020   BitSet variablerefs = new BitSet();
00021 //#endif MARK_N_SWEEP
00022 
00023 // ifdef RACE
00024   List locks; // List of LockStatus
00025   LockStatus arrayLock;
00026 
00027 //#endif RACE
00028 
00029   public Fields(ClassInfo c, int nfields) {
00030     ci = c;
00031     variables = new long[nfields];
00032 
00033 // ifdef RACE
00034     ANALYZE_Fields(nfields);
00035 //#endif RACE
00036   }  
00037   private void ANALYZE_addEntry() {
00038     if (Analyze.on()) {
00039       locks.add(new LockStatus());
00040     }
00041   }  
00042 // ifdef RACE
00043   private void ANALYZE_Fields(int numFields) {
00044     if (Analyze.on()) {
00045       // The ideal solution is that only one of these gets declared and created
00046       // depending on whether the Fields object represents an array or not.
00047       arrayLock = new LockStatus();
00048       locks = new ArrayList(numFields);
00049     }
00050     for(int i = 0; i < numFields; i++)
00051       ANALYZE_addEntry();
00052   }  
00053 //#endif RACE
00054 
00055   public Object clone() {
00056     try {
00057       Fields cv = (Fields)super.clone();
00058 
00059       int l = variables.length;
00060       cv.variables = new long[l];
00061 
00062       System.arraycopy(variables, 0, cv.variables, 0, l);
00063 
00064 // ifdef MARK_N_SWEEP
00065       cv.variablerefs = (BitSet)variablerefs.clone();
00066 //#endif MARK_N_SWEEP
00067 
00068       return cv; 
00069     } catch(CloneNotSupportedException e) {
00070       throw new InternalError(e.toString());
00071     }
00072   }  
00073   public boolean equals(Object obj) {
00074     if(obj == null) return false;
00075 
00076     Fields  cv = (Fields)obj;
00077     long[] v = cv.variables;
00078 
00079     if (ci != cv.getClassInfo()) return false;
00080 
00081     int l = variables.length;
00082     if (l != v.length) return false;
00083 
00084 // ifdef MARK_N_SWEEP
00085     if(!variablerefs.equals(cv.variablerefs)) return false;
00086 //#endif MARK_N_SWEEP
00087 
00088     for(int i = 0; i < l; i++)
00089       if(variables[i] != v[i]) return false;
00090 
00091     if(ci == null && cv.ci != null) return false;
00092     if(ci != null && cv.ci == null) return false;
00093 
00094     return true;
00095   }  
00096   public ClassInfo getClassInfo() {
00097     return ci;
00098   }  
00099   public LockStatus getLockStatus() {
00100     return arrayLock;
00101   }  
00102   public LockStatus getLockStatus(String fieldname) {
00103     int index = ((Integer)ci.fieldNames.get(fieldname)).intValue();
00104     return (LockStatus)locks.get(index);    
00105   }  
00106   public long getValue(int index) { return variables[index]; }  
00107 //#endif MARK_N_SWEEP
00108 
00109   // ---------------------------------------------
00110   //   access to the fields of a class or object
00111   // ---------------------------------------------
00112 
00113   public long getValue(String fieldname) {
00114     return variables[((Integer)ci.fieldNames.get(fieldname)).intValue()];
00115   }  
00116   public long[] getVariables() {
00117     return variables;
00118   }  
00119   public void hash(HashData hd) {
00120     for(int i = 0, s = variables.length; i < s; i++)
00121       hd.add((int)variables[i]);
00122   }  
00123   public int hashCode() {
00124     HashData hd = new HashData();
00125 
00126     for(int i = 0, s = variables.length; i < s; i++)
00127       hd.add((int)variables[i]);
00128 
00129     return hd.getValue();
00130   }  
00131 // ifdef REFERENCE_COUNT
00132 
00133 
00134 
00135 
00136 
00137 
00138 //#endif REFERENCE_COUNT
00139 
00140 // ifdef MARK_N_SWEEP
00141   public boolean isRef(String fieldname) {
00142     return variablerefs.get(((Integer)ci.fieldNames.get(fieldname)).intValue());
00143   }  
00144 //#endif MARK_N_SWEEP
00145 
00146   public void log(int ref, boolean object) {
00147     for(int i = 0; i < variables.length; i++) {
00148       if(ci != null)
00149     Debug.print(Debug.MESSAGE, "    " + (object ? ci.getDynamicFields() : ci.getStaticFields())[i] + ":");
00150       else
00151     Debug.print(Debug.MESSAGE, "    #" + i + ":");
00152 // ifdef MARK_N_SWEEP
00153       if(variablerefs.get(i))
00154     Debug.print(Debug.MESSAGE, "#");
00155 //#endif MARK_N_SWEEP
00156       Debug.println(Debug.MESSAGE, variables[i] + "");
00157     }
00158   }  
00159 // ifdef MARK_N_SWEEP
00160   public void mark(DynamicArea da) {
00161     int length = variables.length;
00162     for(int i = 0; i < length; i++)
00163       if(variablerefs.get(i))
00164     da.mark((int)variables[i]);
00165   }  
00166   public void setValue(int index, long value) {
00167 // ifdef MARK_N_SWEEP
00168     if(variablerefs.get(index)
00169     && variables[index] != -1
00170     && variables[index] != value)
00171       VirtualMachine.activateGC();
00172 //#endif MARK_N_SWEEP
00173 // ifdef REFERENCE_COUNT
00174 
00175 
00176 
00177 
00178 
00179 //#endif REFERENCE_COUNT
00180     variables[index] = (long)value;
00181   }  
00182   public void setValue(String fieldname, long value) {
00183     int index = ((Integer)ci.fieldNames.get(fieldname)).intValue();
00184 
00185 // ifdef MARK_N_SWEEP
00186     if(variablerefs.get(index)
00187     && variables[index] != -1
00188     && variables[index] != value)
00189       VirtualMachine.activateGC();
00190 //#endif MARK_N_SWEEP
00191 // ifdef REFERENCE_COUNT
00192 
00193 
00194 
00195 
00196 
00197 //#endif REFERENCE_COUNT
00198     variables[index] = (long)value;
00199   }  
00200 //#endif MARK_N_SWEEP
00201 
00202 // ifdef MARK_N_SWEEP
00203   public void setValueRef(int idx) {
00204     variablerefs.set(idx);
00205   }  
00206   public int size() {
00207     return variables.length;
00208   }  
00209 }

Generated at Thu Feb 7 06:45:41 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001