VM_Statics.setSlotContents(rvmFieldSlot, o);
VM_Statics.setSlotContents(rvmFieldOffset, o);
  public static void createBootImageObjects(Vector typeNames,                                            String bootImageTypeNamesFile)     throws IllegalAccessException, ClassNotFoundException {          VM_Callbacks.notifyBootImage(typeNames.elements());      long startTime = 0;      long stopTime = 0;            //      // Create types.      //      if (verbose >= 1) say("loading");      if (profile) startTime = System.currentTimeMillis();            for (Enumeration e = typeNames.elements(); e.hasMoreElements(); ) {        //        // get type name        //        String typeName = (String) e.nextElement();        if (verbose >= 4)          say("typeName:", typeName);                //        // create corresponding rvm type        //        VM_Type type;                try {          VM_TypeReference tRef = VM_TypeReference.findOrCreate(typeName);          type = tRef.resolve();        } catch (NoClassDefFoundError ncdf) {          ncdf.printStackTrace();          fail(bootImageTypeNamesFile               + " contains a class named \""                + typeName + "\", but we can't find a class with that name: "               + ncdf);          return;               // NOTREACHED        } catch (IllegalArgumentException ila) {          /* We should've caught any illegal type names at the data validation           * stage, when we read these in.  If not, though,            * VM_TypeReference.findOrCreate() will do its own sanity check.  */          ila.printStackTrace();          fail(bootImageTypeNamesFile               + " is supposed to contain type names.  It contains \""                + typeName + "\", which does not parse as a legal type name: "               + ila);          return;               // NOTREACHED        }        type.markAsBootImageClass();        //        // convert type name from internal form to external form        // ie:    Ljava/lang/Object;   -->     java.lang.Object        //       [Ljava/lang/Object;   -->   [Ljava.lang.Object;        //        // NOTE: duplicate functionality.  There is a method that does the same.        //        typeName = typeName.replace('/','.');        if (typeName.startsWith("L"))          typeName = typeName.substring(1, typeName.length() - 1);        //        // record name/type pair for later lookup by getRvmType()        //        bootImageTypes.put(typeName, type);      }      if (profile) {        stopTime = System.currentTimeMillis();        System.out.println("PROF: \tloading types "+(stopTime-startTime)+" ms");      }              if (verbose >= 1) say(String.valueOf(bootImageTypes.size()), " types");      //      // Lay out fields and method tables.      //      if (profile) startTime = System.currentTimeMillis();      if (verbose >= 1) say("resolving");      for (Enumeration e = bootImageTypes.elements(); e.hasMoreElements(); ) {        VM_Type type = (VM_Type) e.nextElement();        if (verbose >= 2) say("resolving " + type);        // The resolution is supposed to be cached already.        type.resolve();      }      if (profile) {        stopTime = System.currentTimeMillis();        System.out.println("PROF: \tresolving types "+(stopTime-startTime)+" ms");      }      // Set tocRegister early so opt compiler can access it to      //   perform fixed_jtoc optimization (compile static addresses into code).      // In the boot image, the bootrecord comes first followed by a      // Address array and then the TOC.  To do this, we must fully      // simulate the alignment logic in the allocation code!  Rather      // than replicate the allocation code here, we perform dummy      // allocations and then reset the boot image allocator.      VM_BootRecord bootRecord = VM_BootRecord.the_boot_record;      VM_Class rvmBRType = getRvmType(bootRecord.getClass()).asClass();      VM_Array intArrayType =  VM_Array.getPrimitiveArrayType(10);      int brOffset = bootImage.allocateStorage(rvmBRType.getInstanceSize(),                                                VM_ObjectModel.getAlignment(rvmBRType),                                                VM_ObjectModel.getOffsetForAlignment(rvmBRType));      int jtocOffset = bootImage.allocateStorage(intArrayType.getInstanceSize(0),                                                 VM_ObjectModel.getAlignment(intArrayType),                                                 VM_ObjectModel.getOffsetForAlignment(intArrayType));      bootImage.resetAllocator();      bootRecord.tocRegister = bootImageAddress.add(jtocOffset).add(intArrayType.getInstanceSize(0));      //      // Compile methods and populate jtoc with literals, TIBs, and machine code.      //      if (profile) startTime = System.currentTimeMillis();      if (verbose >= 1) say("instantiating");      if (PARALLELIZE < 1) {        int count = 0;        for (Enumeration e = bootImageTypes.elements(); e.hasMoreElements(); ) {            VM_Type type = (VM_Type) e.nextElement();            count++;            if (verbose >= 1) say(count + " instantiating " + type);            long start2 = System.currentTimeMillis();            type.instantiate();            long stop2 = System.currentTimeMillis();            if (profile && stop2 - start2 > classCompileThreshold)              System.out.println("PROF:\t\t"+type+" took "+((stop2 - start2+500)/1000)+" seconds to instantiate");        }      } else {        if (verbose >= 1) say("parallelizing with " + PARALLELIZE + " threads");        BootImageWorker.startup(bootImageTypes.elements());        BootImageWorker [] workers = new BootImageWorker[PARALLELIZE];        for (int i=0; i<workers.length; i++) {          workers[i].id = i;          workers[i].start();        }        try {          for (int i=0; i<workers.length; i++)            workers[i].join();        } catch (InterruptedException ie) {          say("InterruptedException while instantiating");        }      }      if (profile) {        stopTime = System.currentTimeMillis();        System.out.println("PROF: \tinstantiating types "+(stopTime-startTime)+" ms");      }      // Do the portion of JNIEnvironment initialization that can be done      // at bootimage writing time.      VM_CodeArray[] functionTable = BuildJNIFunctionTable.buildTable();      VM_JNIEnvironment.initFunctionTable(functionTable);      //      // Collect the VM class Field to JDK class Field correspondence      // This will be needed when building the images of each object instance      // and for processing the static fields of the boot image classes      //      if (verbose >= 1) say("field info gathering");      if (profile) startTime = System.currentTimeMillis();      bootImageTypeFields = new HashMap(bootImageTypes.size());      // First retrieve the jdk Field table for each class of interest      for (Enumeration e = bootImageTypes.elements(); e.hasMoreElements(); ) {        VM_Type rvmType = (VM_Type) e.nextElement();        FieldInfo fieldInfo;        if (!rvmType.isClassType())          continue; // arrays and primitives have no static or instance fields        Class jdkType = getJdkType(rvmType);        if (jdkType == null)          continue;  // won't need the field info        Key key   = new Key(jdkType);        fieldInfo = (FieldInfo)bootImageTypeFields.get(key);        if (fieldInfo != null) {          fieldInfo.rvmType = rvmType;        } else {          if (verbose >= 1) say("making fieldinfo for " + rvmType);          fieldInfo = new FieldInfo();          fieldInfo.jdkFields = jdkType.getDeclaredFields();          fieldInfo.jdkType = jdkType;          fieldInfo.rvmType = rvmType;          bootImageTypeFields.put(key, fieldInfo);          // Now do all the superclasses if they don't already exist          // Can't add them in next loop as Iterator's don't allow updates to collection          for (Class cls = jdkType.getSuperclass(); cls != null; cls = cls.getSuperclass()) {            key = new Key(cls);            fieldInfo = (FieldInfo)bootImageTypeFields.get(key);            if (fieldInfo != null) {              break;              } else {              if (verbose >= 1) say("making fieldinfo for " + jdkType);              fieldInfo = new FieldInfo();              fieldInfo.jdkFields = cls.getDeclaredFields();              fieldInfo.jdkType = cls;              fieldInfo.rvmType = null;                  bootImageTypeFields.put(key, fieldInfo);            }          }        }      }      // Now build the one-to-one instance and static field maps      for (Iterator iter = bootImageTypeFields.values().iterator(); iter.hasNext();) {        FieldInfo fieldInfo = (FieldInfo)iter.next();        VM_Type rvmType = fieldInfo.rvmType;        if (rvmType == null) {          if (verbose >= 1) say("bootImageTypeField entry has no rvmType:"+fieldInfo.jdkType);          continue;         }        Class jdkType   = fieldInfo.jdkType;        if (verbose >= 1) say("building static and instance fieldinfo for " + rvmType);        // First the static fields        //         VM_Field rvmFields[] = rvmType.getStaticFields();        fieldInfo.jdkStaticFields = new Field[rvmFields.length];        for (int j = 0; j < rvmFields.length; j++) {          String  rvmName = rvmFields[j].getName().toString();          for (int k = 0; k < fieldInfo.jdkFields.length; k++) {            Field f = fieldInfo.jdkFields[k];            if (f.getName().equals(rvmName)) {              fieldInfo.jdkStaticFields[j] = f;              f.setAccessible(true);              break;            }          }        }        // Now the instance fields        //         rvmFields = rvmType.getInstanceFields();        fieldInfo.jdkInstanceFields = new Field[rvmFields.length];        for (int j = 0; j<rvmFields.length; j++) {          String  rvmName = rvmFields[j].getName().toString();          // We look only in the JDK type that corresponds to the          // VM_Type of the field's declaring class.          // This is the only way to correctly handle private fields.          jdkType = getJdkType(rvmFields[j].getDeclaringClass());          if (jdkType == null) continue;          FieldInfo jdkFieldInfo = (FieldInfo)bootImageTypeFields.get(new Key(jdkType));          if (jdkFieldInfo == null) continue;          Field[] jdkFields = jdkFieldInfo.jdkFields;          for (int k = 0; k <jdkFields.length; k++) {            Field f = jdkFields[k];            if (f.getName().equals(rvmName)) {              fieldInfo.jdkInstanceFields[j] = f;              f.setAccessible(true);              break;            }          }        }      }      if (profile) {        stopTime = System.currentTimeMillis();        System.out.println("PROF: \tcreating type mapping "+(stopTime-startTime)+" ms");      }            //      // Create stack, thread, and processor context in which rvm will begin      // execution.      //      int initProc = VM_Scheduler.PRIMORDIAL_PROCESSOR_ID;      // It's actually useless to set the name of the primordial thread here;      // that data is really stored as part of the java.lang.Thread structure,      // which we can not safely create yet.      VM_Thread startupThread = new VM_Thread(new byte[STACK_SIZE_BOOT], null, "Jikes_RVM_Boot_Thread");      VM_Scheduler.processors[initProc].activeThread = startupThread;      // sanity check for bootstrap loader      int idx = startupThread.stack.length - 1;      if (VM.LittleEndian) {        startupThread.stack[idx--] = (byte)0xde;        startupThread.stack[idx--] = (byte)0xad;        startupThread.stack[idx--] = (byte)0xba;        startupThread.stack[idx--] = (byte)0xbe;      } else {        startupThread.stack[idx--] = (byte)0xbe;        startupThread.stack[idx--] = (byte)0xba;        startupThread.stack[idx--] = (byte)0xad;        startupThread.stack[idx--] = (byte)0xde;      }                    //      // Tell rvm where to find itself at execution time.      // This may not be the same place it was at build time, ie. if image is      // moved to another machine with different directory structure.      //      VM_BootstrapClassLoader.setBootstrapRepositories(bootImageRepositoriesAtExecutionTime);            //      // Finally, populate jtoc with static field values.      // This is equivalent to the VM_Class.initialize() phase that would have      // executed each class's static constructors at run time.  We simulate      // this by copying statics created in the host rvm into the appropriate      // slots of the jtoc.      //      if (verbose >= 1) say("populating jtoc with static fields");      if (profile) startTime = System.currentTimeMillis();      for (Enumeration e = bootImageTypes.elements(); e.hasMoreElements(); ) {        VM_Type rvmType = (VM_Type) e.nextElement();        if (verbose >= 1) say("  jtoc for ", rvmType.toString());        if (!rvmType.isClassType())          continue; // arrays and primitives have no static fields        Class jdkType = getJdkType(rvmType);        if (jdkType == null && verbose >= 1) {          say("host has no class \"" + rvmType + "\"");        }        VM_Field rvmFields[] = rvmType.getStaticFields();        for (int j = 0; j < rvmFields.length; ++j) {          VM_Field rvmField     = rvmFields[j];          VM_TypeReference rvmFieldType = rvmField.getType();          int      rvmFieldSlot = (rvmField.getOffsetAsInt() >>> 2);          String   rvmFieldName = rvmField.getName().toString();          Field    jdkFieldAcc  = null;          if (jdkType != null)             jdkFieldAcc = getJdkFieldAccessor(jdkType, j, STATIC_FIELD);          if (jdkFieldAcc == null) {            if (jdkType != null) {              if (verbose >= 2) traceContext.push(rvmFieldType.toString(),                                                  jdkType.getName(), rvmFieldName);              if (verbose >= 2) traceContext.traceFieldNotInHostJdk();              if (verbose >= 2) traceContext.pop();            }            VM_Statics.setSlotContents(rvmFieldSlot, 0);            if (!VM.runningTool)              bootImage.countNulledReference();            continue;          }          if (! Modifier.isStatic(jdkFieldAcc.getModifiers())) {              if (verbose >= 2) traceContext.push(rvmFieldType.toString(),                                                  jdkType.getName(), rvmFieldName);              if (verbose >= 2) traceContext.traceFieldNotStaticInHostJdk();              if (verbose >= 2) traceContext.pop();              VM_Statics.setSlotContents(rvmFieldSlot, 0);            if (!VM.runningTool)              bootImage.countNulledReference();            continue;          }          if (verbose >= 2)             say("    populating jtoc slot ", String.valueOf(rvmFieldSlot),                 " with ", rvmField.toString());          if (rvmFieldType.isPrimitiveType()) {            // field is logical or numeric type            if (rvmFieldType.isBooleanType()) {              VM_Statics.setSlotContents(rvmFieldSlot,                                         jdkFieldAcc.getBoolean(null) ? 1 : 0);            } else if (rvmFieldType.isByteType()) {              VM_Statics.setSlotContents(rvmFieldSlot, jdkFieldAcc.getByte(null));            } else if (rvmFieldType.isCharType()) {              VM_Statics.setSlotContents(rvmFieldSlot, jdkFieldAcc.getChar(null));            } else if (rvmFieldType.isShortType()) {              VM_Statics.setSlotContents(rvmFieldSlot, jdkFieldAcc.getShort(null));            } else if (rvmFieldType.isIntType()) {              try {                VM_Statics.setSlotContents(rvmFieldSlot,                                           jdkFieldAcc.getInt(null));              } catch (IllegalArgumentException ex) {                System.err.println( "type " + rvmType + ", field " + rvmField);                throw ex;              }            } else if (rvmFieldType.isLongType()) {              // note: Endian issues handled in setSlotContents.              VM_Statics.setSlotContents(rvmFieldSlot,                                         jdkFieldAcc.getLong(null));            } else if (rvmFieldType.isFloatType()) {              float f = jdkFieldAcc.getFloat(null);              VM_Statics.setSlotContents(rvmFieldSlot,                                         Float.floatToIntBits(f));            } else if (rvmFieldType.isDoubleType()) {              double d = jdkFieldAcc.getDouble(null);              // note: Endian issues handled in setSlotContents.              VM_Statics.setSlotContents(rvmFieldSlot,                                         Double.doubleToLongBits(d));            } else if (rvmFieldType.equals(VM_TypeReference.Address) ||                       rvmFieldType.equals(VM_TypeReference.Word) ||                       rvmFieldType.equals(VM_TypeReference.Extent) ||                       rvmFieldType.equals(VM_TypeReference.Offset)){              Object o = jdkFieldAcc.get(null);              String msg = " static field " + rvmField.toString();              boolean warn = rvmFieldType.equals(VM_TypeReference.Address);            //-#if RVM_FOR_32_ADDR              VM_Statics.setSlotContents(rvmFieldSlot, getWordValue(o, msg, warn).toInt());            //-#endif            //-#if RVM_FOR_64_ADDR              VM_Statics.setSlotContents(rvmFieldSlot, getWordValue(o, msg, warn).toLong());            //-#endif            } else {              fail("unexpected primitive field type: " + rvmFieldType);            }          } else {            // field is reference type            /* Consistency check. */            if (jdkFieldAcc == null)              fail("internal inconistency: jdkFieldAcc == null");            int modifs = jdkFieldAcc.getModifiers();            /* This crash, realistically, should never occur. */            if (! Modifier.isStatic(modifs))               fail("Consistency failure: About to try to access an instance field (via jdkFieldAcc) as if it were a static one!  The culprit is the field " + jdkFieldAcc.toString());            Object o;            try {              o = jdkFieldAcc.get(null);            } catch (NullPointerException npe) {              fail("Got a NullPointerException while using reflection to retrieve the value of the field " + jdkFieldAcc.toString() + ": " + npe.toString());              o = null;         // Unreached            }            if (verbose >= 3)              say("       setting with ", String.valueOf(VM_Magic.objectAsAddress(o).toInt()));            VM_Statics.setSlotContents(rvmFieldSlot, o);          }        }      }      if (profile) {        stopTime = System.currentTimeMillis();        System.out.println("PROF: \tinitializing jtoc "+(stopTime-startTime)+" ms");      }  }