ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [4/4] ignite git commit: ignite-2080 Data alignment issues with Unsafe
Date Wed, 20 Jan 2016 13:19:28 GMT
ignite-2080 Data alignment issues with Unsafe


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2572a545
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2572a545
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2572a545

Branch: refs/heads/ignite-2080
Commit: 2572a545575b5b878387450f2301cf35386b9add
Parents: 27c9064
Author: agura <agura@gridgain.com>
Authored: Mon Jan 11 14:53:02 2016 +0300
Committer: agura <agura@gridgain.com>
Committed: Wed Jan 20 16:11:08 2016 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryClassDescriptor.java  |   31 +-
 .../internal/binary/BinaryFieldAccessor.java    |   45 +-
 .../internal/binary/BinaryMarshaller.java       |    5 +-
 .../binary/BinaryObjectOffheapImpl.java         |   34 +-
 .../internal/binary/BinaryPrimitives.java       |   51 +-
 .../streams/BinaryAbstractInputStream.java      |   19 +-
 .../streams/BinaryAbstractOutputStream.java     |   40 +-
 .../binary/streams/BinaryAbstractStream.java    |   29 -
 .../binary/streams/BinaryHeapInputStream.java   |   21 +-
 .../binary/streams/BinaryHeapOutputStream.java  |   28 +-
 .../streams/BinaryMemoryAllocatorChunk.java     |    9 +-
 .../streams/BinaryOffheapInputStream.java       |   22 +-
 .../streams/BinaryOffheapOutputStream.java      |   36 +-
 .../internal/direct/DirectMessageReader.java    |    6 +
 .../internal/direct/DirectMessageWriter.java    |    6 +
 .../stream/v1/DirectByteBufferStreamImplV1.java |  106 +-
 .../stream/v2/DirectByteBufferStreamImplV2.java |  110 +-
 .../stream/v3/DirectByteBufferStreamImplV3.java | 1595 ++++++++++++++++++
 .../managers/communication/GridIoManager.java   |    2 +-
 .../cache/GridCacheEvictionManager.java         |    7 +-
 .../cache/GridCacheOffheapSwapEntry.java        |   24 +-
 .../cache/GridCacheSwapEntryImpl.java           |   61 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  |   15 +-
 .../dht/atomic/GridDhtAtomicCache.java          |   13 +-
 .../local/atomic/GridLocalAtomicCache.java      |    9 +-
 .../IgniteCacheObjectProcessorImpl.java         |    7 +-
 .../PlatformBigEndianOutputStreamImpl.java      |   14 +-
 .../memory/PlatformInputStreamImpl.java         |   53 +-
 .../platform/memory/PlatformMemoryUtils.java    |  104 +-
 .../memory/PlatformOutputStreamImpl.java        |   58 +-
 .../ignite/internal/util/GridHandleTable.java   |   17 +-
 .../ignite/internal/util/GridJavaProcess.java   |    3 -
 .../internal/util/GridSpinReadWriteLock.java    |   10 +-
 .../apache/ignite/internal/util/GridUnsafe.java | 1083 +++++++++++-
 .../ignite/internal/util/IgniteUtils.java       |   99 +-
 .../internal/util/io/GridUnsafeDataInput.java   |   96 +-
 .../internal/util/io/GridUnsafeDataOutput.java  |   98 +-
 .../util/offheap/unsafe/GridUnsafeMap.java      |   84 +-
 .../util/offheap/unsafe/GridUnsafeMemory.java   |  106 +-
 .../optimized/OptimizedClassDescriptor.java     |   22 +-
 .../optimized/OptimizedMarshaller.java          |    5 +-
 .../optimized/OptimizedMarshallerUtils.java     |   44 +-
 .../optimized/OptimizedObjectInputStream.java   |   10 +-
 .../ignite/internal/GridAffinitySelfTest.java   |    2 +-
 .../binary/BinaryFieldsOffheapSelfTest.java     |   13 +-
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   13 +-
 .../binary/BinaryMarshallerSelfTest.java        |   91 +-
 .../binary/BinaryObjectBuilderSelfTest.java     |   23 +-
 .../mutabletest/GridBinaryTestClasses.java      |    3 +-
 .../cache/GridCacheConcurrentMapSelfTest.java   |   13 +-
 ...CacheLocalOffHeapAndSwapMetricsSelfTest.java |    2 +-
 ...ContinuousQueryFailoverAbstractSelfTest.java |    6 +
 .../ignite/lang/GridBasicPerformanceTest.java   |   11 +-
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java |    2 +-
 .../testframework/junits/GridAbstractTest.java  |    4 +-
 .../hadoop/shuffle/HadoopShuffleJob.java        |    5 +-
 .../hadoop/shuffle/HadoopShuffleMessage.java    |   10 +-
 .../shuffle/streams/HadoopDataOutStream.java    |    6 +-
 .../HadoopConcurrentHashMultimapSelftest.java   |    6 +-
 .../collections/HadoopSkipListSelfTest.java     |    5 +-
 60 files changed, 3449 insertions(+), 1003 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 1ffa9e5..75f52e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -17,20 +17,6 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryReflectiveSerializer;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -47,14 +33,23 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReflectiveSerializer;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Binary class descriptor.
  */
 public class BinaryClassDescriptor {
-    /** */
-    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
     /** Apache Ignite base package name. */
     private static final String OAI_PKG = "org.apache.ignite";
 
@@ -778,7 +773,7 @@ public class BinaryClassDescriptor {
      */
     private Object newInstance() throws BinaryObjectException {
         try {
-            return ctor != null ? ctor.newInstance() : UNSAFE.allocateInstance(cls);
+            return ctor != null ? ctor.newInstance() : GridUnsafe.allocateInstance(cls);
         }
         catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
             throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
index 2d69cbd..0027110 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
@@ -17,11 +17,6 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
-
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
@@ -29,6 +24,9 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
 import java.util.UUID;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
  * Field accessor to speedup access.
@@ -157,9 +155,6 @@ public abstract class BinaryFieldAccessor {
      * Base primitive field accessor.
      */
     private static abstract class AbstractPrimitiveAccessor extends BinaryFieldAccessor {
-        /** Unsafe instance. */
-        protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
         /** Offset. */
         protected final long offset;
 
@@ -175,7 +170,7 @@ public abstract class BinaryFieldAccessor {
 
             assert field != null;
 
-            offset = UNSAFE.objectFieldOffset(field);
+            offset = GridUnsafe.objectFieldOffset(field);
         }
     }
 
@@ -196,7 +191,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            byte val = UNSAFE.getByte(obj, offset);
+            byte val = GridUnsafe.getByte(obj, offset);
 
             writer.writeByteFieldPrimitive(val);
         }
@@ -205,7 +200,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             byte val = reader.readByte(id);
 
-            UNSAFE.putByte(obj, offset, val);
+            GridUnsafe.putByte(obj, offset, val);
         }
     }
 
@@ -226,7 +221,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            boolean val = UNSAFE.getBoolean(obj, offset);
+            boolean val = GridUnsafe.getBoolean(obj, offset);
 
             writer.writeBooleanFieldPrimitive(val);
         }
@@ -235,7 +230,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             boolean val = reader.readBoolean(id);
 
-            UNSAFE.putBoolean(obj, offset, val);
+            GridUnsafe.putBoolean(obj, offset, val);
         }
     }
 
@@ -256,7 +251,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            short val = UNSAFE.getShort(obj, offset);
+            short val = GridUnsafe.getShort(obj, offset);
 
             writer.writeShortFieldPrimitive(val);
         }
@@ -265,7 +260,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             short val = reader.readShort(id);
 
-            UNSAFE.putShort(obj, offset, val);
+            GridUnsafe.putShort(obj, offset, val);
         }
     }
 
@@ -286,7 +281,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            char val = UNSAFE.getChar(obj, offset);
+            char val = GridUnsafe.getChar(obj, offset);
 
             writer.writeCharFieldPrimitive(val);
         }
@@ -295,7 +290,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             char val = reader.readChar(id);
 
-            UNSAFE.putChar(obj, offset, val);
+            GridUnsafe.putChar(obj, offset, val);
         }
     }
 
@@ -316,7 +311,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            int val = UNSAFE.getInt(obj, offset);
+            int val = GridUnsafe.getInt(obj, offset);
 
             writer.writeIntFieldPrimitive(val);
         }
@@ -325,7 +320,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             int val = reader.readInt(id);
 
-            UNSAFE.putInt(obj, offset, val);
+            GridUnsafe.putInt(obj, offset, val);
         }
     }
 
@@ -346,7 +341,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            long val = UNSAFE.getLong(obj, offset);
+            long val = GridUnsafe.getLong(obj, offset);
 
             writer.writeLongFieldPrimitive(val);
         }
@@ -355,7 +350,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             long val = reader.readLong(id);
 
-            UNSAFE.putLong(obj, offset, val);
+            GridUnsafe.putLong(obj, offset, val);
         }
     }
 
@@ -376,7 +371,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            float val = UNSAFE.getFloat(obj, offset);
+            float val = GridUnsafe.getFloat(obj, offset);
 
             writer.writeFloatFieldPrimitive(val);
         }
@@ -385,7 +380,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             float val = reader.readFloat(id);
 
-            UNSAFE.putFloat(obj, offset, val);
+            GridUnsafe.putFloat(obj, offset, val);
         }
     }
 
@@ -406,7 +401,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
             writer.writeFieldIdNoSchemaUpdate(id);
 
-            double val = UNSAFE.getDouble(obj, offset);
+            double val = GridUnsafe.getDouble(obj, offset);
 
             writer.writeDoubleFieldPrimitive(val);
         }
@@ -415,7 +410,7 @@ public abstract class BinaryFieldAccessor {
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
             double val = reader.readDouble(id);
 
-            UNSAFE.putDouble(obj, offset, val);
+            GridUnsafe.putDouble(obj, offset, val);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
index 5480967..29a1fca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
@@ -24,7 +24,6 @@ import java.io.OutputStream;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.marshaller.AbstractMarshaller;
 import org.apache.ignite.marshaller.MarshallerContext;
 import org.jetbrains.annotations.Nullable;
@@ -52,9 +51,7 @@ public class BinaryMarshaller extends AbstractMarshaller {
     @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
     public static boolean available() {
         try {
-            Unsafe unsafe = GridUnsafe.unsafe();
-
-            Class<? extends Unsafe> unsafeCls = unsafe.getClass();
+            Class<? extends Unsafe> unsafeCls = Unsafe.class;
 
             unsafeCls.getMethod("allocateInstance", Class.class);
             unsafeCls.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 696a34b..07ab4d3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -17,6 +17,16 @@
 
 package org.apache.ignite.internal.binary;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectBuilder;
@@ -26,23 +36,10 @@ import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
 import org.apache.ignite.plugin.extensions.communication.MessageWriter;
 import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
@@ -54,9 +51,6 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
     private static final long serialVersionUID = 0L;
 
     /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
     private final BinaryContext ctx;
 
     /** */
@@ -97,22 +91,22 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
 
     /** {@inheritDoc} */
     @Override public int typeId() {
-        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.TYPE_ID_POS);
+        return BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.TYPE_ID_POS);
     }
 
     /** {@inheritDoc} */
     @Override public int length() {
-        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.TOTAL_LEN_POS);
+        return BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.TOTAL_LEN_POS);
     }
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.HASH_CODE_POS);
+        return BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.HASH_CODE_POS);
     }
 
     /** {@inheritDoc} */
     @Override protected int schemaId() {
-        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.SCHEMA_ID_POS);
+        return BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.SCHEMA_ID_POS);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
index a6a867c..23a572b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
@@ -17,24 +17,13 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
-
 import java.nio.ByteOrder;
+import org.apache.ignite.internal.util.GridUnsafe;
 
 /**
  * Primitives writer.
  */
 public abstract class BinaryPrimitives {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
-    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
     /** Whether little endian is set. */
     private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
 
@@ -44,7 +33,7 @@ public abstract class BinaryPrimitives {
      * @param val Value.
      */
     public static void writeByte(byte[] arr, int off, byte val) {
-        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
+        GridUnsafe.putByte(arr, GridUnsafe.BYTE_ARR_OFF + off, val);
     }
 
     /**
@@ -53,7 +42,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static byte readByte(byte[] arr, int off) {
-        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
+        return GridUnsafe.getByte(arr, GridUnsafe.BYTE_ARR_OFF + off);
     }
 
     /**
@@ -62,7 +51,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static byte readByte(long ptr, int off) {
-        return UNSAFE.getByte(ptr + off);
+        return GridUnsafe.getByte(ptr + off);
     }
 
     /**
@@ -73,7 +62,7 @@ public abstract class BinaryPrimitives {
     public static byte[] readByteArray(byte[] arr, int off, int len) {
         byte[] arr0 = new byte[len];
 
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, BYTE_ARR_OFF, len);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF + off, arr0, GridUnsafe.BYTE_ARR_OFF, len);
 
         return arr0;
     }
@@ -86,7 +75,7 @@ public abstract class BinaryPrimitives {
     public static byte[] readByteArray(long ptr, int off, int len) {
         byte[] arr0 = new byte[len];
 
-        UNSAFE.copyMemory(null, ptr + off, arr0, BYTE_ARR_OFF, len);
+        GridUnsafe.copyMemory(null, ptr + off, arr0, GridUnsafe.BYTE_ARR_OFF, len);
 
         return arr0;
     }
@@ -127,7 +116,7 @@ public abstract class BinaryPrimitives {
         if (BIG_ENDIAN)
             val = Short.reverseBytes(val);
 
-        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
+        GridUnsafe.putShortAligned(arr, GridUnsafe.BYTE_ARR_OFF + off, val);
     }
 
     /**
@@ -136,7 +125,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static short readShort(byte[] arr, int off) {
-        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
+        short val = GridUnsafe.getShortAligned(arr, GridUnsafe.BYTE_ARR_OFF + off);
 
         if (BIG_ENDIAN)
             val = Short.reverseBytes(val);
@@ -150,7 +139,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static short readShort(long ptr, int off) {
-        short val = UNSAFE.getShort(ptr + off);
+        short val = GridUnsafe.getShort(ptr + off);
 
         if (BIG_ENDIAN)
             val = Short.reverseBytes(val);
@@ -167,7 +156,7 @@ public abstract class BinaryPrimitives {
         if (BIG_ENDIAN)
             val = Character.reverseBytes(val);
 
-        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
+        GridUnsafe.putCharAligned(arr, GridUnsafe.BYTE_ARR_OFF + off, val);
     }
 
     /**
@@ -176,7 +165,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static char readChar(byte[] arr, int off) {
-        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
+        char val = GridUnsafe.getCharAligned(arr, GridUnsafe.BYTE_ARR_OFF + off);
 
         if (BIG_ENDIAN)
             val = Character.reverseBytes(val);
@@ -190,7 +179,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static char readChar(long ptr, int off) {
-        char val = UNSAFE.getChar(ptr + off);
+        char val = GridUnsafe.getChar(ptr + off);
 
         if (BIG_ENDIAN)
             val = Character.reverseBytes(val);
@@ -206,7 +195,7 @@ public abstract class BinaryPrimitives {
     public static char[] readCharArray(byte[] arr, int off, int len) {
         char[] arr0 = new char[len];
 
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, CHAR_ARR_OFF, len << 1);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF + off, arr0, GridUnsafe.CHAR_ARR_OFF, len << 1);
 
         if (BIG_ENDIAN) {
             for (int i = 0; i < len; i++)
@@ -224,7 +213,7 @@ public abstract class BinaryPrimitives {
     public static char[] readCharArray(long ptr, int off, int len) {
         char[] arr0 = new char[len];
 
-        UNSAFE.copyMemory(null, ptr + off, arr0, CHAR_ARR_OFF, len << 1);
+        GridUnsafe.copyMemory(null, ptr + off, arr0, GridUnsafe.CHAR_ARR_OFF, len << 1);
 
         if (BIG_ENDIAN) {
             for (int i = 0; i < len; i++)
@@ -243,7 +232,7 @@ public abstract class BinaryPrimitives {
         if (BIG_ENDIAN)
             val = Integer.reverseBytes(val);
 
-        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
+        GridUnsafe.putIntAligned(arr, GridUnsafe.BYTE_ARR_OFF + off, val);
     }
 
     /**
@@ -252,7 +241,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static int readInt(byte[] arr, int off) {
-        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
+        int val = GridUnsafe.getIntAligned(arr, GridUnsafe.BYTE_ARR_OFF + off);
 
         if (BIG_ENDIAN)
             val = Integer.reverseBytes(val);
@@ -266,7 +255,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static int readInt(long ptr, int off) {
-        int val = UNSAFE.getInt(ptr + off);
+        int val = GridUnsafe.getInt(ptr + off);
 
         if (BIG_ENDIAN)
             val = Integer.reverseBytes(val);
@@ -283,7 +272,7 @@ public abstract class BinaryPrimitives {
         if (BIG_ENDIAN)
             val = Long.reverseBytes(val);
 
-        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
+        GridUnsafe.putLongAligned(arr, GridUnsafe.BYTE_ARR_OFF + off, val);
     }
 
     /**
@@ -292,7 +281,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static long readLong(byte[] arr, int off) {
-        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
+        long val = GridUnsafe.getLongAligned(arr, GridUnsafe.BYTE_ARR_OFF + off);
 
         if (BIG_ENDIAN)
             val = Long.reverseBytes(val);
@@ -306,7 +295,7 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static long readLong(long ptr, int off) {
-        long val = UNSAFE.getLong(ptr + off);
+        long val = GridUnsafe.getLong(ptr + off);
 
         if (BIG_ENDIAN)
             val = Long.reverseBytes(val);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
index 334f455..05e4992 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.binary.streams;
 
 import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.util.GridUnsafe;
 
 /**
  * Binary abstract input stream.
@@ -40,7 +41,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         byte[] res = new byte[cnt];
 
-        copyAndShift(res, BYTE_ARR_OFF, cnt);
+        copyAndShift(res, GridUnsafe.BYTE_ARR_OFF, cnt);
 
         return res;
     }
@@ -56,7 +57,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         boolean[] res = new boolean[cnt];
 
-        copyAndShift(res, BOOLEAN_ARR_OFF, cnt);
+        copyAndShift(res, GridUnsafe.BOOLEAN_ARR_OFF, cnt);
 
         return res;
     }
@@ -83,7 +84,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         short[] res = new short[cnt];
 
-        copyAndShift(res, SHORT_ARR_OFF, len);
+        copyAndShift(res, GridUnsafe.SHORT_ARR_OFF, len);
 
         if (!LITTLE_ENDIAN) {
             for (int i = 0; i < res.length; i++)
@@ -115,7 +116,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         char[] res = new char[cnt];
 
-        copyAndShift(res, CHAR_ARR_OFF, len);
+        copyAndShift(res, GridUnsafe.CHAR_ARR_OFF, len);
 
         if (!LITTLE_ENDIAN) {
             for (int i = 0; i < res.length; i++)
@@ -147,7 +148,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         int[] res = new int[cnt];
 
-        copyAndShift(res, INT_ARR_OFF, len);
+        copyAndShift(res, GridUnsafe.INT_ARR_OFF, len);
 
         if (!LITTLE_ENDIAN) {
             for (int i = 0; i < res.length; i++)
@@ -201,7 +202,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
         float[] res = new float[cnt];
 
         if (LITTLE_ENDIAN)
-            copyAndShift(res, FLOAT_ARR_OFF, len);
+            copyAndShift(res, GridUnsafe.FLOAT_ARR_OFF, len);
         else {
             for (int i = 0; i < res.length; i++) {
                 int x = readIntFast();
@@ -237,7 +238,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         long[] res = new long[cnt];
 
-        copyAndShift(res, LONG_ARR_OFF, len);
+        copyAndShift(res, GridUnsafe.LONG_ARR_OFF, len);
 
         if (!LITTLE_ENDIAN) {
             for (int i = 0; i < res.length; i++)
@@ -261,7 +262,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
         double[] res = new double[cnt];
 
         if (LITTLE_ENDIAN)
-            copyAndShift(res, DOUBLE_ARR_OFF, len);
+            copyAndShift(res, GridUnsafe.DOUBLE_ARR_OFF, len);
         else {
             for (int i = 0; i < res.length; i++) {
                 long x = readLongFast();
@@ -280,7 +281,7 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
         if (len > remaining())
             len = remaining();
 
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+        copyAndShift(arr, GridUnsafe.BYTE_ARR_OFF + off, len);
 
         return len;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
index 4221cbe..5a60c5e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
 /**
  * Base binary output stream.
  */
@@ -36,7 +38,7 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
     @Override public void writeByteArray(byte[] val) {
         ensureCapacity(pos + val.length);
 
-        copyAndShift(val, BYTE_ARR_OFF, val.length);
+        copyAndShift(val, GridUnsafe.BYTE_ARR_OFF, val.length);
     }
 
     /** {@inheritDoc} */
@@ -48,7 +50,7 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
     @Override public void writeBooleanArray(boolean[] val) {
         ensureCapacity(pos + val.length);
 
-        copyAndShift(val, BOOLEAN_ARR_OFF, val.length);
+        copyAndShift(val, GridUnsafe.BOOLEAN_ARR_OFF, val.length);
     }
 
     /** {@inheritDoc} */
@@ -70,12 +72,13 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, SHORT_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.SHORT_ARR_OFF, cnt);
         else {
-            for (short item : val)
+            for (short item : val) {
                 writeShortFast(Short.reverseBytes(item));
 
-            shift(cnt);
+                shift(2);
+            }
         }
     }
 
@@ -98,12 +101,13 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, CHAR_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.CHAR_ARR_OFF, cnt);
         else {
-            for (char item : val)
+            for (char item : val) {
                 writeCharFast(Character.reverseBytes(item));
 
-            shift(cnt);
+                shift(2);
+            }
         }
     }
 
@@ -140,12 +144,13 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, INT_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.INT_ARR_OFF, cnt);
         else {
-            for (int item : val)
+            for (int item : val) {
                 writeIntFast(Integer.reverseBytes(item));
 
-            shift(cnt);
+                shift(4);
+            }
         }
     }
 
@@ -161,7 +166,7 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, FLOAT_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.FLOAT_ARR_OFF, cnt);
         else {
             for (float item : val) {
                 writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
@@ -190,12 +195,13 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, LONG_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.LONG_ARR_OFF, cnt);
         else {
-            for (long item : val)
+            for (long item : val) {
                 writeLongFast(Long.reverseBytes(item));
 
-            shift(cnt);
+                shift(8);
+            }
         }
     }
 
@@ -211,7 +217,7 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
         ensureCapacity(pos + cnt);
 
         if (LITTLE_ENDIAN)
-            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
+            copyAndShift(val, GridUnsafe.DOUBLE_ARR_OFF, cnt);
         else {
             for (double item : val) {
                 writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
@@ -225,7 +231,7 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
     @Override public void write(byte[] arr, int off, int len) {
         ensureCapacity(pos + len);
 
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+        copyAndShift(arr, GridUnsafe.BYTE_ARR_OFF + off, len);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
index 1e8ce09..6b2ff58 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
@@ -18,8 +18,6 @@
 package org.apache.ignite.internal.binary.streams;
 
 import java.nio.ByteOrder;
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
 
 /**
  * Binary abstract stream.
@@ -34,33 +32,6 @@ public abstract class BinaryAbstractStream implements BinaryStream {
     /** Whether little endian is used on the platform. */
     protected static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
 
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: boolean. */
-    protected static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Array offset: short. */
-    protected static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
-
-    /** Array offset: char. */
-    protected static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** Array offset: int. */
-    protected static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
-
-    /** Array offset: float. */
-    protected static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
-
-    /** Array offset: long. */
-    protected static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
-
-    /** Array offset: double. */
-    protected static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
-
     /** Position. */
     protected int pos;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
index 732b8c7..204f2be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.binary.streams;
 
 import java.util.Arrays;
+import org.apache.ignite.internal.util.GridUnsafe;
 
 /**
  * Binary off-heap input stream.
@@ -75,7 +76,7 @@ public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
         if (data.length < len) {
             byte[] data0 = new byte[len];
 
-            UNSAFE.copyMemory(data, BYTE_ARR_OFF, data0, BYTE_ARR_OFF, data.length);
+            GridUnsafe.copyMemory(data, GridUnsafe.BYTE_ARR_OFF, data0, GridUnsafe.BYTE_ARR_OFF, data.length);
 
             data = data0;
         }
@@ -97,7 +98,7 @@ public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
     @Override public byte[] arrayCopy() {
         byte[] res = new byte[len];
 
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, res.length);
+        GridUnsafe.copyMemory(data, GridUnsafe.BYTE_ARR_OFF, res, GridUnsafe.BYTE_ARR_OFF, res.length);
 
         return res;
     }
@@ -114,39 +115,39 @@ public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
 
     /** {@inheritDoc} */
     @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF + pos, target, off, len);
+        GridUnsafe.copyMemory(data, GridUnsafe.BYTE_ARR_OFF + pos, target, off, len);
 
         shift(len);
     }
 
     /** {@inheritDoc} */
     @Override protected short readShortFast() {
-        return UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+        return GridUnsafe.getShortAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected char readCharFast() {
-        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
+        return GridUnsafe.getCharAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntFast() {
-        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+        return GridUnsafe.getIntAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected long readLongFast() {
-        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
+        return GridUnsafe.getLongAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
+        return GridUnsafe.getByte(data, GridUnsafe.BYTE_ARR_OFF + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+        short res = GridUnsafe.getShortAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
 
         if (!LITTLE_ENDIAN)
             res = Short.reverseBytes(res);
@@ -156,7 +157,7 @@ public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
 
     /** {@inheritDoc} */
     @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+        int res = GridUnsafe.getIntAligned(data, GridUnsafe.BYTE_ARR_OFF + pos);
 
         if (!LITTLE_ENDIAN)
             res = Integer.reverseBytes(res);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
index 7553f3b..af16cc4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
 /**
  * Binary heap output stream.
  */
@@ -71,7 +73,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
     @Override public byte[] arrayCopy() {
         byte[] res = new byte[pos];
 
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, pos);
+        GridUnsafe.copyMemory(data, GridUnsafe.BYTE_ARR_OFF, res, GridUnsafe.BYTE_ARR_OFF, pos);
 
         return res;
     }
@@ -88,34 +90,34 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
 
     /** {@inheritDoc} */
     @Override protected void copyAndShift(Object src, long off, int len) {
-        UNSAFE.copyMemory(src, off, data, BYTE_ARR_OFF + pos, len);
+        GridUnsafe.copyMemory(src, off, data, GridUnsafe.BYTE_ARR_OFF + pos, len);
 
         shift(len);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putShortAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putCharAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putIntAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putLongAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(data, BYTE_ARR_OFF + pos++, val);
+        GridUnsafe.putByte(data, GridUnsafe.BYTE_ARR_OFF + pos++, val);
     }
 
     /** {@inheritDoc} */
@@ -123,7 +125,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Short.reverseBytes(val);
 
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putShortAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
 
         shift(2);
     }
@@ -133,7 +135,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Short.reverseBytes(val);
 
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putShortAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
@@ -141,7 +143,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Character.reverseBytes(val);
 
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putCharAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
 
         shift(2);
     }
@@ -151,7 +153,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Integer.reverseBytes(val);
 
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putIntAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
 
         shift(4);
     }
@@ -161,7 +163,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Integer.reverseBytes(val);
 
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putIntAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
     }
 
     /** {@inheritDoc} */
@@ -169,7 +171,7 @@ public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Long.reverseBytes(val);
 
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+        GridUnsafe.putLongAligned(data, GridUnsafe.BYTE_ARR_OFF + pos, val);
 
         shift(8);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
index 7c73742..f9db7da 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.binary.streams;
 
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK;
 
@@ -27,12 +26,6 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RE
  * Memory allocator chunk.
  */
 public class BinaryMemoryAllocatorChunk {
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
     /** Buffer size re-check frequency. */
     private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000);
 
@@ -79,7 +72,7 @@ public class BinaryMemoryAllocatorChunk {
         if (this.data == data)
             this.data = newData;
 
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, newData, BYTE_ARR_OFF, data.length);
+        GridUnsafe.copyMemory(data, GridUnsafe.BYTE_ARR_OFF, newData, GridUnsafe.BYTE_ARR_OFF, data.length);
 
         return newData;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
index cff002f..c1c0a4a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
 /**
  * Binary off-heap input stream.
  */
@@ -70,7 +72,7 @@ public class BinaryOffheapInputStream extends BinaryAbstractInputStream {
     @Override public byte[] arrayCopy() {
         byte[] res = new byte[len];
 
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, res.length);
+        GridUnsafe.copyMemory(null, ptr, res, GridUnsafe.BYTE_ARR_OFF, res.length);
 
         return res;
     }
@@ -82,44 +84,44 @@ public class BinaryOffheapInputStream extends BinaryAbstractInputStream {
 
     /** {@inheritDoc} */
     @Override protected byte readByteAndShift() {
-        return UNSAFE.getByte(ptr + pos++);
+        return GridUnsafe.getByte(ptr + pos++);
     }
 
     /** {@inheritDoc} */
     @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(null, ptr + pos, target, off, len);
+        GridUnsafe.copyMemory(null, ptr + pos, target, off, len);
 
         shift(len);
     }
 
     /** {@inheritDoc} */
     @Override protected short readShortFast() {
-        return UNSAFE.getShort(ptr + pos);
+        return GridUnsafe.getShort(ptr + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected char readCharFast() {
-        return UNSAFE.getChar(ptr + pos);
+        return GridUnsafe.getChar(ptr + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntFast() {
-        return UNSAFE.getInt(ptr + pos);
+        return GridUnsafe.getInt(ptr + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected long readLongFast() {
-        return UNSAFE.getLong(ptr + pos);
+        return GridUnsafe.getLong(ptr + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(ptr + pos);
+        return GridUnsafe.getByte(ptr + pos);
     }
 
     /** {@inheritDoc} */
     @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(ptr + pos);
+        short res = GridUnsafe.getShort(ptr + pos);
 
         if (!LITTLE_ENDIAN)
             res = Short.reverseBytes(res);
@@ -129,7 +131,7 @@ public class BinaryOffheapInputStream extends BinaryAbstractInputStream {
 
     /** {@inheritDoc} */
     @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(ptr + pos);
+        int res = GridUnsafe.getInt(ptr + pos);
 
         if (!LITTLE_ENDIAN)
             res = Integer.reverseBytes(res);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
index 080a357..9203437 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
 /**
  * Binary offheap output stream.
  */
@@ -73,7 +75,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
     @Override public byte[] arrayCopy() {
         byte[] res = new byte[pos];
 
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, pos);
+        GridUnsafe.copyMemory(null, ptr, res, GridUnsafe.BYTE_ARR_OFF, pos);
 
         return res;
     }
@@ -94,34 +96,34 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
 
     /** {@inheritDoc} */
     @Override protected void writeByteAndShift(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
+        GridUnsafe.putByte(ptr + pos++, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void copyAndShift(Object src, long offset, int len) {
-        UNSAFE.copyMemory(src, offset, null, ptr + pos, len);
+        GridUnsafe.copyMemory(src, offset, null, ptr + pos, len);
 
         shift(len);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(ptr + pos, val);
+        GridUnsafe.putShort(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(ptr + pos, val);
+        GridUnsafe.putChar(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(ptr + pos, val);
+        GridUnsafe.putInt(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(ptr + pos, val);
+        GridUnsafe.putLong(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
@@ -131,7 +133,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
+        GridUnsafe.putByte(ptr + pos++, val);
     }
 
     /** {@inheritDoc} */
@@ -139,7 +141,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Short.reverseBytes(val);
 
-        UNSAFE.putShort(ptr + pos, val);
+        GridUnsafe.putShort(ptr + pos, val);
 
         shift(2);
     }
@@ -149,7 +151,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Short.reverseBytes(val);
 
-        UNSAFE.putShort(ptr + pos, val);
+        GridUnsafe.putShort(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
@@ -157,7 +159,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Character.reverseBytes(val);
 
-        UNSAFE.putChar(ptr + pos, val);
+        GridUnsafe.putChar(ptr + pos, val);
 
         shift(2);
     }
@@ -167,7 +169,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Integer.reverseBytes(val);
 
-        UNSAFE.putInt(ptr + pos, val);
+        GridUnsafe.putInt(ptr + pos, val);
 
         shift(4);
     }
@@ -177,7 +179,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Integer.reverseBytes(val);
 
-        UNSAFE.putInt(ptr + pos, val);
+        GridUnsafe.putInt(ptr + pos, val);
     }
 
     /** {@inheritDoc} */
@@ -185,7 +187,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
         if (!LITTLE_ENDIAN)
             val = Long.reverseBytes(val);
 
-        UNSAFE.putLong(ptr + pos, val);
+        GridUnsafe.putLong(ptr + pos, val);
 
         shift(8);
     }
@@ -197,7 +199,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
      * @return Pointer.
      */
     protected long allocate(int cap) {
-        return UNSAFE.allocateMemory(cap);
+        return GridUnsafe.allocateMemory(cap);
     }
 
     /**
@@ -208,7 +210,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
      * @return New pointer.
      */
     protected long reallocate(long ptr, int cap) {
-        return UNSAFE.reallocateMemory(ptr, cap);
+        return GridUnsafe.reallocateMemory(ptr, cap);
     }
 
     /**
@@ -217,6 +219,6 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
      * @param ptr Pointer.
      */
     protected void release(long ptr) {
-        UNSAFE.freeMemory(ptr);
+        GridUnsafe.freeMemory(ptr);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
index 10bc7e2..a52db61 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.direct.stream.DirectByteBufferStream;
 import org.apache.ignite.internal.direct.stream.v1.DirectByteBufferStreamImplV1;
 import org.apache.ignite.internal.direct.stream.v2.DirectByteBufferStreamImplV2;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.direct.stream.v3.DirectByteBufferStreamImplV3;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.extensions.communication.Message;
@@ -404,6 +405,11 @@ public class DirectMessageReader implements MessageReader {
 
                     break;
 
+                case 3:
+                    stream = new DirectByteBufferStreamImplV3(msgFactory);
+
+                    break;
+
                 default:
                     throw new IllegalStateException("Invalid protocol version: " + protoVer);
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
index b265c6c..1f5d417 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
@@ -29,6 +29,7 @@ import org.apache.ignite.internal.direct.stream.v1.DirectByteBufferStreamImplV1;
 import org.apache.ignite.internal.direct.stream.v2.DirectByteBufferStreamImplV2;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.direct.stream.v3.DirectByteBufferStreamImplV3;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.extensions.communication.Message;
@@ -367,6 +368,11 @@ public class DirectMessageWriter implements MessageWriter {
 
                     break;
 
+                case 3:
+                    stream = new DirectByteBufferStreamImplV3(null);
+
+                    break;
+
                 default:
                     throw new IllegalStateException("Invalid protocol version: " + protoVer);
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2572a545/modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v1/DirectByteBufferStreamImplV1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v1/DirectByteBufferStreamImplV1.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v1/DirectByteBufferStreamImplV1.java
index 67fa9e7..8dd262f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v1/DirectByteBufferStreamImplV1.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v1/DirectByteBufferStreamImplV1.java
@@ -37,7 +37,6 @@ import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemTy
 import org.apache.ignite.plugin.extensions.communication.MessageFactory;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
 import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import sun.misc.Unsafe;
 import sun.nio.ch.DirectBuffer;
 
 /**
@@ -45,33 +44,6 @@ import sun.nio.ch.DirectBuffer;
  */
 public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
-    private static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
-
-    /** */
-    private static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
-
-    /** */
-    private static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
-
-    /** */
-    private static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
-
-    /** */
-    private static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
-
-    /** */
-    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** */
-    private static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
-
-    /** */
     private static final byte[] BYTE_ARR_EMPTY = new byte[0];
 
     /** */
@@ -303,7 +275,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
             this.buf = buf;
 
             heapArr = buf.isDirect() ? null : buf.array();
-            baseOff = buf.isDirect() ? ((DirectBuffer)buf).address() : BYTE_ARR_OFF;
+            baseOff = buf.isDirect() ? ((DirectBuffer)buf).address() : GridUnsafe.BYTE_ARR_OFF;
         }
     }
 
@@ -324,7 +296,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putByte(heapArr, baseOff + pos, val);
+            GridUnsafe.putByte(heapArr, baseOff + pos, val);
 
             buf.position(pos + 1);
         }
@@ -337,7 +309,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putShort(heapArr, baseOff + pos, val);
+            GridUnsafe.putShortAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 2);
         }
@@ -350,7 +322,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putInt(heapArr, baseOff + pos, val);
+            GridUnsafe.putIntAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 4);
         }
@@ -363,7 +335,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putLong(heapArr, baseOff + pos, val);
+            GridUnsafe.putLongAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 8);
         }
@@ -378,7 +350,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putFloat(heapArr, baseOff + pos, val);
+            GridUnsafe.putFloatAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 4);
         }
@@ -391,7 +363,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putDouble(heapArr, baseOff + pos, val);
+            GridUnsafe.putDoubleAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 8);
         }
@@ -404,7 +376,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putChar(heapArr, baseOff + pos, val);
+            GridUnsafe.putCharAligned(heapArr, baseOff + pos, val);
 
             buf.position(pos + 2);
         }
@@ -417,7 +389,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         if (lastFinished) {
             int pos = buf.position();
 
-            UNSAFE.putBoolean(heapArr, baseOff + pos, val);
+            GridUnsafe.putBoolean(heapArr, baseOff + pos, val);
 
             buf.position(pos + 1);
         }
@@ -426,7 +398,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeByteArray(byte[] val) {
         if (val != null)
-            lastFinished = writeArray(val, BYTE_ARR_OFF, val.length, val.length);
+            lastFinished = writeArray(val, GridUnsafe.BYTE_ARR_OFF, val.length, val.length);
         else
             writeInt(-1);
     }
@@ -434,7 +406,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeByteArray(byte[] val, long off, int len) {
         if (val != null)
-            lastFinished = writeArray(val, BYTE_ARR_OFF + off, len, len);
+            lastFinished = writeArray(val, GridUnsafe.BYTE_ARR_OFF + off, len, len);
         else
             writeInt(-1);
     }
@@ -442,7 +414,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeShortArray(short[] val) {
         if (val != null)
-            lastFinished = writeArray(val, SHORT_ARR_OFF, val.length, val.length << 1);
+            lastFinished = writeArray(val, GridUnsafe.SHORT_ARR_OFF, val.length, val.length << 1);
         else
             writeInt(-1);
     }
@@ -450,7 +422,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeIntArray(int[] val) {
         if (val != null)
-            lastFinished = writeArray(val, INT_ARR_OFF, val.length, val.length << 2);
+            lastFinished = writeArray(val, GridUnsafe.INT_ARR_OFF, val.length, val.length << 2);
         else
             writeInt(-1);
     }
@@ -458,7 +430,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeLongArray(long[] val) {
         if (val != null)
-            lastFinished = writeArray(val, LONG_ARR_OFF, val.length, val.length << 3);
+            lastFinished = writeArray(val, GridUnsafe.LONG_ARR_OFF, val.length, val.length << 3);
         else
             writeInt(-1);
     }
@@ -466,7 +438,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeFloatArray(float[] val) {
         if (val != null)
-            lastFinished = writeArray(val, FLOAT_ARR_OFF, val.length, val.length << 2);
+            lastFinished = writeArray(val, GridUnsafe.FLOAT_ARR_OFF, val.length, val.length << 2);
         else
             writeInt(-1);
     }
@@ -474,7 +446,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeDoubleArray(double[] val) {
         if (val != null)
-            lastFinished = writeArray(val, DOUBLE_ARR_OFF, val.length, val.length << 3);
+            lastFinished = writeArray(val, GridUnsafe.DOUBLE_ARR_OFF, val.length, val.length << 3);
         else
             writeInt(-1);
     }
@@ -482,7 +454,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeCharArray(char[] val) {
         if (val != null)
-            lastFinished = writeArray(val, CHAR_ARR_OFF, val.length, val.length << 1);
+            lastFinished = writeArray(val, GridUnsafe.CHAR_ARR_OFF, val.length, val.length << 1);
         else
             writeInt(-1);
     }
@@ -490,7 +462,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /** {@inheritDoc} */
     @Override public void writeBooleanArray(boolean[] val) {
         if (val != null)
-            lastFinished = writeArray(val, BOOLEAN_ARR_OFF, val.length, val.length);
+            lastFinished = writeArray(val, GridUnsafe.BOOLEAN_ARR_OFF, val.length, val.length);
         else
             writeInt(-1);
     }
@@ -653,7 +625,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 1);
 
-            return UNSAFE.getByte(heapArr, baseOff + pos);
+            return GridUnsafe.getByte(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -668,7 +640,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 2);
 
-            return UNSAFE.getShort(heapArr, baseOff + pos);
+            return GridUnsafe.getShortAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -683,7 +655,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 4);
 
-            return UNSAFE.getInt(heapArr, baseOff + pos);
+            return GridUnsafe.getIntAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -698,7 +670,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 8);
 
-            return UNSAFE.getLong(heapArr, baseOff + pos);
+            return GridUnsafe.getLongAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -713,7 +685,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 4);
 
-            return UNSAFE.getFloat(heapArr, baseOff + pos);
+            return GridUnsafe.getFloatAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -728,7 +700,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 8);
 
-            return UNSAFE.getDouble(heapArr, baseOff + pos);
+            return GridUnsafe.getDoubleAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -743,7 +715,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 2);
 
-            return UNSAFE.getChar(heapArr, baseOff + pos);
+            return GridUnsafe.getCharAligned(heapArr, baseOff + pos);
         }
         else
             return 0;
@@ -758,7 +730,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
             buf.position(pos + 1);
 
-            return UNSAFE.getBoolean(heapArr, baseOff + pos);
+            return GridUnsafe.getBoolean(heapArr, baseOff + pos);
         }
         else
             return false;
@@ -766,42 +738,42 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
 
     /** {@inheritDoc} */
     @Override public byte[] readByteArray() {
-        return readArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF);
+        return readArray(BYTE_ARR_CREATOR, 0, GridUnsafe.BYTE_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public short[] readShortArray() {
-        return readArray(SHORT_ARR_CREATOR, 1, SHORT_ARR_OFF);
+        return readArray(SHORT_ARR_CREATOR, 1, GridUnsafe.SHORT_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public int[] readIntArray() {
-        return readArray(INT_ARR_CREATOR, 2, INT_ARR_OFF);
+        return readArray(INT_ARR_CREATOR, 2, GridUnsafe.INT_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public long[] readLongArray() {
-        return readArray(LONG_ARR_CREATOR, 3, LONG_ARR_OFF);
+        return readArray(LONG_ARR_CREATOR, 3, GridUnsafe.LONG_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public float[] readFloatArray() {
-        return readArray(FLOAT_ARR_CREATOR, 2, FLOAT_ARR_OFF);
+        return readArray(FLOAT_ARR_CREATOR, 2, GridUnsafe.FLOAT_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public double[] readDoubleArray() {
-        return readArray(DOUBLE_ARR_CREATOR, 3, DOUBLE_ARR_OFF);
+        return readArray(DOUBLE_ARR_CREATOR, 3, GridUnsafe.DOUBLE_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public char[] readCharArray() {
-        return readArray(CHAR_ARR_CREATOR, 1, CHAR_ARR_OFF);
+        return readArray(CHAR_ARR_CREATOR, 1, GridUnsafe.CHAR_ARR_OFF);
     }
 
     /** {@inheritDoc} */
     @Override public boolean[] readBooleanArray() {
-        return readArray(BOOLEAN_ARR_CREATOR, 0, BOOLEAN_ARR_OFF);
+        return readArray(BOOLEAN_ARR_CREATOR, 0, GridUnsafe.BOOLEAN_ARR_OFF);
     }
 
     /** {@inheritDoc} */
@@ -1037,7 +1009,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         int remaining = buf.remaining();
 
         if (toWrite <= remaining) {
-            UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, toWrite);
+            GridUnsafe.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, toWrite);
 
             pos += toWrite;
 
@@ -1048,7 +1020,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
             return true;
         }
         else {
-            UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining);
+            GridUnsafe.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining);
 
             pos += remaining;
 
@@ -1103,7 +1075,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
         lastFinished = toRead <= remaining;
 
         if (lastFinished) {
-            UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead);
+            GridUnsafe.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead);
 
             buf.position(pos + toRead);
 
@@ -1116,7 +1088,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
             return arr;
         }
         else {
-            UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining);
+            GridUnsafe.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining);
 
             buf.position(pos + remaining);
 
@@ -1360,7 +1332,7 @@ public class DirectByteBufferStreamImplV1 implements DirectByteBufferStream {
     /**
      * Array creator.
      */
-    private static interface ArrayCreator<T> {
+    private interface ArrayCreator<T> {
         /**
          * @param len Array length or {@code -1} if array was not fully read.
          * @return New array.


Mime
View raw message