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/03/29 19:33:05 UTC
[datasketches-memory] branch master updated: Cleanup comments that
reflect differences in JDK 9 - 16
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
The following commit(s) were added to refs/heads/master by this push:
new 07f45e8 Cleanup comments that reflect differences in JDK 9 - 16
07f45e8 is described below
commit 07f45e8616f728c79f4b2fc7c37714b698d0f67a
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon Mar 29 12:32:38 2021 -0700
Cleanup comments that reflect differences in JDK 9 - 16
---
.../apache/datasketches/memory/AllocateDirect.java | 4 ++--
.../datasketches/memory/AllocateDirectMap.java | 23 ++++++++++++----------
.../org/apache/datasketches/memory/NioBits.java | 12 ++++++-----
tools/MemoryCheckstyle.xml | 3 ++-
4 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/memory/AllocateDirect.java b/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
index 805554c..b031ce0 100644
--- a/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
+++ b/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
@@ -24,7 +24,7 @@ import static org.apache.datasketches.memory.UnsafeUtil.unsafe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import sun.misc.Cleaner;
+import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
/**
* Provides access to direct (native) memory.
@@ -37,7 +37,7 @@ final class AllocateDirect implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(AllocateDirect.class);
private final Deallocator deallocator;
- private final Cleaner cleaner; //TODO-JDK9 import jdk.internal.ref.Cleaner;
+ private final Cleaner cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
private final long nativeBaseOffset;
/**
diff --git a/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java b/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
index cc73064..29c2d48 100644
--- a/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
+++ b/src/main/java/org/apache/datasketches/memory/AllocateDirectMap.java
@@ -33,7 +33,7 @@ import java.nio.channels.FileChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import sun.misc.Cleaner; //TODO-JDK9 jdk.internal.ref.Cleaner;
+import sun.misc.Cleaner; //JDK9+ moved to jdk.internal.ref.Cleaner;
import sun.nio.ch.FileChannelImpl;
/**
@@ -67,25 +67,27 @@ class AllocateDirectMap implements Map {
static final Method MAPPED_BYTE_BUFFER_FORCE0_METHOD;
static {
- try {
+ try { //The FileChannelImpl methods map0 and unmap0 still exist in 16
FILE_CHANNEL_IMPL_MAP0_METHOD = FileChannelImpl.class
- .getDeclaredMethod("map0", int.class, long.class, long.class);
+ .getDeclaredMethod("map0", int.class, long.class, long.class); //JDK14 add boolean.class
FILE_CHANNEL_IMPL_MAP0_METHOD.setAccessible(true);
FILE_CHANNEL_IMPL_UNMAP0_METHOD = FileChannelImpl.class
- .getDeclaredMethod("unmap0", long.class, long.class);
+ .getDeclaredMethod("unmap0", long.class, long.class); //OK through jDK16
FILE_CHANNEL_IMPL_UNMAP0_METHOD.setAccessible(true);
+
+ //The MappedByteBuffer methods load0, isLoaded0 and force0 are removed in 15
MAPPED_BYTE_BUFFER_LOAD0_METHOD = MappedByteBuffer.class
- .getDeclaredMethod("load0", long.class, long.class);
+ .getDeclaredMethod("load0", long.class, long.class); //JDK15 removed
MAPPED_BYTE_BUFFER_LOAD0_METHOD.setAccessible(true);
MAPPED_BYTE_BUFFER_ISLOADED0_METHOD = MappedByteBuffer.class
- .getDeclaredMethod("isLoaded0", long.class, long.class, int.class);
+ .getDeclaredMethod("isLoaded0", long.class, long.class, int.class); //JDK15 removed
MAPPED_BYTE_BUFFER_ISLOADED0_METHOD.setAccessible(true);
MAPPED_BYTE_BUFFER_FORCE0_METHOD = MappedByteBuffer.class
- .getDeclaredMethod("force0", FileDescriptor.class, long.class, long.class);
+ .getDeclaredMethod("force0", FileDescriptor.class, long.class, long.class); //JDK15 removed
MAPPED_BYTE_BUFFER_FORCE0_METHOD.setAccessible(true);
} catch (final Exception e) {
throw new RuntimeException("Could not reflect static methods: " + e);
@@ -93,7 +95,7 @@ class AllocateDirectMap implements Map {
}
private final Deallocator deallocator;
- private final Cleaner cleaner;
+ private final Cleaner cleaner;//JDK9+ moved to jdk.internal.ref.Cleaner;
final long capacityBytes;
final RandomAccessFile raf;
@@ -228,9 +230,10 @@ class AllocateDirectMap implements Map {
final long mapPosition = position - pagePosition;
final long mapSize = lengthBytes + pagePosition;
final int mapMode = resourceReadOnly ? MAP_RO : MAP_RW;
+ //final boolean isSync = true; //required as of JDK14, but it is more complex
try {
- final long nativeBaseOffset =
- (long) FILE_CHANNEL_IMPL_MAP0_METHOD.invoke(fileChannel, mapMode, mapPosition, mapSize);
+ final long nativeBaseOffset = //JDK14 add isSync
+ (long) FILE_CHANNEL_IMPL_MAP0_METHOD.invoke(fileChannel, mapMode, mapPosition, mapSize);
return nativeBaseOffset;
} catch (final InvocationTargetException e) {
throw new RuntimeException("Exception while mapping", e.getTargetException());
diff --git a/src/main/java/org/apache/datasketches/memory/NioBits.java b/src/main/java/org/apache/datasketches/memory/NioBits.java
index a2627b4..a089a30 100644
--- a/src/main/java/org/apache/datasketches/memory/NioBits.java
+++ b/src/main/java/org/apache/datasketches/memory/NioBits.java
@@ -50,7 +50,7 @@ final class NioBits {
static {
try {
- VM_CLASS = Class.forName("sun.misc.VM");
+ VM_CLASS = Class.forName("sun.misc.VM"); //JDK9+ moved to jdk.internal.misc.VM
VM_MAX_DIRECT_MEMORY_METHOD =
VM_CLASS.getDeclaredMethod("maxDirectMemory");
VM_MAX_DIRECT_MEMORY_METHOD.setAccessible(true);
@@ -66,13 +66,15 @@ final class NioBits {
NIO_BITS_CLASS = Class.forName("java.nio.Bits");
NIO_BITS_RESERVE_MEMORY_METHOD = NIO_BITS_CLASS
- .getDeclaredMethod("reserveMemory", long.class, int.class);
+ .getDeclaredMethod("reserveMemory", long.class, int.class); //JD16 requires (long, long)
NIO_BITS_RESERVE_MEMORY_METHOD.setAccessible(true);
NIO_BITS_UNRESERVE_MEMORY_METHOD = NIO_BITS_CLASS
- .getDeclaredMethod("unreserveMemory", long.class, int.class);
+ .getDeclaredMethod("unreserveMemory", long.class, int.class); //JD16 requires (long, long)
NIO_BITS_UNRESERVE_MEMORY_METHOD.setAccessible(true);
+ //JDK 8-10: "count", "reservedMemory", "totalCapacity"
+ //JDK 11-16: "COUNT", "RESERVE_MEMORY", "TOTAL_CAPACITY"
final Field countField = NIO_BITS_CLASS.getDeclaredField("count");
countField.setAccessible(true);
nioBitsCount = (AtomicLong) (countField.get(null));
@@ -165,9 +167,9 @@ final class NioBits {
while (capacity > 0) {
final long chunk = Math.min(capacity, chunkSizeLimit);
if (capacity == chunk) {
- method.invoke(null, allocationSize, (int) capacity);
+ method.invoke(null, allocationSize, (int) capacity); //JDK 16 remove cast to int
} else {
- method.invoke(null, chunk, (int) chunk);
+ method.invoke(null, chunk, (int) chunk); //JDK 16 remove cast to int
}
capacity -= chunk;
allocationSize -= chunk;
diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml
index 3b80313..351293a 100644
--- a/tools/MemoryCheckstyle.xml
+++ b/tools/MemoryCheckstyle.xml
@@ -124,10 +124,11 @@ under the License.
<property name="scope" value="public"/>
</module>
<module name="JavadocParagraph"/>
+ <!--
<module name="JavadocTagContinuationIndentation">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
- </module>
+ </module> -->
<module name="NonEmptyAtclauseDescription"/>
<module name="SingleLineJavadoc">
<property name="ignoreInlineTags" value="false"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org