ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/5] ignite git commit: ignite-2080 Data alignment issues with Unsafe
Date Tue, 02 Feb 2016 17:27:48 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java
index 359d36c..3f58447 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMap.java
@@ -45,8 +45,23 @@ import static org.apache.ignite.internal.util.offheap.GridOffHeapEvent.REHASH;
  */
 public class GridUnsafeMap implements GridOffHeapMap {
     /** Header size. */
-    private static final int HEADER = 4 /*hash*/ + 4 /*key-size*/  + 4 /*value-size*/ + 8 /*queue-address*/ +
-        8 /*next-address*/;
+    private static final int HEADER_SIZE = 8 /*queue-address*/ + 8 /*next-address*/ + 4 /*hash*/ + 4 /*key-size*/
+        + 4 /*value-size*/;
+
+    /** Header queue address offset. */
+    private static final long HEADER_QUEUE_ADDR_OFF = 0;
+
+    /** Header next address offset. */
+    private static final long HEADER_NEXT_ADDR_OFF = 8;
+
+    /** Header hash offset. */
+    private static final long HEADER_HASH_OFF = 16;
+
+    /** Header key size offset. */
+    private static final long HEADER_KEY_SIZE_OFF = 20;
+
+    /** Header value size. */
+    private static final long HEADER_VALUE_SIZE = 24;
 
     /** Debug flag. */
     private static final boolean DEBUG = false;
@@ -789,7 +804,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                                 int keyLen = Entry.readKeyLength(entryAddr, mem);
                                 int valLen = Entry.readValueLength(entryAddr, mem);
 
-                                byte[] valBytes =  mem.readBytes(entryAddr + HEADER + keyLen, valLen);
+                                byte[] valBytes =  mem.readBytes(entryAddr + HEADER_SIZE + keyLen, valLen);
 
                                 bin.add(F.t(Entry.readKeyBytes(entryAddr, mem), valBytes));
                             }
@@ -860,9 +875,9 @@ public class GridUnsafeMap implements GridOffHeapMap {
                                 int keyLen = Entry.readKeyLength(entryAddr, mem);
                                 int valLen = Entry.readValueLength(entryAddr, mem);
 
-                                T2<Long, Integer> keyPtr = new T2<>(entryAddr + HEADER, keyLen);
+                                T2<Long, Integer> keyPtr = new T2<>(entryAddr + HEADER_SIZE, keyLen);
 
-                                T2<Long, Integer> valPtr = new T2<>(entryAddr + HEADER + keyLen, valLen);
+                                T2<Long, Integer> valPtr = new T2<>(entryAddr + HEADER_SIZE + keyLen, valLen);
 
                                 T res = c.apply(keyPtr, valPtr);
 
@@ -1033,7 +1048,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                                 int keyLen = Entry.readKeyLength(cur, mem);
                                 int valLen = Entry.readValueLength(cur, mem);
 
-                                valBytes = mem.readBytes(cur + HEADER + keyLen, valLen);
+                                valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);
                             }
 
                             if (rmvEvicted) {
@@ -1101,7 +1116,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
             if (cnt + 1 > threshold)
                 rehash();
 
-            int size = HEADER + keyBytes.length + valBytes.length;
+            int size = HEADER_SIZE + keyBytes.length + valBytes.length;
 
             boolean poll = !mem.reserve(size);
 
@@ -1230,7 +1245,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                     }
                 }
 
-                size = HEADER + keyBytes.length + valBytes.length;
+                size = HEADER_SIZE + keyBytes.length + valBytes.length;
 
                 poll = !mem.reserve(size);
 
@@ -1332,7 +1347,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                                 keyLen = Entry.readKeyLength(cur, mem);
                                 valLen = Entry.readValueLength(cur, mem);
 
-                                long valPtr = cur + HEADER + keyLen;
+                                long valPtr = cur + HEADER_SIZE + keyLen;
 
                                 if (!p.apply(valPtr, valLen))
                                     return null;
@@ -1353,7 +1368,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                                     valLen = Entry.readValueLength(cur, mem);
                                 }
 
-                                valBytes = mem.readBytes(cur + HEADER + keyLen, valLen);
+                                valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);
                             }
                             else
                                 valBytes = EMPTY_BYTES;
@@ -1445,7 +1460,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                         int keyLen = Entry.readKeyLength(addr, mem);
                         int valLen = Entry.readValueLength(addr, mem);
 
-                        return new IgniteBiTuple<>(addr + HEADER + keyLen, valLen);
+                        return new IgniteBiTuple<>(addr + HEADER_SIZE + keyLen, valLen);
                     }
 
                     addr = Entry.nextAddress(addr, mem);
@@ -1510,7 +1525,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
                             int keyLen = Entry.readKeyLength(addr, mem);
                             int valLen = Entry.readValueLength(addr, mem);
 
-                            return mem.readBytes(addr + HEADER + keyLen, valLen);
+                            return mem.readBytes(addr + HEADER_SIZE + keyLen, valLen);
                         }
                     }
 
@@ -1570,7 +1585,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Entry memory size.
          */
         static int size(byte[] keyBytes, byte[] valBytes) {
-            return HEADER + keyBytes.length + valBytes.length;
+            return HEADER_SIZE + keyBytes.length + valBytes.length;
         }
 
         /**
@@ -1579,7 +1594,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Entry size.
          */
         static int size(long addr, GridUnsafeMemory mem) {
-            return HEADER + readKeyLength(addr, mem) + readValueLength(addr, mem);
+            return HEADER_SIZE + readKeyLength(addr, mem) + readValueLength(addr, mem);
         }
 
         /**
@@ -1588,7 +1603,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Hash.
          */
         static int hash(long ptr, GridUnsafeMemory mem) {
-            return mem.readInt(ptr);
+            return mem.readInt(ptr + HEADER_HASH_OFF);
         }
 
         /**
@@ -1597,7 +1612,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void hash(long ptr, int hash, GridUnsafeMemory mem) {
-            mem.writeInt(ptr, hash);
+            mem.writeInt(ptr + HEADER_HASH_OFF, hash);
         }
 
         /**
@@ -1606,7 +1621,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Key length.
          */
         static int readKeyLength(long ptr, GridUnsafeMemory mem) {
-            int len = mem.readInt(ptr + 4);
+            int len = mem.readInt(ptr + HEADER_KEY_SIZE_OFF);
 
             assert len >= 0 : "Invalid key length [addr=" + String.format("0x%08x", ptr) +
                 ", len=" + Long.toHexString(len) + ']';
@@ -1622,7 +1637,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void writeKeyLength(long ptr, int len, GridUnsafeMemory mem) {
-            mem.writeInt(ptr + 4, len);
+            mem.writeInt(ptr + HEADER_KEY_SIZE_OFF, len);
         }
 
         /**
@@ -1631,7 +1646,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Value length.
          */
         static int readValueLength(long ptr, GridUnsafeMemory mem) {
-            int len = mem.readInt(ptr + 8);
+            int len = mem.readInt(ptr + HEADER_VALUE_SIZE);
 
             assert len >= 0 : "Invalid value length [addr=" + String.format("0x%08x", ptr) +
                 ", len=" + Integer.toHexString(len) + ']';
@@ -1647,7 +1662,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void writeValueLength(long ptr, int len, GridUnsafeMemory mem) {
-            mem.writeInt(ptr + 8, len);
+            mem.writeInt(ptr + HEADER_VALUE_SIZE, len);
         }
 
         /**
@@ -1656,7 +1671,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Queue address.
          */
         static long queueAddress(long ptr, GridUnsafeMemory mem) {
-            return mem.readLong(ptr + 12);
+            return mem.readLong(ptr + HEADER_QUEUE_ADDR_OFF);
         }
 
         /**
@@ -1665,7 +1680,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void queueAddress(long ptr, long qAddr, GridUnsafeMemory mem) {
-            mem.writeLong(ptr + 12, qAddr);
+            mem.writeLong(ptr + HEADER_QUEUE_ADDR_OFF, qAddr);
         }
 
         /**
@@ -1675,7 +1690,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return {@code True} if changed to zero.
          */
         static boolean clearQueueAddress(long ptr, long qAddr, GridUnsafeMemory mem) {
-            return mem.casLong(ptr + 12, qAddr, 0);
+            return mem.casLong(ptr + HEADER_QUEUE_ADDR_OFF, qAddr, 0);
         }
 
         /**
@@ -1684,7 +1699,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @return Next address.
          */
         static long nextAddress(long ptr, GridUnsafeMemory mem) {
-            return mem.readLong(ptr + 20);
+            return mem.readLong(ptr + HEADER_NEXT_ADDR_OFF);
         }
 
         /**
@@ -1695,7 +1710,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void nextAddress(long ptr, long addr, GridUnsafeMemory mem) {
-            mem.writeLong(ptr + 20, addr);
+            mem.writeLong(ptr + HEADER_NEXT_ADDR_OFF, addr);
         }
 
         /**
@@ -1706,7 +1721,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
         static byte[] readKeyBytes(long ptr, GridUnsafeMemory mem) {
             int keyLen = readKeyLength(ptr, mem);
 
-            return mem.readBytes(ptr + HEADER, keyLen);
+            return mem.readBytes(ptr + HEADER_SIZE, keyLen);
         }
 
         /**
@@ -1715,7 +1730,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void writeKeyBytes(long ptr, byte[] keyBytes, GridUnsafeMemory mem) {
-            mem.writeBytes(ptr + HEADER, keyBytes);
+            mem.writeBytes(ptr + HEADER_SIZE, keyBytes);
         }
 
         /**
@@ -1727,7 +1742,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
             int keyLen = readKeyLength(ptr, mem);
             int valLen = readValueLength(ptr, mem);
 
-            return mem.readBytes(ptr + HEADER + keyLen, valLen);
+            return mem.readBytes(ptr + HEADER_SIZE + keyLen, valLen);
         }
 
         /**
@@ -1746,7 +1761,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
          * @param mem Memory.
          */
         static void writeValueBytes(long ptr, int keyLen, byte[] valBytes, GridUnsafeMemory mem) {
-            mem.writeBytes(ptr + HEADER + keyLen, valBytes);
+            mem.writeBytes(ptr + HEADER_SIZE + keyLen, valBytes);
         }
 
         /**
@@ -1799,7 +1814,7 @@ public class GridUnsafeMap implements GridOffHeapMap {
         static boolean keyEquals(long ptr, byte[] keyBytes, GridUnsafeMemory mem) {
             long len = readKeyLength(ptr, mem);
 
-            return len == keyBytes.length && mem.compare(ptr + HEADER, keyBytes);
+            return len == keyBytes.length && GridUnsafeMemory.compare(ptr + HEADER_SIZE, keyBytes);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java
index cf0cb5c..87ba2f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafeMemory.java
@@ -25,7 +25,6 @@ import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.lang.IgniteBiTuple;
-import sun.misc.Unsafe;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_OFFHEAP_SAFE_RELEASE;
 import static org.apache.ignite.internal.util.offheap.GridOffHeapEvent.ALLOCATE;
@@ -35,18 +34,9 @@ import static org.apache.ignite.internal.util.offheap.GridOffHeapEvent.RELEASE;
  * Unsafe memory.
  */
 public class GridUnsafeMemory {
-    /** Unsafe handle. */
-    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
     /** Free byte. */
     private static final byte FREE = (byte)0;
 
-    /** Byte array offset. */
-    public static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Address size. */
-    private static final int ADDR_SIZE = UNSAFE.addressSize();
-
     /** Safe offheap release flag. */
     private static final boolean SAFE_RELEASE = IgniteSystemProperties.getBoolean(IGNITE_OFFHEAP_SAFE_RELEASE);
 
@@ -174,7 +164,7 @@ public class GridUnsafeMemory {
             cnt.addAndGet(size);
 
         try {
-            long ptr = UNSAFE.allocateMemory(size);
+            long ptr = GridUnsafe.allocateMemory(size);
 
             if (init)
                 fill(ptr, size, FREE);
@@ -198,7 +188,7 @@ public class GridUnsafeMemory {
      * @param b Value.
      */
     public void fill(long ptr, long size, byte b) {
-        UNSAFE.setMemory(ptr, size, b);
+        GridUnsafe.setMemory(ptr, size, b);
     }
 
     /**
@@ -233,7 +223,7 @@ public class GridUnsafeMemory {
             if (SAFE_RELEASE)
                 fill(ptr, size, (byte)0xAB);
 
-            UNSAFE.freeMemory(ptr);
+            GridUnsafe.freeMemory(ptr);
 
             cnt.addAndGet(-size);
 
@@ -247,7 +237,7 @@ public class GridUnsafeMemory {
      * @return Long value.
      */
     public long readLong(long ptr) {
-        return UNSAFE.getLong(ptr);
+        return GridUnsafe.getLong(ptr);
     }
 
     /**
@@ -255,7 +245,7 @@ public class GridUnsafeMemory {
      * @param v Long value.
      */
     public void writeLong(long ptr, long v) {
-        UNSAFE.putLong(ptr, v);
+        GridUnsafe.putLong(ptr, v);
     }
 
     /**
@@ -263,7 +253,7 @@ public class GridUnsafeMemory {
      * @return Long value.
      */
     public long readLongVolatile(long ptr) {
-        return UNSAFE.getLongVolatile(null, ptr);
+        return GridUnsafe.getLongVolatile(null, ptr);
     }
 
     /**
@@ -271,7 +261,7 @@ public class GridUnsafeMemory {
      * @param v Long value.
      */
     public void writeLongVolatile(long ptr, long v) {
-        UNSAFE.putLongVolatile(null, ptr, v);
+        GridUnsafe.putLongVolatile(null, ptr, v);
     }
 
     /**
@@ -281,7 +271,7 @@ public class GridUnsafeMemory {
      * @return {@code true} If operation succeeded.
      */
     public boolean casLong(long ptr, long exp, long v) {
-        return UNSAFE.compareAndSwapLong(null, ptr, exp, v);
+        return GridUnsafe.compareAndSwapLong(null, ptr, exp, v);
     }
 
     /**
@@ -289,7 +279,7 @@ public class GridUnsafeMemory {
      * @return Integer value.
      */
     public int readInt(long ptr) {
-        return UNSAFE.getInt(ptr);
+        return GridUnsafe.getInt(ptr);
     }
 
     /**
@@ -297,7 +287,7 @@ public class GridUnsafeMemory {
      * @param v Integer value.
      */
     public void writeInt(long ptr, int v) {
-        UNSAFE.putInt(ptr, v);
+        GridUnsafe.putInt(ptr, v);
     }
 
     /**
@@ -305,7 +295,7 @@ public class GridUnsafeMemory {
      * @return Integer value.
      */
     public int readIntVolatile(long ptr) {
-        return UNSAFE.getIntVolatile(null, ptr);
+        return GridUnsafe.getIntVolatile(null, ptr);
     }
 
     /**
@@ -313,7 +303,7 @@ public class GridUnsafeMemory {
      * @param v Integer value.
      */
     public void writeIntVolatile(long ptr, int v) {
-        UNSAFE.putIntVolatile(null, ptr, v);
+        GridUnsafe.putIntVolatile(null, ptr, v);
     }
 
     /**
@@ -323,7 +313,7 @@ public class GridUnsafeMemory {
      * @return {@code true} If operation succeeded.
      */
     public boolean casInt(long ptr, int exp, int v) {
-        return UNSAFE.compareAndSwapInt(null, ptr, exp, v);
+        return GridUnsafe.compareAndSwapInt(null, ptr, exp, v);
     }
 
     /**
@@ -331,7 +321,7 @@ public class GridUnsafeMemory {
      * @return Float value.
      */
     public float readFloat(long ptr) {
-        return UNSAFE.getFloat(ptr);
+        return GridUnsafe.getFloat(ptr);
     }
 
     /**
@@ -339,7 +329,7 @@ public class GridUnsafeMemory {
      * @param v Value.
      */
     public void writeFloat(long ptr, float v) {
-        UNSAFE.putFloat(ptr, v);
+        GridUnsafe.putFloat(ptr, v);
     }
 
     /**
@@ -347,7 +337,7 @@ public class GridUnsafeMemory {
      * @return Double value.
      */
     public double readDouble(long ptr) {
-        return UNSAFE.getDouble(ptr);
+        return GridUnsafe.getDouble(ptr);
     }
 
     /**
@@ -355,7 +345,7 @@ public class GridUnsafeMemory {
      * @param v Value.
      */
     public void writeDouble(long ptr, double v) {
-        UNSAFE.putDouble(ptr, v);
+        GridUnsafe.putDouble(ptr, v);
     }
 
     /**
@@ -363,7 +353,7 @@ public class GridUnsafeMemory {
      * @return Short value.
      */
     public short readShort(long ptr) {
-        return UNSAFE.getShort(ptr);
+        return GridUnsafe.getShort(ptr);
     }
 
     /**
@@ -371,7 +361,7 @@ public class GridUnsafeMemory {
      * @param v Short value.
      */
     public void writeShort(long ptr, short v) {
-        UNSAFE.putShort(ptr, v);
+        GridUnsafe.putShort(ptr, v);
     }
 
     /**
@@ -379,7 +369,7 @@ public class GridUnsafeMemory {
      * @return Integer value.
      */
     public byte readByte(long ptr) {
-        return UNSAFE.getByte(ptr);
+        return GridUnsafe.getByte(ptr);
     }
 
     /**
@@ -387,7 +377,7 @@ public class GridUnsafeMemory {
      * @return Integer value.
      */
     public byte readByteVolatile(long ptr) {
-        return UNSAFE.getByteVolatile(null, ptr);
+        return GridUnsafe.getByteVolatile(null, ptr);
     }
 
     /**
@@ -395,7 +385,7 @@ public class GridUnsafeMemory {
      * @param v Integer value.
      */
     public void writeByte(long ptr, byte v) {
-        UNSAFE.putByte(ptr, v);
+        GridUnsafe.putByte(ptr, v);
     }
 
     /**
@@ -403,7 +393,7 @@ public class GridUnsafeMemory {
      * @param v Integer value.
      */
     public void writeByteVolatile(long ptr, byte v) {
-        UNSAFE.putByteVolatile(null, ptr, v);
+        GridUnsafe.putByteVolatile(null, ptr, v);
     }
 
     /**
@@ -483,8 +473,8 @@ public class GridUnsafeMemory {
         int words = size / 8;
 
         for (int i = 0; i < words; i++) {
-            long w1 = UNSAFE.getLong(ptr1);
-            long w2 = UNSAFE.getLong(ptr2);
+            long w1 = GridUnsafe.getLong(ptr1);
+            long w2 = GridUnsafe.getLong(ptr2);
 
             if (w1 != w2)
                 return false;
@@ -496,8 +486,8 @@ public class GridUnsafeMemory {
         int left = size % 8;
 
         for (int i = 0; i < left; i++) {
-            byte b1 = UNSAFE.getByte(ptr1);
-            byte b2 = UNSAFE.getByte(ptr2);
+            byte b1 = GridUnsafe.getByte(ptr1);
+            byte b2 = GridUnsafe.getByte(ptr2);
 
             if (b1 != b2)
                 return false;
@@ -517,7 +507,7 @@ public class GridUnsafeMemory {
      * @return {@code True} if equals.
      */
     public static boolean compare(long ptr, byte[] bytes) {
-        final int addrSize = ADDR_SIZE;
+        final int addrSize = GridUnsafe.ADDR_SIZE;
 
         // Align reads to address size.
         int off = (int)(ptr % addrSize);
@@ -527,7 +517,7 @@ public class GridUnsafeMemory {
 
         if (align != addrSize) {
             for (int i = 0; i < align && i < len; i++) {
-                if (UNSAFE.getByte(ptr) != bytes[i])
+                if (GridUnsafe.getByte(ptr) != bytes[i])
                     return false;
 
                 ptr++;
@@ -550,19 +540,14 @@ public class GridUnsafeMemory {
                 for (int i = 0; i < words; i++) {
                     int step = i * addrSize + align;
 
-                    int word = UNSAFE.getInt(ptr);
+                    int word = GridUnsafe.getInt(ptr);
 
-                    int comp = 0;
-
-                    comp |= (0xffL & bytes[step + 3]) << 24;
-                    comp |= (0xffL & bytes[step + 2]) << 16;
-                    comp |= (0xffL & bytes[step + 1]) << 8;
-                    comp |= (0xffL & bytes[step]);
+                    int comp = GridUnsafe.getInt(bytes, GridUnsafe.BYTE_ARR_OFF + step);
 
                     if (word != comp)
                         return false;
 
-                    ptr += ADDR_SIZE;
+                    ptr += GridUnsafe.ADDR_SIZE;
                 }
 
                 break;
@@ -571,23 +556,14 @@ public class GridUnsafeMemory {
                 for (int i = 0; i < words; i++) {
                     int step = i * addrSize + align;
 
-                    long word = UNSAFE.getLong(ptr);
-
-                    long comp = 0;
+                    long word = GridUnsafe.getLong(ptr);
 
-                    comp |= (0xffL & bytes[step + 7]) << 56;
-                    comp |= (0xffL & bytes[step + 6]) << 48;
-                    comp |= (0xffL & bytes[step + 5]) << 40;
-                    comp |= (0xffL & bytes[step + 4]) << 32;
-                    comp |= (0xffL & bytes[step + 3]) << 24;
-                    comp |= (0xffL & bytes[step + 2]) << 16;
-                    comp |= (0xffL & bytes[step + 1]) << 8;
-                    comp |= (0xffL & bytes[step]);
+                    long comp = GridUnsafe.getLong(bytes, GridUnsafe.BYTE_ARR_OFF + step);
 
                     if (word != comp)
                         return false;
 
-                    ptr += ADDR_SIZE;
+                    ptr += GridUnsafe.ADDR_SIZE;
                 }
 
                 break;
@@ -596,7 +572,7 @@ public class GridUnsafeMemory {
         if (left != 0) {
             // Compare left overs byte by byte.
             for (int i = 0; i < left; i++)
-                if (UNSAFE.getByte(ptr + i) != bytes[i + align + words * ADDR_SIZE])
+                if (GridUnsafe.getByte(ptr + i) != bytes[i + align + words * GridUnsafe.ADDR_SIZE])
                     return false;
         }
 
@@ -618,7 +594,7 @@ public class GridUnsafeMemory {
      * @return The same array as passed in one.
      */
     public byte[] readBytes(long ptr, byte[] arr) {
-        UNSAFE.copyMemory(null, ptr, arr, BYTE_ARR_OFF, arr.length);
+        GridUnsafe.copyMemory(null, ptr, arr, GridUnsafe.BYTE_ARR_OFF, arr.length);
 
         return arr;
     }
@@ -631,7 +607,7 @@ public class GridUnsafeMemory {
      * @return The same array as passed in one.
      */
     public byte[] readBytes(long ptr, byte[] arr, int off, int len) {
-        UNSAFE.copyMemory(null, ptr, arr, BYTE_ARR_OFF + off, len);
+        GridUnsafe.copyMemory(null, ptr, arr, GridUnsafe.BYTE_ARR_OFF + off, len);
 
         return arr;
     }
@@ -643,7 +619,7 @@ public class GridUnsafeMemory {
      * @param arr Array.
      */
     public void writeBytes(long ptr, byte[] arr) {
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
     }
 
     /**
@@ -655,7 +631,7 @@ public class GridUnsafeMemory {
      * @param len Length.
      */
     public void writeBytes(long ptr, byte[] arr, int off, int len) {
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, null, ptr, len);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF + off, null, ptr, len);
     }
 
     /**
@@ -666,7 +642,7 @@ public class GridUnsafeMemory {
      * @param len Length in bytes.
      */
     public void copyMemory(long srcPtr, long destPtr, long len) {
-        UNSAFE.copyMemory(srcPtr, destPtr, len);
+        GridUnsafe.copyMemory(srcPtr, destPtr, len);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
index a4f4cdc..c5be139 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
@@ -47,7 +47,6 @@ import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.MarshallerContext;
 import org.apache.ignite.marshaller.MarshallerExclusions;
-import sun.misc.Unsafe;
 
 import static java.lang.reflect.Modifier.isFinal;
 import static java.lang.reflect.Modifier.isPrivate;
@@ -92,9 +91,6 @@ import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.co
  * Class descriptor.
  */
 class OptimizedClassDescriptor {
-    /** Unsafe. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
     /** Class. */
     private final Class<?> cls;
 
@@ -273,7 +269,7 @@ class OptimizedClassDescriptor {
                 type = PROPS;
 
                 try {
-                    dfltsFieldOff = UNSAFE.objectFieldOffset(Properties.class.getDeclaredField("defaults"));
+                    dfltsFieldOff = GridUnsafe.objectFieldOffset(Properties.class.getDeclaredField("defaults"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
@@ -285,7 +281,7 @@ class OptimizedClassDescriptor {
                 type = HASH_MAP;
 
                 try {
-                    loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+                    loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
@@ -295,7 +291,7 @@ class OptimizedClassDescriptor {
                 type = HASH_SET;
 
                 try {
-                    loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+                    loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
@@ -307,8 +303,10 @@ class OptimizedClassDescriptor {
                 type = LINKED_HASH_MAP;
 
                 try {
-                    loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
-                    accessOrderFieldOff = UNSAFE.objectFieldOffset(LinkedHashMap.class.getDeclaredField("accessOrder"));
+                    loadFactorFieldOff =
+                        GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+                    accessOrderFieldOff =
+                        GridUnsafe.objectFieldOffset(LinkedHashMap.class.getDeclaredField("accessOrder"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
@@ -318,7 +316,7 @@ class OptimizedClassDescriptor {
                 type = LINKED_HASH_SET;
 
                 try {
-                    loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+                    loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
@@ -472,7 +470,7 @@ class OptimizedClassDescriptor {
 
                                         fieldInfo = new FieldInfo(f,
                                             serField.getName(),
-                                            UNSAFE.objectFieldOffset(f),
+                                            GridUnsafe.objectFieldOffset(f),
                                             fieldType(serField.getType()));
                                     }
 
@@ -496,7 +494,7 @@ class OptimizedClassDescriptor {
 
                                 if (!isStatic(mod) && !isTransient(mod)) {
                                     FieldInfo fieldInfo = new FieldInfo(f, f.getName(),
-                                        UNSAFE.objectFieldOffset(f), fieldType(f.getType()));
+                                        GridUnsafe.objectFieldOffset(f), fieldType(f.getType()));
 
                                     clsFields.add(fieldInfo);
                                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
index b2c98b2..b3caca2 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentMap;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.AbstractMarshaller;
 import org.jetbrains.annotations.Nullable;
@@ -274,9 +273,7 @@ public class OptimizedMarshaller 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/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
index da92b90..fa6f962 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
@@ -34,16 +34,12 @@ import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.marshaller.MarshallerContext;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import sun.misc.Unsafe;
 
 /**
  * Miscellaneous utility methods to facilitate {@link OptimizedMarshaller}.
  */
 class OptimizedMarshallerUtils {
     /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
     static final long HASH_SET_MAP_OFF;
 
     /** */
@@ -158,12 +154,12 @@ class OptimizedMarshallerUtils {
         long mapOff;
 
         try {
-            mapOff = UNSAFE.objectFieldOffset(HashSet.class.getDeclaredField("map"));
+            mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("map"));
         }
         catch (NoSuchFieldException e) {
             try {
                 // Workaround for legacy IBM JRE.
-                mapOff = UNSAFE.objectFieldOffset(HashSet.class.getDeclaredField("backingMap"));
+                mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("backingMap"));
             }
             catch (NoSuchFieldException e2) {
                 throw new IgniteException("Initialization failure.", e2);
@@ -358,7 +354,7 @@ class OptimizedMarshallerUtils {
      * @return Byte value.
      */
     static byte getByte(Object obj, long off) {
-        return UNSAFE.getByte(obj, off);
+        return GridUnsafe.getByteField(obj, off);
     }
 
     /**
@@ -369,7 +365,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setByte(Object obj, long off, byte val) {
-        UNSAFE.putByte(obj, off, val);
+        GridUnsafe.putByteField(obj, off, val);
     }
 
     /**
@@ -380,7 +376,7 @@ class OptimizedMarshallerUtils {
      * @return Short value.
      */
     static short getShort(Object obj, long off) {
-        return UNSAFE.getShort(obj, off);
+        return GridUnsafe.getShortField(obj, off);
     }
 
     /**
@@ -391,7 +387,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setShort(Object obj, long off, short val) {
-        UNSAFE.putShort(obj, off, val);
+        GridUnsafe.putShortField(obj, off, val);
     }
 
     /**
@@ -402,7 +398,7 @@ class OptimizedMarshallerUtils {
      * @return Integer value.
      */
     static int getInt(Object obj, long off) {
-        return UNSAFE.getInt(obj, off);
+        return GridUnsafe.getIntField(obj, off);
     }
 
     /**
@@ -413,7 +409,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setInt(Object obj, long off, int val) {
-        UNSAFE.putInt(obj, off, val);
+        GridUnsafe.putIntField(obj, off, val);
     }
 
     /**
@@ -424,7 +420,7 @@ class OptimizedMarshallerUtils {
      * @return Long value.
      */
     static long getLong(Object obj, long off) {
-        return UNSAFE.getLong(obj, off);
+        return GridUnsafe.getLongField(obj, off);
     }
 
     /**
@@ -435,7 +431,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setLong(Object obj, long off, long val) {
-        UNSAFE.putLong(obj, off, val);
+        GridUnsafe.putLongField(obj, off, val);
     }
 
     /**
@@ -446,7 +442,7 @@ class OptimizedMarshallerUtils {
      * @return Float value.
      */
     static float getFloat(Object obj, long off) {
-        return UNSAFE.getFloat(obj, off);
+        return GridUnsafe.getFloatField(obj, off);
     }
 
     /**
@@ -457,7 +453,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setFloat(Object obj, long off, float val) {
-        UNSAFE.putFloat(obj, off, val);
+        GridUnsafe.putFloatField(obj, off, val);
     }
 
     /**
@@ -468,7 +464,7 @@ class OptimizedMarshallerUtils {
      * @return Double value.
      */
     static double getDouble(Object obj, long off) {
-        return UNSAFE.getDouble(obj, off);
+        return GridUnsafe.getDoubleField(obj, off);
     }
 
     /**
@@ -479,7 +475,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setDouble(Object obj, long off, double val) {
-        UNSAFE.putDouble(obj, off, val);
+        GridUnsafe.putDoubleField(obj, off, val);
     }
 
     /**
@@ -490,7 +486,7 @@ class OptimizedMarshallerUtils {
      * @return Char value.
      */
     static char getChar(Object obj, long off) {
-        return UNSAFE.getChar(obj, off);
+        return GridUnsafe.getCharField(obj, off);
     }
 
     /**
@@ -501,7 +497,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setChar(Object obj, long off, char val) {
-        UNSAFE.putChar(obj, off, val);
+        GridUnsafe.putCharField(obj, off, val);
     }
 
     /**
@@ -512,7 +508,7 @@ class OptimizedMarshallerUtils {
      * @return Boolean value.
      */
     static boolean getBoolean(Object obj, long off) {
-        return UNSAFE.getBoolean(obj, off);
+        return GridUnsafe.getBooleanField(obj, off);
     }
 
     /**
@@ -523,7 +519,7 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setBoolean(Object obj, long off, boolean val) {
-        UNSAFE.putBoolean(obj, off, val);
+        GridUnsafe.putBooleanField(obj, off, val);
     }
 
     /**
@@ -534,7 +530,7 @@ class OptimizedMarshallerUtils {
      * @return Value.
      */
     static Object getObject(Object obj, long off) {
-        return UNSAFE.getObject(obj, off);
+        return GridUnsafe.getObjectField(obj, off);
     }
 
     /**
@@ -545,6 +541,6 @@ class OptimizedMarshallerUtils {
      * @param val Value.
      */
     static void setObject(Object obj, long off, Object val) {
-        UNSAFE.putObject(obj, off, val);
+        GridUnsafe.putObjectField(obj, off, val);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
index ce9ee0b..988a777 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
@@ -45,7 +45,6 @@ import org.apache.ignite.internal.util.io.GridDataInput;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.MarshallerContext;
-import sun.misc.Unsafe;
 
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ARRAY_LIST;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN;
@@ -98,9 +97,6 @@ import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.se
  * Optimized object input stream.
  */
 class OptimizedObjectInputStream extends ObjectInputStream {
-    /** Unsafe. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
     /** Dummy object for HashSet. */
     private static final Object DUMMY = new Object();
 
@@ -544,7 +540,7 @@ class OptimizedObjectInputStream extends ObjectInputStream {
         Object obj;
 
         try {
-            obj = UNSAFE.allocateInstance(cls);
+            obj = GridUnsafe.allocateInstance(cls);
         }
         catch (InstantiationException e) {
             throw new IOException(e);
@@ -642,7 +638,7 @@ class OptimizedObjectInputStream extends ObjectInputStream {
     @SuppressWarnings("unchecked")
     HashSet<?> readHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
         try {
-            HashSet<Object> set = (HashSet<Object>)UNSAFE.allocateInstance(HashSet.class);
+            HashSet<Object> set = (HashSet<Object>)GridUnsafe.allocateInstance(HashSet.class);
 
             handles.assign(set);
 
@@ -714,7 +710,7 @@ class OptimizedObjectInputStream extends ObjectInputStream {
     @SuppressWarnings("unchecked")
     LinkedHashSet<?> readLinkedHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
         try {
-            LinkedHashSet<Object> set = (LinkedHashSet<Object>)UNSAFE.allocateInstance(LinkedHashSet.class);
+            LinkedHashSet<Object> set = (LinkedHashSet<Object>)GridUnsafe.allocateInstance(LinkedHashSet.class);
 
             handles.assign(set);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/GridTestIoUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/GridTestIoUtils.java b/modules/core/src/test/java/org/apache/ignite/GridTestIoUtils.java
index de09e06..983afde 100644
--- a/modules/core/src/test/java/org/apache/ignite/GridTestIoUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/GridTestIoUtils.java
@@ -40,7 +40,6 @@ import static junit.framework.Assert.fail;
  * IO test utilities.
  */
 public final class GridTestIoUtils {
-
     /**
      * Serializes a given object into byte array.
      *
@@ -187,6 +186,122 @@ public final class GridTestIoUtils {
             assertEquals(expSize.longValue(), pos);
     }
 
+    /**
+     * Gets short value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static short getShortByByteLE(byte[] arr) {
+        return getShortByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets short value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static short getShortByByteLE(byte[] arr, int off) {
+        return (short)((arr[off] & 0xff) | arr[off + 1] << 8);
+    }
+
+    /**
+     * Gets char value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static char getCharByByteLE(byte[] arr) {
+        return getCharByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets char value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static char getCharByByteLE(byte[] arr, int off) {
+        return (char)((arr[off] & 0xff) | arr[off + 1] << 8);
+    }
+
+    /**
+     * Gets integer value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static int getIntByByteLE(byte[] arr) {
+        return getIntByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets integer value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static int getIntByByteLE(byte[] arr, int off) {
+        return ((int)arr[off] & 0xff) | ((int)arr[off + 1] & 0xff) << 8 |
+            ((int)arr[off + 2] & 0xff) << 16 | ((int)arr[off + 3] & 0xff) << 24;
+    }
+
+    /**
+     * Gets long value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static long getLongByByteLE(byte[] arr) {
+        return getLongByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets long value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static long getLongByByteLE(byte[] arr, int off) {
+        return ((long)arr[off] & 0xff) | ((long)arr[off + 1] & 0xff) << 8 | ((long)arr[off + 2] & 0xff) << 16 |
+            ((long)arr[off + 3] & 0xff) << 24 | ((long)arr[off + 4] & 0xff) << 32 | ((long)arr[off + 5] & 0xff) << 40 |
+            ((long)arr[off + 6] & 0xff) << 48 | ((long)arr[off + 7] & 0xff) << 56;
+    }
+
+    /**
+     * Gets float value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static float getFloatByByteLE(byte[] arr) {
+        return getFloatByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets float value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static float getFloatByByteLE(byte[] arr, int off) {
+        return Float.intBitsToFloat(getIntByByteLE(arr, off));
+    }
+
+    /**
+     * Gets double value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     */
+    public static double getDoubleByByteLE(byte[] arr) {
+        return getDoubleByByteLE(arr, 0);
+    }
+
+    /**
+     * Gets double value from byte array assuming that value stored in little-endian byte order.
+     *
+     * @param arr Byte array.
+     * @param off Offset.
+     */
+    public static double getDoubleByByteLE(byte[] arr, int off) {
+        return Double.longBitsToDouble(getLongByByteLE(arr, off));
+    }
 
     /**
      * Closes resource.

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/GridAffinitySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinitySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinitySelfTest.java
index 0515685..a75023f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinitySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinitySelfTest.java
@@ -116,7 +116,7 @@ public class GridAffinitySelfTest extends GridCommonAbstractTest {
         return F.view(Arrays.asList(g.configuration().getCacheConfiguration()), new IgnitePredicate<CacheConfiguration>() {
             @Override public boolean apply(CacheConfiguration c) {
                 return !CU.MARSH_CACHE_NAME.equals(c.getName()) && !CU.UTILITY_CACHE_NAME.equals(c.getName()) &&
-                    !CU.ATOMICS_CACHE_NAME.equals(c.getName());
+                    !CU.ATOMICS_CACHE_NAME.equals(c.getName()) && !CU.SYS_CACHE_HADOOP_MR.equals(c.getName());
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
index 87cc527..1546252 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
@@ -19,18 +19,11 @@ package org.apache.ignite.internal.binary;
 
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.eclipse.jetty.util.ConcurrentHashSet;
-import sun.misc.Unsafe;
 
 /**
  * Field tests for heap-based binaries.
  */
 public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
-    /** Unsafe instance. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Byte array offset for unsafe mechanics. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
     /** Allocated unsafe pointer. */
     private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
 
@@ -40,7 +33,7 @@ public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
 
         // Cleanup allocated objects.
         for (Long ptr : ptrs)
-            UNSAFE.freeMemory(ptr);
+            GridUnsafe.freeMemory(ptr);
 
         ptrs.clear();
     }
@@ -49,11 +42,11 @@ public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
     @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception {
         byte[] arr = marsh.marshal(obj);
 
-        long ptr = UNSAFE.allocateMemory(arr.length);
+        long ptr = GridUnsafe.allocateMemory(arr.length);
 
         ptrs.add(ptr);
 
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
 
         return new BinaryObjectOffheapImpl(binaryContext(marsh), ptr, 0, arr.length);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
index fe9ba17..796c027 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
@@ -19,18 +19,11 @@ package org.apache.ignite.internal.binary;
 
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.eclipse.jetty.util.ConcurrentHashSet;
-import sun.misc.Unsafe;
 
 /**
  * Compact offsets tests for offheap binary objects.
  */
 public class BinaryFooterOffsetsOffheapSelfTest extends BinaryFooterOffsetsAbstractSelfTest {
-    /** Unsafe instance. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Byte array offset for unsafe mechanics. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
     /** Allocated unsafe pointer. */
     private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
 
@@ -40,7 +33,7 @@ public class BinaryFooterOffsetsOffheapSelfTest extends BinaryFooterOffsetsAbstr
 
         // Cleanup allocated objects.
         for (Long ptr : ptrs)
-            UNSAFE.freeMemory(ptr);
+            GridUnsafe.freeMemory(ptr);
 
         ptrs.clear();
     }
@@ -49,11 +42,11 @@ public class BinaryFooterOffsetsOffheapSelfTest extends BinaryFooterOffsetsAbstr
     @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception {
         byte[] arr = marsh.marshal(obj);
 
-        long ptr = UNSAFE.allocateMemory(arr.length);
+        long ptr = GridUnsafe.allocateMemory(arr.length);
 
         ptrs.add(ptr);
 
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
 
         return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index fa0f9a7..37b908a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -88,7 +88,6 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
 
 import static org.apache.ignite.internal.binary.streams.BinaryMemoryAllocator.INSTANCE;
 import static org.junit.Assert.assertArrayEquals;
@@ -99,12 +98,6 @@ import static org.junit.Assert.assertNotEquals;
  */
 @SuppressWarnings({"OverlyStrongTypeCast", "ArrayHashCode", "ConstantConditions"})
 public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
     /**
      * @throws Exception If failed.
      */
@@ -2378,13 +2371,13 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
             assertFalse(offheapObj2.equals(offheapObj));
         }
         finally {
-            UNSAFE.freeMemory(ptr);
+            GridUnsafe.freeMemory(ptr);
 
             if (ptr1 > 0)
-                UNSAFE.freeMemory(ptr1);
+                GridUnsafe.freeMemory(ptr1);
 
             if (ptr2 > 0)
-                UNSAFE.freeMemory(ptr2);
+                GridUnsafe.freeMemory(ptr2);
         }
     }
 
@@ -2975,9 +2968,9 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
     private long copyOffheap(BinaryObjectImpl obj) {
         byte[] arr = obj.array();
 
-        long ptr = UNSAFE.allocateMemory(arr.length);
+        long ptr = GridUnsafe.allocateMemory(arr.length);
 
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+        GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
 
         return ptr;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
index 059703e..990c928 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
@@ -46,7 +46,8 @@ import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import sun.misc.Unsafe;
+
+import static org.apache.ignite.internal.util.GridUnsafe.BIG_ENDIAN;
 
 /**
  * Binary builder test.
@@ -54,12 +55,6 @@ import sun.misc.Unsafe;
 @SuppressWarnings("ResultOfMethodCallIgnored")
 public class BinaryObjectBuilderDefaultMappersSelfTest extends GridCommonAbstractTest {
     /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
     private static IgniteConfiguration cfg;
 
     /** {@inheritDoc} */
@@ -766,16 +761,21 @@ public class BinaryObjectBuilderDefaultMappersSelfTest extends GridCommonAbstrac
 
         byte[] arr = ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
 
-        long ptr = UNSAFE.allocateMemory(arr.length + 5);
+        long ptr = GridUnsafe.allocateMemory(arr.length + 5);
 
         try {
             long ptr0 = ptr;
 
-            UNSAFE.putBoolean(null, ptr0++, false);
+            GridUnsafe.putBoolean(null, ptr0++, false);
+
+            int len = arr.length;
 
-            UNSAFE.putInt(ptr0, arr.length);
+            if (BIG_ENDIAN)
+                GridUnsafe.putIntLE(ptr0, len);
+            else
+                GridUnsafe.putInt(ptr0, len);
 
-            UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
+            GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
 
             BinaryObject offheapObj = (BinaryObject)
                 ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
@@ -801,7 +801,7 @@ public class BinaryObjectBuilderDefaultMappersSelfTest extends GridCommonAbstrac
             assertEquals(offheapObj, po);
         }
         finally {
-            UNSAFE.freeMemory(ptr);
+            GridUnsafe.freeMemory(ptr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
index ae615b1..5ddb87d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
@@ -31,14 +31,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
-
 import org.apache.ignite.binary.BinaryMapFactory;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryReader;
 import org.apache.ignite.binary.BinaryWriter;
 import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.binary.BinaryObject;
 
 /**
  *

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/AbstractBinaryStreamByteOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/AbstractBinaryStreamByteOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/AbstractBinaryStreamByteOrderSelfTest.java
new file mode 100644
index 0000000..c68a886
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/AbstractBinaryStreamByteOrderSelfTest.java
@@ -0,0 +1,464 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.binary.streams;
+
+import java.util.Random;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+
+import static org.apache.ignite.GridTestIoUtils.getCharByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getDoubleByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getFloatByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getIntByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getLongByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getShortByByteLE;
+
+/**
+ * Binary input/output streams byte order sanity tests.
+ */
+public abstract class AbstractBinaryStreamByteOrderSelfTest extends GridCommonAbstractTest {
+    /** Array length. */
+    protected static final int ARR_LEN = 16;
+
+    /** Rnd. */
+    private static final Random RND = new Random();
+
+    /** Out. */
+    protected BinaryAbstractOutputStream out;
+
+    /** In. */
+    protected BinaryAbstractInputStream in;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        init();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        out.close();
+    }
+
+    /**
+     * Initializes streams.
+     */
+    protected abstract void init();
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShort() throws Exception {
+        short val = (short)RND.nextLong();
+
+        reset();
+
+        out.unsafeWriteShort(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readShort());
+
+        reset();
+
+        out.unsafeWriteShort(0, val);
+        out.shift(2);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readShortFast());
+
+        reset();
+
+        out.writeShortFast(val);
+        out.shift(2);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readShortPositioned(0));
+
+        reset();
+
+        out.writeShort(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readShortPositioned(0));
+
+        reset();
+
+        out.writeShort(0, val);
+        out.shift(2);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readShortPositioned(0));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShortArray() throws Exception {
+        short[] arr = new short[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = (short)RND.nextLong();
+
+        out.writeShortArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getShortByByteLE(outArr, i * 2));
+
+        Assert.assertArrayEquals(arr, in.readShortArray(ARR_LEN));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testChar() throws Exception {
+        char val = (char)RND.nextLong();
+
+        reset();
+
+        out.unsafeWriteChar(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readChar());
+
+        reset();
+
+        out.writeCharFast(val);
+        out.shift(2);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readCharFast());
+
+        reset();
+
+        out.writeChar(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readChar());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCharArray() throws Exception {
+        char[] arr = new char[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = (char)RND.nextLong();
+
+        out.writeCharArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getCharByByteLE(outArr, i * 2));
+
+        Assert.assertArrayEquals(arr, in.readCharArray(ARR_LEN));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInt() throws Exception {
+        int val = RND.nextInt();
+
+        reset();
+
+        out.unsafeWriteInt(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readInt());
+
+        reset();
+
+        out.unsafeWriteInt(0, val);
+        out.shift(4);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readIntFast());
+
+        reset();
+
+        out.writeIntFast(val);
+        out.shift(4);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readIntPositioned(0));
+
+        reset();
+
+        out.writeInt(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readIntPositioned(0));
+
+        reset();
+
+        out.writeInt(0, val);
+        out.shift(4);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readIntPositioned(0));
+
+        reset();
+
+        out.writeIntArray(new int[] {val});
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readIntArray(1)[0]);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIntArray() throws Exception {
+        int[] arr = new int[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextInt();
+
+        out.writeIntArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getIntByByteLE(outArr, i * 4));
+
+        Assert.assertArrayEquals(arr, in.readIntArray(ARR_LEN));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLong() throws Exception {
+        long val = RND.nextLong();
+
+        reset();
+
+        out.unsafeWriteLong(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readLong());
+
+        reset();
+
+        out.writeLongFast(val);
+        out.shift(8);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readLongFast());
+
+        reset();
+
+        out.writeLong(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readLong());
+
+        reset();
+
+        out.writeLongArray(new long[] {val});
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readLongArray(1)[0]);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLongArray() throws Exception {
+        long[] arr = new long[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextLong();
+
+        out.writeLongArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getLongByByteLE(outArr, i * 8));
+
+        Assert.assertArrayEquals(arr, in.readLongArray(ARR_LEN));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloat() throws Exception {
+        float val = RND.nextFloat();
+
+        reset();
+
+        out.unsafeWriteFloat(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readFloat(), 0);
+
+        reset();
+
+        out.writeFloat(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readFloat(), 0);
+
+        reset();
+
+        out.writeFloatArray(new float[] {val});
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readFloatArray(1)[0], 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloatArray() throws Exception {
+        float[] arr = new float[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextFloat();
+
+        out.writeFloatArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getFloatByByteLE(outArr, i * 4), 0);
+
+        Assert.assertArrayEquals(arr, in.readFloatArray(ARR_LEN), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDouble() throws Exception {
+        double val = RND.nextDouble();
+
+        reset();
+
+        out.unsafeWriteDouble(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readDouble(), 0);
+
+        reset();
+
+        out.writeDouble(val);
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readDouble(), 0);
+
+        reset();
+
+        out.writeDoubleArray(new double[] {val});
+
+        checkValueLittleEndian(val);
+        assertEquals(val, in.readDoubleArray(1)[0], 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDoubleArray() throws Exception {
+        double[] arr = new double[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextDouble();
+
+        out.writeDoubleArray(arr);
+
+        byte[] outArr = array();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getDoubleByByteLE(outArr, i * 8), 0);
+
+        Assert.assertArrayEquals(arr, in.readDoubleArray(ARR_LEN), 0);
+    }
+
+    /**
+     *
+     */
+    private void reset() {
+        in.position(0);
+        out.position(0);
+    }
+
+    /**
+     *
+     */
+    private byte[] array() {
+        return out.array();
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(short exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getShortByByteLE(arr));
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(char exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getCharByByteLE(arr));
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(int exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getIntByByteLE(arr));
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(long exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getLongByByteLE(arr));
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(float exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getFloatByByteLE(arr), 0);
+    }
+
+    /**
+     * @param exp Expected.
+     */
+    private void checkValueLittleEndian(double exp) {
+        byte[] arr = array();
+
+        assertEquals(exp, getDoubleByByteLE(arr), 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryHeapStreamByteOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryHeapStreamByteOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryHeapStreamByteOrderSelfTest.java
new file mode 100644
index 0000000..4b86748
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryHeapStreamByteOrderSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.binary.streams;
+
+/**
+ * Binary heap input/output stream byte order sanity tests.
+ */
+public class BinaryHeapStreamByteOrderSelfTest extends AbstractBinaryStreamByteOrderSelfTest {
+    /** {@inheritDoc} */
+    @Override protected void init() {
+        out = new BinaryHeapOutputStream(ARR_LEN * 8);
+        in = new BinaryHeapInputStream(out.array());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryOffheapStreamByteOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryOffheapStreamByteOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryOffheapStreamByteOrderSelfTest.java
new file mode 100644
index 0000000..6e9c41a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/streams/BinaryOffheapStreamByteOrderSelfTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.binary.streams;
+
+/**
+ * Binary offheap input/output stream byte order sanity tests.
+ */
+public class BinaryOffheapStreamByteOrderSelfTest extends AbstractBinaryStreamByteOrderSelfTest {
+    /** {@inheritDoc} */
+    @Override protected void init() {
+        int cap = ARR_LEN * 8;
+
+        out = new BinaryOffheapOutputStream(cap);
+        in = new BinaryOffheapInputStream(((BinaryOffheapOutputStream)out).pointer(), cap);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2ByteOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2ByteOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2ByteOrderSelfTest.java
new file mode 100644
index 0000000..d96f796
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2ByteOrderSelfTest.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.direct.stream.v2;
+
+import java.nio.ByteBuffer;
+import java.util.Random;
+import junit.framework.TestCase;
+import org.apache.ignite.internal.direct.stream.DirectByteBufferStream;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.plugin.extensions.communication.MessageFactory;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.GridTestIoUtils.getCharByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getDoubleByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getFloatByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getIntByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getLongByByteLE;
+import static org.apache.ignite.GridTestIoUtils.getShortByByteLE;
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * {@link DirectByteBufferStreamImplV2} byte order sanity tests.
+ */
+public class DirectByteBufferStreamImplV2ByteOrderSelfTest extends TestCase {
+    /** Array length. */
+    private static final int ARR_LEN = 16;
+
+    /** Length bytes. */
+    private static final int LEN_BYTES = 1;
+
+    /** Rnd. */
+    private static final Random RND = new Random();
+
+    /** Stream. */
+    private DirectByteBufferStream stream;
+
+    /** Buff. */
+    private ByteBuffer buff;
+
+    /** Array. */
+    private byte[] outArr;
+
+    /** {@inheritDoc} */
+    @Override public void setUp() throws Exception {
+        super.setUp();
+
+        stream = new DirectByteBufferStreamImplV2(new MessageFactory() {
+            @Nullable @Override public Message create(byte type) {
+                return null;
+            }
+        });
+
+        outArr = new byte[ARR_LEN * 8 + LEN_BYTES];
+
+        buff = ByteBuffer.wrap(outArr);
+
+        stream.setBuffer(buff);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShort() throws Exception {
+        short val = (short)RND.nextLong();
+
+        stream.writeShort(val);
+
+        buff.rewind();
+
+        assertEquals(val, getShortByByteLE(outArr));
+        assertEquals(val, stream.readShort());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShortArray() throws Exception {
+        short[] arr = new short[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = (short)RND.nextLong();
+
+        stream.writeShortArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getShortByByteLE(outArr, i * 2 + LEN_BYTES));
+
+        assertArrayEquals(arr, stream.readShortArray());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testChar() throws Exception {
+        char val = (char)RND.nextLong();
+
+        stream.writeChar(val);
+
+        buff.rewind();
+
+        assertEquals(val, getCharByByteLE(outArr));
+        assertEquals(val, stream.readChar());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCharArray() throws Exception {
+        char[] arr = new char[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = (char)RND.nextLong();
+
+        stream.writeCharArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getCharByByteLE(outArr, i * 2 + LEN_BYTES));
+
+        assertArrayEquals(arr, stream.readCharArray());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIntArray() throws Exception {
+        int[] arr = new int[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextInt();
+
+        stream.writeIntArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getIntByByteLE(outArr, i * 4 + LEN_BYTES));
+
+        assertArrayEquals(arr, stream.readIntArray());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLongArray() throws Exception {
+        long[] arr = new long[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextLong();
+
+        stream.writeLongArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getLongByByteLE(outArr, i * 8 + LEN_BYTES));
+
+        assertArrayEquals(arr, stream.readLongArray());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloat() throws Exception {
+        float val = RND.nextFloat();
+
+        stream.writeFloat(val);
+
+        buff.rewind();
+
+        assertEquals(val, getFloatByByteLE(outArr), 0);
+        assertEquals(val, stream.readFloat(), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloatArray() throws Exception {
+        float[] arr = new float[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextFloat();
+
+        stream.writeFloatArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getFloatByByteLE(outArr, i * 4 + LEN_BYTES), 0);
+
+        assertArrayEquals(arr, stream.readFloatArray(), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDouble() throws Exception {
+        double val = RND.nextDouble();
+
+        stream.writeDouble(val);
+
+        buff.rewind();
+
+        assertEquals(val, getDoubleByByteLE(outArr), 0);
+        assertEquals(val, stream.readDouble(), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDoubleArray() throws Exception {
+        double[] arr = new double[ARR_LEN];
+
+        for (int i = 0; i < ARR_LEN; i++)
+            arr[i] = RND.nextDouble();
+
+        stream.writeDoubleArray(arr);
+
+        buff.rewind();
+
+        for (int i = 0; i < ARR_LEN; i++)
+            assertEquals(arr[i], getDoubleByByteLE(outArr, i * 8 + LEN_BYTES), 0);
+
+        assertArrayEquals(arr, stream.readDoubleArray(), 0);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
index 5bb6794..4887b79 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
@@ -27,7 +27,6 @@ import javax.cache.Cache;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -165,17 +164,11 @@ public class GridCacheConcurrentMapSelfTest extends GridCommonAbstractTest {
 
                 Iterator<Cache.Entry<Integer, String>> it = null;
 
-                boolean created = false;
-
                 for (int i = start; i < start + cnt; i++) {
                     int key = i % cnt;
 
-                    if (!created && i >= start + tid * 100) {
-                        if (it == null)
-                            it = c.iterator();
-
-                        created = true;
-                    }
+                    if (it == null && i >= start + tid * 100)
+                        it = c.iterator();
 
                     c.put(key, Integer.toString(key));
 
@@ -342,7 +335,7 @@ public class GridCacheConcurrentMapSelfTest extends GridCommonAbstractTest {
 
                     return null;
                 }
-            }, Runtime.getRuntime().availableProcessors());
+            }, Math.min(16, Runtime.getRuntime().availableProcessors()));
 
             for (int r = 0; r < 10; r++) {
                 System.gc();

http://git-wip-us.apache.org/repos/asf/ignite/blob/a87decdc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
index 5de3d0f..1c65f9b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
@@ -228,6 +228,12 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
             qryClnCache.put(keys.get(0), 100);
         }
 
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                return lsnr.evts.size() == 1;
+            }
+        }, 5000);
+
         assertEquals(lsnr.evts.size(), 1);
     }
 


Mime
View raw message