You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by dc...@apache.org on 2021/05/11 21:20:39 UTC
[datasketches-memory] 01/01: Merge noSplitPackage into
multi-release branch
This is an automated email from the ASF dual-hosted git repository.
dcromberge pushed a commit to branch multi-module-experimental
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit ee21b6ed2d0c210b7eef2f89eed28db4a12fb771
Merge: e5af17d 9ac70eb
Author: David Cromberge <da...@gmail.com>
AuthorDate: Tue May 11 22:20:23 2021 +0100
Merge noSplitPackage into multi-release branch
.../apache/datasketches/memory/AllocateDirect.java | 2 +-
.../datasketches/memory/AllocateDirectMap.java | 11 +-
.../memory/BBNonNativeWritableBufferImpl.java | 4 +-
.../memory/BBNonNativeWritableMemoryImpl.java | 4 +-
.../datasketches/memory/BBWritableBufferImpl.java | 4 +-
.../datasketches/memory/BBWritableMemoryImpl.java | 4 +-
.../org/apache/datasketches/memory/BaseState.java | 23 +-
.../memory/BaseWritableBufferImpl.java | 2 +-
.../memory/BaseWritableMemoryImpl.java | 12 +-
.../apache/datasketches/memory/CompareAndCopy.java | 13 +-
.../memory/DirectNonNativeWritableBufferImpl.java | 11 +-
.../memory/DirectNonNativeWritableMemoryImpl.java | 11 +-
.../memory/DirectWritableBufferImpl.java | 10 +-
.../memory/DirectWritableMemoryImpl.java | 6 +-
.../memory/HeapNonNativeWritableBufferImpl.java | 4 +-
.../memory/HeapNonNativeWritableMemoryImpl.java | 4 +-
.../memory/HeapWritableBufferImpl.java | 4 +-
.../memory/HeapWritableMemoryImpl.java | 4 +-
.../java/org/apache/datasketches/memory/Ints.java | 4 +-
.../apache/datasketches/memory/JDK7Compatible.java | 26 +-
.../memory/MapNonNativeWritableBufferImpl.java | 11 +-
.../memory/MapNonNativeWritableMemoryImpl.java | 11 +-
.../datasketches/memory/MapWritableBufferImpl.java | 11 +-
.../datasketches/memory/MapWritableMemoryImpl.java | 11 +-
.../org/apache/datasketches/memory/Memory.java | 16 +-
.../org/apache/datasketches/memory/NioBits.java | 2 +-
.../java/org/apache/datasketches/memory/Prim.java | 8 +-
.../apache/datasketches/memory/StepBoolean.java | 10 +-
.../org/apache/datasketches/memory/UnsafeUtil.java | 8 +-
.../java/org/apache/datasketches/memory/Util.java | 49 +++-
.../apache/datasketches/memory/WritableMemory.java | 25 +-
.../memory/{ => test}/internal/MemoryCleaner.java | 2 +-
.../{ => test}/internal/VirtualMachineMemory.java | 2 +-
.../apache/datasketches/memory/NioBitsTest.java | 79 ------
.../datasketches/memory/SpecificLeafTest.java | 186 --------------
.../{ => test}/AllocateDirectMapMemoryTest.java | 4 +-
.../{ => test}/AllocateDirectMemoryTest.java | 79 ++++--
.../AllocateDirectWritableMapMemoryTest.java | 58 +++--
.../memory/{ => test}/BaseBufferTest.java | 6 +-
.../memory/{ => test}/BaseStateTest.java | 32 ++-
.../memory/{ => test}/Buffer2Test.java | 7 +-
.../memory/{ => test}/BufferBoundaryCheckTest.java | 3 +-
.../memory/{ => test}/BufferInvariantsTest.java | 6 +-
.../{ => test}/BufferReadWriteSafetyTest.java | 6 +-
.../datasketches/memory/{ => test}/BufferTest.java | 7 +-
.../memory/{ => test}/CommonBufferTest.java | 5 +-
.../memory/{ => test}/CommonMemoryTest.java | 4 +-
.../memory/{ => test}/CopyMemoryOverlapTest.java | 5 +-
.../memory/{ => test}/CopyMemoryTest.java | 7 +-
.../{ => test}/ExampleMemoryRequestServerTest.java | 5 +-
.../{ => test}/IgnoredArrayOverflowTest.java | 4 +-
.../memory/{ => test}/IsValidUtf8TestUtil.java | 2 +-
.../memory/{ => test}/LeafImplTest.java | 120 +++++----
.../memory/{ => test}/MemoryBoundaryCheckTest.java | 4 +-
.../{ => test}/MemoryReadWriteSafetyTest.java | 6 +-
.../datasketches/memory/{ => test}/MemoryTest.java | 79 ++++--
.../memory/{ => test}/MemoryWriteToTest.java | 20 +-
.../datasketches/memory/test/NioBitsTest.java | 166 ++++++++++++
.../NonNativeWritableBufferImplTest.java | 5 +-
.../NonNativeWritableMemoryImplTest.java | 4 +-
.../datasketches/memory/test/ReflectUtil.java | 139 +++++++++++
.../datasketches/memory/test/SpecificLeafTest.java | 278 +++++++++++++++++++++
.../memory/{ => test}/UnsafeUtilTest.java | 20 +-
.../datasketches/memory/{ => test}/Utf8Test.java | 6 +-
.../datasketches/memory/{ => test}/UtilTest.java | 5 +-
.../memory/{ => test}/WritableBufferImplTest.java | 12 +-
.../memory/{ => test}/WritableDirectCopyTest.java | 5 +-
.../memory/{ => test}/WritableMemoryImplTest.java | 12 +-
.../memory/{ => test}/WritableMemoryTest.java | 13 +-
.../memory/{ => test}/XxHash64LoopingTest.java | 3 +-
.../memory/{ => test}/XxHash64Test.java | 4 +-
.../memory/{ => test}/ZeroCapacityTest.java | 4 +-
.../{ => test}/internal/MemoryCleanerTest.java | 2 +-
.../internal/VirtualMachineMemoryTest.java | 2 +-
.../datasketches/memory/test/package-info.java | 9 +-
.../memory/java9/tests/MemoryCleanerTest.java | 2 +-
.../java9/tests/VirtualMachineMemoryTest.java | 2 +-
.../src/main/java/module-info.java | 2 +-
.../memory/{ => test}/internal/MemoryCleaner.java | 2 +-
.../{ => test}/internal/VirtualMachineMemory.java | 2 +-
80 files changed, 1183 insertions(+), 579 deletions(-)
diff --cc datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
index 27211d9,b031ce0..a3fb6d9
--- a/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
+++ b/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
@@@ -19,11 -19,12 +19,11 @@@
package org.apache.datasketches.memory;
- import org.apache.datasketches.memory.internal.MemoryCleaner;
-import static org.apache.datasketches.memory.UnsafeUtil.unsafe;
++import org.apache.datasketches.memory.test.internal.MemoryCleaner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.apache.datasketches.memory.UnsafeUtil.unsafe;
-import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
+import java.util.logging.Logger;
/**
* Provides access to direct (native) memory.
diff --cc datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
index 7d65394,25bfef7..7b25cf8
--- a/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
+++ b/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
@@@ -29,10 -29,11 +29,10 @@@ import java.lang.reflect.InvocationTarg
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
+import java.util.logging.Logger;
- import org.apache.datasketches.memory.internal.MemoryCleaner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
++import org.apache.datasketches.memory.test.internal.MemoryCleaner;
-import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
import sun.nio.ch.FileChannelImpl;
/**
diff --cc datasketches-memory-base/src/main/java/org/apache/datasketches/memory/NioBits.java
index 61b67e7,a089a30..a7182f4
--- a/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/NioBits.java
+++ b/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/NioBits.java
@@@ -19,8 -19,6 +19,8 @@@
package org.apache.datasketches.memory;
- import org.apache.datasketches.memory.internal.VirtualMachineMemory;
++import org.apache.datasketches.memory.test.internal.VirtualMachineMemory;
+
import static org.apache.datasketches.memory.UnsafeUtil.unsafe;
import java.lang.reflect.Field;
diff --cc datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
index 4be7abb,0000000..93587f2
mode 100644,000000..100644
--- a/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
+++ b/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
@@@ -1,53 -1,0 +1,53 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
- package org.apache.datasketches.memory.internal;
++package org.apache.datasketches.memory.test.internal;
+
+import sun.misc.Cleaner;
+
+/**
+ * Extracts a version-dependent reference to the `sun.misc.Cleaner` into
+ * a standalone class. The package name for Cleaner has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ *
+ * For more information, see:
+ * https://openjdk.java.net/jeps/238
+ */
+public class MemoryCleaner {
+ private final Cleaner cleaner;
+
+ /**
+ * Creates a new `sun.misc.Cleaner`.
+ * @param referent the object to be cleaned
+ * @param deallocator - the cleanup code to be run when the cleaner is invoked.
+ * return MemoryCleaner
+ */
+ public MemoryCleaner(Object referent, Runnable deallocator) {
+ cleaner = Cleaner.create(referent, deallocator);
+ }
+
+ /**
+ * Runs this cleaner, if it has not been run before.
+ */
+ public void clean() {
+ cleaner.clean();
+ }
+}
+
diff --cc datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
index c61a638,0000000..ef8c9db
mode 100644,000000..100644
--- a/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
+++ b/datasketches-memory-base/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
@@@ -1,72 -1,0 +1,72 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
- package org.apache.datasketches.memory.internal;
++package org.apache.datasketches.memory.test.internal;
+
+import java.lang.reflect.Method;
+
+/**
+ * Extracts a version-dependent reference to the `sun.misc.VM` into a standalone
+ * class. The package name for VM has changed in later versions. The appropriate
+ * class will be loaded by the class loader depending on the Java version that
+ * is used.
+ * For more information, see: https://openjdk.java.net/jeps/238
+ */
+public final class VirtualMachineMemory {
+
+ private static final Class<?> VM_CLASS;
+ private static final Method VM_MAX_DIRECT_MEMORY_METHOD;
+ private static final Method VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD;
+ private static final long maxDBBMemory;
+ private static final boolean isPageAligned;
+
+ static {
+ try {
+ VM_CLASS = Class.forName("sun.misc.VM");
+ VM_MAX_DIRECT_MEMORY_METHOD = VM_CLASS.getDeclaredMethod("maxDirectMemory");
+ VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
+ maxDBBMemory = (long) VM_MAX_DIRECT_MEMORY_METHOD.invoke(null); // static method
+
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD = VM_CLASS.getDeclaredMethod("isDirectMemoryPageAligned");
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.setAccessible(true);
+ isPageAligned = (boolean) VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.invoke(null); // static method
+ } catch (final Exception e) {
+ throw new RuntimeException("Could not acquire sun.misc.VM: " + e.getClass());
+ }
+ }
+
+ /**
+ * Returns the maximum amount of allocatable direct buffer memory. The
+ * directMemory variable is initialized during system initialization.
+ *
+ * @return the maximum amount of allocatable direct buffer memory.
+ */
+ public static long getMaxDBBMemory() {
+ return maxDBBMemory;
+ }
+
+ /**
+ * Returns true if the direct buffers should be page aligned.
+ *
+ * @return flag that determines whether direct buffers should be page aligned.
+ */
+ public static boolean getIsPageAligned() {
+ return isPageAligned;
+ }
+}
diff --cc datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
index 0000000,f6b7710..f6b7710
mode 000000,100644..100644
--- a/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
+++ b/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
diff --cc datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
index 0000000,fc6333c..fc6333c
mode 000000,100644..100644
--- a/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
+++ b/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
diff --cc datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
index 0000000,72cbd01..72cbd01
mode 000000,100644..100644
--- a/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
+++ b/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
diff --cc datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/MemoryCleanerTest.java
index 231f8c5,0000000..5ebe603
mode 100644,000000..100644
--- a/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/MemoryCleanerTest.java
+++ b/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/MemoryCleanerTest.java
@@@ -1,63 -1,0 +1,63 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
- package org.apache.datasketches.memory.internal;
++package org.apache.datasketches.memory.test.internal;
+
+import org.testng.annotations.Test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+@SuppressWarnings("javadoc")
+public class MemoryCleanerTest {
+
+ @Test
+ public void cleanerDeallocates() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ cleaner.clean();
+ assertTrue(deallocator.getHasRun());
+ }
+
+ @Test
+ public void noDeallocation() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ assertFalse(deallocator.getHasRun());
+ }
+
+ private static final class SimpleDeallocator implements Runnable {
+ static final AtomicBoolean hasRun = new AtomicBoolean();
+
+ private SimpleDeallocator() {
+ hasRun.set(false);
+ }
+
+ @Override
+ public void run() {
+ hasRun.compareAndSet(false, true);
+ }
+
+ public Boolean getHasRun() {
+ return hasRun.get();
+ }
+ }
+}
diff --cc datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemoryTest.java
index f883ba8,ebced06..41405cf
--- a/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemoryTest.java
+++ b/datasketches-memory-base/src/test/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemoryTest.java
@@@ -17,21 -17,22 +17,21 @@@
* under the License.
*/
- package org.apache.datasketches.memory.internal;
-package org.apache.datasketches.memory;
++package org.apache.datasketches.memory.test.internal;
-/**
- * The exception thrown when attempting to write into a read-only Resource.
- *
- * @author Praveenkumar Venkatesan
- */
-public class ReadOnlyException extends UnsupportedOperationException {
- private static final long serialVersionUID = 1L;
+import org.testng.annotations.Test;
+
+@SuppressWarnings("javadoc")
+public class VirtualMachineMemoryTest {
- /**
- * Read Only Exception
- * @param message the error message
- */
- public ReadOnlyException(final String message) {
- super(message);
+ @Test
+ public void maxDirectBufferMemory() {
+ assert(VirtualMachineMemory.getMaxDBBMemory() >= 0);
}
-}
+ @Test
+ public void inertPageAlignment() {
+ System.out.println("VM page alignment:" + VirtualMachineMemory.getIsPageAligned());
+ assert(true);
+ }
+}
diff --cc datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/MemoryCleanerTest.java
index 5553d11,0000000..e41bf5d
mode 100644,000000..100644
--- a/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/MemoryCleanerTest.java
+++ b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/MemoryCleanerTest.java
@@@ -1,64 -1,0 +1,64 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.java9.tests;
+
- import org.apache.datasketches.memory.internal.MemoryCleaner;
++import org.apache.datasketches.memory.test.internal.MemoryCleaner;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+@SuppressWarnings("javadoc")
+public class MemoryCleanerTest {
+
+ @Test
+ public void cleanerDeallocates() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ cleaner.clean();
+ assertTrue(deallocator.getHasRun());
+ }
+
+ @Test
+ public void noDeallocation() {
+ SimpleDeallocator deallocator = new SimpleDeallocator();
+ MemoryCleaner cleaner = new MemoryCleaner(this, deallocator);
+ assertFalse(deallocator.getHasRun());
+ }
+
+ private static final class SimpleDeallocator implements Runnable {
+ static final AtomicBoolean hasRun = new AtomicBoolean();
+
+ private SimpleDeallocator() {
+ hasRun.set(false);
+ }
+
+ @Override
+ public void run() {
+ hasRun.compareAndSet(false, true);
+ }
+
+ public Boolean getHasRun() {
+ return hasRun.get();
+ }
+ }
+}
diff --cc datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/VirtualMachineMemoryTest.java
index 2504e99,ebced06..1109207
--- a/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/VirtualMachineMemoryTest.java
+++ b/datasketches-memory-java9-tests/src/test/java/org/apache/datasketches/memory/java9/tests/VirtualMachineMemoryTest.java
@@@ -17,22 -17,22 +17,22 @@@
* under the License.
*/
-package org.apache.datasketches.memory;
+package org.apache.datasketches.memory.java9.tests;
- import org.apache.datasketches.memory.internal.VirtualMachineMemory;
-/**
- * The exception thrown when attempting to write into a read-only Resource.
- *
- * @author Praveenkumar Venkatesan
- */
-public class ReadOnlyException extends UnsupportedOperationException {
- private static final long serialVersionUID = 1L;
++import org.apache.datasketches.memory.test.internal.VirtualMachineMemory;
+import org.testng.annotations.Test;
+
+@SuppressWarnings("javadoc")
+public class VirtualMachineMemoryTest {
- /**
- * Read Only Exception
- * @param message the error message
- */
- public ReadOnlyException(final String message) {
- super(message);
+ @Test
+ public void maxDirectBufferMemory() {
+ assert(VirtualMachineMemory.getMaxDBBMemory() >= 0);
}
-}
+ @Test
+ public void inertPageAlignment() {
+ System.out.println("VM page alignment:" + VirtualMachineMemory.getIsPageAligned());
+ assert(true);
+ }
+}
diff --cc datasketches-memory-java9/src/main/java/module-info.java
index b21e9f0,be97bb8..d33d401
--- a/datasketches-memory-java9/src/main/java/module-info.java
+++ b/datasketches-memory-java9/src/main/java/module-info.java
@@@ -17,11 -17,4 +17,11 @@@
* under the License.
*/
-package org.apache.datasketches.memory.test;
+module org.apache.datasketches.memory {
+ requires java.base;
+ requires java.logging;
+ requires jdk.unsupported;
+
+ exports org.apache.datasketches.memory;
- exports org.apache.datasketches.memory.internal to org.apache.datasketches.memory.java9.tests;
++ exports org.apache.datasketches.memory.test.internal to org.apache.datasketches.memory.java9.tests;
+}
diff --cc datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
index 3d803fc,0000000..29d7db0
mode 100644,000000..100644
--- a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/MemoryCleaner.java
@@@ -1,52 -1,0 +1,52 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
- package org.apache.datasketches.memory.internal;
++package org.apache.datasketches.memory.test.internal;
+
+import jdk.internal.ref.Cleaner;
+
+/**
+ * Extracts a version-dependent reference to the `jdk.internal.ref.Cleaner` into
+ * a standalone class. The package name for Cleaner has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ *
+ * For more information, see:
+ * https://openjdk.java.net/jeps/238
+ */
+public class MemoryCleaner {
+ private final Cleaner cleaner;
+
+ /**
+ * Creates a new `jdk.internal.ref.Cleaner`.
+ * @param referent the object to be cleaned
+ * @param deallocator - the cleanup code to be run when the cleaner is invoked.
+ * return MemoryCleaner
+ */
+ public MemoryCleaner(Object referent, Runnable deallocator) {
+ cleaner = Cleaner.create(referent, deallocator);
+ }
+
+ /**
+ * Runs this cleaner, if it has not been run before.
+ */
+ public void clean() {
+ cleaner.clean();
+ }
+}
diff --cc datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
index 605abf4,0000000..0de1a7d
mode 100644,000000..100644
--- a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
+++ b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/test/internal/VirtualMachineMemory.java
@@@ -1,74 -1,0 +1,74 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
- package org.apache.datasketches.memory.internal;
++package org.apache.datasketches.memory.test.internal;
+
+import java.lang.reflect.Method;
+
+/**
+ * Extracts a version-dependent reference to the `jdk.internal.misc.VM` into
+ * a standalone class. The package name for VM has changed in
+ * later versions. The appropriate class will be loaded by the class loader
+ * depending on the Java version that is used.
+ *
+ * For more information, see:
+ * https://openjdk.java.net/jeps/238
+ */
+public final class VirtualMachineMemory {
+
+ private static final Class<?> VM_CLASS;
+ private static final Method VM_MAX_DIRECT_MEMORY_METHOD;
+ private static final Method VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD;
+ private static final long maxDBBMemory;
+ private static final boolean isPageAligned;
+
+ static {
+ try {
+ VM_CLASS = Class.forName("jdk.internal.misc.VM");
+ VM_MAX_DIRECT_MEMORY_METHOD = VM_CLASS.getDeclaredMethod("maxDirectMemory");
+ VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
+ maxDBBMemory = (long) VM_MAX_DIRECT_MEMORY_METHOD.invoke(null); //static method
+
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD =
+ VM_CLASS.getDeclaredMethod("isDirectMemoryPageAligned");
+ VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD.setAccessible(true);
+ isPageAligned = (boolean) VM_IS_DIRECT_MEMORY_PAGE_ALIGNED_METHOD
+ .invoke(null); //static method
+ } catch (final Exception e) {
+ throw new RuntimeException("Could not acquire jdk.internal.misc.VM: " + e.getClass());
+ }
+ }
+
+ /**
+ * Returns the maximum amount of allocatable direct buffer memory.
+ * The directMemory variable is initialized during system initialization.
+ * @return the maximum amount of allocatable direct buffer memory.
+ */
+ public static long getMaxDBBMemory() {
+ return maxDBBMemory;
+ }
+
+ /**
+ * Returns true if the direct buffers should be page aligned.
+ * @return flag that determines whether direct buffers should be page aligned.
+ */
+ public static boolean getIsPageAligned() {
+ return isPageAligned;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org