You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by GitBox <gi...@apache.org> on 2021/08/10 14:58:29 UTC

[GitHub] [datasketches-memory] davecromberge commented on a change in pull request #136: Ds java issue358

davecromberge commented on a change in pull request #136:
URL: https://github.com/apache/datasketches-memory/pull/136#discussion_r686095780



##########
File path: datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
##########
@@ -30,91 +32,92 @@
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
-import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Util;
+import org.apache.datasketches.memory.MemoryRequestServer;
 import org.apache.datasketches.memory.WritableBuffer;
-
-import org.apache.datasketches.memory.WritableMemory;
+import org.apache.datasketches.memory.WritableHandle;
 import org.apache.datasketches.memory.WritableMapHandle;
+import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
 /**
  * @author Lee Rhodes
  */
 @SuppressWarnings("javadoc")
 public class LeafImplTest {
-  static final ByteOrder LE = ByteOrder.LITTLE_ENDIAN;
-  static final ByteOrder BE = ByteOrder.BIG_ENDIAN;
+  private static final ByteOrder NO = nativeByteOrder;
+  private static final ByteOrder NNO = nonNativeByteOrder;
+  private static final MemoryRequestServer dummyMemReqSvr = new DummyMemoryRequestServer();
+  
+  private static ByteOrder otherOrder(ByteOrder order) { return (order == NO) ? NNO : NO; } 
+  
+  static class DummyMemoryRequestServer implements MemoryRequestServer {
+    @Override
+    public WritableMemory request(long capacityBytes) { return null; }
+    @Override
+    public void requestClose(WritableMemory memToClose, WritableMemory newMemory) { }
+  }
   
   @Test
   public void checkDirectLeafs() throws Exception {
     long off = 0;
     long cap = 128;
-    try (WritableHandle wdh = WritableMemory.allocateDirect(cap)) {
-      WritableMemory memLE = wdh.getWritable();
-      memLE.putShort(0, (short) 1);
-      checkDirect(memLE, off, cap);
+    // Off Heap, Native order, No ByteBuffer, has MemReqSvr
+    try (WritableHandle wdh = WritableMemory.allocateDirect(cap, NO, dummyMemReqSvr)) {
+      WritableMemory memNO = wdh.getWritable();
+      memNO.putShort(0, (short) 1);
+      assertNull(ReflectUtil.getUnsafeObject(memNO));
+      assertTrue(memNO.isDirect());
+      checkCombinations(memNO, off, cap, memNO.isDirect(), NO, false, true);
+    }
+    // Off Heap, Non Native order, No ByteBuffer, has MemReqSvr
+    try (WritableHandle wdh = WritableMemory.allocateDirect(cap, NNO, dummyMemReqSvr)) {
+      WritableMemory memNNO = wdh.getWritable();
+      memNNO.putShort(0, (short) 1);
+      assertNull(ReflectUtil.getUnsafeObject(memNNO));
+      assertTrue(memNNO.isDirect());
+      checkCombinations(memNNO, off, cap, memNNO.isDirect(), NNO, false, true);

Review comment:
       Is the result of ReflectUtil.getUnsafeObject null in both cases because the memory is off-heap?

##########
File path: datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
##########
@@ -363,10 +366,11 @@ void putBooleanArray(boolean[] srcArray, int srcOffsetBooleans,
 
   //OTHER WRITABLE API METHODS
   /**
-   * For Direct Memory only. Other types of backing resources will return null.
-   * Gets the MemoryRequestServer object used by dynamic off-heap (Direct) memory objects
-   * to request additional memory.
-   * Set using {@link WritableMemory#allocateDirect(long, MemoryRequestServer)}.
+   * For ByteBuffer and Direct Memory backed resources only. Heap and Map backed resources will return null.
+   * Gets the MemoryRequestServer object used by dynamic Memory-backed objects
+   * to request additional memory.  To customize the actions of the MemoryRequestServer,
+   * extend the MemoryRequestServer interfact and
+   * set using {@link WritableMemory#allocateDirect(long, ByteOrder, MemoryRequestServer)}.

Review comment:
       Minor: typo in `interfact`.

##########
File path: datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
##########
@@ -446,4 +442,41 @@ static final String toHex(final BaseStateImpl state, final String preamble, fina
     return sb.toString();
   }
 
+  //MONITORING
+
+  /**
+   * Gets the current number of active direct memory allocations.
+   * @return the current number of active direct memory allocations.
+   */
+  public static final long getCurrentDirectMemoryAllocations() {
+    return BaseStateImpl.currentDirectMemoryAllocations_.get();
+  }
+
+  /**
+   * Gets the current size of active direct memory allocated.
+   * @return the current size of active direct memory allocated.
+   */
+  public static final long getCurrentDirectMemoryAllocated() {
+    return BaseStateImpl.currentDirectMemoryAllocated_.get();
+  }
+
+  /**
+   * Gets the current number of active direct memory map allocations.
+   * @return the current number of active direct memory map allocations.
+   */
+  public static final long getCurrentDirectMemoryMapAllocations() {
+    return BaseStateImpl.currentDirectMemoryMapAllocations_.get();
+  }
+
+  /**
+   * Gets the current size of active direct memory map allocated.
+   * @return the current size of active direct memory map allocated.
+   */
+  public static final long getCurrentDirectMemoryMapAllocated() {
+    return BaseStateImpl.currentDirectMemoryMapAllocated_.get();
+  }

Review comment:
       What is the difference between allocated vs allocations?  Is the latter some kind of rate measurement?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org