if (VM.VerifyAssertions) VM._assert(state == CLASS_LOADED);
if (VM.VerifyAssertions) VM._assert(state == CLASS_LOADED, descriptor.toString() );
  public final synchronized void resolve() throws VM_ResolutionException {    if (isResolved())      return;    if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Class: (begin) resolve "                                           + descriptor + "\n");    if (VM.VerifyAssertions) VM._assert(state == CLASS_LOADED);    // load/resolve superclass    //    if (VM.verboseClassLoading) VM.sysWrite("[Loading superclasses of "+                                            descriptor.classNameFromDescriptor()                                            +"]\n");    if (superClass != null) {      superClass.load();      superClass.resolve();      depth = 1 + superClass.depth;      thinLockOffset = superClass.thinLockOffset;      instanceSize = superClass.instanceSize;    } else {      instanceSize = VM_ObjectModel.computeScalarHeaderSize(this);    }    for (int i=0; i<declaredInterfaces.length; i++) {      declaredInterfaces[i].load();      declaredInterfaces[i].resolve();    }    if (isSynchronizedObject() || this == VM_Type.JavaLangClassType)      VM_ObjectModel.allocateThinLock(this);    if (VM.verboseClassLoading) VM.sysWrite("[Preparing "+                                            descriptor.classNameFromDescriptor()                                            +"]\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 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 (method.isObjectInitializer() || method.isStatic())  {	  VM_Callbacks.notifyMethodOverride(method, null);	  staticMethods.addElement(method);	  if (VM.VerifyUnint) {	    if (!method.isInterruptible() && method.isSynchronized()) {	      if (VM.ParanoidVerifyUnint || !VM_PragmaLogicallyUninterruptible.declaredBy(method)) {		VM.sysWriteln("WARNING: "+method+" cannot be both uninterruptible and synchronized");	      }	    }	  }	  continue;	}	// Now deal with virtual methods	if (method.isSynchronized()) {	  VM_ObjectModel.allocateThinLock(this);	  if (VM.VerifyUnint) {	    if (!method.isInterruptible()) {	      if (VM.ParanoidVerifyUnint || !VM_PragmaLogicallyUninterruptible.declaredBy(method)) {		VM.sysWriteln("WARNING: "+method+" cannot be both uninterruptible and synchronized");	      }	    }	  }	}	// 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	}      }      this.staticFields   = staticFields.finish();      this.instanceFields = instanceFields.finish();      this.staticMethods  = staticMethods.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_Type  fieldType = field.getType();      byte     slotType;      if (fieldType.isReferenceType())	slotType = VM_Statics.REFERENCE_FIELD;      ///	(SJF:: Note: we DO need to have a JTOC entry even       //               for final static      ///	       private fields. (for serialization) )      else if (fieldType.getStackWords() == 2)	slotType = VM_Statics.WIDE_NUMERIC_FIELD;      else	slotType = VM_Statics.NUMERIC_FIELD;      field.offset = (VM_Statics.allocateSlot(slotType) << 2);      // (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 and update dynamic linking data structures    int referenceFieldCount = 0;    for (int i = 0, n = instanceFields.length; i < n; ++i) {      VM_Field field     = instanceFields[i];      if (field.getType().isReferenceType())	referenceFieldCount += 1;      // Should be ok to do here instead of in initialize, because      // "new" will ensure that the class is instantiated before it       // creates an instance.      VM_TableBasedDynamicLinker.setFieldOffset(field, field.offset);    }    // 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 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) << 2;      }    }    // create "type information block" and initialize its first four words    //    typeInformationBlock = VM_Interface.newTIB(TIB_FIRST_VIRTUAL_METHOD_INDEX + virtualMethods.length);    VM_Statics.setSlotContents(tibSlot, typeInformationBlock);    // Initialize dynamic type checking data structures    typeInformationBlock[0] = 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)    // 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) << 2;      // Should be OK to do here instead of in initialize because       // "new" will ensure that the class is instantiated before       // it creates an instance      VM_TableBasedDynamicLinker.setMethodOffset(method, method.offset);    }    state = CLASS_RESOLVED; // can't move this beyond "finalize" code block    VM_Callbacks.notifyClassResolved(this);    // check for a "finalize" method that overrides the one in java.lang.Object    //    VM_Method finalize = findVirtualMethod(VM_ClassLoader.StandardObjectFinalizerMethodName,                                            VM_ClassLoader.StandardObjectFinalizerMethodDescriptor);    if (finalize.getDeclaringClass().getSuperClass() != null)      finalizeMethod = finalize;    else      finalizeMethod = null;    if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Class: (end)   resolve " + descriptor + "\n");  }