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

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

commit 98377a9158eecb44bf9ebc5681d34fcdea26d0c2
Author: Lee Rhodes <[email protected]>
AuthorDate: Thu Sep 28 10:56:27 2023 -0700

    Changing ResourceScope to MemoryScope everywhere.
---
 .../apache/datasketches/memory/MemoryScope.java    |  3 +-
 .../internal/AllocateDirectMapMemoryTest.java      | 17 ++++++-----
 .../memory/internal/AllocateDirectMemoryTest.java  | 13 ++++-----
 .../AllocateDirectWritableMapMemoryTest.java       | 17 ++++++-----
 .../memory/internal/BaseBufferTest.java            |  5 ++--
 .../memory/internal/BufferInvariantsTest.java      |  7 ++---
 .../datasketches/memory/internal/BufferTest.java   |  9 +++---
 .../memory/internal/CommonBufferTest.java          | 13 ++++-----
 .../memory/internal/CommonMemoryTest.java          | 15 +++++-----
 .../memory/internal/CopyMemoryOverlapTest.java     |  7 ++---
 .../memory/internal/CopyMemoryTest.java            |  5 ++--
 .../internal/ExampleMemoryRequestServerTest.java   |  7 ++---
 .../memory/internal/IgnoredArrayOverflowTest.java  |  5 ++--
 .../datasketches/memory/internal/LeafImplTest.java | 11 ++++----
 .../memory/internal/MemoryReadWriteSafetyTest.java |  9 +++---
 .../datasketches/memory/internal/MemoryTest.java   | 13 ++++-----
 .../memory/internal/MemoryWriteToTest.java         |  5 ++--
 .../memory/internal/MurmurHash3v3Test.java         |  4 +--
 .../internal/NativeWritableBufferImplTest.java     | 15 +++++-----
 .../internal/NativeWritableMemoryImplTest.java     | 33 +++++++++++-----------
 .../memory/internal/SpecificLeafTest.java          |  7 ++---
 .../memory/internal/WritableDirectCopyTest.java    | 23 ++++++++-------
 .../memory/internal/ZeroCapacityTest.java          |  5 ++--
 23 files changed, 114 insertions(+), 134 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/memory/MemoryScope.java 
b/src/main/java/org/apache/datasketches/memory/MemoryScope.java
index 053c344..a48795b 100644
--- a/src/main/java/org/apache/datasketches/memory/MemoryScope.java
+++ b/src/main/java/org/apache/datasketches/memory/MemoryScope.java
@@ -27,7 +27,7 @@ import 
org.apache.datasketches.memory.internal.MemoryScopeImpl;
 /**
  * A wrapper around jdk.incubator.foreign.ResourceScope
  */
-public abstract class MemoryScope {
+public abstract class MemoryScope implements AutoCloseable {
 
   /**
    * @return a new <i>MemoryScope</i> that wraps a 
<i>ResourceScope.globalScope()</i>.
@@ -86,6 +86,7 @@ public abstract class MemoryScope {
   /**
    * Closes this the underlying <i>ResourceScope</i>.
    */
+  @Override
   public abstract void close();
 
   /**
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 161eb1b..29a1345 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -33,10 +33,9 @@ import java.io.File;
 import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.MemoryScope;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class AllocateDirectMapMemoryTest {
   private static final String LS = System.getProperty("line.separator");
 
@@ -45,7 +44,7 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     file.setReadOnly();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file, scope);
     }
     assertFalse(mem.isAlive());
@@ -55,7 +54,7 @@ public class AllocateDirectMapMemoryTest {
   public void testIllegalArguments() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file, -1, Integer.MAX_VALUE, scope, 
ByteOrder.nativeOrder());
       fail("Failed: test IllegalArgumentException: Position was negative.");
       mem.getCapacity();
@@ -63,7 +62,7 @@ public class AllocateDirectMapMemoryTest {
     catch (IllegalArgumentException e) {
       //ok
     }
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file, 0, -1, scope, ByteOrder.nativeOrder());
       fail("Failed: testIllegalArgumentException: Size was negative.");
     } catch (IllegalArgumentException e) {
@@ -76,7 +75,7 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file, 0, memCapacity, scope, ByteOrder.nativeOrder());
       assertEquals(memCapacity, mem.getCapacity());
       //mem.close(); //a close inside the TWR block will throw excption when 
the TWR block ends
@@ -90,7 +89,7 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file, 0, memCapacity, scope, ByteOrder.nativeOrder());
       mem.load();
       assertTrue(mem.isLoaded());
@@ -102,9 +101,9 @@ public class AllocateDirectMapMemoryTest {
   public void testHandleHandoff() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     Memory mem = Memory.map(file, 0, memCapacity, scope, 
ByteOrder.nativeOrder());
-    ResourceScope.Handle handle = scope.acquire();
+    MemoryScope.Handle handle = scope.acquire();
     try {
       mem.load();
       assertTrue(mem.isLoaded());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
index b22148c..2eaa572 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
@@ -25,11 +25,10 @@ import static org.testng.Assert.assertTrue;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class AllocateDirectMemoryTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -37,9 +36,9 @@ public class AllocateDirectMemoryTest {
   public void simpleAllocateDirect() {
     int longs = 32;
     WritableMemory wMem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wMem = WritableMemory.allocateDirect(longs << 3, scope, memReqSvr);
-      for (int i = 0; i<longs; i++) {
+      for (int i = 0; i < longs; i++) {
         wMem.putLong(i << 3, i);
         assertEquals(wMem.getLong(i << 3), i);
       }
@@ -55,7 +54,7 @@ public class AllocateDirectMemoryTest {
     int longs1 = 32;
     int bytes1 = longs1 << 3;
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.allocateDirect(bytes1, scope, memReqSvr);
 
       for (int i = 0; i < longs1; i++) { //puts data in origWmem
@@ -79,7 +78,7 @@ public class AllocateDirectMemoryTest {
   @Test
   public void checkNonNativeDirect() {
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.allocateDirect( 128, 8, scope,
           BaseState.NON_NATIVE_BYTE_ORDER,
           memReqSvr);
@@ -93,7 +92,7 @@ public class AllocateDirectMemoryTest {
   public void checkExplicitCloseNoTWR() {
     final long cap = 128;
     WritableMemory wmem = null;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     wmem = WritableMemory.allocateDirect(cap, scope, memReqSvr);
     wmem.close(); //explicit close
   }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 1f33854..c7d64ae 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -40,12 +40,11 @@ import java.nio.file.InvalidPathException;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class AllocateDirectWritableMapMemoryTest {
   private static final String LS = System.getProperty("line.separator");
   private final MemoryRequestServer memReqSvr = BaseState.defaultMemReqSvr;
@@ -61,7 +60,7 @@ public class AllocateDirectWritableMapMemoryTest {
       IOException, SecurityException {
     File file = getResourceFile("GettysburgAddress.txt");
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(file,scope);
       byte[] byteArr = new byte[(int)mem.getCapacity()];
       mem.getByteArray(0, byteArr, 0, byteArr.length);
@@ -88,7 +87,7 @@ public class AllocateDirectWritableMapMemoryTest {
     file.deleteOnExit();  //comment out if you want to examine the file.
 
     WritableMemory dstMem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) { //this 
scope manages two Memory objects
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) { //this scope 
manages two Memory objects
       dstMem = WritableMemory.writableMap(file, 0, numBytes, scope, 
ByteOrder.nativeOrder());
 
       WritableMemory srcMem
@@ -121,7 +120,7 @@ public class AllocateDirectWritableMapMemoryTest {
 
     final long bytes = 8;
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.writableMap(file, 0L, bytes, scope, 
BaseState.NON_NATIVE_BYTE_ORDER);
       wmem.putChar(0, (char) 1);
       assertEquals(wmem.getByte(1), (byte) 1);
@@ -134,7 +133,7 @@ public class AllocateDirectWritableMapMemoryTest {
       throws IllegalArgumentException, InvalidPathException, 
IllegalStateException, UnsupportedOperationException,
       IOException, SecurityException {
     File dummy = createFile("dummy.txt", ""); //zero length
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     Memory.map(dummy, 0, dummy.length(), scope, ByteOrder.nativeOrder());
     scope.close();
   }
@@ -147,7 +146,7 @@ public class AllocateDirectWritableMapMemoryTest {
     assertTrue(file.canRead());
     assertFalse(file.canWrite());
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.writableMap(file, scope); //throws 
ReadOnlyException
       wmem.getCapacity();
     }
@@ -159,7 +158,7 @@ public class AllocateDirectWritableMapMemoryTest {
       IOException, SecurityException {
     File file = getResourceFile("GettysburgAddress.txt");
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.writableMap(file, 0, 1 << 20, scope, 
ByteOrder.nativeOrder());
       //throws ReadOnlyException
       wmem.getCapacity();
@@ -180,7 +179,7 @@ public class AllocateDirectWritableMapMemoryTest {
 
     Memory mem = null;
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       mem = Memory.map(origFile, 0, origBytes, scope, ByteOrder.nativeOrder());
       mem.load();
       assertTrue(mem.isLoaded());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
index 73cd01f..38f5594 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
@@ -25,11 +25,10 @@ import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -81,7 +80,7 @@ public class BaseBufferTest {
   public void checkCheckNotAliveAfterTWR() {
     WritableMemory wmem;
     Buffer buf;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       wmem = WritableMemory.allocateDirect(100, scope, memReqSvr);
       buf = wmem.asBuffer();
     }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
index 4b233be..3fe6f89 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
@@ -27,12 +27,11 @@ import java.nio.ByteBuffer;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -165,7 +164,7 @@ public class BufferInvariantsTest {
 
   @Test
   public void checkLimitsDirect() throws Exception {
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(100, scope, 
memReqSvr);
       Buffer buf = wmem.asBuffer();
       buf.setStartPositionEnd(40, 45, 50);
@@ -236,7 +235,7 @@ public class BufferInvariantsTest {
   @Test
   public void testBufDirect() throws Exception {
     int n = 25;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
     WritableMemory wmem = WritableMemory.allocateDirect(n, scope, memReqSvr);
     WritableBuffer buf = wmem.asWritableBuffer();
     for (byte i = 0; i < n; i++) { buf.putByte(i); }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
index c9e58f0..7cbc5ff 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
@@ -29,19 +29,18 @@ import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 import org.testng.collections.Lists;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class BufferTest {
   private final MemoryRequestServer memReqSvr = BaseState.defaultMemReqSvr;
   @Test
   public void checkDirectRoundTrip() throws Exception {
     int n = 1024; //longs
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
     WritableMemory wmem = WritableMemory.allocateDirect(n * 8, scope, 
memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       for (int i = 0; i < n; i++) {
@@ -285,7 +284,7 @@ public class BufferTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkParentUseAfterFree() throws Exception {
     int bytes = 64 * 8;
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
MemoryScope.newConfinedScope(), memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     wbuf.close();
     //with -ea assert: Memory not valid.
@@ -297,7 +296,7 @@ public class BufferTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkRegionUseAfterFree() throws Exception {
     int bytes = 64;
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
MemoryScope.newConfinedScope(), memReqSvr);
     Buffer region = wmem.asBuffer().region();
     region.close();
     //with -ea assert: Memory not valid.
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
index 8d3b519..c739e09 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
@@ -23,18 +23,17 @@ import static org.testng.Assert.assertEquals;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class CommonBufferTest {
   private final MemoryRequestServer memReqSvr = BaseState.defaultMemReqSvr;
   @Test
   public void checkSetGet() throws Exception {
     int memCapacity = 60; //must be at least 60
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
@@ -136,7 +135,7 @@ public class CommonBufferTest {
   @Test
   public void checkSetGetArrays() throws Exception {
     int memCapacity = 32;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
@@ -221,7 +220,7 @@ public class CommonBufferTest {
   @Test
   public void checkSetGetPartialArraysWithOffset() throws Exception {
     int memCapacity = 32;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
@@ -306,7 +305,7 @@ public class CommonBufferTest {
   @Test
   public void checkSetClearMemoryRegions() throws Exception {
     int memCapacity = 64; //must be 64
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
@@ -395,7 +394,7 @@ public class CommonBufferTest {
   @Test
   public void checkToHexStringAllMem() throws Exception {
     int memCapacity = 48; //must be 48
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
index 9245a59..183ac66 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
@@ -29,17 +29,16 @@ import static org.testng.Assert.assertTrue;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class CommonMemoryTest {
   private final MemoryRequestServer memReqSvr = BaseState.defaultMemReqSvr;
   @Test
   public void checkSetGet() throws Exception {
     int memCapacity = 16; //must be at least 8
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       assertEquals(mem.getCapacity(), memCapacity);
       setGetTests(mem);
@@ -91,7 +90,7 @@ public class CommonMemoryTest {
   @Test
   public void checkSetGetArrays() throws Exception {
     int memCapacity = 32;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       setGetArraysTests(mem);
@@ -161,7 +160,7 @@ public class CommonMemoryTest {
   @Test
   public void checkSetGetPartialArraysWithOffset() throws Exception {
     int memCapacity = 32;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       setGetPartialArraysWithOffsetTests(mem);
@@ -231,7 +230,7 @@ public class CommonMemoryTest {
   @Test
   public void checkSetClearIsBits() throws Exception {
     int memCapacity = 8;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       mem.clear();
@@ -272,7 +271,7 @@ public class CommonMemoryTest {
   @Test
   public void checkSetClearMemoryRegions() throws Exception {
     int memCapacity = 64; //must be 64
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       setClearMemoryRegionsTests(mem); //requires println enabled to visually 
check
@@ -343,7 +342,7 @@ public class CommonMemoryTest {
   @Test
   public void checkToHexStringAllMem() throws Exception {
     int memCapacity = 48; //must be 48
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       toHexStringAllMemTests(mem); //requires println enabled to visually check
     }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
index 8a4bdc0..8596ee7 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
@@ -24,11 +24,10 @@ import static org.testng.Assert.assertEquals;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -96,7 +95,7 @@ public class CopyMemoryOverlapTest {
     println("CopyUp       : " + copyUp);
     println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, 
scope, memReqSvr);
       fill(backingMem); //fill mem with 0 thru copyLongs -1
       //listMem(backingMem, "Original");
@@ -136,7 +135,7 @@ public class CopyMemoryOverlapTest {
     println("CopyUp       : " + copyUp);
     println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, 
scope, memReqSvr);
       fill(backingMem); //fill mem with 0 thru copyLongs -1
       //listMem(backingMem, "Original");
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
index f0af8c4..8b54fef 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
@@ -26,12 +26,11 @@ import java.util.concurrent.ThreadLocalRandom;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class CopyMemoryTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -151,7 +150,7 @@ public class CopyMemoryTest {
 
   @SuppressWarnings("resource")
   private static WritableMemory genWmem(int longs, boolean empty) {
-    WritableMemory wmem = WritableMemory.allocateDirect(longs << 3, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(longs << 3, 
MemoryScope.newConfinedScope(), memReqSvr);
     if (empty) {
       wmem.clear();
     } else {
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
index eacc079..7fe98e7 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
@@ -22,11 +22,10 @@ package org.apache.datasketches.memory.internal;
 import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * Examples of how to use the MemoryRequestServer with a memory hungry client.
  * @author Lee Rhodes
@@ -44,7 +43,7 @@ public class ExampleMemoryRequestServerTest {
     int bytes = 8;
     ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer(true);
     WritableMemory memStart = null;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     memStart = WritableMemory.allocateDirect(bytes, 8, scope, 
ByteOrder.nativeOrder(), svr);
     MemoryClient client = new MemoryClient(memStart);
     client.process();
@@ -107,7 +106,7 @@ public class ExampleMemoryRequestServerTest {
      ByteOrder order = currentWMem.getByteOrder();
      WritableMemory wmem;
      if (offHeap) {
-       wmem = WritableMemory.allocateDirect(newCapacityBytes, 8, 
ResourceScope.newConfinedScope(), order, this);
+       wmem = WritableMemory.allocateDirect(newCapacityBytes, 8, 
MemoryScope.newConfinedScope(), order, this);
      } else {
        if (newCapacityBytes > Integer.MAX_VALUE) {
          throw new IllegalArgumentException("Requested capacity exceeds 
Integer.MAX_VALUE.");
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
index c9d3b4b..7018875 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
@@ -23,13 +23,12 @@ import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class IgnoredArrayOverflowTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -39,7 +38,7 @@ public class IgnoredArrayOverflowTest {
   @SuppressWarnings("resource")
   @BeforeClass
   public void allocate() {
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     memory = WritableMemory.allocateDirect(MAX_SIZE, 8L, scope, 
ByteOrder.nativeOrder(), memReqSvr);
   }
 
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
index 8105dc6..4682023 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -30,12 +30,11 @@ import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -60,14 +59,14 @@ public class LeafImplTest {
     long off = 0;
     long cap = 128;
     // Off Heap, Native order, No ByteBuffer, has MemReqSvr
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory memNO = WritableMemory.allocateDirect(cap, 8, scope, NBO, 
dummyMemReqSvr);
       memNO.putShort(0, (short) 1);
       assertTrue(memNO.isDirect());
       checkCombinations(memNO, off, cap, memNO.isDirect(), NBO, false, true);
     }
     // Off Heap, Non Native order, No ByteBuffer, has MemReqSvr
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory memNNO = WritableMemory.allocateDirect(cap, 8, scope, 
NNBO, dummyMemReqSvr);
       memNNO.putShort(0, (short) 1);
       assertTrue(memNNO.isDirect());
@@ -129,14 +128,14 @@ public class LeafImplTest {
     assertTrue(file.isFile());
     file.deleteOnExit();  //comment out if you want to examine the file.
     // Off Heap, Native order, No ByteBuffer, No MemReqSvr
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory memNO = WritableMemory.writableMap(file, off, cap, scope, 
NBO);
       memNO.putShort(0, (short) 1);
       assertTrue(memNO.isDirect());
       checkCombinations(memNO, off, cap, memNO.isDirect(), NBO, false, false);
     }
     // Off heap, Non Native order, No ByteBuffer, no MemReqSvr
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory memNNO = WritableMemory.writableMap(file, off, cap, 
scope, NNBO);
       memNNO.putShort(0, (short) 1);
       assertTrue(memNNO.isDirect());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
index 0b3b8fb..9c4d519 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
@@ -26,11 +26,10 @@ import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class MemoryReadWriteSafetyTest {
 
   // Test various operations with read-only Memory
@@ -183,7 +182,7 @@ public class MemoryReadWriteSafetyTest {
     try (RandomAccessFile raf = new RandomAccessFile(tempFile, "rw")) {
       raf.setLength(8);
       //System.out.println(UtilTest.getFileAttributes(tempFile));
-      try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+      try (MemoryScope scope = MemoryScope.newConfinedScope()) {
         Memory mem = Memory.map(tempFile, scope);
         ((WritableMemory) mem).putInt(0, 1);
       }
@@ -196,7 +195,7 @@ public class MemoryReadWriteSafetyTest {
     File tempFile = File.createTempFile("test", "test");
     tempFile.deleteOnExit();
     new RandomAccessFile(tempFile, "rw").setLength(8);
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       Memory mem = Memory.map(tempFile, 0, 4, scope, ByteOrder.nativeOrder());
       ((WritableMemory) mem).putInt(0, 1);
     }
@@ -208,7 +207,7 @@ public class MemoryReadWriteSafetyTest {
     tempFile.deleteOnExit();
     try (RandomAccessFile raf = new RandomAccessFile(tempFile, "rw")) {
       raf.setLength(8);
-      try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+      try (MemoryScope scope = MemoryScope.newConfinedScope()) {
         Memory.map(tempFile, 0, 16, scope, ByteOrder.nativeOrder());
       }
     }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index 85e3663..aea25ee 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -37,14 +37,13 @@ import java.util.List;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 import org.testng.collections.Lists;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class MemoryTest {
   private static final String LS = System.getProperty("line.separator");
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
@@ -58,7 +57,7 @@ public class MemoryTest {
   @Test
   public void checkDirectRoundTrip() throws Exception {
     int n = 1024; //longs
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(n * 8, scope, 
memReqSvr);
       for (int i = 0; i < n; i++) {
         mem.putLong(i * 8, i);
@@ -355,7 +354,7 @@ public class MemoryTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkParentUseAfterFree() throws Exception {
     int bytes = 64 * 8;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
     wmem.close();
     //with -ea assert: Memory not valid.
@@ -367,7 +366,7 @@ public class MemoryTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkRegionUseAfterFree() throws Exception {
     int bytes = 64;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
     Memory region = wmem.region(0L, bytes);
     wmem.close();
@@ -387,7 +386,7 @@ public class MemoryTest {
     wbuf = wmem.asWritableBuffer();
     assertNull(wbuf.getMemoryRequestServer());
     //OFF HEAP
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
        wmem = WritableMemory.allocateDirect(16, scope, memReqSvr);  //OFF HEAP
       assertNotNull(wmem.getMemoryRequestServer());
       wbuf = wmem.asWritableBuffer();
@@ -406,7 +405,7 @@ public class MemoryTest {
     wbuf = wmem.asWritableBuffer();
     assertNotNull(wbuf.getMemoryRequestServer());
     //OFF HEAP
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem2 = WritableMemory.allocateDirect(16, scope, 
memReqSvr);
       assertNotNull(wmem2.getMemoryRequestServer());
       wbuf = wmem.asWritableBuffer();
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
index f995154..a3ea973 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
@@ -29,11 +29,10 @@ import java.util.concurrent.ThreadLocalRandom;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class MemoryWriteToTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -59,7 +58,7 @@ public class MemoryWriteToTest {
 
   @Test
   public void testOffHeap() throws Exception {
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(((1 << 20) * 5) + 10, 
scope, memReqSvr);
       testWriteTo(mem.region(0, 0));
       testOffHeap(mem, 7);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java 
b/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
index 3d4ce07..b8e0c83 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
@@ -26,12 +26,12 @@ import static org.testng.Assert.fail;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import jdk.incubator.foreign.MemorySegment;
-import jdk.incubator.foreign.ResourceScope;
 
 /**
  * Tests the MurmurHash3 against specific, known hash results given known
@@ -274,7 +274,7 @@ public class MurmurHash3v3Test {
       Memory mem = Memory.wrap(new byte[0]);
       out = hash(mem, 0L, 4L, 1L, out);
     } catch (final IllegalArgumentException e) { }
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       Memory mem = WritableMemory.allocateDirect(8, scope, memReqSvr);
       long[] out = new long[2];
       out = hash(mem, 0L, 4L, 1L, out);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index 42ee82d..1e7104c 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -31,13 +31,12 @@ import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class NativeWritableBufferImplTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -47,7 +46,7 @@ public class NativeWritableBufferImplTest {
   @Test
   public void checkNativeCapacityAndClose() throws Exception {
     int memCapacity = 64;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     assertEquals(wbuf.getCapacity(), memCapacity);
@@ -188,7 +187,7 @@ public class NativeWritableBufferImplTest {
   @Test
   public void checkNativeBaseBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       wbuf.toHexString("Force Assertion Error", memCapacity, 8, false);
@@ -200,7 +199,7 @@ public class NativeWritableBufferImplTest {
   @Test
   public void checkNativeSrcArrayBound() throws Exception {
     long memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       byte[] srcArray = { 1, -2, 3, -4 };
@@ -213,7 +212,7 @@ public class NativeWritableBufferImplTest {
   @Test(expectedExceptions = IndexOutOfBoundsException.class)
   public void checkRegionBounds() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       wbuf.writableRegion(1, 64, wbuf.getByteOrder()); //wrong!
@@ -329,7 +328,7 @@ public class NativeWritableBufferImplTest {
     int memCapacity = 64;
     WritableBuffer mem = 
WritableMemory.allocate(memCapacity).asWritableBuffer();
     assertFalse(mem.isDirect());
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     assertTrue(wbuf.isDirect());
@@ -384,7 +383,7 @@ public class NativeWritableBufferImplTest {
     byte[] arr1 = new byte[] {0, 1, 2, 3};
     byte[] arr2 = new byte[] {0, 1, 2, 4};
     byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(4, scope, memReqSvr);
       WritableMemory mem2 = WritableMemory.allocateDirect(4, scope, memReqSvr);
       WritableMemory mem3 = WritableMemory.allocateDirect(5, scope, memReqSvr);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index e2adeff..653f5a2 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -31,12 +31,11 @@ import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableBuffer;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 public class NativeWritableMemoryImplTest {
   private static final MemoryRequestServer memReqSvr = 
BaseState.defaultMemReqSvr;
 
@@ -46,7 +45,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkNativeCapacityAndClose() throws Exception {
     int memCapacity = 64;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
     assertEquals(memCapacity, wmem.getCapacity());
 
@@ -187,7 +186,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkNativeBaseBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.toHexString("Force Assertion Error", memCapacity, 8, false);
     } catch (IllegalArgumentException e) {
@@ -198,7 +197,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkNativeSrcArrayBound() throws Exception {
     long memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       byte[] srcArray = { 1, -2, 3, -4 };
       wmem.putByteArray(0L, srcArray, 0, 5);
@@ -219,7 +218,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyWithinNativeSmall() throws Exception {
     int memCapacity = 64;
     int half = memCapacity/2;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.clear();
 
@@ -241,7 +240,7 @@ public class NativeWritableMemoryImplTest {
     int memCapLongs = memCapacity / 8;
     int halfBytes = memCapacity / 2;
     int halfLongs = memCapLongs / 2;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.clear();
 
@@ -260,7 +259,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkCopyWithinNativeSrcBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.copyTo(32, wmem, 32, 33);  //hit source bound check
       fail("Did Not Catch Assertion Error: source bound");
@@ -273,7 +272,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkCopyWithinNativeDstBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.copyTo(0, wmem, 32, 33);  //hit dst bound check
       fail("Did Not Catch Assertion Error: dst bound");
@@ -287,7 +286,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyCrossNativeSmall() throws Exception {
     int memCapacity = 64;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
@@ -308,7 +307,7 @@ public class NativeWritableMemoryImplTest {
     int memCapacity = (2<<20) + 64;
     int memCapLongs = memCapacity / 8;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
@@ -328,7 +327,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkCopyCrossNativeAndByteArray() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i= 0; i < wmem.getCapacity(); i++) {
@@ -349,7 +348,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyCrossRegionsSameNative() throws Exception {
     int memCapacity = 128;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i= 0; i < wmem1.getCapacity(); i++) {
@@ -375,7 +374,7 @@ public class NativeWritableMemoryImplTest {
   @Test
   public void checkCopyCrossNativeArrayAndHierarchicalRegions() throws 
Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i= 0; i < wmem1.getCapacity(); i++) { //fill with numbers
@@ -405,7 +404,7 @@ public class NativeWritableMemoryImplTest {
   @Test(expectedExceptions = IndexOutOfBoundsException.class)
   public void checkRegionBounds() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       wmem.writableRegion(1, 64);
     }
@@ -517,7 +516,7 @@ public class NativeWritableMemoryImplTest {
     int memCapacity = 64;
     WritableMemory mem = WritableMemory.allocate(memCapacity);
     assertFalse(mem.isDirect());
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       assertTrue(wmem.isDirect());
     }
@@ -578,7 +577,7 @@ public class NativeWritableMemoryImplTest {
     byte[] arr2 = new byte[] {0, 1, 2, 4};
     byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(4, scope, memReqSvr);
       WritableMemory mem2 = WritableMemory.allocateDirect(4, scope, memReqSvr);
       WritableMemory mem3 = WritableMemory.allocateDirect(5, scope, memReqSvr);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 962097d..4dfb11f 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -32,11 +32,10 @@ import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -74,7 +73,7 @@ public class SpecificLeafTest {
   @Test
   public void checkDirectLeafs() throws Exception {
     int bytes = 128;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
       assertFalse(((BaseStateImpl)wmem).isReadOnly());
       assertTrue(wmem.isDirect());
@@ -112,7 +111,7 @@ public class SpecificLeafTest {
     file.deleteOnExit();  //comment out if you want to examine the file.
 
     final long bytes = 128;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.writableMap(file, 0L, bytes, scope, 
ByteOrder.nativeOrder());
       assertTrue(mem.isMapped());
       assertFalse(mem.isReadOnly());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
index 0c3afab..0092ce5 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
@@ -25,11 +25,10 @@ import static org.testng.Assert.fail;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -42,7 +41,7 @@ public class WritableDirectCopyTest {
   public void checkCopyWithinNativeSmall() throws Exception {
     int memCapacity = 64;
     int half = memCapacity / 2;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       mem.clear();
 
@@ -64,7 +63,7 @@ public class WritableDirectCopyTest {
     int memCapLongs = memCapacity / 8;
     int halfBytes = memCapacity / 2;
     int halfLongs = memCapLongs / 2;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       mem.clear();
 
@@ -83,7 +82,7 @@ public class WritableDirectCopyTest {
   @Test
   public void checkCopyWithinNativeOverlap() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       mem.clear();
       //println(mem.toHexString("Clear 64", 0, memCapacity));
@@ -99,7 +98,7 @@ public class WritableDirectCopyTest {
   @Test
   public void checkCopyWithinNativeSrcBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       mem.copyTo(32, mem, 32, 33);  //hit source bound check
       fail("Did Not Catch Assertion Error: source bound");
@@ -111,7 +110,7 @@ public class WritableDirectCopyTest {
   @Test
   public void checkCopyWithinNativeDstBound() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       mem.copyTo(0, mem, 32, 33);  //hit dst bound check
       fail("Did Not Catch Assertion Error: dst bound");
@@ -124,7 +123,7 @@ public class WritableDirectCopyTest {
   public void checkCopyCrossNativeSmall() throws Exception {
     int memCapacity = 64;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
@@ -145,7 +144,7 @@ public class WritableDirectCopyTest {
     int memCapacity = (2 << 20) + 64;
     int memCapLongs = memCapacity / 8;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
       WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
@@ -165,7 +164,7 @@ public class WritableDirectCopyTest {
   @Test
   public void checkCopyCrossNativeAndByteArray() throws Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) {
@@ -186,7 +185,7 @@ public class WritableDirectCopyTest {
   public void checkCopyCrossRegionsSameNative() throws Exception {
     int memCapacity = 128;
 
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) {
@@ -212,7 +211,7 @@ public class WritableDirectCopyTest {
   @Test
   public void checkCopyCrossNativeArrayAndHierarchicalRegions() throws 
Exception {
     int memCapacity = 64;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
+    try (MemoryScope scope = MemoryScope.newConfinedScope()) {
       WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) { //fill with numbers
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
index e54b6d9..d8ce4ab 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
@@ -26,12 +26,11 @@ import java.nio.ByteBuffer;
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.MemoryScope;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import jdk.incubator.foreign.ResourceScope;
-
 /**
  * @author Lee Rhodes
  */
@@ -49,7 +48,7 @@ public class ZeroCapacityTest {
     Memory mem3 = Memory.wrap(ByteBuffer.allocateDirect(0));
     mem3.region(0, 0);
     WritableMemory nullMem = null;
-    ResourceScope scope = ResourceScope.newConfinedScope();
+    MemoryScope scope = MemoryScope.newConfinedScope();
     try { //Invalid allocation size : 0
       nullMem = WritableMemory.allocateDirect(0, scope, memReqSvr);
       Assert.fail();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to