ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [14/19] ignite git commit: ignite-2080 Data alignment issues with Unsafe
Date Wed, 03 Feb 2016 03:24:55 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/a87decdc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a87decdc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a87decdc

Branch: refs/heads/ignite-2450
Commit: a87decdca4009a2af857d8ca6a46e5a719786a6d
Parents: 4035d40
Author: agura <agura@gridgain.com>
Authored: Mon Jan 11 14:53:02 2016 +0300
Committer: agura <agura@gridgain.com>
Committed: Tue Feb 2 20:26:24 2016 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryClassDescriptor.java  |    6 +-
 .../internal/binary/BinaryFieldAccessor.java    |   45 +-
 .../internal/binary/BinaryMarshaller.java       |    5 +-
 .../binary/BinaryObjectOffheapImpl.java         |   34 +-
 .../internal/binary/BinaryPrimitives.java       |  117 +-
 .../streams/BinaryAbstractInputStream.java      |   53 +-
 .../streams/BinaryAbstractOutputStream.java     |   90 +-
 .../binary/streams/BinaryAbstractStream.java    |   34 -
 .../binary/streams/BinaryHeapInputStream.java   |   43 +-
 .../binary/streams/BinaryHeapOutputStream.java  |   86 +-
 .../streams/BinaryMemoryAllocatorChunk.java     |    9 +-
 .../streams/BinaryOffheapInputStream.java       |   42 +-
 .../streams/BinaryOffheapOutputStream.java      |   94 +-
 .../internal/direct/DirectMessageReader.java    |    2 +-
 .../internal/direct/DirectMessageWriter.java    |    2 +-
 .../stream/v1/DirectByteBufferStreamImplV1.java |  106 +-
 .../stream/v2/DirectByteBufferStreamImplV2.java |  351 ++++-
 .../cache/GridCacheEvictionManager.java         |    7 +-
 .../cache/GridCacheOffheapSwapEntry.java        |   24 +-
 .../cache/GridCacheSwapEntryImpl.java           |   61 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  |    8 +-
 .../dht/atomic/GridDhtAtomicCache.java          |   13 +-
 .../local/atomic/GridLocalAtomicCache.java      |    9 +-
 .../IgniteCacheObjectProcessorImpl.java         |    7 +-
 .../platform/memory/PlatformAbstractMemory.java |    6 +-
 .../PlatformBigEndianOutputStreamImpl.java      |   14 +-
 .../memory/PlatformInputStreamImpl.java         |   53 +-
 .../platform/memory/PlatformMemoryUtils.java    |  108 +-
 .../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 | 1483 +++++++++++++++++-
 .../ignite/internal/util/IgniteUtils.java       |   99 +-
 .../internal/util/io/GridUnsafeDataInput.java   |  145 +-
 .../internal/util/io/GridUnsafeDataOutput.java  |  165 +-
 .../util/offheap/unsafe/GridUnsafeMap.java      |   75 +-
 .../util/offheap/unsafe/GridUnsafeMemory.java   |  106 +-
 .../optimized/OptimizedClassDescriptor.java     |   22 +-
 .../optimized/OptimizedMarshaller.java          |    5 +-
 .../optimized/OptimizedMarshallerUtils.java     |   44 +-
 .../optimized/OptimizedObjectInputStream.java   |   10 +-
 .../java/org/apache/ignite/GridTestIoUtils.java |  117 +-
 .../ignite/internal/GridAffinitySelfTest.java   |    2 +-
 .../binary/BinaryFieldsOffheapSelfTest.java     |   13 +-
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   13 +-
 .../binary/BinaryMarshallerSelfTest.java        |   17 +-
 ...naryObjectBuilderDefaultMappersSelfTest.java |   24 +-
 .../mutabletest/GridBinaryTestClasses.java      |    3 +-
 .../AbstractBinaryStreamByteOrderSelfTest.java  |  464 ++++++
 .../BinaryHeapStreamByteOrderSelfTest.java      |   29 +
 .../BinaryOffheapStreamByteOrderSelfTest.java   |   31 +
 ...ByteBufferStreamImplV2ByteOrderSelfTest.java |  244 +++
 .../cache/GridCacheConcurrentMapSelfTest.java   |   13 +-
 ...ContinuousQueryFailoverAbstractSelfTest.java |    6 +
 ...dUnsafeDataInputOutputByteOrderSelfTest.java |  249 +++
 .../ignite/lang/GridBasicPerformanceTest.java   |   11 +-
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java |    2 +-
 .../testframework/junits/GridAbstractTest.java  |    4 +-
 .../IgniteBinaryObjectsTestSuite.java           |    6 +
 .../IgniteMarshallerSelfTestSuite.java          |    4 +
 .../hadoop/shuffle/HadoopShuffleJob.java        |    5 +-
 .../hadoop/shuffle/HadoopShuffleMessage.java    |   10 +-
 .../shuffle/streams/HadoopDataOutStream.java    |    6 +-
 .../HadoopConcurrentHashMultimapSelftest.java   |    6 +-
 .../collections/HadoopSkipListSelfTest.java     |    5 +-
 66 files changed, 3851 insertions(+), 1104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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 233e74b..5cb8a86 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
@@ -46,16 +46,12 @@ 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;
 
 /**
  * Binary class descriptor.
  */
 public class BinaryClassDescriptor {
     /** */
-    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
     @GridToStringExclude
     private final BinaryContext ctx;
 
@@ -776,7 +772,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/a87decdc/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..8c8bf27 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.getByteField(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.putByteField(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.getBooleanField(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.putBooleanField(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.getShortField(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.putShortField(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.getCharField(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.putCharField(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.getIntField(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.putIntField(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.getLongField(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.putLongField(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.getFloatField(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.putFloatField(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.getDoubleField(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.putDoubleField(obj, offset, val);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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/a87decdc/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/a87decdc/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..8b82fad 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
@@ -18,33 +18,20 @@
 package org.apache.ignite.internal.binary;
 
 import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
 
-import java.nio.ByteOrder;
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
 
 /**
  * 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;
-
     /**
      * @param arr Array.
      * @param off Offset.
      * @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 +40,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 +49,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 +60,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 +73,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;
     }
@@ -124,10 +111,12 @@ public abstract class BinaryPrimitives {
      * @param val Value.
      */
     public static void writeShort(byte[] arr, int off, short val) {
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(arr, pos, val);
+        else
+            GridUnsafe.putShort(arr, pos, val);
     }
 
     /**
@@ -136,12 +125,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static short readShort(byte[] arr, int off) {
-        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(arr, pos) : GridUnsafe.getShort(arr, pos);
     }
 
     /**
@@ -150,12 +136,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static short readShort(long ptr, int off) {
-        short val = UNSAFE.getShort(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
+        long addr = ptr + off;
 
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(addr) : GridUnsafe.getShort(addr);
     }
 
     /**
@@ -164,10 +147,12 @@ public abstract class BinaryPrimitives {
      * @param val Value.
      */
     public static void writeChar(byte[] arr, int off, char val) {
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putCharLE(arr, pos, val);
+        else
+            GridUnsafe.putChar(arr, pos, val);
     }
 
     /**
@@ -176,12 +161,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static char readChar(byte[] arr, int off) {
-        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getCharLE(arr, pos): GridUnsafe.getChar(arr, pos);
     }
 
     /**
@@ -190,12 +172,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static char readChar(long ptr, int off) {
-        char val = UNSAFE.getChar(ptr + off);
+        long addr = ptr + off;
 
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getCharLE(addr) : GridUnsafe.getChar(addr);
     }
 
     /**
@@ -206,7 +185,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 +203,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++)
@@ -240,10 +219,12 @@ public abstract class BinaryPrimitives {
      * @param val Value.
      */
     public static void writeInt(byte[] arr, int off, int val) {
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(arr, pos, val);
+        else
+            GridUnsafe.putInt(arr, pos, val);
     }
 
     /**
@@ -252,12 +233,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static int readInt(byte[] arr, int off) {
-        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(arr, pos) : GridUnsafe.getInt(arr, pos);
     }
 
     /**
@@ -266,12 +244,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static int readInt(long ptr, int off) {
-        int val = UNSAFE.getInt(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long addr = ptr + off;
 
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(addr) : GridUnsafe.getInt(addr);
     }
 
     /**
@@ -280,10 +255,12 @@ public abstract class BinaryPrimitives {
      * @param val Value.
      */
     public static void writeLong(byte[] arr, int off, long val) {
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putLongLE(arr, pos, val);
+        else
+            GridUnsafe.putLong(arr, pos, val);
     }
 
     /**
@@ -292,12 +269,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static long readLong(byte[] arr, int off) {
-        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
+        long pos = GridUnsafe.BYTE_ARR_OFF + off;
 
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getLongLE(arr, pos) : GridUnsafe.getLong(arr, pos);
     }
 
     /**
@@ -306,12 +280,9 @@ public abstract class BinaryPrimitives {
      * @return Value.
      */
     public static long readLong(long ptr, int off) {
-        long val = UNSAFE.getLong(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
+        long addr = ptr + off;
 
-        return val;
+        return BIG_ENDIAN ? GridUnsafe.getLongLE(addr) : GridUnsafe.getLong(addr);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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..b6c30bb 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,9 @@
 package org.apache.ignite.internal.binary.streams;
 
 import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
 
 /**
  * Binary abstract input stream.
@@ -40,7 +43,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 +59,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;
     }
@@ -69,9 +72,6 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         shift(2);
 
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
         return res;
     }
 
@@ -83,9 +83,9 @@ 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) {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++)
                 res[i] = Short.reverseBytes(res[i]);
         }
@@ -101,9 +101,6 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         shift(2);
 
-        if (!LITTLE_ENDIAN)
-            res = Character.reverseBytes(res);
-
         return res;
     }
 
@@ -115,9 +112,9 @@ 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) {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++)
                 res[i] = Character.reverseBytes(res[i]);
         }
@@ -133,9 +130,6 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         shift(4);
 
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
         return res;
     }
 
@@ -147,9 +141,9 @@ 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) {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++)
                 res[i] = Integer.reverseBytes(res[i]);
         }
@@ -200,17 +194,17 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         float[] res = new float[cnt];
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, FLOAT_ARR_OFF, len);
-        else {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++) {
                 int x = readIntFast();
 
                 shift(4);
 
-                res[i] = Float.intBitsToFloat(Integer.reverseBytes(x));
+                res[i] = Float.intBitsToFloat(x);
             }
         }
+        else
+            copyAndShift(res, GridUnsafe.FLOAT_ARR_OFF, len);
 
         return res;
     }
@@ -223,9 +217,6 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         shift(8);
 
-        if (!LITTLE_ENDIAN)
-            res = Long.reverseBytes(res);
-
         return res;
     }
 
@@ -237,9 +228,9 @@ 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) {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++)
                 res[i] = Long.reverseBytes(res[i]);
         }
@@ -260,17 +251,17 @@ public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
 
         double[] res = new double[cnt];
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, DOUBLE_ARR_OFF, len);
-        else {
+        if (BIG_ENDIAN) {
             for (int i = 0; i < res.length; i++) {
                 long x = readLongFast();
 
                 shift(8);
 
-                res[i] = Double.longBitsToDouble(Long.reverseBytes(x));
+                res[i] = Double.longBitsToDouble(x);
             }
         }
+        else
+            copyAndShift(res, GridUnsafe.DOUBLE_ARR_OFF, len);
 
         return res;
     }
@@ -280,7 +271,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/a87decdc/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..b9df68e 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,10 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
+
 /**
  * Base binary output stream.
  */
@@ -36,7 +40,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,16 +52,13 @@ 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} */
     @Override public void writeShort(short val) {
         ensureCapacity(pos + 2);
 
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
         writeShortFast(val);
 
         shift(2);
@@ -69,23 +70,21 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, SHORT_ARR_OFF, cnt);
-        else {
-            for (short item : val)
-                writeShortFast(Short.reverseBytes(item));
+        if (BIG_ENDIAN) {
+            for (short item : val) {
+                writeShortFast(item);
 
-            shift(cnt);
+                shift(2);
+            }
         }
+        else
+            copyAndShift(val, GridUnsafe.SHORT_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
     @Override public void writeChar(char val) {
         ensureCapacity(pos + 2);
 
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
         writeCharFast(val);
 
         shift(2);
@@ -97,23 +96,21 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, CHAR_ARR_OFF, cnt);
-        else {
-            for (char item : val)
-                writeCharFast(Character.reverseBytes(item));
+        if (BIG_ENDIAN) {
+            for (char item : val) {
+                writeCharFast(item);
 
-            shift(cnt);
+                shift(2);
+            }
         }
+        else
+            copyAndShift(val, GridUnsafe.CHAR_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
     @Override public void writeInt(int val) {
         ensureCapacity(pos + 4);
 
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
         writeIntFast(val);
 
         shift(4);
@@ -139,14 +136,15 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, INT_ARR_OFF, cnt);
-        else {
-            for (int item : val)
-                writeIntFast(Integer.reverseBytes(item));
+        if (BIG_ENDIAN) {
+            for (int item : val) {
+                writeIntFast(item);
 
-            shift(cnt);
+                shift(4);
+            }
         }
+        else
+            copyAndShift(val, GridUnsafe.INT_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
@@ -160,24 +158,21 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, FLOAT_ARR_OFF, cnt);
-        else {
+        if (BIG_ENDIAN) {
             for (float item : val) {
-                writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
+                writeIntFast(Float.floatToIntBits(item));
 
                 shift(4);
             }
         }
+        else
+            copyAndShift(val, GridUnsafe.FLOAT_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
     @Override public void writeLong(long val) {
         ensureCapacity(pos + 8);
 
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
         writeLongFast(val);
 
         shift(8);
@@ -189,14 +184,15 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, LONG_ARR_OFF, cnt);
-        else {
-            for (long item : val)
-                writeLongFast(Long.reverseBytes(item));
+        if (BIG_ENDIAN) {
+            for (long item : val) {
+                writeLongFast(item);
 
-            shift(cnt);
+                shift(8);
+            }
         }
+        else
+            copyAndShift(val, GridUnsafe.LONG_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
@@ -210,22 +206,22 @@ public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
 
         ensureCapacity(pos + cnt);
 
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
-        else {
+        if (BIG_ENDIAN) {
             for (double item : val) {
-                writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
+                writeLongFast(Double.doubleToLongBits(item));
 
                 shift(8);
             }
         }
+        else
+            copyAndShift(val, GridUnsafe.DOUBLE_ARR_OFF, cnt);
     }
 
     /** {@inheritDoc} */
     @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/a87decdc/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..2983cbc 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
@@ -17,10 +17,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.
  */
@@ -31,36 +27,6 @@ public abstract class BinaryAbstractStream implements BinaryStream {
     /** Byte: one. */
     protected static final byte BYTE_ONE = 1;
 
-    /** 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/a87decdc/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..b584373 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,9 +18,12 @@
 package org.apache.ignite.internal.binary.streams;
 
 import java.util.Arrays;
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
 
 /**
- * Binary off-heap input stream.
+ * Binary heap input stream.
  */
 public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
     /**
@@ -75,7 +78,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 +100,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,53 +117,57 @@ 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);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(data, off) : GridUnsafe.getShort(data, off);
+
     }
 
     /** {@inheritDoc} */
     @Override protected char readCharFast() {
-        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getCharLE(data, off) : GridUnsafe.getChar(data, off);
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntFast() {
-        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(data, off) : GridUnsafe.getInt(data, off);
     }
 
     /** {@inheritDoc} */
     @Override protected long readLongFast() {
-        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getLongLE(data, off) : GridUnsafe.getLong(data, off);
     }
 
     /** {@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);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(data, off) : GridUnsafe.getShort(data, off);
 
-        return res;
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(data, off) : GridUnsafe.getInt(data, off);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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..2c31641 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,10 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
+
 /**
  * Binary heap output stream.
  */
@@ -71,7 +75,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,88 +92,120 @@ 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);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(data, off, val);
+        else
+            GridUnsafe.putShort(data, off, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putCharLE(data, off, val);
+        else
+            GridUnsafe.putChar(data, off, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(data, off, val);
+        else
+            GridUnsafe.putInt(data, off, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putLongLE(data, off, val);
+        else
+            GridUnsafe.putLong(data, off, 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} */
     @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(data, off, val);
+        else
+            GridUnsafe.putShort(data, off, val);
 
         shift(2);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(data, off, val);
+        else
+            GridUnsafe.putShort(data, off, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putCharLE(data, off, val);
+        else
+            GridUnsafe.putChar(data, off, val);
 
         shift(2);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(data, off, val);
+        else
+            GridUnsafe.putInt(data, off, val);
 
         shift(4);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(data, off, val);
+        else
+            GridUnsafe.putInt(data, off, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
+        long off = GridUnsafe.BYTE_ARR_OFF + pos;
 
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putLongLE(data, off, val);
+        else
+            GridUnsafe.putLong(data, off, val);
 
         shift(8);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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/a87decdc/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..9230846 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,10 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
+
 /**
  * Binary off-heap input stream.
  */
@@ -70,7 +74,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,59 +86,61 @@ 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);
+        long addr = ptr + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(addr) : GridUnsafe.getShort(addr);
     }
 
     /** {@inheritDoc} */
     @Override protected char readCharFast() {
-        return UNSAFE.getChar(ptr + pos);
+        long addr = ptr + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getCharLE(addr) : GridUnsafe.getChar(addr);
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntFast() {
-        return UNSAFE.getInt(ptr + pos);
+        long addr = ptr + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(addr) : GridUnsafe.getInt(addr);
     }
 
     /** {@inheritDoc} */
     @Override protected long readLongFast() {
-        return UNSAFE.getLong(ptr + pos);
+        long addr = ptr + pos;
+
+        return BIG_ENDIAN ? GridUnsafe.getLongLE(addr) : GridUnsafe.getLong(addr);
     }
 
     /** {@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);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
+        long addr = ptr + pos;
 
-        return res;
+        return BIG_ENDIAN ? GridUnsafe.getShortLE(addr) : GridUnsafe.getShort(addr);
     }
 
     /** {@inheritDoc} */
     @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(ptr + pos);
+        long addr = ptr + pos;
 
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
+        return BIG_ENDIAN ? GridUnsafe.getIntLE(addr) : GridUnsafe.getInt(addr);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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..1cb9f4f 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,10 @@
 
 package org.apache.ignite.internal.binary.streams;
 
+import org.apache.ignite.internal.util.GridUnsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
+
 /**
  * Binary offheap output stream.
  */
@@ -73,7 +77,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 +98,54 @@ 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);
+        long addr = ptr + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(addr, val);
+        else
+            GridUnsafe.putShort(addr, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(ptr + pos, val);
+        long addr = ptr + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putCharLE(addr, val);
+        else
+            GridUnsafe.putChar(addr, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(ptr + pos, val);
+        long addr = ptr + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(addr, val);
+        else
+            GridUnsafe.putInt(addr, val);
     }
 
     /** {@inheritDoc} */
     @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(ptr + pos, val);
+        long addr = ptr + pos;
+
+        if (BIG_ENDIAN)
+            GridUnsafe.putLongLE(addr, val);
+        else
+            GridUnsafe.putLong(addr, val);
     }
 
     /** {@inheritDoc} */
@@ -131,61 +155,73 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
+        GridUnsafe.putByte(ptr + pos++, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putShort(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(addr, val);
+        else
+            GridUnsafe.putShort(addr, val);
 
         shift(2);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putShort(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putShortLE(addr, val);
+        else
+            GridUnsafe.putShort(addr, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putChar(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putCharLE(addr, val);
+        else
+            GridUnsafe.putChar(addr, val);
 
         shift(2);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putInt(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(addr, val);
+        else
+            GridUnsafe.putInt(addr, val);
 
         shift(4);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putInt(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putIntLE(addr, val);
+        else
+            GridUnsafe.putInt(addr, val);
     }
 
     /** {@inheritDoc} */
     @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
+        long addr = ptr + pos;
 
-        UNSAFE.putLong(ptr + pos, val);
+        if (BIG_ENDIAN)
+            GridUnsafe.putLongLE(addr, val);
+        else
+            GridUnsafe.putLong(addr, val);
 
         shift(8);
     }
@@ -197,7 +233,7 @@ public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
      * @return Pointer.
      */
     protected long allocate(int cap) {
-        return UNSAFE.allocateMemory(cap);
+        return GridUnsafe.allocateMemory(cap);
     }
 
     /**
@@ -208,7 +244,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 +253,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/a87decdc/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..b567a03 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
@@ -26,8 +26,8 @@ import org.apache.ignite.internal.direct.state.DirectMessageState;
 import org.apache.ignite.internal.direct.state.DirectMessageStateItem;
 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.v2.DirectByteBufferStreamImplV2;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.extensions.communication.Message;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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..be17113 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
@@ -26,9 +26,9 @@ import org.apache.ignite.internal.direct.state.DirectMessageState;
 import org.apache.ignite.internal.direct.state.DirectMessageStateItem;
 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.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.direct.stream.v2.DirectByteBufferStreamImplV2;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.extensions.communication.Message;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/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..2187945 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.putShort(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.putInt(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.putLong(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.putFloat(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.putDouble(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.putChar(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.getShort(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.getInt(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.getLong(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.getFloat(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.getDouble(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.getChar(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