code: static long shallowSizeOfInstance(Class<?> clazz) {
      if (clazz.isArray())
        throw new IllegalArgumentException("This method does not work with array classes.");
      if (clazz.isPrimitive())
        return primitiveSizes.get(clazz);
      
      long size = NUM_BYTES_OBJECT_HEADER;
  
      // Walk type hierarchy
      for (;clazz != null; clazz = clazz.getSuperclass()) {
        final Class<?> target = clazz;
        final Field[] fields = AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
          @Override
          public Field[] run() {
            return target.getDeclaredFields();
          }
        });
        for (Field f : fields) {
          if (!Modifier.isStatic(f.getModifiers())) {
            size = adjustForField(size, f);
          }
        }
      }
      return alignObjectSize(size);    
    }
docs: Returns the shallow instance size in bytes an instance of the given class would occupy.
  This works with all conventional classes and primitive types, but not with arrays
  (the size then depends on the number of elements and varies from object to object).
  
  @see #shallowSizeOf(Object)
  @throws IllegalArgumentException if {@code clazz} is an array class.