public static long sizeOfInstanceWithUnsafe ( Class < ? > type ) { while ( type != null ) { long size = 0 ; for ( Field f : declaredFieldsOf ( type ) ) size = Math . max ( size , unsafe . objectFieldOffset ( f ) + sizeOf ( f ) ) ; if ( size > 0 ) return roundTo ( size , SPEC . getObjectPadding ( ) ) ; type = type . getSuperclass ( ) ; } return roundTo ( SPEC . getObjectHeaderSize ( ) , SPEC . getObjectPadding ( ) ) ; }
attemps to use sun . misc . Unsafe to find the maximum object offset this work around helps deal with long alignment