field.offset = (VM_Statics.allocateSlot(slotType) << LOG_BYTES_IN_INT);
field.offset = VM_Statics.allocateSlot(slotType);
  public final synchronized void resolve() {    if (isResolved()) return;    if (VM.TraceClassLoading && VM.runningVM) VM.sysWriteln("VM_Class: (begin) resolve "+this);    if (VM.VerifyAssertions) VM._assert(state == CLASS_LOADED);    // Resolve superclass and super interfaces    //    if (superClass != null) {      superClass.resolve();    }    for (int i=0; i<declaredInterfaces.length; i++) {      declaredInterfaces[i].resolve();    }    if (isInterface()) {      if (VM.VerifyAssertions) VM._assert(superClass == null);      depth = 1;     } else if (isJavaLangObjectType()) {      if (VM.VerifyAssertions) VM._assert(superClass == null);      instanceSize = VM_ObjectModel.computeScalarHeaderSize(this);      alignment = BYTES_IN_ADDRESS;    } else {      if (VM.VerifyAssertions) VM._assert(superClass != null);      depth = superClass.depth + 1;      thinLockOffset = superClass.thinLockOffset;      instanceSize = superClass.instanceSize;      emptySlot = superClass.emptySlot;      alignment= superClass.alignment;    }    if (isSynchronizedObject() || this == VM_Type.JavaLangClassType)      VM_ObjectModel.allocateThinLock(this);    if (VM.verboseClassLoading) VM.sysWrite("[Preparing "+this+"]\n");    // build field and method lists for this class    //    {      VM_FieldVector  staticFields   = new VM_FieldVector();      VM_FieldVector  instanceFields = new VM_FieldVector();      VM_MethodVector staticMethods  = new VM_MethodVector();      VM_MethodVector constructorMethods  = new VM_MethodVector();      VM_MethodVector virtualMethods = new VM_MethodVector();      // start with fields and methods of superclass      //      if (superClass != null) {        VM_Field fields[] = superClass.getInstanceFields();        for (int i = 0, n = fields.length; i < n; ++i)          instanceFields.addElement(fields[i]);        VM_Method methods[] = superClass.getVirtualMethods();        for (int i = 0, n = methods.length; i < n; ++i)          virtualMethods.addElement(methods[i]);      }      // append fields defined by this class      //      VM_Field fields[] = getDeclaredFields();      for (int i = 0, n = fields.length; i < n; ++i) {        VM_Field field = fields[i];        if (field.isStatic())          staticFields.addElement(field);        else          instanceFields.addElement(field);      }      // append/overlay methods defined by this class      //      VM_Method methods[] = getDeclaredMethods();      for (int i = 0, n = methods.length; i < n; ++i) {        VM_Method method = methods[i];        if (VM.VerifyUnint) {          if (!method.isInterruptible() && method.isSynchronized()) {            if (VM.ParanoidVerifyUnint || !LogicallyUninterruptiblePragma.declaredBy(method)) {              VM.sysWriteln("WARNING: "+method+" cannot be both uninterruptible and synchronized");            }          }        }        if (method.isObjectInitializer()) {          VM_Callbacks.notifyMethodOverride(method, null);          constructorMethods.addElement(method);        } else if (method.isStatic()) {          if (!method.isClassInitializer()) {            VM_Callbacks.notifyMethodOverride(method, null);            staticMethods.addElement(method);          }        } else { // Virtual method          if (method.isSynchronized()) {            VM_ObjectModel.allocateThinLock(this);          }          // method could override something in superclass - check for it          //          int superclassMethodIndex = -1;          for (int j = 0, m = virtualMethods.size(); j < m; ++j) {            VM_Method alreadyDefinedMethod = virtualMethods.elementAt(j);            if (alreadyDefinedMethod.getName() == method.getName() &&                alreadyDefinedMethod.getDescriptor() == method.getDescriptor()) {              // method already defined in superclass              superclassMethodIndex = j;              break;            }          }          if (superclassMethodIndex == -1) {            VM_Callbacks.notifyMethodOverride(method, null);            virtualMethods.addElement(method);                          // append          } else {            VM_Method superc = (VM_Method)virtualMethods.elementAt(superclassMethodIndex);            if (VM.VerifyUnint) {              if (!superc.isInterruptible() && method.isInterruptible()) {                VM.sysWriteln("WARNING: interruptible "+method+" overrides uninterruptible "+superc);              }            }            VM_Callbacks.notifyMethodOverride(method, superc);            virtualMethods.setElementAt(method, superclassMethodIndex); // override          }        }      }      // Deal with Miranda methods.      // If this is an abstract class, then for each      // interface that this class implements, ensure that a corresponding virtual      // method is declared.  If one is not, then create an abstract method to fill the void.      if (!isInterface() && isAbstract()) {        for (int i=0; i<declaredInterfaces.length; i++) {          VM_Class I = declaredInterfaces[i];          VM_Method[] iMeths = I.getVirtualMethods();          outer:           for (int j=0; j<iMeths.length; j++) {            VM_Method iMeth = iMeths[j];            VM_Atom iName = iMeth.getName();            VM_Atom iDesc = iMeth.getDescriptor();            for (int k=0; k<virtualMethods.size(); k++) {              VM_Method vMeth = virtualMethods.elementAt(k);              if (vMeth.getName() == iName && vMeth.getDescriptor() == iDesc) continue outer;            }            VM_MemberReference mRef = VM_MemberReference.findOrCreate(typeRef, iName, iDesc);            virtualMethods.addElement(new VM_AbstractMethod(this, mRef, ACC_ABSTRACT | ACC_PUBLIC,                                                             iMeth.getExceptionTypes()));          }        }      }      // If this is an interface, inherit methods from its superinterfaces      if (isInterface()) {        for (int i=0; i<declaredInterfaces.length; i++) {          VM_Method[] meths = declaredInterfaces[i].getVirtualMethods();          for (int j=0; j<meths.length; j++) {            virtualMethods.addUniqueElement(meths[j]);          }        }      }            this.staticFields   = staticFields.finish();      this.instanceFields = instanceFields.finish();      this.staticMethods  = staticMethods.finish();      this.constructorMethods = constructorMethods.finish();      this.virtualMethods = virtualMethods.finish();    }    // allocate space for class fields    //    for (int i = 0, n = staticFields.length; i < n; ++i) {      VM_Field field = staticFields[i];      VM_TypeReference fieldType = field.getType();      byte slotType;      if (fieldType.isReferenceType())        slotType = VM_Statics.REFERENCE_FIELD;      else if (fieldType.getSize() == BYTES_IN_LONG)        slotType = VM_Statics.WIDE_NUMERIC_FIELD;      else        slotType = VM_Statics.NUMERIC_FIELD;      field.offset = (VM_Statics.allocateSlot(slotType) << LOG_BYTES_IN_INT);      // (SJF): Serialization nastily accesses even final private static      //           fields via pseudo-reflection! So, we must shove the      //           values of final static fields into the JTOC.  Now      //           seems to be a good time.      if (field.isFinal()) {        setFinalStaticJTOCEntry(field,field.offset);      }    }    // lay out instance fields    //    VM_ObjectModel.layoutInstanceFields(this);    // count reference fields    int referenceFieldCount = 0;    for (int i = 0, n = instanceFields.length; i < n; ++i) {      VM_Field field     = instanceFields[i];      if (field.getType().isReferenceType())        referenceFieldCount += 1;    }    // record offsets of those instance fields that contain references    //    referenceOffsets = new int[referenceFieldCount];    for (int i = 0, j = 0, n = instanceFields.length; i < n; ++i) {      VM_Field field = instanceFields[i];      if (field.getType().isReferenceType())        referenceOffsets[j++] = field.offset;    }    // Allocate space for <init> method pointers    //    for (int i = 0, n = constructorMethods.length; i < n; ++i) {      VM_Method method = constructorMethods[i];      method.offset = VM_Statics.allocateSlot(VM_Statics.METHOD) << LOG_BYTES_IN_INT;    }    // Allocate space for static method pointers    //    for (int i = 0, n = staticMethods.length; i < n; ++i) {      VM_Method method = staticMethods[i];      if (method.isClassInitializer()) {        method.offset = 0xdeadbeef; // should never be used.      } else {        method.offset = VM_Statics.allocateSlot(VM_Statics.METHOD) << LOG_BYTES_IN_INT;      }    }    // create "type information block" and initialize its first four words    //    if (isInterface()) {      // the TIB for an Interface doesn't need space for IMT and VTable; will never be used.      typeInformationBlock = MM_Interface.newTIB(TIB_FIRST_INTERFACE_METHOD_INDEX);    } else {      typeInformationBlock = MM_Interface.newTIB(TIB_FIRST_VIRTUAL_METHOD_INDEX + virtualMethods.length);    }          VM_Statics.setSlotContents(tibSlot, typeInformationBlock);    // Initialize dynamic type checking data structures    typeInformationBlock[TIB_TYPE_INDEX] = this;    typeInformationBlock[TIB_SUPERCLASS_IDS_INDEX] = VM_DynamicTypeCheck.buildSuperclassIds(this);    typeInformationBlock[TIB_DOES_IMPLEMENT_INDEX] = VM_DynamicTypeCheck.buildDoesImplement(this);    // (element type for arrays not used classes)    if (!isInterface()) {      // lay out virtual method section of type information block       // (to be filled in by instantiate)      for (int i = 0, n = virtualMethods.length; i < n; ++i) {        VM_Method method = virtualMethods[i];        method.offset = (TIB_FIRST_VIRTUAL_METHOD_INDEX + i) << LOG_BYTES_IN_ADDRESS;      }    }    // RCGC: Determine if class is inherently acyclic    acyclic = false;    // must initially be false for recursive types    boolean foundCyclic = false;    for (int i = 0; i < instanceFields.length; i++) {      VM_TypeReference ft = instanceFields[i].getType();      if (!(ft.isResolved() && ft.peekResolvedType().isAcyclicReference())) {        foundCyclic = true;         break;      }    }    if (!foundCyclic) {      acyclic = true;    }    state = CLASS_RESOLVED; // can't move this beyond "finalize" code block    if (VM.writingBootImage) {      //-#if RVM_WITH_OPT_COMPILER      OptCLDepManager.classInitialized(this, true);      //-#endif    }            VM_Callbacks.notifyClassResolved(this);    MM_Interface.notifyClassResolved(this);    // check for a "finalize" method that overrides the one in java.lang.Object    //    finalizeMethod = null;    if (!isInterface()) {      VM_Method finalize = findVirtualMethod(VM_ClassLoader.StandardObjectFinalizerMethodName,                                              VM_ClassLoader.StandardObjectFinalizerMethodDescriptor);      if (!finalize.getDeclaringClass().isJavaLangObjectType()) {        finalizeMethod = finalize;      }    }    if (VM.TraceClassLoading && VM.runningVM) VM.sysWriteln("VM_Class: (end)   resolve " + this);  }