public static long sizeOf(Class clazz){
  long maxSize=headerSize(clazz);
  while (clazz != Object.class) {
    for (    Field f : clazz.getDeclaredFields()) {
      if ((f.getModifiers() & Modifier.STATIC) == 0) {
        long offset=unsafe.objectFieldOffset(f);
        if (offset > maxSize) {
          maxSize=offset + 1;
        }
      }
    }
    clazz=clazz.getSuperclass();
  }
  return roundUpTo8(maxSize);
}

public static long sizeOf ( Class clazz ) { long maxSize = headerSize ( clazz ) ; while ( clazz != Object . class ) { for ( Field f : clazz . getDeclaredFields ( ) ) { if ( ( f . getModifiers ( ) & Modifier . STATIC ) == 0 ) { long offset = unsafe . objectFieldOffset ( f ) ; if ( offset > maxSize ) { maxSize = offset + 1 ; } } } clazz = clazz . getSuperclass ( ) ; } return roundUpTo8 ( maxSize ) ; }
returns the size of an instance of this class ( in bytes ) . instances include a header + all fields + padded to 8 bytes . if this is an array , it does not include the size of the elements .
