private void doCopy(
      final int offset, final MemoryChunk other, final int otherOffset, final int count) {
    if (!(other instanceof AshmemMemoryChunk)) {
      throw new IllegalArgumentException("Cannot copy two incompatible MemoryChunks");
    }
    Preconditions.checkState(!isClosed());
    Preconditions.checkState(!other.isClosed());
    Preconditions.checkNotNull(mByteBuffer);
    Preconditions.checkNotNull(other.getByteBuffer());
    MemoryChunkUtil.checkBounds(offset, other.getSize(), otherOffset, count, getSize());
    mByteBuffer.position(offset);
    // ByteBuffer can't be null at this point
    other.getByteBuffer().position(otherOffset);
    // Recover the necessary part to be copied as a byte array.
    // This requires a copy, for now there is not a more efficient alternative.
    byte[] b = new byte[count];
    mByteBuffer.get(b, 0, count);
    other.getByteBuffer().put(b, 0, count);
  }
This does actual copy. It should be called only when we hold locks on both this and other
objects
memory-types/ashmem/src/main/java/com/facebook/imagepipeline/memory/AshmemMemoryChunk.java