Пример #1
0
 /**
  * Align the offsets of the fields in the class optimized for minimal object size.
  *
  * @param fields
  * @return The objectsize taken by all the fields
  */
 private static final int alignInstanceFields(VmField[] fields, int slotSize) {
   int objectSize = 0;
   for (byte currentTypeSize : TYPE_SIZES) {
     boolean aligned = false;
     for (VmField f : fields) {
       if (!f.isStatic() && (f.getTypeSize() == currentTypeSize)) {
         if (!aligned) {
           // Align on the current type size
           objectSize = align(objectSize, Math.min(currentTypeSize, slotSize));
           aligned = true;
         }
         final VmInstanceField fld = (VmInstanceField) f;
         fld.setOffset(objectSize);
         objectSize += currentTypeSize;
       }
     }
   }
   // Make sure the object size is 32-bit aligned
   return align(objectSize, 4);
 }