Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19222#discussion_r147573486
  
    --- Diff: 
common/unsafe/src/main/java/org/apache/spark/unsafe/memory/MemoryBlock.java ---
    @@ -17,47 +17,168 @@
     
     package org.apache.spark.unsafe.memory;
     
    -import javax.annotation.Nullable;
    -
     import org.apache.spark.unsafe.Platform;
     
    +import javax.annotation.Nullable;
    +
     /**
    - * A consecutive block of memory, starting at a {@link MemoryLocation} 
with a fixed size.
    + * A declaration of interfaces of MemoryBlock classes .
      */
    -public class MemoryBlock extends MemoryLocation {
    +public abstract class MemoryBlock {
    +  @Nullable
    +  protected final Object obj;
     
    -  private final long length;
    +  protected final long offset;
    +
    +  protected final long length;
     
       /**
        * Optional page number; used when this MemoryBlock represents a page 
allocated by a
    -   * TaskMemoryManager. This field is public so that it can be modified by 
the TaskMemoryManager,
    -   * which lives in a different package.
    +   * TaskMemoryManager. This field can be updated using setPageNumber 
method so that
    +   * this can be modified by the TaskMemoryManager, which lives in a 
different package.
        */
    -  public int pageNumber = -1;
    +  private int pageNumber = -1;
     
       public MemoryBlock(@Nullable Object obj, long offset, long length) {
    -    super(obj, offset);
    +    this.obj = obj;
    +    this.offset = offset;
         this.length = length;
       }
     
    +  public MemoryBlock() {
    +    this(null, 0, 0);
    +  }
    +
    +  public final Object getBaseObject() {
    +    return obj;
    +  }
    +
    +  public final long getBaseOffset() {
    +    return offset;
    +  }
    +
       /**
        * Returns the size of the memory block.
        */
    -  public long size() {
    +  public final long size() {
         return length;
       }
     
    -  /**
    -   * Creates a memory block pointing to the memory used by the long array.
    -   */
    -  public static MemoryBlock fromLongArray(final long[] array) {
    -    return new MemoryBlock(array, Platform.LONG_ARRAY_OFFSET, array.length 
* 8L);
    +  public final void setPageNumber(int pageNum) {
    +    pageNumber = pageNum;
    +  }
    +
    +  public final int getPageNumber() {
    +    return pageNumber;
       }
     
       /**
        * Fills the memory block with the specified byte value.
        */
    -  public void fill(byte value) {
    +  public final void fill(byte value) {
         Platform.setMemory(obj, offset, length, value);
       }
    +
    +  /**
    +   * Instantiate the same type of MemoryBlock with new offset and size
    +   */
    +  public abstract MemoryBlock allocate(long offset, long size);
    +
    +
    +  public abstract int getInt(long offset);
    +
    +  public abstract void putInt(long offset, int value);
    +
    +  public abstract boolean getBoolean(long offset);
    +
    +  public abstract void putBoolean(long offset, boolean value);
    +
    +  public abstract byte getByte(long offset);
    +
    +  public abstract void putByte(long offset, byte value);
    +
    +  public abstract short getShort(long offset);
    +
    +  public abstract void putShort(long offset, short value);
    +
    +  public abstract long getLong(long offset);
    +
    +  public abstract void putLong(long offset, long value);
    +
    +  public abstract float getFloat(long offset);
    +
    +  public abstract void putFloat(long offset, float value);
    +
    +  public abstract double getDouble(long offset);
    +
    +  public abstract void putDouble(long offset, double value);
    +
    +  public abstract Object getObjectVolatile(long offset);
    +
    +  public abstract void putObjectVolatile(long offset, Object value);
    +
    +  public static final void copyMemory(
    --- End diff --
    
    `copyMemory` has two kinds of arguments: `src` and `dst`.  
    If we make them non-static method, it is not easy to understand whether 
`this` is `src` or `dst`. If we keep method name `MemoryBlock.copy`, I think 
that it is good to keep current form (it is common in `memcpy`).
    
    Or, can we prepare two methods `MemoryBlock.copyFrom(srcOffset, dst...)` 
and `MemoryBlock.copyTo(src..., dstOffset)`.
    
    @cloud-fan What do you think?



---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to