You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/02 13:02:01 UTC

[4/7] ignite git commit: IGNITE-1814: Reworked primitives.

IGNITE-1814: Reworked primitives.


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

Branch: refs/heads/ignite-1814
Commit: c74b98e9f64db7a7163505824d66e13cf6c240b6
Parents: 4a170d3
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 2 13:20:01 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 2 13:20:01 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableObjectImpl.java   |  39 +-
 .../internal/portable/PortablePrimitives.java   | 376 ++++++-------------
 .../portable/builder/PortableBuilderReader.java |  39 +-
 3 files changed, 147 insertions(+), 307 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c74b98e9/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
index de77778..a4deef0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
@@ -63,9 +63,6 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
     private static final long serialVersionUID = 0L;
 
     /** */
-    private static final PortablePrimitives PRIM = PortablePrimitives.get();
-
-    /** */
     @GridDirectTransient
     private PortableContext ctx;
 
@@ -154,7 +151,7 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
 
     /** {@inheritDoc} */
     @Override public int length() {
-        return PRIM.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
     }
 
     /**
@@ -230,7 +227,7 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
 
     /** {@inheritDoc} */
     @Override public int typeId() {
-        return PRIM.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
     }
 
     /** {@inheritDoc} */
@@ -261,63 +258,63 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
     @SuppressWarnings("unchecked")
     @Nullable @Override protected <F> F fieldByOrder(int order) {
         // Get field position
-        int schemaOffset = PRIM.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
         int fieldOffsetSize =
-            PortableUtils.fieldOffsetSize(PRIM.readShort(arr, start + GridPortableMarshaller.FLAGS_POS));
+            PortableUtils.fieldOffsetSize(PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS));
 
         int fieldPos;
 
         if (fieldOffsetSize == PortableUtils.OFFSET_1)
-            fieldPos = start + PRIM.readInt(arr, start + schemaOffset + order * 5) & 0xFF;
+            fieldPos = start + PortablePrimitives.readInt(arr, start + schemaOffset + order * 5) & 0xFF;
         else if (fieldOffsetSize == PortableUtils.OFFSET_2)
-            fieldPos = start + PRIM.readInt(arr, start + schemaOffset + order * 6) & 0xFFFF;
+            fieldPos = start + PortablePrimitives.readInt(arr, start + schemaOffset + order * 6) & 0xFFFF;
         else
-            fieldPos = start + PRIM.readInt(arr, start + schemaOffset + order * 8);
+            fieldPos = start + PortablePrimitives.readInt(arr, start + schemaOffset + order * 8);
 
         // Read header and try performing fast lookup for well-known types (the most common types go first).
-        byte hdr = PRIM.readByte(arr, fieldPos);
+        byte hdr = PortablePrimitives.readByte(arr, fieldPos);
 
         Object val;
 
         switch (hdr) {
             case INT:
-                val = PRIM.readInt(arr, fieldPos + 1);
+                val = PortablePrimitives.readInt(arr, fieldPos + 1);
 
                 break;
 
             case LONG:
-                val = PRIM.readLong(arr, fieldPos + 1);
+                val = PortablePrimitives.readLong(arr, fieldPos + 1);
 
                 break;
 
             case BOOLEAN:
-                val = PRIM.readBoolean(arr, fieldPos + 1);
+                val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
 
                 break;
 
             case SHORT:
-                val = PRIM.readShort(arr, fieldPos + 1);
+                val = PortablePrimitives.readShort(arr, fieldPos + 1);
 
                 break;
 
             case BYTE:
-                val = PRIM.readByte(arr, fieldPos + 1);
+                val = PortablePrimitives.readByte(arr, fieldPos + 1);
 
                 break;
 
             case CHAR:
-                val = PRIM.readChar(arr, fieldPos + 1);
+                val = PortablePrimitives.readChar(arr, fieldPos + 1);
 
                 break;
 
             case FLOAT:
-                val = PRIM.readFloat(arr, fieldPos + 1);
+                val = PortablePrimitives.readFloat(arr, fieldPos + 1);
 
                 break;
 
             case DOUBLE:
-                val = PRIM.readDouble(arr, fieldPos + 1);
+                val = PortablePrimitives.readDouble(arr, fieldPos + 1);
 
                 break;
 
@@ -381,12 +378,12 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return PRIM.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
     }
 
     /** {@inheritDoc} */
     @Override protected int schemaId() {
-        return PRIM.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/c74b98e9/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
index 9bd1b7b..b60ac68 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
@@ -20,377 +20,223 @@ package org.apache.ignite.internal.portable;
 import org.apache.ignite.internal.util.GridUnsafe;
 import sun.misc.Unsafe;
 
-import static java.nio.ByteOrder.LITTLE_ENDIAN;
-import static java.nio.ByteOrder.nativeOrder;
+import java.nio.ByteOrder;
 
 /**
  * Primitives writer.
  */
 public abstract class PortablePrimitives {
     /** */
-    private static final PortablePrimitives INSTANCE =
-        nativeOrder() == LITTLE_ENDIAN ? new UnsafePrimitives() : new BytePrimitives();
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
 
-    /**
-     * @return Primitives writer.
-     */
-    public static PortablePrimitives get() {
-        return INSTANCE;
-    }
+    /** */
+    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 abstract void writeByte(byte[] arr, int off, byte val);
+    public static void writeByte(byte[] arr, int off, byte val) {
+        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract byte readByte(byte[] arr, int off);
+    public static byte readByte(byte[] arr, int off) {
+        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeShort(byte[] arr, int off, short val);
+    public static void writeBoolean(byte[] arr, int off, boolean val) {
+        writeByte(arr, off, val ? (byte)1 : (byte)0);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract short readShort(byte[] arr, int off);
+    public static boolean readBoolean(byte[] arr, int off) {
+        return readByte(arr, off) == 1;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeInt(byte[] arr, int off, int val);
+    public static void writeShort(byte[] arr, int off, short val) {
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract int readInt(byte[] arr, int off);
+    public static short readShort(byte[] arr, int off) {
+        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        return val;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeLong(byte[] arr, int off, long val);
+    public static void writeChar(byte[] arr, int off, char val) {
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract long readLong(byte[] arr, int off);
+    public static char readChar(byte[] arr, int off) {
+        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
 
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public abstract void writeFloat(byte[] arr, int off, float val);
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        return val;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract float readFloat(byte[] arr, int off);
+    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);
+
+        if (BIG_ENDIAN) {
+            for (int i = 0; i < len; i++)
+                arr0[i] = Character.reverseBytes(arr0[i]);
+        }
+
+        return arr0;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeDouble(byte[] arr, int off, double val);
+    public static void writeInt(byte[] arr, int off, int val) {
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract double readDouble(byte[] arr, int off);
+    public static int readInt(byte[] arr, int off) {
+        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        return val;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeChar(byte[] arr, int off, char val);
+    public static void writeLong(byte[] arr, int off, long val) {
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract char readChar(byte[] arr, int off);
+    public static long readLong(byte[] arr, int off) {
+        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        return val;
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @param val Value.
      */
-    public abstract void writeBoolean(byte[] arr, int off, boolean val);
+    public static void writeFloat(byte[] arr, int off, float val) {
+        int val0 = Float.floatToIntBits(val);
+
+        writeInt(arr, off, val0);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
      * @return Value.
      */
-    public abstract boolean readBoolean(byte[] arr, int off);
+    public static float readFloat(byte[] arr, int off) {
+        int val = readInt(arr, off);
+
+        return Float.intBitsToFloat(val);
+    }
 
     /**
      * @param arr Array.
      * @param off Offset.
-     * @return Value.
+     * @param val Value.
      */
-    public abstract char[] readCharArray(byte[] arr, int off, int len);
-
-    /** */
-    private static class UnsafePrimitives extends PortablePrimitives {
-        /** */
-        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);
-
-        /** {@inheritDoc} */
-        @Override public void writeByte(byte[] arr, int off, byte val) {
-            UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public byte readByte(byte[] arr, int off) {
-            return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeShort(byte[] arr, int off, short val) {
-            UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public short readShort(byte[] arr, int off) {
-            return UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeInt(byte[] arr, int off, int val) {
-            UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public int readInt(byte[] arr, int off) {
-            return UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeLong(byte[] arr, int off, long val) {
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public long readLong(byte[] arr, int off) {
-            return UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeFloat(byte[] arr, int off, float val) {
-            UNSAFE.putFloat(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public float readFloat(byte[] arr, int off) {
-            return UNSAFE.getFloat(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeDouble(byte[] arr, int off, double val) {
-            UNSAFE.putDouble(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public double readDouble(byte[] arr, int off) {
-            return UNSAFE.getDouble(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeChar(byte[] arr, int off, char val) {
-            UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public char readChar(byte[] arr, int off) {
-            return UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBoolean(byte[] arr, int off, boolean val) {
-            UNSAFE.putBoolean(arr, BYTE_ARR_OFF + off, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean readBoolean(byte[] arr, int off) {
-            return UNSAFE.getBoolean(arr, BYTE_ARR_OFF + off);
-        }
-
-        /** {@inheritDoc} */
-        @Override public 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);
+    public static void writeDouble(byte[] arr, int off, double val) {
+        long val0 = Double.doubleToLongBits(val);
 
-            return arr0;
-        }
+        writeLong(arr, off, val0);
     }
 
-    /** */
-    private static class BytePrimitives extends PortablePrimitives {
-        /** {@inheritDoc} */
-        @Override public void writeByte(byte[] arr, int off, byte val) {
-            arr[off] = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public byte readByte(byte[] arr, int off) {
-            return arr[off];
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeShort(byte[] arr, int off, short val) {
-            arr[off++] = (byte)(val & 0xff);
-            arr[off] = (byte)((val >>> 8) & 0xff);
-        }
-
-        /** {@inheritDoc} */
-        @Override public short readShort(byte[] arr, int off) {
-            short val = 0;
-
-            val |= (arr[off++] & 0xff);
-            val |= (arr[off] & 0xff) << 8;
-
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeInt(byte[] arr, int off, int val) {
-            arr[off++] = (byte)(val & 0xff);
-            arr[off++] = (byte)((val >>> 8) & 0xff);
-            arr[off++] = (byte)((val >>> 16) & 0xff);
-            arr[off] = (byte)((val >>> 24) & 0xff);
-        }
-
-        /** {@inheritDoc} */
-        @Override public int readInt(byte[] arr, int off) {
-            int val = 0;
-
-            val |= (arr[off++] & 0xff);
-            val |= (arr[off++] & 0xff) << 8;
-            val |= (arr[off++] & 0xff) << 16;
-            val |= (arr[off] & 0xff) << 24;
-
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeLong(byte[] arr, int off, long val) {
-            arr[off++] = (byte)(val & 0xffL);
-            arr[off++] = (byte)((val >>> 8) & 0xffL);
-            arr[off++] = (byte)((val >>> 16) & 0xffL);
-            arr[off++] = (byte)((val >>> 24) & 0xffL);
-            arr[off++] = (byte)((val >>> 32) & 0xffL);
-            arr[off++] = (byte)((val >>> 40) & 0xffL);
-            arr[off++] = (byte)((val >>> 48) & 0xffL);
-            arr[off] = (byte)((val >>> 56) & 0xffL);
-        }
-
-        /** {@inheritDoc} */
-        @Override public long readLong(byte[] arr, int off) {
-            long val = 0;
-
-            val |= (arr[off++] & 0xffL);
-            val |= (arr[off++] & 0xffL) << 8;
-            val |= (arr[off++] & 0xffL) << 16;
-            val |= (arr[off++] & 0xffL) << 24;
-            val |= (arr[off++] & 0xffL) << 32;
-            val |= (arr[off++] & 0xffL) << 40;
-            val |= (arr[off++] & 0xffL) << 48;
-            val |= (arr[off] & 0xffL) << 56;
-
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeFloat(byte[] arr, int off, float val) {
-            writeInt(arr, off, Float.floatToIntBits(val));
-        }
-
-        /** {@inheritDoc} */
-        @Override public float readFloat(byte[] arr, int off) {
-            return Float.intBitsToFloat(readInt(arr, off));
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeDouble(byte[] arr, int off, double val) {
-            writeLong(arr, off, Double.doubleToLongBits(val));
-        }
-
-        /** {@inheritDoc} */
-        @Override public double readDouble(byte[] arr, int off) {
-            return Double.longBitsToDouble(readLong(arr, off));
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeChar(byte[] arr, int off, char val) {
-            arr[off++] = (byte)(val & 0xff);
-            arr[off] = (byte)((val >>> 8) & 0xff);
-        }
-
-        /** {@inheritDoc} */
-        @Override public char readChar(byte[] arr, int off) {
-            char val = 0;
-
-            val |= (arr[off++] & 0xff);
-            val |= (arr[off] & 0xff) << 8;
-
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBoolean(byte[] arr, int off, boolean val) {
-            arr[off] = (byte)(val ? 1 : 0);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean readBoolean(byte[] arr, int off) {
-            return arr[off] != 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public char[] readCharArray(byte[] arr, int off, int len) {
-            char[] val = new char[len];
-
-            for (int i = 0; i < len; i++) {
-                val[i] = readChar(arr, off);
-
-                off += 2;
-            }
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static double readDouble(byte[] arr, int off) {
+        long val = readLong(arr, off);
 
-            return val;
-        }
+        return Double.longBitsToDouble(val);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/c74b98e9/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
index b999cde..57ae3e7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
@@ -40,9 +40,6 @@ import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
  */
 public class PortableBuilderReader implements PortablePositionReadable {
     /** */
-    private static final PortablePrimitives PRIM = PortablePrimitives.get();
-
-    /** */
     private final Map<Integer, PortableBuilderImpl> objMap = new HashMap<>();
 
     /** */
@@ -120,7 +117,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
      * @return Read int value.
      */
     public int readInt(int off) {
-        return PRIM.readInt(arr, pos + off);
+        return PortablePrimitives.readInt(arr, pos + off);
     }
 
     /**
@@ -128,24 +125,24 @@ public class PortableBuilderReader implements PortablePositionReadable {
      * @return Read byte value.
      */
     public byte readByteAbsolute(int pos) {
-        return PRIM.readByte(arr, pos);
+        return PortablePrimitives.readByte(arr, pos);
     }
 
     /** {@inheritDoc} */
     @Override public short readShortPositioned(int pos) {
-        return PRIM.readShort(arr, pos);
+        return PortablePrimitives.readShort(arr, pos);
     }
 
     /** {@inheritDoc} */
     @Override public int readIntPositioned(int pos) {
-        return PRIM.readInt(arr, pos);
+        return PortablePrimitives.readInt(arr, pos);
     }
 
     /**
      * @return Read length of array.
      */
     public int readLength() {
-        return PRIM.readInt(arr, pos);
+        return PortablePrimitives.readInt(arr, pos);
     }
 
     /**
@@ -154,9 +151,9 @@ public class PortableBuilderReader implements PortablePositionReadable {
      * @return String length.
      */
     public int readStringLength() {
-        boolean utf = PRIM.readBoolean(arr, pos);
+        boolean utf = PortablePrimitives.readBoolean(arr, pos);
 
-        int arrLen = PRIM.readInt(arr, pos + 1);
+        int arrLen = PortablePrimitives.readInt(arr, pos + 1);
 
         return 1 + (utf ? arrLen : arrLen << 1);
     }
@@ -186,7 +183,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
             pos += len;
         }
         else {
-            str = String.valueOf(PRIM.readCharArray(arr, pos, len));
+            str = String.valueOf(PortablePrimitives.readCharArray(arr, pos, len));
 
             pos += len << 1;
         }
@@ -389,22 +386,22 @@ public class PortableBuilderReader implements PortablePositionReadable {
                 return arr[pos + 1];
 
             case GridPortableMarshaller.SHORT:
-                return PRIM.readShort(arr, pos + 1);
+                return PortablePrimitives.readShort(arr, pos + 1);
 
             case GridPortableMarshaller.INT:
-                return PRIM.readInt(arr, pos + 1);
+                return PortablePrimitives.readInt(arr, pos + 1);
 
             case GridPortableMarshaller.LONG:
-                return PRIM.readLong(arr, pos + 1);
+                return PortablePrimitives.readLong(arr, pos + 1);
 
             case GridPortableMarshaller.FLOAT:
-                return PRIM.readFloat(arr, pos + 1);
+                return PortablePrimitives.readFloat(arr, pos + 1);
 
             case GridPortableMarshaller.DOUBLE:
-                return PRIM.readDouble(arr, pos + 1);
+                return PortablePrimitives.readDouble(arr, pos + 1);
 
             case GridPortableMarshaller.CHAR:
-                return PRIM.readChar(arr, pos + 1);
+                return PortablePrimitives.readChar(arr, pos + 1);
 
             case GridPortableMarshaller.BOOLEAN:
                 return arr[pos + 1] != 0;
@@ -518,7 +515,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
                 return arr[pos++];
 
             case GridPortableMarshaller.SHORT: {
-                Object res = PRIM.readShort(arr, pos);
+                Object res = PortablePrimitives.readShort(arr, pos);
                 pos += 2;
                 return res;
             }
@@ -638,7 +635,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
                     if (flag != GridPortableMarshaller.DATE)
                         throw new PortableException("Invalid flag value: " + flag);
 
-                    long time = PRIM.readLong(arr, pos);
+                    long time = PortablePrimitives.readLong(arr, pos);
 
                     pos += 8;
 
@@ -662,11 +659,11 @@ public class PortableBuilderReader implements PortablePositionReadable {
                     if (flag != GridPortableMarshaller.TIMESTAMP)
                         throw new PortableException("Invalid flag value: " + flag);
 
-                    long time = PRIM.readLong(arr, pos);
+                    long time = PortablePrimitives.readLong(arr, pos);
 
                     pos += 8;
 
-                    int nano = PRIM.readInt(arr, pos);
+                    int nano = PortablePrimitives.readInt(arr, pos);
 
                     pos += 4;