### Question:
HFileBlock extends SchemaConfigured implements Cacheable { @Override public long heapSize() { long size = ClassSize.align( SCHEMA_CONFIGURED_UNALIGNED_HEAP_SIZE + 2 * ClassSize.REFERENCE + 6 * Bytes.SIZEOF_INT + 1 * Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_LONG + Bytes.SIZEOF_BOOLEAN ); if (buf != null) { size += ClassSize.align(buf.capacity() + BYTE_BUFFER_HEAP_SIZE); } return ClassSize.align(size); } HFileBlock(BlockType blockType, int onDiskSizeWithoutHeader,
      int uncompressedSizeWithoutHeader, long prevBlockOffset, ByteBuffer buf,
      boolean fillHeader, long offset, boolean includesMemstoreTS, 
      int minorVersion, int bytesPerChecksum, byte checksumType,
      int onDiskDataSizeWithHeader);   HFileBlock(ByteBuffer b, int minorVersion); BlockType getBlockType(); short getDataBlockEncodingId(); int getOnDiskSizeWithHeader(); int getUncompressedSizeWithoutHeader(); long getPrevBlockOffset(); ByteBuffer getBufferReadOnly(); @Override String toString(); void assumeUncompressed(); void expectType(BlockType expectedType); long getOffset(); DataInputStream getByteStream(); @Override long heapSize(); static boolean readWithExtra(InputStream in, byte buf[],
      int bufOffset, int necessaryLen, int extraLen); int getNextBlockOnDiskSizeWithHeader(); @Override int getSerializedLength(); @Override void serialize(ByteBuffer destination); @Override CacheableDeserializer<Cacheable> getDeserializer(); @Override boolean equals(Object comparison); boolean doesIncludeMemstoreTS(); DataBlockEncoding getDataBlockEncoding(); int headerSize(); byte[] getDummyHeaderForVersion(); static final boolean FILL_HEADER; static final boolean DONT_FILL_HEADER; static final int ENCODED_HEADER_SIZE; static final int BYTE_BUFFER_HEAP_SIZE; }### Answer:
@Test public void testBlockHeapSize() { if (ClassSize.is32BitJVM()) { assertTrue(HFileBlock.BYTE_BUFFER_HEAP_SIZE == 64); } else { assertTrue(HFileBlock.BYTE_BUFFER_HEAP_SIZE == 80); } for (int size : new int[] { 100, 256, 12345 }) { byte[] byteArr = new byte[HFileBlock.HEADER_SIZE_WITH_CHECKSUMS + size]; ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size); HFileBlock block = new HFileBlock(BlockType.DATA, size, size, -1, buf, HFileBlock.FILL_HEADER, -1, includesMemstoreTS, HFileBlock.MINOR_VERSION_NO_CHECKSUM, 0, ChecksumType.NULL.getCode(), 0); long byteBufferExpectedSize = ClassSize.align(ClassSize.estimateBase(buf.getClass(), true) + HFileBlock.HEADER_SIZE_WITH_CHECKSUMS + size); long hfileBlockExpectedSize = ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true)); long expected = hfileBlockExpectedSize + byteBufferExpectedSize; assertEquals("Block data size: " + size + ", byte buffer expected " + "size: " + byteBufferExpectedSize + ", HFileBlock class expected " + "size: " + hfileBlockExpectedSize + ";", expected, block.heapSize()); } }