You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2017/12/06 03:02:26 UTC
incubator-ratis git commit: RATIS-166. Remove the use of
sun.misc.Unsafe. Contributed by Kit Hui
Repository: incubator-ratis
Updated Branches:
refs/heads/master c29ba46c8 -> 9a8daa1d5
RATIS-166. Remove the use of sun.misc.Unsafe. Contributed by Kit Hui
Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/9a8daa1d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/9a8daa1d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/9a8daa1d
Branch: refs/heads/master
Commit: 9a8daa1d5cdceb4e58d56dbca435e361c19dc107
Parents: c29ba46
Author: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Authored: Wed Dec 6 11:01:49 2017 +0800
Committer: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Committed: Wed Dec 6 11:01:49 2017 +0800
----------------------------------------------------------------------
.../org/apache/ratis/io/nativeio/NativeIO.java | 50 +-------------------
1 file changed, 2 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/9a8daa1d/ratis-common/src/main/java/org/apache/ratis/io/nativeio/NativeIO.java
----------------------------------------------------------------------
diff --git a/ratis-common/src/main/java/org/apache/ratis/io/nativeio/NativeIO.java b/ratis-common/src/main/java/org/apache/ratis/io/nativeio/NativeIO.java
index 921fb32..92d7e52 100644
--- a/ratis-common/src/main/java/org/apache/ratis/io/nativeio/NativeIO.java
+++ b/ratis-common/src/main/java/org/apache/ratis/io/nativeio/NativeIO.java
@@ -23,15 +23,8 @@ import org.apache.ratis.util.NativeCodeLoader;
import org.apache.ratis.util.PlatformUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import sun.misc.Unsafe;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.lang.reflect.Field;
+
+import java.io.*;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
@@ -118,10 +111,6 @@ public class NativeIO {
return NativeIO.getMemlockLimit();
}
- public long getOperatingSystemPageSize() {
- return NativeIO.getOperatingSystemPageSize();
- }
-
public void posixFadviseIfPossible(String identifier,
FileDescriptor fd, long offset, long len, int flags)
throws NativeIOException {
@@ -267,26 +256,6 @@ public class NativeIO {
mlock_native(buffer, len);
}
- /**
- * Unmaps the block from memory. See munmap(2).
- *
- * There isn't any portable way to unmap a memory region in Java.
- * So we use the sun.nio method here.
- * Note that unmapping a memory region could cause crashes if code
- * continues to reference the unmapped code. However, if we don't
- * manually unmap the memory, we are dependent on the finalizer to
- * do it, and we have no idea when the finalizer will run.
- *
- * @param buffer The buffer to unmap.
- */
- public static void munmap(MappedByteBuffer buffer) {
- if (buffer instanceof sun.nio.ch.DirectBuffer) {
- sun.misc.Cleaner cleaner =
- ((sun.nio.ch.DirectBuffer)buffer).cleaner();
- cleaner.clean();
- }
- }
-
/** Linux only methods used for getOwner() implementation */
private static native long getUIDforFDOwnerforOwner(FileDescriptor fd) throws IOException;
private static native String getUserName(long uid) throws IOException;
@@ -556,21 +525,6 @@ public class NativeIO {
private static native long getMemlockLimit0();
- /**
- * @return the operating system's page size.
- */
- static long getOperatingSystemPageSize() {
- try {
- Field f = Unsafe.class.getDeclaredField("theUnsafe");
- f.setAccessible(true);
- Unsafe unsafe = (Unsafe)f.get(null);
- return unsafe.pageSize();
- } catch (Throwable e) {
- LOG.warn("Unable to get operating system page size. Guessing 4096.", e);
- return 4096;
- }
- }
-
private static class CachedUid {
final long timestamp;
final String username;