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 2021/11/13 01:35:45 UTC
[datasketches-memory] 01/02: Removed requirements for VM class
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch Jdk17_Panama
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit c6816a51c391792283af35d12f0917dc4d99c94c
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Thu Nov 11 21:45:36 2021 -0800
Removed requirements for VM class
---
.../datasketches/memory/test/NioBitsTest.java | 10 +--
.../datasketches/memory/test/ReflectUtil.java | 33 ----------
.../memory/test/VirtualMachineMemoryTest.java | 39 ------------
.../memory/internal/AllocateDirect.java | 12 +---
.../memory/internal/VirtualMachineMemory.java | 74 ----------------------
.../java/org/apache/datasketches/memory/Map.java | 46 --------------
.../memory/internal/VirtualMachineMemory.java | 74 ----------------------
.../apache/datasketches/memory/package-info.java | 20 ------
8 files changed, 4 insertions(+), 304 deletions(-)
diff --git a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
index 9e45535..b0fa1e7 100644
--- a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
+++ b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
@@ -30,13 +30,6 @@ import org.testng.annotations.Test;
public class NioBitsTest {
@Test
- public void checkVMParams() {
- println("Max MemoryImpl: " + ReflectUtil.getMaxDirectByteBufferMemory());
- println("Page Aligned: " + ReflectUtil.isPageAligned());
- println("Page Size: " + ReflectUtil.pageSize());
- }
-
- @Test
public void checkGetAtomicFields() {
//testing this beyond 2GB may not work on JVMs < 8GB.
//This should be checked manually
@@ -59,8 +52,7 @@ public class NioBitsTest {
long count = ReflectUtil.getDirectAllocationsCount();
long resMem = ReflectUtil.getReservedMemory();
long totCap = ReflectUtil.getTotalCapacity();
- long maxDBBmem = ReflectUtil.getMaxDirectByteBufferMemory();
- String s = String.format("%,10d\t%,15d\t%,15d\t%,15d", count, resMem, totCap, maxDBBmem);
+ String s = String.format("%,10d\t%,15d\t%,15d", count, resMem, totCap);
println(s);
}
diff --git a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
index 3d27dda..85aa569 100644
--- a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
+++ b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java
@@ -40,7 +40,6 @@ public final class ReflectUtil {
static final Method CHECK_VALID; //BaseStateImpl
static final Method GET_DIRECT_ALLOCATIONS_COUNT; //NioBits
- static final Method GET_MAX_DIRECT_BYTE_BUFFER_MEMORY; //NioBits
static final Method GET_NATIVE_BASE_OFFSET; //BaseStateImpl
static final Method GET_RESERVED_MEMORY; //NioBits
static final Method GET_TOTAL_CAPACITY; //NioBits
@@ -53,11 +52,9 @@ public final class ReflectUtil {
static final Method IS_HEAP_TYPE; //BaseStateImpl
static final Method IS_MAP_TYPE; //BaseStateImpl
static final Method IS_NON_NATIVE_TYPE; //BaseStateImpl
- static final Method IS_PAGE_ALIGHED; //NioBits
static final Method IS_READ_ONLY_TYPE; //BaseStateImpl
static final Method IS_REGION_TYPE; //BaseStateImpl
static final Method PAGE_COUNT; //NioBits
- static final Method PAGE_SIZE; //NioBits
static final Method RESERVE_MEMORY; //NioBits
static final Method UNRESERVE_MEMORY; //NioBits
static final Method WRAP_DIRECT; //BaseWritableMemoryImpl
@@ -76,8 +73,6 @@ public final class ReflectUtil {
getMethod(BASE_STATE, "checkValid", (Class<?>[])null); //not static
GET_DIRECT_ALLOCATIONS_COUNT =
getMethod(NIO_BITS, "getDirectAllocationsCount", (Class<?>[])null); //static
- GET_MAX_DIRECT_BYTE_BUFFER_MEMORY =
- getMethod(NIO_BITS, "getMaxDirectByteBufferMemory", (Class<?>[])null); //static
GET_NATIVE_BASE_OFFSET =
getMethod(BASE_STATE, "getNativeBaseOffset", (Class<?>[])null);
GET_RESERVED_MEMORY =
@@ -102,16 +97,12 @@ public final class ReflectUtil {
getMethod(BASE_STATE, "isMapType", (Class<?>[])null); //not static
IS_NON_NATIVE_TYPE =
getMethod(BASE_STATE, "isNonNativeType", (Class<?>[])null); //not static
- IS_PAGE_ALIGHED =
- getMethod(NIO_BITS, "isPageAligned", (Class<?>[])null); //static
IS_READ_ONLY_TYPE =
getMethod(BASE_STATE, "isReadOnlyType", (Class<?>[])null); //not static
IS_REGION_TYPE =
getMethod(BASE_STATE, "isRegionType", (Class<?>[])null); //not static
PAGE_COUNT =
getMethod(NIO_BITS, "pageCount", long.class); //static
- PAGE_SIZE =
- getMethod(NIO_BITS, "pageSize", (Class<?>[])null); //static
RESERVE_MEMORY =
getMethod(NIO_BITS, "reserveMemory", long.class, long.class); //static
UNRESERVE_MEMORY =
@@ -237,14 +228,6 @@ public final class ReflectUtil {
}
}
- static long getMaxDirectByteBufferMemory() {
- try {
- return (long) GET_MAX_DIRECT_BYTE_BUFFER_MEMORY.invoke(null);
- } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
-
static long getNativeBaseOffset(final Object target) {
try {
return (long) GET_NATIVE_BASE_OFFSET.invoke(target);
@@ -341,14 +324,6 @@ public final class ReflectUtil {
}
}
- static boolean isPageAligned() {
- try {
- return (boolean) IS_PAGE_ALIGHED.invoke(null);
- } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
-
static boolean isReadOnlyType(final Object target) {
try {
return (boolean) IS_READ_ONLY_TYPE.invoke(target);
@@ -373,14 +348,6 @@ public final class ReflectUtil {
}
}
- static int pageSize() {
- try {
- return (int) PAGE_SIZE.invoke(null);
- } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
-
static void reserveMemory(final long allocationSize, final long capacity) {
try {
RESERVE_MEMORY.invoke(null, allocationSize, capacity);
diff --git a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java b/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
deleted file mode 100644
index ab23861..0000000
--- a/datasketches-memory-java8-tests/src/test/java/org/apache/datasketches/memory/test/VirtualMachineMemoryTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.test;
-
-import org.apache.datasketches.memory.internal.VirtualMachineMemory;
-import org.testng.annotations.Test;
-
-@SuppressWarnings({"javadoc","unused"})
-public class VirtualMachineMemoryTest {
-
- @Test
- public void maxDirectBufferMemory() {
- assert(VirtualMachineMemory.getMaxDBBMemory() >= 0);
- }
-
- @Test
- public void inertPageAlignment() {
- boolean result = VirtualMachineMemory.getIsPageAligned();
- //System.out.println("VM page alignment:" + result);
- assert(true); //no exception was thrown
- }
-}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
index ae649ef..72fdd6b 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
@@ -46,9 +46,8 @@ final class AllocateDirect {
* @param capacityBytes the the requested capacity of off-heap memory. Cannot be zero.
*/
AllocateDirect(final long capacityBytes) {
- final boolean pageAligned = NioBits.isPageAligned();
- final long pageSize = NioBits.pageSize();
- final long allocationSize = capacityBytes + (pageAligned ? pageSize : 0);
+ //round up to multiple of 8 bytes
+ final long allocationSize = ((capacityBytes & 7L) > 0L) ? ((capacityBytes >>> 3) + 1L) << 3 : capacityBytes;
NioBits.reserveMemory(allocationSize, capacityBytes);
final long nativeAddress;
@@ -58,12 +57,7 @@ final class AllocateDirect {
NioBits.unreserveMemory(allocationSize, capacityBytes);
throw new RuntimeException(err);
}
- if (pageAligned && ((nativeAddress % pageSize) != 0)) {
- //Round up to page boundary
- nativeBaseOffset = (nativeAddress & ~(pageSize - 1L)) + pageSize;
- } else {
- nativeBaseOffset = nativeAddress;
- }
+ nativeBaseOffset = nativeAddress;
deallocator = new Deallocator(nativeAddress, allocationSize, capacityBytes);
cleaner = new MemoryCleaner(this, deallocator);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
deleted file mode 100644
index c4497e9..0000000
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.InvocationTargetException;
-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 ClassNotFoundException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException | SecurityException e) {
- throw new RuntimeException("Could not acquire sun.misc.VM class: " + 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 --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java
deleted file mode 100644
index 6b99059..0000000
--- a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/Map.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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;
-
-/**
- * Read only interface for a memory mapped file
- *
- * @author Roman Leventov
- * @author Lee Rhodes
- * @author Praveenkumar Venkatesan
- */
-public interface Map extends AutoCloseable {
-
- /**
- * @see <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html#load--">
- * java/nio/MappedByteBuffer.load</a>
- */
- void load();
-
- /**
- * @return true if loaded
- *
- * @see <a href=
- * "https://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html#isLoaded--"> java
- * /nio/MappedByteBuffer.isLoaded</a>
- */
- boolean isLoaded();
-
-}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
deleted file mode 100644
index d644228..0000000
--- a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/internal/VirtualMachineMemory.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.InvocationTargetException;
-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 ClassNotFoundException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException | SecurityException 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;
- }
-}
diff --git a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java b/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java
deleted file mode 100644
index d2f9b3b..0000000
--- a/datasketches-memory-java9/src/main/java/org/apache/datasketches/memory/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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;
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org