You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2025/05/06 06:38:41 UTC

(ignite) branch master updated: IGNITE-25296 Make BinaryObjectImpl package private (#12052)

This is an automated email from the ASF dual-hosted git repository.

nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 31f14af476f IGNITE-25296 Make BinaryObjectImpl package private (#12052)
31f14af476f is described below

commit 31f14af476fc07ddc482f4baa6358c7fb180b9b5
Author: Nikolay <ni...@apache.org>
AuthorDate: Tue May 6 09:38:33 2025 +0300

    IGNITE-25296 Make BinaryObjectImpl package private (#12052)
---
 .../calcite/exec/exp/ExpressionFactoryImpl.java    |  6 +-
 .../ignite/internal/binary/BinaryObjectEx.java     | 30 +++++++++
 .../ignite/internal/binary/BinaryObjectExImpl.java | 22 -------
 .../ignite/internal/binary/BinaryObjectImpl.java   | 14 ++---
 .../internal/binary/BinaryObjectOffheapImpl.java   |  5 --
 .../apache/ignite/internal/binary/BinaryUtils.java | 71 +++++++++++++++++++---
 .../ignite/internal/binary/BinaryWriterEx.java     |  2 +-
 .../ignite/internal/binary/BinaryWriterExImpl.java |  2 +-
 .../internal/binary/GridBinaryMarshaller.java      |  4 +-
 .../binary/builder/BinaryBuilderReader.java        |  9 +--
 .../binary/builder/BinaryObjectBuilderImpl.java    |  8 +--
 .../binary/builder/BinaryPlainBinaryObject.java    |  4 +-
 .../query/index/sorted/QueryIndexRowHandler.java   |  9 +--
 .../index/sorted/keys/CacheJavaObjectIndexKey.java |  8 +--
 .../query/index/sorted/keys/IndexKeyFactory.java   |  4 +-
 .../communication/GridIoMessageFactory.java        |  6 +-
 .../binary/CacheObjectBinaryProcessorImpl.java     | 20 +++---
 .../cache/query/PlatformContinuousQueryImpl.java   |  7 ++-
 .../client/cache/ClientCacheInvokeRequest.java     |  4 +-
 .../cache/ClientCacheQueryContinuousRequest.java   |  4 +-
 .../platform/compute/PlatformCompute.java          |  3 +-
 .../query/stat/ColumnStatisticsCollector.java      |  7 ++-
 .../ignite/client/BinaryConfigurationTest.java     | 14 ++---
 .../org/apache/ignite/client/IgniteBinaryTest.java |  4 +-
 .../internal/binary/BinaryMarshallerSelfTest.java  |  6 +-
 .../internal/binary/BinaryObjectTestUtils.java     | 15 +++++
 .../inline/InlineIndexKeyTypeRegistryTest.java     |  6 +-
 .../IgniteCachePutKeyAttachedBinaryObjectTest.java |  3 +-
 .../cache/IgniteCacheStoreValueAbstractTest.java   |  6 +-
 .../GridCacheBinaryObjectsAbstractSelfTest.java    |  5 +-
 .../snapshot/IgniteClusterSnapshotCheckTest.java   |  8 ++-
 .../junits/GridTestBinaryMarshaller.java           |  3 +-
 .../processors/query/h2/dml/DmlBatchSender.java    |  4 +-
 .../query/h2/opt/GridH2ValueCacheObject.java       |  8 +--
 .../binary/BinaryObjectImplSerializer.java         |  2 +-
 35 files changed, 199 insertions(+), 134 deletions(-)

diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
index d8ca610970e..9aeb358ae6c 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
@@ -62,7 +62,7 @@ import org.apache.calcite.rex.RexShuttle;
 import org.apache.calcite.rex.RexUtil;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.validate.SqlConformance;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
 import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler;
 import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler.RowFactory;
@@ -251,7 +251,7 @@ public class ExpressionFactoryImpl<Row> implements ExpressionFactory<Row> {
     /** */
     @SuppressWarnings("rawtypes")
     private static int compare(Object o1, Object o2, int nullComparison) {
-        if (o1 instanceof BinaryObjectImpl)
+        if (BinaryUtils.isBinaryObjectImpl(o1))
             return compareBinary(o1, o2, nullComparison);
 
         final Comparable c1 = (Comparable)o1;
@@ -268,7 +268,7 @@ public class ExpressionFactoryImpl<Row> implements ExpressionFactory<Row> {
         else if (o2 == null)
             return -nullComparison;
 
-        return BinaryObjectImpl.compareForDml(o1, o2);
+        return BinaryUtils.compareForDml(o1, o2);
     }
 
     /** {@inheritDoc} */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
index 61e36ecb2d2..66ef859ac68 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -74,4 +74,34 @@ public interface BinaryObjectEx extends BinaryObject {
     @Nullable public default String enumClassName() {
         throw new UnsupportedOperationException("Not enum");
     }
+
+    /**
+     * @return {@code True} if object has bytes array.
+     */
+    public default boolean hasBytes() {
+        return false;
+    }
+
+    /**
+     * @return Object array if object is byte array based, otherwise {@code null}.
+     */
+    public default byte[] bytes() {
+        return null;
+    }
+
+    /**
+     * @return Object start.
+     */
+    public default int start() {
+        throw new UnsupportedOperationException("Has no array");
+    }
+
+    /**
+     * Get binary context.
+     *
+     * @return Binary context.
+     */
+    public default BinaryContext context() {
+        throw new UnsupportedOperationException("Context unknown");
+    }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
index 65e1a4b3c2c..5dc64d18779 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
@@ -47,21 +47,6 @@ abstract class BinaryObjectExImpl implements BinaryObjectEx {
      */
     public abstract int length();
 
-    /**
-     * @return Object start.
-     */
-    public abstract int start();
-
-    /**
-     * @return {@code True} if object has bytes array.
-     */
-    public abstract boolean hasBytes();
-
-    /**
-     * @return Object array if object has byte array based, otherwise {@code null}.
-     */
-    public abstract byte[] bytes();
-
     /**
      * @return Object offheap address is object is offheap based, otherwise 0.
      */
@@ -150,13 +135,6 @@ abstract class BinaryObjectExImpl implements BinaryObjectEx {
      */
     public abstract BinarySchema createSchema();
 
-    /**
-     * Get binary context.
-     *
-     * @return Binary context.
-     */
-    public abstract BinaryContext context();
-
     /** {@inheritDoc} */
     @Override public BinaryObjectBuilder toBuilder() throws BinaryObjectException {
         return BinaryObjectBuilders.builder(this);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 0e9cb65787c..c9e544f4ffe 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -56,7 +56,7 @@ import static org.apache.ignite.internal.binary.GridBinaryMarshaller.TRANSFORMED
  * Binary object implementation.
  */
 @IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
-public final class BinaryObjectImpl extends BinaryObjectExImpl implements Externalizable, KeyCacheObject {
+final class BinaryObjectImpl extends BinaryObjectExImpl implements Externalizable, KeyCacheObject {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -98,7 +98,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param arr Array.
      * @param start Start.
      */
-    public BinaryObjectImpl(BinaryContext ctx, byte[] arr, int start) {
+    BinaryObjectImpl(BinaryContext ctx, byte[] arr, int start) {
         assert ctx != null;
         assert arr != null;
 
@@ -113,7 +113,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param ctx Context.
      * @param bytes Array/ValBytes.
      */
-    public BinaryObjectImpl(BinaryContext ctx, byte[] bytes) {
+    BinaryObjectImpl(BinaryContext ctx, byte[] bytes) {
         assert ctx != null;
         assert bytes != null;
 
@@ -130,7 +130,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param valBytes Value bytes.
      * @param coCtx Cache object context.
      */
-    public BinaryObjectImpl(BinaryContext ctx, byte[] valBytes, CacheObjectContext coCtx) {
+    BinaryObjectImpl(BinaryContext ctx, byte[] valBytes, CacheObjectContext coCtx) {
         assert ctx != null;
         assert valBytes != null;
         assert coCtx != null;
@@ -943,9 +943,9 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @return Comparison result.
      */
     @SuppressWarnings("unchecked")
-    public static int compareForDml(Object first, Object second) {
-        boolean firstBinary = first instanceof BinaryObjectImpl;
-        boolean secondBinary = second instanceof BinaryObjectImpl;
+    static int compareForDml(Object first, Object second) {
+        boolean firstBinary = BinaryUtils.isBinaryObjectImpl(first);
+        boolean secondBinary = BinaryUtils.isBinaryObjectImpl(second);
 
         if (firstBinary) {
             if (secondBinary)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index fba0e6d06d2..b7e833e9779 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -144,11 +144,6 @@ class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Externalizab
         return start;
     }
 
-    /** {@inheritDoc} */
-    @Override public byte[] bytes() {
-        return null;
-    }
-
     /** {@inheritDoc} */
     @Override public boolean putValue(ByteBuffer buf) throws IgniteCheckedException {
         throw new UnsupportedOperationException("TODO implement");
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index 5521a371164..82e0db4ee90 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -55,7 +55,9 @@ import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.function.BiConsumer;
 import java.util.function.Function;
+import java.util.function.Supplier;
 import java.util.function.ToIntFunction;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
@@ -74,6 +76,7 @@ import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
 import org.apache.ignite.internal.binary.streams.BinaryStreams;
 import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.MutableSingletonList;
@@ -82,6 +85,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.platform.PlatformType;
+import org.apache.ignite.plugin.extensions.communication.Message;
 import org.jetbrains.annotations.Nullable;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -1572,11 +1576,8 @@ public class BinaryUtils {
 
             BinaryObjectImpl binO = new BinaryObjectImpl(ctx, arr, start);
 
-            if (detach) {
-                binO.detachAllowed(true);
-
-                return binO.detach();
-            }
+            if (detach)
+                return (BinaryObject)detach(binO);
 
             return binO;
         }
@@ -1765,13 +1766,31 @@ public class BinaryUtils {
      * @param ctx Context.
      * @param arr Array.
      */
-    public static CacheObject binaryEnum(BinaryContext ctx, byte[] arr) {
+    public static BinaryObjectEx binaryEnum(BinaryContext ctx, byte[] arr) {
         return new BinaryEnumObjectImpl(ctx, arr);
     }
 
+    /**
+     * @param register Register method.
+     */
+    public static void registerMessages(BiConsumer<Short, Supplier<Message>> register) {
+        register.accept((short)113, BinaryObjectImpl::new);
+        register.accept((short)119, BinaryEnumObjectImpl::new);
+    }
+
     /** */
-    public static CacheObject binaryEnum() {
-        return new BinaryEnumObjectImpl();
+    public static BinaryObjectEx binaryObject(BinaryContext ctx, byte[] arr, int start) {
+        return new BinaryObjectImpl(ctx, arr, start);
+    }
+
+    /** */
+    public static BinaryObjectEx binaryObject(BinaryContext ctx, byte[] bytes) {
+        return new BinaryObjectImpl(ctx, bytes);
+    }
+
+    /** */
+    public static BinaryObject binaryObject(BinaryContext ctx, byte[] valBytes, CacheObjectContext coCtx) {
+        return new BinaryObjectImpl(ctx, valBytes, coCtx);
     }
 
     /**
@@ -2955,6 +2974,14 @@ public class BinaryUtils {
         return val instanceof BinaryObjectExImpl;
     }
 
+    /**
+     * @param val Value to check.
+     * @return {@code True} if {@code val} instance of {@link BinaryObjectImpl}.
+     */
+    public static boolean isBinaryObjectImpl(Object val) {
+        return val instanceof BinaryObjectImpl;
+    }
+
     /**
      * @param val Value to check.
      * @return {@code True} if {@code val} instance of {@link BinaryArray}.
@@ -3028,6 +3055,34 @@ public class BinaryUtils {
         return Arrays.deepEquals((Object[])a1, (Object[])a2);
     }
 
+    /**
+     * Compare two objects for DML operation.
+     *
+     * @param first First.
+     * @param second Second.
+     * @return Comparison result.
+     */
+    public static int compareForDml(Object first, Object second) {
+        return BinaryObjectImpl.compareForDml(first, second);
+    }
+
+    /**
+     * @param o Object to detach.
+     * @return Detached object.
+     */
+    public static Object detach(Object o) {
+        ((BinaryObjectImpl)o).detachAllowed(true);
+        return ((BinaryObjectImpl)o).detach();
+    }
+
+    /**
+     * @param o
+     */
+    public static void detachAllowedIfPossible(Object o) {
+        if (isBinaryObjectImpl(o))
+            ((BinaryObjectImpl)o).detachAllowed(true);
+    }
+
     /**
      * Enum type.
      */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterEx.java
index 3944958c969..a5d6ac778a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterEx.java
@@ -211,5 +211,5 @@ public interface BinaryWriterEx extends BinaryWriter, BinaryRawWriter, ObjectOut
      * @param po Binary object.
      * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
      */
-    public void writeBinaryObject(@Nullable BinaryObjectImpl po) throws BinaryObjectException;
+    public void writeBinaryObject(@Nullable BinaryObjectEx po) throws BinaryObjectException;
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 2892088d24b..5521381a60c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -600,7 +600,7 @@ class BinaryWriterExImpl implements BinaryWriterEx {
     }
 
     /** {@inheritDoc} */
-    @Override public void writeBinaryObject(@Nullable BinaryObjectImpl po) throws BinaryObjectException {
+    @Override public void writeBinaryObject(@Nullable BinaryObjectEx po) throws BinaryObjectException {
         if (po == null)
             out.writeByte(GridBinaryMarshaller.NULL);
         else {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
index 1250ce8832e..4ebac2bd59a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -314,8 +314,8 @@ public class GridBinaryMarshaller {
      * Unwrap binary object.
      */
     private Object unwrapBinary(Object obj, BinaryReaderHandles hnds, Class<?> clazz) {
-        if (obj instanceof BinaryObjectImpl) {
-            BinaryObjectImpl obj0 = (BinaryObjectImpl)obj;
+        if (BinaryUtils.isBinaryObjectImpl(obj)) {
+            BinaryObjectEx obj0 = (BinaryObjectEx)obj;
             BinaryInputStream in = BinaryStreams.inputStream(obj0.bytes(), obj0.start());
 
             return deserialize(in, null, hnds);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
index 544a0a8021a..ecb7715b735 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
@@ -22,9 +22,10 @@ import java.sql.Timestamp;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.internal.binary.BinaryContext;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryPositionReadable;
 import org.apache.ignite.internal.binary.BinaryPrimitives;
 import org.apache.ignite.internal.binary.BinaryReaderEx;
@@ -62,7 +63,7 @@ class BinaryBuilderReader implements BinaryPositionReadable {
      *
      * @param objImpl Binary object
      */
-    BinaryBuilderReader(BinaryObjectImpl objImpl) {
+    BinaryBuilderReader(BinaryObjectEx objImpl) {
         ctx = objImpl.context();
         arr = objImpl.bytes();
         pos = objImpl.start();
@@ -492,7 +493,7 @@ class BinaryBuilderReader implements BinaryPositionReadable {
 
                 int start = readIntPositioned(pos + 4 + size);
 
-                BinaryObjectImpl binaryObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
+                BinaryObject binaryObj = BinaryUtils.binaryObject(ctx, arr, pos + 4 + start);
 
                 return new BinaryPlainBinaryObject(binaryObj);
             }
@@ -844,7 +845,7 @@ class BinaryBuilderReader implements BinaryPositionReadable {
 
                 int start = readInt();
 
-                BinaryObjectImpl binaryObj = new BinaryObjectImpl(ctx, arr, pos - 4 - size + start);
+                BinaryObject binaryObj = BinaryUtils.binaryObject(ctx, arr, pos - 4 - size + start);
 
                 return new BinaryPlainBinaryObject(binaryObj);
             }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index da84c51e6f0..795f1889aeb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -32,7 +32,7 @@ import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.binary.BinaryFieldMetadata;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinarySchema;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.BinaryWriterEx;
@@ -115,7 +115,7 @@ class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     /**
      * @param obj Object to wrap.
      */
-    public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
+    public BinaryObjectBuilderImpl(BinaryObjectEx obj) {
         this(new BinaryBuilderReader(obj), obj.start());
         reader.registerObject(this);
     }
@@ -186,7 +186,7 @@ class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
             byte[] arr = writer.array();
 
-            return new BinaryObjectImpl(ctx, arr, 0);
+            return BinaryUtils.binaryObject(ctx, arr, 0);
         }
     }
 
@@ -586,7 +586,7 @@ class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @return New builder.
      */
     public static BinaryObjectBuilderImpl wrap(BinaryObject obj) {
-        return new BinaryObjectBuilderImpl((BinaryObjectImpl)BinaryUtils.unwrapTemporary(obj));
+        return new BinaryObjectBuilderImpl((BinaryObjectEx)BinaryUtils.unwrapTemporary(obj));
     }
 
     /**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
index 21494766de3..8de3514b872 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.binary.builder;
 
 import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.BinaryWriterEx;
 
@@ -43,6 +43,6 @@ class BinaryPlainBinaryObject implements BinaryLazyValue {
 
     /** {@inheritDoc} */
     @Override public void writeTo(BinaryWriterEx writer, BinaryBuilderSerializer ctx) {
-        writer.writeBinaryObject((BinaryObjectImpl)BinaryUtils.unwrapTemporary(binaryObj));
+        writer.writeBinaryObject((BinaryObjectEx)BinaryUtils.unwrapTemporary(binaryObj));
     }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java
index 58ba2dfdcdb..14ca0ca05c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java
@@ -22,7 +22,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKeyFactory;
@@ -147,11 +147,8 @@ public class QueryIndexRowHandler implements InlineIndexRowHandler {
 
     /** */
     private Object getBinaryObject(CacheObject o) {
-        if (o instanceof BinaryObjectImpl) {
-            ((BinaryObjectImpl)o).detachAllowed(true);
-            o = ((BinaryObjectImpl)o).detach();
-            return o;
-        }
+        if (BinaryUtils.isBinaryObjectImpl(o))
+            return BinaryUtils.detach(o);
 
         return null;
     }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/CacheJavaObjectIndexKey.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/CacheJavaObjectIndexKey.java
index 66e79b1253b..8219235d56b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/CacheJavaObjectIndexKey.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/CacheJavaObjectIndexKey.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.cache.query.index.sorted.keys;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cache.query.index.IndexProcessor;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
@@ -47,10 +47,8 @@ public class CacheJavaObjectIndexKey extends JavaObjectIndexKey {
     public CacheJavaObjectIndexKey(CacheObject obj, CacheObjectValueContext valCtx) {
         assert obj != null;
 
-        if (obj instanceof BinaryObjectImpl) {
-            ((BinaryObjectImpl)obj).detachAllowed(true);
-            obj = ((BinaryObjectImpl)obj).detach();
-        }
+        if (BinaryUtils.isBinaryObjectImpl(obj))
+            obj = (CacheObject)BinaryUtils.detach(obj);
 
         this.obj = obj;
         this.valCtx = valCtx;
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
index 0ec5b34d845..6cfec38b822 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
@@ -23,7 +23,7 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.function.Function;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
 import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -76,7 +76,7 @@ public class IndexKeyFactory {
             case UUID:
                 return new UuidIndexKey((UUID)o);
             case JAVA_OBJECT:
-                if (BinaryObjectImpl.class == o.getClass())
+                if (BinaryUtils.isBinaryObjectImpl(o))
                     return new CacheJavaObjectIndexKey((CacheObject)o, coctx);
 
                 return new PlainJavaObjectIndexKey(o, null);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index eb8feb4b790..652181c77b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -25,7 +25,6 @@ import org.apache.ignite.internal.GridJobSiblingsResponse;
 import org.apache.ignite.internal.GridTaskCancelRequest;
 import org.apache.ignite.internal.GridTaskSessionRequest;
 import org.apache.ignite.internal.IgniteDiagnosticMessage;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.managers.checkpoint.GridCheckpointRequest;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
@@ -293,13 +292,14 @@ public class GridIoMessageFactory implements MessageFactoryProvider {
         factory.register((short)109, GridQueryNextPageResponse::new);
         factory.register((short)111, AffinityTopologyVersion::new);
         factory.register((short)112, GridCacheSqlQuery::new);
-        factory.register((short)113, BinaryObjectImpl::new);
+        // 113 - BinaryObjectImpl
         factory.register((short)114, GridDhtPartitionSupplyMessage::new);
         factory.register((short)115, UUIDCollectionMessage::new);
         factory.register((short)116, GridNearSingleGetRequest::new);
         factory.register((short)117, GridNearSingleGetResponse::new);
         factory.register((short)118, CacheContinuousQueryBatchAck::new);
-        factory.register((short)119, BinaryUtils::binaryEnum);
+        // 119 - BinaryEnumObjectImpl
+        BinaryUtils.registerMessages(factory::register);
 
         // [120..123] - DR
         factory.register((short)124, GridMessageCollection::new);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 06df4fef473..02e24622048 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -64,7 +64,6 @@ import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.binary.BinaryMetadata;
 import org.apache.ignite.internal.binary.BinaryMetadataHandler;
 import org.apache.ignite.internal.binary.BinaryObjectEx;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryTypeImpl;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
@@ -518,8 +517,7 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
         Object obj0 = binaryMarsh.unmarshal(arr, null);
 
         // Possible if a class has writeObject method.
-        if (obj0 instanceof BinaryObjectImpl)
-            ((BinaryObjectImpl)obj0).detachAllowed(true);
+        BinaryUtils.detachAllowedIfPossible(obj0);
 
         return obj0;
     }
@@ -1192,7 +1190,7 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
         if (obj instanceof KeyCacheObject) {
             KeyCacheObject key = (KeyCacheObject)obj;
 
-            if (key instanceof BinaryObjectImpl) {
+            if (BinaryUtils.isBinaryObjectImpl(key)) {
                 // Need to create a copy because the key can be reused at the application layer after that (IGNITE-3505).
                 key = key.copy(partition(ctx, cctx, key));
             }
@@ -1205,7 +1203,7 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
 
         obj = toBinary(obj, false);
 
-        if (obj instanceof BinaryObjectImpl) {
+        if (BinaryUtils.isBinaryObjectImpl(obj)) {
             ((KeyCacheObject)obj).partition(partition(ctx, cctx, obj));
 
             return (KeyCacheObject)obj;
@@ -1297,11 +1295,11 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
     /** {@inheritDoc} */
     @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) {
         switch (type) {
-            case BinaryObjectImpl.TYPE_BINARY:
-                return new BinaryObjectImpl(binaryContext(), bytes, ctx);
+            case CacheObject.TYPE_BINARY:
+                return (CacheObject)BinaryUtils.binaryObject(binaryContext(), bytes, ctx);
 
-            case BinaryObjectImpl.TYPE_BINARY_ENUM:
-                return BinaryUtils.binaryEnum(binaryContext(), bytes);
+            case CacheObject.TYPE_BINARY_ENUM:
+                return (CacheObject)BinaryUtils.binaryEnum(binaryContext(), bytes);
 
             case CacheObject.TYPE_BYTE_ARR:
                 return new CacheObjectByteArrayImpl(bytes);
@@ -1317,8 +1315,8 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
     @Override public KeyCacheObject toKeyCacheObject(CacheObjectContext ctx, byte type, byte[] bytes)
         throws IgniteCheckedException {
         switch (type) {
-            case BinaryObjectImpl.TYPE_BINARY:
-                return new BinaryObjectImpl(binaryContext(), bytes);
+            case CacheObject.TYPE_BINARY:
+                return (KeyCacheObject)BinaryUtils.binaryObject(binaryContext(), bytes);
 
             case CacheObject.TYPE_BYTE_ARR:
                 throw new IllegalArgumentException("Byte arrays cannot be used as cache keys.");
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
index 2895d0d9a98..fce0c57830c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
@@ -34,7 +34,8 @@ import org.apache.ignite.cache.query.Query;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
@@ -107,8 +108,8 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
      * @return Java filter or null.
      */
     private static CacheEntryEventFilter getJavaFilter(Object filter, GridKernalContext ctx) {
-        if (filter instanceof BinaryObjectImpl) {
-            BinaryObjectImpl bo = (BinaryObjectImpl)filter;
+        if (BinaryUtils.isBinaryObjectImpl(filter)) {
+            BinaryObjectEx bo = (BinaryObjectEx)filter;
 
             if (bo.typeId() == GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY) {
                 PlatformJavaObjectFactoryProxy prx = bo.deserialize();
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheInvokeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheInvokeRequest.java
index ee8ca7dbffc..2116dba0c70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheInvokeRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheInvokeRequest.java
@@ -21,7 +21,7 @@ import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.EntryProcessorException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryReaderEx;
 import org.apache.ignite.internal.processors.platform.client.ClientConnectionContext;
 import org.apache.ignite.internal.processors.platform.client.ClientObjectResponse;
@@ -129,7 +129,7 @@ public class ClientCacheInvokeRequest extends ClientCacheKeyRequest {
                     "Entry processor should be marshalled as a BinaryObject: " + entryProc.getClass());
             }
 
-            BinaryObjectImpl bo = (BinaryObjectImpl)entryProc;
+            BinaryObjectEx bo = (BinaryObjectEx)entryProc;
 
             if (entryProcPlatform == ClientPlatform.JAVA)
                 return bo.deserialize();
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheQueryContinuousRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheQueryContinuousRequest.java
index dac5a7b0093..92bd9118ce3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheQueryContinuousRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheQueryContinuousRequest.java
@@ -25,7 +25,7 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
 import org.apache.ignite.cache.query.ContinuousQuery;
 import org.apache.ignite.cache.query.QueryCursor;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryReaderEx;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -113,7 +113,7 @@ public class ClientCacheQueryContinuousRequest extends ClientCacheRequest {
             throw new IgniteClientException(ClientStatus.FAILED,
                     "Filter must be a BinaryObject: " + filter.getClass());
 
-        BinaryObjectImpl bo = (BinaryObjectImpl)filter;
+        BinaryObjectEx bo = (BinaryObjectEx)filter;
 
         switch (filterPlatform) {
             case ClientPlatform.JAVA: {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
index 7ab823211bc..9dc90bf0008 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
@@ -30,7 +30,6 @@ import org.apache.ignite.cluster.ClusterGroup;
 import org.apache.ignite.compute.ComputeTaskFuture;
 import org.apache.ignite.internal.IgniteComputeHandler;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryReaderEx;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.BinaryWriterEx;
@@ -387,7 +386,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
 
         Collection<UUID> nodeIds = readNodeIds(reader);
 
-        if (!keepBinary && (arg instanceof BinaryObjectImpl || BinaryUtils.isBinaryArray(arg)))
+        if (!keepBinary && (BinaryUtils.isBinaryObjectImpl(arg) || BinaryUtils.isBinaryArray(arg)))
             arg = ((BinaryObject)arg).deserialize();
 
         if (nodeIds != null)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/ColumnStatisticsCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/ColumnStatisticsCollector.java
index 7d59c4a1dd7..5db0766aec8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/ColumnStatisticsCollector.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/ColumnStatisticsCollector.java
@@ -33,7 +33,8 @@ import java.util.Set;
 import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cache.query.index.IndexProcessor;
 import org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnOverrides;
 import org.apache.ignite.internal.processors.query.stat.hll.HLL;
@@ -318,8 +319,8 @@ public class ColumnStatisticsCollector {
             buf = (byte[])obj;
         else if (cls.isAssignableFrom(String.class))
             buf = ((String)obj).getBytes(StandardCharsets.UTF_8);
-        else if (obj instanceof BinaryObjectImpl)
-            buf = ((BinaryObjectImpl)obj).bytes();
+        else if (BinaryUtils.isBinaryObjectImpl(obj))
+            buf = ((BinaryObjectEx)obj).bytes();
         else {
             try {
                 buf = IndexProcessor.serializer.serialize(obj);
diff --git a/modules/core/src/test/java/org/apache/ignite/client/BinaryConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/client/BinaryConfigurationTest.java
index 52779e8ccba..543e020ccdd 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/BinaryConfigurationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/BinaryConfigurationTest.java
@@ -23,7 +23,7 @@ import org.apache.ignite.binary.BinaryBasicNameMapper;
 import org.apache.ignite.binary.BinaryNameMapper;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.ClientConfiguration;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.client.thin.AbstractThinClientTest;
 import org.apache.ignite.internal.processors.platform.client.IgniteClientException;
 import org.apache.ignite.testframework.GridTestUtils;
@@ -51,7 +51,7 @@ public class BinaryConfigurationTest extends AbstractThinClientTest {
         Ignite server = startGrid(0);
 
         try (IgniteClient client = startClient(0)) {
-            BinaryObjectImpl res = getClientBinaryObjectFromServer(server, client);
+            BinaryObjectEx res = getClientBinaryObjectFromServer(server, client);
 
             // Server-side defaults are compact footers and full name mapper.
             assertTrue(res.isFlagSet(FLAG_COMPACT_FOOTER));
@@ -79,7 +79,7 @@ public class BinaryConfigurationTest extends AbstractThinClientTest {
                 .setLogger(new ListeningTestLogger(baseCfg.getLogger(), listener));
 
         try (IgniteClient client = Ignition.startClient(clientCfg)) {
-            BinaryObjectImpl res = getClientBinaryObjectFromServer(server, client);
+            BinaryObjectEx res = getClientBinaryObjectFromServer(server, client);
 
             // Server-side defaults are compact footers and full name mapper.
             assertTrue(res.isFlagSet(FLAG_COMPACT_FOOTER));
@@ -105,7 +105,7 @@ public class BinaryConfigurationTest extends AbstractThinClientTest {
                 .setBinaryConfiguration(binaryCfg);
 
         try (IgniteClient client = Ignition.startClient(clientCfg)) {
-            BinaryObjectImpl res = getClientBinaryObjectFromServer(server, client);
+            BinaryObjectEx res = getClientBinaryObjectFromServer(server, client);
 
             assertFalse(res.isFlagSet(FLAG_COMPACT_FOOTER));
             assertEquals("Person", res.type().typeName());
@@ -153,7 +153,7 @@ public class BinaryConfigurationTest extends AbstractThinClientTest {
                 .setLogger(new ListeningTestLogger(baseCfg.getLogger(), listener));
 
         try (IgniteClient client = Ignition.startClient(clientCfg)) {
-            BinaryObjectImpl res = getClientBinaryObjectFromServer(server, client);
+            BinaryObjectEx res = getClientBinaryObjectFromServer(server, client);
 
             assertTrue(res.isFlagSet(FLAG_COMPACT_FOOTER));
             assertEquals("org.apache.ignite.client.Person_", res.type().typeName());
@@ -168,10 +168,10 @@ public class BinaryConfigurationTest extends AbstractThinClientTest {
      * @param client Client.
      * @return Binary object.
      */
-    private BinaryObjectImpl getClientBinaryObjectFromServer(Ignite server, IgniteClient client) {
+    private BinaryObjectEx getClientBinaryObjectFromServer(Ignite server, IgniteClient client) {
         client.getOrCreateCache("c").put(1, new Person(1, "1"));
 
-        return server.cache("c").<Integer, BinaryObjectImpl>withKeepBinary().get(1);
+        return server.cache("c").<Integer, BinaryObjectEx>withKeepBinary().get(1);
     }
 
     /**
diff --git a/modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java b/modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
index 016adee55bc..2059d1ee137 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
@@ -46,7 +46,7 @@ import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.ClientConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.odbc.ClientListenerProcessor;
 import org.apache.ignite.internal.util.typedef.X;
@@ -417,7 +417,7 @@ public class IgniteBinaryTest extends GridCommonAbstractTest {
             try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
                 int typeId = GridBinaryMarshaller.OBJ;
 
-                BinaryObjectImpl binObj = (BinaryObjectImpl)ignite.binary().builder(Character.toString((char)typeId))
+                BinaryObjectEx binObj = (BinaryObjectEx)ignite.binary().builder(Character.toString((char)typeId))
                         .setField("dummy", "dummy")
                         .build();
 
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 f870bf1bf81..c969690c889 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
@@ -3753,7 +3753,7 @@ public class BinaryMarshallerSelfTest extends AbstractBinaryArraysTest {
      * @param marsh Binary marshaller.
      * @return Instance of BinaryObjectOffheapImpl.
      */
-    private BinaryObjectOffheapImpl marshalOffHeap(BinaryObjectImpl obj, BinaryMarshaller marsh) {
+    private BinaryObjectOffheapImpl marshalOffHeap(BinaryObjectEx obj, BinaryMarshaller marsh) {
         long ptr = copyOffheap(obj);
 
         return new BinaryObjectOffheapImpl(binaryContext(marsh),
@@ -3979,7 +3979,7 @@ public class BinaryMarshallerSelfTest extends AbstractBinaryArraysTest {
      * @param obj Object.
      * @return Offheap address.
      */
-    private long copyOffheap(BinaryObjectImpl obj) {
+    private long copyOffheap(BinaryObjectEx obj) {
         byte[] arr = obj.bytes();
 
         long ptr = GridUnsafe.allocateMemory(arr.length);
@@ -4063,7 +4063,7 @@ public class BinaryMarshallerSelfTest extends AbstractBinaryArraysTest {
      * @param marsh Marshaller.
      * @return Result object.
      */
-    private <T> T unmarshal(BinaryObjectImpl bo, BinaryMarshaller marsh) throws IgniteCheckedException {
+    private <T> T unmarshal(BinaryObjectEx bo, BinaryMarshaller marsh) throws IgniteCheckedException {
         return marsh.unmarshal(bo.bytes(), null);
     }
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectTestUtils.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectTestUtils.java
index 875ef787bbc..f0fea335cb4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectTestUtils.java
@@ -38,4 +38,19 @@ public class BinaryObjectTestUtils {
     public static int binaryArrayIdentityResolverHashCode(BinaryObject obj) {
         return BinaryArrayIdentityResolver.instance().hashCode(obj);
     }
+
+    /**
+     * @return Binary object instance.
+     */
+    public static BinaryObject binaryObject() {
+        return new BinaryObjectImpl();
+    }
+
+    /**
+     * @param o Object.
+     * @return {@link BinaryObjectImpl#detached()} value.
+     */
+    public static boolean isDetached(Object o) {
+        return ((BinaryObjectImpl)o).detached();
+    }
 }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyTypeRegistryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyTypeRegistryTest.java
index 7247cad333f..2f4b2809187 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyTypeRegistryTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyTypeRegistryTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.cache.query.index.sorted.inline;
 
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectTestUtils;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IntegerIndexKey;
@@ -61,14 +61,14 @@ public class InlineIndexKeyTypeRegistryTest extends GridCommonAbstractTest {
         assertEquals(IndexKeyType.INT, t.type());
 
         t = InlineIndexKeyTypeRegistry.get(
-            new PlainJavaObjectIndexKey(new BinaryObjectImpl(), null),
+            new PlainJavaObjectIndexKey(BinaryObjectTestUtils.binaryObject(), null),
             IndexKeyType.JAVA_OBJECT,
             pojoArrayKeyTypeSettings
         );
         assertEquals(IndexKeyType.JAVA_OBJECT, t.type());
 
         t = InlineIndexKeyTypeRegistry.get(
-            new PlainJavaObjectIndexKey(new BinaryObjectImpl(), null),
+            new PlainJavaObjectIndexKey(BinaryObjectTestUtils.binaryObject(), null),
             IndexKeyType.INT,
             pojoArrayKeyTypeSettings
         );
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutKeyAttachedBinaryObjectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutKeyAttachedBinaryObjectTest.java
index 91277f85abf..152f0ab6138 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutKeyAttachedBinaryObjectTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutKeyAttachedBinaryObjectTest.java
@@ -25,7 +25,6 @@ import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.failure.StopNodeFailureHandler;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -70,7 +69,7 @@ public class IgniteCachePutKeyAttachedBinaryObjectTest extends GridCommonAbstrac
         BinaryObjectBuilder holdBuilder = grid(0).binary().builder(HolderKey.class.getName());
 
         //Creating attached key which stores as byte array.
-        BinaryObjectImpl attachedKey = holdBuilder.setField("id", new AttachedKey(1))
+        BinaryObject attachedKey = holdBuilder.setField("id", new AttachedKey(1))
             .build()
             .field("id");
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
index f48f929fd7f..b3e17e9e777 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
@@ -37,7 +37,7 @@ import org.apache.ignite.cache.store.CacheStoreAdapter;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.lang.IgniteBiInClosure;
@@ -408,8 +408,8 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
      */
     @SuppressWarnings("IfMayBeConditional")
     private Object reflectiveValue(CacheObject obj) {
-        if (obj instanceof BinaryObjectImpl)
-            return GridTestUtils.getFieldValue(obj, BinaryObjectImpl.class, "obj");
+        if (BinaryUtils.isBinaryObjectImpl(obj))
+            return GridTestUtils.getFieldValue(obj, obj.getClass(), "obj");
         else
             return GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val");
     }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index f90aff17215..4715e48eaeb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -56,7 +56,6 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.binary.BinaryContext;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryObjectTestUtils;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
@@ -166,10 +165,10 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
                 Object val = CU.value(e.rawGet(), c.context(), false);
 
                 if (key instanceof BinaryObject)
-                    assert ((BinaryObjectImpl)key).detached() : val;
+                    assert BinaryObjectTestUtils.isDetached(key) : key;
 
                 if (val instanceof BinaryObject)
-                    assert ((BinaryObjectImpl)val).detached() : val;
+                    assert BinaryObjectTestUtils.isDetached(val) : val;
             }
         }
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
index ec470579557..25c9a8bc229 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
@@ -41,6 +41,7 @@ import javax.cache.expiry.Duration;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -48,7 +49,7 @@ import org.apache.ignite.internal.GridJobExecuteRequest;
 import org.apache.ignite.internal.GridTopic;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.binary.BinaryContext;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.management.cache.CacheFilterEnum;
 import org.apache.ignite.internal.management.cache.CacheIdleVerifyCommandArg;
 import org.apache.ignite.internal.management.cache.IdleVerifyResult;
@@ -57,6 +58,7 @@ import org.apache.ignite.internal.management.cache.VerifyBackupPartitionsTask;
 import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheGroupContext;
+import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
@@ -415,10 +417,10 @@ public class IgniteClusterSnapshotCheckTest extends AbstractSnapshotSelfTest {
                 new Random().nextBytes(bytes);
 
                 try {
-                    BinaryObjectImpl newVal = new BinaryObjectImpl(binCtx, binCtx.marshaller().marshal(new Value(bytes)), 0);
+                    BinaryObject newVal = BinaryUtils.binaryObject(binCtx, binCtx.marshaller().marshal(new Value(bytes)), 0);
 
                     boolean success = cached.initialValue(
-                        newVal,
+                        (CacheObject)newVal,
                         new GridCacheVersion(row0.version().topologyVersion(),
                             row0.version().nodeOrder(),
                             row0.version().order() + 1),
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestBinaryMarshaller.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestBinaryMarshaller.java
index 08387b580fa..da1d31646a8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestBinaryMarshaller.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestBinaryMarshaller.java
@@ -25,7 +25,6 @@ import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree;
@@ -58,7 +57,7 @@ public class GridTestBinaryMarshaller {
     public BinaryObject marshal(Object obj) throws IgniteCheckedException {
         byte[] bytes = marsh.marshal(obj);
 
-        return new BinaryObjectImpl(U.<GridBinaryMarshaller>field(marsh, "impl").context(), bytes, 0);
+        return BinaryUtils.binaryObject(U.<GridBinaryMarshaller>field(marsh, "impl").context(), bytes, 0);
     }
 
     /**
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
index 874a44bd56b..5e4ad2830ff 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlBatchSender.java
@@ -35,7 +35,7 @@ import javax.cache.processor.EntryProcessorException;
 import javax.cache.processor.EntryProcessorResult;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
@@ -447,7 +447,7 @@ public class DmlBatchSender {
         @Override public int compare(Object first, Object second) {
             // We assume that only simple types or BinaryObjectImpl are possible. The latter comes from the fact
             // that we use BinaryObjectBuilder which produces only on-heap binary objects.
-            return BinaryObjectImpl.compareForDml(first, second);
+            return BinaryUtils.compareForDml(first, second);
         }
     }
 }
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
index 5b1dfcd4380..1ebb3425c3d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -21,7 +21,7 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Types;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.h2.message.DbException;
@@ -51,10 +51,8 @@ public class GridH2ValueCacheObject extends Value {
     public GridH2ValueCacheObject(CacheObject obj, CacheObjectValueContext valCtx) {
         assert obj != null;
 
-        if (obj instanceof BinaryObjectImpl) {
-            ((BinaryObjectImpl)obj).detachAllowed(true);
-            obj = ((BinaryObjectImpl)obj).detach();
-        }
+        if (BinaryUtils.isBinaryObjectImpl(obj))
+            obj = (CacheObject)BinaryUtils.detach(obj);
 
         this.obj = obj;
         this.valCtx = valCtx;
diff --git a/modules/json/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImplSerializer.java b/modules/json/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImplSerializer.java
index eb843e76a4a..a82373e6a6f 100644
--- a/modules/json/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImplSerializer.java
+++ b/modules/json/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImplSerializer.java
@@ -43,7 +43,7 @@ class BinaryObjectImplSerializer extends JsonSerializer<BinaryObjectImpl> {
                 for (String name : meta.fieldNames()) {
                     Object val = bin.field(name);
 
-                    if (val instanceof BinaryObjectImpl) {
+                    if (BinaryUtils.isBinaryObjectImpl(val)) {
                         BinaryObjectImpl ref = (BinaryObjectImpl)val;
 
                         if (ref.hasCircularReferences()) {