public static long sizeOfInstance ( Class < ? > type ) { long size = SPEC . getObjectHeaderSize ( ) + sizeOfDeclaredFields ( type ) ; while ( ( type = type . getSuperclass ( ) ) != Object . class && type != null ) size += roundTo ( sizeOfDeclaredFields ( type ) , SPEC . getSuperclassFieldPadding ( ) ) ; return roundTo ( size , SPEC . getObjectPadding ( ) ) ; }
sizeOfInstanceWithUnsafe is safe against this miscounting