You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2025/06/17 00:25:50 UTC

(datasketches-java) branch thetaRework updated: Remove use of aligned heap segments. Consider in the future.

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch thetaRework
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git


The following commit(s) were added to refs/heads/thetaRework by this push:
     new e0a9710eb Remove use of aligned heap segments.  Consider in the future.
e0a9710eb is described below

commit e0a9710ebde3030f6a40d1a134058c6e40250e6e
Author: Lee Rhodes <le...@gmail.com>
AuthorDate: Mon Jun 16 16:54:17 2025 -0700

    Remove use of aligned heap segments.  Consider in the future.
---
 src/main/java/org/apache/datasketches/common/Util.java         |  4 ++--
 .../apache/datasketches/theta2/DirectQuickSelectSketch.java    | 10 +---------
 .../org/apache/datasketches/theta2/BackwardConversions.java    |  2 +-
 3 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/common/Util.java b/src/main/java/org/apache/datasketches/common/Util.java
index 4701ddf9e..493ad7879 100644
--- a/src/main/java/org/apache/datasketches/common/Util.java
+++ b/src/main/java/org/apache/datasketches/common/Util.java
@@ -909,7 +909,7 @@ public final class Util {
   }
 
   /**
-   * Request a new heap MemorySegment with the given capacityBytes and 8-byte aligned or one byte aligned.
+   * Request a new heap MemorySegment with the given capacityBytes and either 8-byte aligned or one byte aligned.
    *
    * <p>If <i>aligned</i> is true, the returned MemorySegment will be constructed from a <i>long[]</i> array,
    * and, as a result, it will have a memory alignment of 8 bytes.
@@ -923,7 +923,7 @@ public final class Util {
    * @param aligned if true, the new heap segment will have an alignment of 8 bytes, otherwise the alignment will be 1 byte.
    * @return a new MemorySegment with the requested capacity and alignment.
    */
-  public static MemorySegment newHeapSegment(final int capacityBytes, final boolean aligned) {
+  public static MemorySegment alignedHeapSegment(final int capacityBytes, final boolean aligned) {
     if (aligned) {
       final int lenLongs = capacityBytes >>> 3;
       final long[] array = ((capacityBytes & 0x7) == 0)
diff --git a/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketch.java b/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketch.java
index 193385a1f..213dd7f4a 100644
--- a/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketch.java
+++ b/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketch.java
@@ -24,7 +24,6 @@ import static java.lang.foreign.ValueLayout.JAVA_FLOAT_UNALIGNED;
 import static java.lang.foreign.ValueLayout.JAVA_INT_UNALIGNED;
 import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED;
 import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
-import static org.apache.datasketches.common.Util.newHeapSegment;
 import static org.apache.datasketches.theta2.PreambleUtil.EMPTY_FLAG_MASK;
 import static org.apache.datasketches.theta2.PreambleUtil.FLAGS_BYTE;
 import static org.apache.datasketches.theta2.PreambleUtil.PREAMBLE_LONGS_BYTE;
@@ -316,14 +315,7 @@ class DirectQuickSelectSketch extends DirectQuickSelectSketchR {
           tgtLgArrLongs = Math.min(lgArrLongs + lgRF, lgNomLongs + 1);
           final int tgtArrBytes = 8 << tgtLgArrLongs;
           final int reqBytes = tgtArrBytes + preBytes;
-
-          //memReqSvr_ = (memReqSvr_ == null) ? wseg_.getMemoryRequestServer() : memReqSvr_;
-          //if (memReqSvr_ == null) { //in case the MRS is not enabled or null.
-          //  throw new SketchesArgumentException("Out of Memory, MemoryRequestServer is null, cannot expand.");
-          //}
-          //final MemorySegment newDstSeg = memReqSvr_.request(wseg_, reqBytes);
-
-          final MemorySegment newDstSeg = newHeapSegment(reqBytes, false);
+          final MemorySegment newDstSeg = MemorySegment.ofArray(new byte[reqBytes]);
 
           moveAndResize(wseg_, preambleLongs, lgArrLongs, newDstSeg, tgtLgArrLongs, thetaLong);
           wseg_ = newDstSeg;
diff --git a/src/test/java/org/apache/datasketches/theta2/BackwardConversions.java b/src/test/java/org/apache/datasketches/theta2/BackwardConversions.java
index bec67b219..74aec9bb8 100644
--- a/src/test/java/org/apache/datasketches/theta2/BackwardConversions.java
+++ b/src/test/java/org/apache/datasketches/theta2/BackwardConversions.java
@@ -220,7 +220,7 @@ public class BackwardConversions {
     final int entries = skV3.getRetainedEntries(true);
     final boolean unordered = !(skV3.isOrdered());
     final byte flags = (byte) (0xA | (unordered ? 16 : 0)); //Unordered, NoRebuild, notEmpty, ReadOnly, LE
-    wseg = Util.newHeapSegment((preLongs + entries) << 3, false);
+    wseg = MemorySegment.ofArray(new byte[(preLongs + entries) << 3]);
     wseg.set(JAVA_BYTE, 0, (byte) preLongs); //preLongs
     wseg.set(JAVA_BYTE, 1, (byte) 2); //SerVer
     wseg.set(JAVA_BYTE, 2, (byte) 3); //SetSketch


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