Skip to content

Commit

Permalink
interim mods for JDK11
Browse files Browse the repository at this point in the history
  • Loading branch information
leerho committed Dec 3, 2020
1 parent a3b3c7e commit 029d8f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/main/java/org/apache/datasketches/memory/AllocateDirect.java
Expand Up @@ -24,7 +24,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sun.misc.Cleaner;
import sun.misc.Cleaner; //JDK 8
//import jdk.internal.ref.Cleaner; //JDK 9+

/**
* Provides access to direct (native) memory.
Expand All @@ -34,9 +35,9 @@
*/
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;
private final long nativeBaseOffset;

/**
Expand All @@ -60,14 +61,14 @@ final class AllocateDirect implements AutoCloseable {
NioBits.unreserveMemory(allocationSize, capacityBytes);
throw err;
}
if (pageAligned && ((nativeAddress % pageSize) != 0)) {
if (pageAligned && nativeAddress % pageSize != 0) {
//Round up to page boundary
nativeBaseOffset = (nativeAddress & ~(pageSize - 1L)) + pageSize;
} else {
nativeBaseOffset = nativeAddress;
}
deallocator = new Deallocator(nativeAddress, allocationSize, capacityBytes);
cleaner = Cleaner.create(this, deallocator);
cleaner = Cleaner.create(this, deallocator);
}

@Override
Expand Down Expand Up @@ -112,7 +113,7 @@ private Deallocator(final long nativeAddress, final long allocationSize, final l
this.nativeAddress = nativeAddress;
this.allocationSize = allocationSize;
this.capacity = capacity;
assert (nativeAddress != 0);
assert nativeAddress != 0;
}

StepBoolean getValid() {
Expand Down
Expand Up @@ -33,7 +33,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sun.misc.Cleaner; //TODO-JDK9 jdk.internal.ref.Cleaner;
import sun.misc.Cleaner; //JDK 8
//import jdk.internal.ref.Cleaner; //JDK 9+
import sun.nio.ch.FileChannelImpl;

/**
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/org/apache/datasketches/memory/UnsafeUtilTest.java
Expand Up @@ -53,6 +53,11 @@ public void checkJDK7methods() {
}
}

@Test
public void checkJDK_MAJOR() {
println(UnsafeUtil.JDK_MAJOR);
}

@Test
public void checkJdkString() {
String jdkVer;
Expand All @@ -63,7 +68,7 @@ public void checkJdkString() {
jdkVer = good1_8Strings[i];
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR
int jdkMajor = p[0] == 1 ? p[1] : p[0]; //model the actual JDK_MAJOR
if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
}
Expand Down Expand Up @@ -156,10 +161,10 @@ public void printlnTest() {
}

/**
* @param s String to print
* @param o String to print
*/
static void println(final String s) {
//System.out.println(s);
static void println(final Object o) {
//System.out.println(o.toString());
}

}

0 comments on commit 029d8f4

Please sign in to comment.