ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [18/50] [abbrv] incubator-ignite git commit: IGNITE-141 - Marshallers refactoring
Date Wed, 11 Mar 2015 06:45:38 GMT
IGNITE-141 - Marshallers refactoring


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

Branch: refs/heads/ignite-51
Commit: b98e7e6a3321be8236165e0b37129d1667db4979
Parents: 13518b2
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Fri Mar 6 16:45:12 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Fri Mar 6 16:45:12 2015 -0800

----------------------------------------------------------------------
 .../optimized/OptimizedClassDescriptor.java     | 337 +++++--------------
 .../optimized/OptimizedMarshallerUtils.java     | 121 ++++++-
 .../optimized/OptimizedObjectInputStream.java   | 111 +++++-
 .../optimized/OptimizedObjectOutputStream.java  |   6 +-
 .../optimized/OptimizedMarshallerSelfTest.java  |   6 +-
 .../OptimizedObjectStreamSelfTest.java          |   3 +-
 6 files changed, 296 insertions(+), 288 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
index 5ce6956..5bc2bab 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
@@ -19,7 +19,6 @@ package org.apache.ignite.marshaller.optimized;
 
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.marshaller.*;
 import sun.misc.*;
@@ -30,6 +29,7 @@ import java.util.*;
 
 import static java.lang.reflect.Modifier.*;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.*;
+import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ENUM;
 
 /**
  * Class descriptor.
@@ -38,99 +38,6 @@ class OptimizedClassDescriptor {
     /** Unsafe. */
     private static final Unsafe UNSAFE = GridUnsafe.unsafe();
 
-    /** */
-    private static final int TYPE_BYTE = 1;
-
-    /** */
-    private static final int TYPE_SHORT = 2;
-
-    /** */
-    private static final int TYPE_INT = 3;
-
-    /** */
-    private static final int TYPE_LONG = 4;
-
-    /** */
-    private static final int TYPE_FLOAT = 5;
-
-    /** */
-    private static final int TYPE_DOUBLE = 6;
-
-    /** */
-    private static final int TYPE_CHAR = 7;
-
-    /** */
-    private static final int TYPE_BOOLEAN = 8;
-
-    /** */
-    private static final int TYPE_BYTE_ARR = 9;
-
-    /** */
-    private static final int TYPE_SHORT_ARR = 10;
-
-    /** */
-    private static final int TYPE_INT_ARR = 11;
-
-    /** */
-    private static final int TYPE_LONG_ARR = 12;
-
-    /** */
-    private static final int TYPE_FLOAT_ARR = 13;
-
-    /** */
-    private static final int TYPE_DOUBLE_ARR = 14;
-
-    /** */
-    private static final int TYPE_CHAR_ARR = 15;
-
-    /** */
-    private static final int TYPE_BOOLEAN_ARR = 16;
-
-    /** */
-    private static final int TYPE_OBJ_ARR = 17;
-
-    /** */
-    private static final int TYPE_STR = 18;
-
-    /** */
-    private static final int TYPE_ENUM = 19;
-
-    /** */
-    private static final int TYPE_UUID = 20;
-
-    /** */
-    private static final int TYPE_PROPS = 21;
-
-    /** */
-    private static final int TYPE_ARRAY_LIST = 22;
-
-    /** */
-    private static final int TYPE_HASH_MAP = 23;
-
-    /** */
-    private static final int TYPE_HASH_SET = 24;
-
-    /** */
-    private static final int TYPE_LINKED_LIST = 25;
-
-    /** */
-    private static final int TYPE_LINKED_HASH_MAP = 26;
-
-    /** */
-    private static final int TYPE_LINKED_HASH_SET = 27;
-
-    /** */
-    private static final int TYPE_DATE = 28;
-
-    /** */
-    private static final int TYPE_CLS = 29;
-
-    /** */
-    private static final int TYPE_EXTERNALIZABLE = 50;
-
-    /** */
-    private static final int TYPE_SERIALIZABLE = 51;
-
     /** Class. */
     private final Class<?> cls;
 
@@ -194,9 +101,6 @@ class OptimizedClassDescriptor {
     /** Load factor field offset. */
     private long loadFactorFieldOff;
 
-    /** Map field offset. */
-    private long mapFieldOff;
-
     /** Access order field offset. */
     private long accessOrderFieldOff;
 
@@ -236,82 +140,82 @@ class OptimizedClassDescriptor {
             Class<?> parent;
 
             if (cls == byte.class || cls == Byte.class) {
-                type = TYPE_BYTE;
+                type = BYTE;
 
                 isPrimitive = true;
             }
             else if (cls == short.class || cls == Short.class) {
-                type = TYPE_SHORT;
+                type = SHORT;
 
                 isPrimitive = true;
             }
             else if (cls == int.class || cls == Integer.class) {
-                type = TYPE_INT;
+                type = INT;
 
                 isPrimitive = true;
             }
             else if (cls == long.class || cls == Long.class) {
-                type = TYPE_LONG;
+                type = LONG;
 
                 isPrimitive = true;
             }
             else if (cls == float.class || cls == Float.class) {
-                type = TYPE_FLOAT;
+                type = FLOAT;
 
                 isPrimitive = true;
             }
             else if (cls == double.class || cls == Double.class) {
-                type = TYPE_DOUBLE;
+                type = DOUBLE;
 
                 isPrimitive = true;
             }
             else if (cls == char.class || cls == Character.class) {
-                type = TYPE_CHAR;
+                type = CHAR;
 
                 isPrimitive = true;
             }
             else if (cls == boolean.class || cls == Boolean.class) {
-                type = TYPE_BOOLEAN;
+                type = BOOLEAN;
 
                 isPrimitive = true;
             }
             else if (cls == byte[].class)
-                type = TYPE_BYTE_ARR;
+                type = BYTE_ARR;
             else if (cls == short[].class)
-                type = TYPE_SHORT_ARR;
+                type = SHORT_ARR;
             else if (cls == int[].class)
-                type = TYPE_INT_ARR;
+                type = INT_ARR;
             else if (cls == long[].class)
-                type = TYPE_LONG_ARR;
+                type = LONG_ARR;
             else if (cls == float[].class)
-                type = TYPE_FLOAT_ARR;
+                type = FLOAT_ARR;
             else if (cls == double[].class)
-                type = TYPE_DOUBLE_ARR;
+                type = DOUBLE_ARR;
             else if (cls == char[].class)
-                type = TYPE_CHAR_ARR;
+                type = CHAR_ARR;
             else if (cls == boolean[].class)
-                type = TYPE_BOOLEAN_ARR;
+                type = BOOLEAN_ARR;
             else if (cls.isArray())
-                type = TYPE_OBJ_ARR;
+                type = OBJ_ARR;
             else if (cls == String.class)
-                type = TYPE_STR;
+                type = STR;
             else if (cls.isEnum()) {
-                type = TYPE_ENUM;
+                type = ENUM;
 
                 isEnum = true;
                 enumVals = cls.getEnumConstants();
             }
             // Support for enum constants, based on anonymous children classes.
             else if ((parent = cls.getSuperclass()) != null && parent.isEnum()) {
-                type = TYPE_ENUM;
+                type = ENUM;
 
                 isEnum = true;
                 enumVals = parent.getEnumConstants();
             }
             else if (cls == UUID.class)
-                type = TYPE_UUID;
+                type = UUID;
             else if (cls == Properties.class) {
-                type = TYPE_PROPS;
+                type = PROPS;
 
                 try {
                     dfltsFieldOff = UNSAFE.objectFieldOffset(Properties.class.getDeclaredField("defaults"));
@@ -321,9 +225,9 @@ class OptimizedClassDescriptor {
                 }
             }
             else if (cls == ArrayList.class)
-                type = TYPE_ARRAY_LIST;
+                type = ARRAY_LIST;
             else if (cls == HashMap.class) {
-                type = TYPE_HASH_MAP;
+                type = HASH_MAP;
 
                 try {
                     loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
@@ -333,20 +237,19 @@ class OptimizedClassDescriptor {
                 }
             }
             else if (cls == HashSet.class) {
-                type = TYPE_HASH_SET;
+                type = HASH_SET;
 
                 try {
                     loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
-                    mapFieldOff = UNSAFE.objectFieldOffset(HashSet.class.getDeclaredField("map"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
                 }
             }
             else if (cls == LinkedList.class)
-                type = TYPE_LINKED_LIST;
+                type = LINKED_LIST;
             else if (cls == LinkedHashMap.class) {
-                type = TYPE_LINKED_HASH_MAP;
+                type = LINKED_HASH_MAP;
 
                 try {
                     loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
@@ -357,20 +260,19 @@ class OptimizedClassDescriptor {
                 }
             }
             else if (cls == LinkedHashSet.class) {
-                type = TYPE_LINKED_HASH_SET;
+                type = LINKED_HASH_SET;
 
                 try {
                     loadFactorFieldOff = UNSAFE.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
-                    mapFieldOff = UNSAFE.objectFieldOffset(HashSet.class.getDeclaredField("map"));
                 }
                 catch (NoSuchFieldException e) {
                     throw new IOException(e);
                 }
             }
             else if (cls == Date.class)
-                type = TYPE_DATE;
+                type = DATE;
             else if (cls == Class.class) {
-                type = TYPE_CLS;
+                type = CLS;
 
                 isCls = true;
             }
@@ -416,7 +318,7 @@ class OptimizedClassDescriptor {
                 }
 
                 if (Externalizable.class.isAssignableFrom(cls)) {
-                    type = TYPE_EXTERNALIZABLE;
+                    type = EXTERNALIZABLE;
 
                     try {
                         constructor = !Modifier.isStatic(cls.getModifiers()) && cls.getDeclaringClass()
!= null ?
@@ -430,7 +332,7 @@ class OptimizedClassDescriptor {
                     }
                 }
                 else {
-                    type = TYPE_SERIALIZABLE;
+                    type = SERIALIZABLE;
 
                     isSerial = Serializable.class.isAssignableFrom(cls);
 
@@ -647,167 +549,172 @@ class OptimizedClassDescriptor {
      */
     @SuppressWarnings("ForLoopReplaceableByForEach")
     void write(OptimizedObjectOutputStream out, Object obj) throws IOException {
+        out.write(type);
+
         switch (type) {
-            case TYPE_BYTE:
+            case BYTE:
                 out.writeByte((Byte)obj);
 
                 break;
 
-            case TYPE_SHORT:
+            case SHORT:
                 out.writeShort((Short)obj);
 
                 break;
 
-            case TYPE_INT:
+            case INT:
                 out.writeInt((Integer)obj);
 
                 break;
 
-            case TYPE_LONG:
+            case LONG:
                 out.writeLong((Long)obj);
 
                 break;
 
-            case TYPE_FLOAT:
+            case FLOAT:
                 out.writeFloat((Float)obj);
 
                 break;
 
-            case TYPE_DOUBLE:
+            case DOUBLE:
                 out.writeDouble((Double)obj);
 
                 break;
 
-            case TYPE_CHAR:
+            case CHAR:
                 out.writeChar((Character)obj);
 
                 break;
 
-            case TYPE_BOOLEAN:
+            case BOOLEAN:
                 out.writeBoolean((Boolean)obj);
 
                 break;
 
-            case TYPE_BYTE_ARR:
+            case BYTE_ARR:
                 out.writeByteArray((byte[])obj);
 
                 break;
 
-            case TYPE_SHORT_ARR:
+            case SHORT_ARR:
                 out.writeShortArray((short[])obj);
 
                 break;
 
-            case TYPE_INT_ARR:
+            case INT_ARR:
                 out.writeIntArray((int[])obj);
 
                 break;
 
-            case TYPE_LONG_ARR:
+            case LONG_ARR:
                 out.writeLongArray((long[])obj);
 
                 break;
 
-            case TYPE_FLOAT_ARR:
+            case FLOAT_ARR:
                 out.writeFloatArray((float[])obj);
 
                 break;
 
-            case TYPE_DOUBLE_ARR:
+            case DOUBLE_ARR:
                 out.writeDoubleArray((double[])obj);
 
                 break;
 
-            case TYPE_CHAR_ARR:
+            case CHAR_ARR:
                 out.writeCharArray((char[])obj);
 
                 break;
 
-            case TYPE_BOOLEAN_ARR:
+            case BOOLEAN_ARR:
                 out.writeBooleanArray((boolean[])obj);
 
                 break;
 
-            case TYPE_OBJ_ARR:
+            case OBJ_ARR:
                 out.writeUTF(obj.getClass().getComponentType().getName());
                 out.writeArray((Object[])obj);
 
                 break;
 
-            case TYPE_STR:
+            case STR:
                 out.writeString((String)obj);
 
                 break;
 
-            case TYPE_ENUM:
-                out.writeInt(((Enum)obj).ordinal());
-
-                break;
-
-            case TYPE_UUID:
+            case UUID:
                 out.writeUuid((UUID)obj);
 
                 break;
 
-            case TYPE_PROPS:
+            case PROPS:
                 out.writeProperties((Properties)obj, dfltsFieldOff);
 
                 break;
 
-            case TYPE_ARRAY_LIST:
+            case ARRAY_LIST:
                 out.writeArrayList((ArrayList<?>)obj);
 
                 break;
 
-            case TYPE_HASH_MAP:
+            case HASH_MAP:
                 out.writeHashMap((HashMap<?, ?>)obj, loadFactorFieldOff, false);
 
                 break;
 
-            case TYPE_HASH_SET:
-                out.writeHashSet((HashSet<?>)obj, mapFieldOff, loadFactorFieldOff);
+            case HASH_SET:
+                out.writeHashSet((HashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
 
                 break;
 
-            case TYPE_LINKED_LIST:
+            case LINKED_LIST:
                 out.writeLinkedList((LinkedList<?>)obj);
 
                 break;
 
-            case TYPE_LINKED_HASH_MAP:
+            case LINKED_HASH_MAP:
                 out.writeLinkedHashMap((LinkedHashMap<?, ?>)obj, loadFactorFieldOff,
accessOrderFieldOff, false);
 
                 break;
 
-            case TYPE_LINKED_HASH_SET:
-                out.writeLinkedHashSet((LinkedHashSet<?>)obj, mapFieldOff, loadFactorFieldOff);
+            case LINKED_HASH_SET:
+                out.writeLinkedHashSet((LinkedHashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
 
                 break;
 
-            case TYPE_DATE:
+            case DATE:
                 out.writeDate((Date)obj);
 
                 break;
 
-            case TYPE_CLS:
+            case CLS:
                 OptimizedClassDescriptor desc = classDescriptor((Class<?>)obj, ctx,
mapper);
 
                 out.writeInt(desc.typeId());
 
                 break;
 
-            case TYPE_EXTERNALIZABLE:
+            case ENUM:
+                out.writeInt(typeId);
+                out.writeInt(((Enum)obj).ordinal());
+
+                break;
+
+            case EXTERNALIZABLE:
+                out.writeInt(typeId);
                 out.writeShort(checksum);
                 out.writeExternalizable(obj);
 
                 break;
 
-            case TYPE_SERIALIZABLE:
+            case SERIALIZABLE:
                 if (out.requireSerializable() && !isSerial)
                     throw new NotSerializableException("Must implement java.io.Serializable
or " +
                         "set OptimizedMarshaller.setRequireSerializable() to false " +
                         "(note that performance may degrade if object is not Serializable):
" + name);
 
+                out.writeInt(typeId);
                 out.writeShort(checksum);
                 out.writeSerializable(obj, writeObjMtds, fields);
 
@@ -828,105 +735,23 @@ class OptimizedClassDescriptor {
      */
     Object read(OptimizedObjectInputStream in) throws ClassNotFoundException, IOException
{
         switch (type) {
-            case TYPE_BYTE:
-                return in.readByte();
-
-            case TYPE_SHORT:
-                return in.readShort();
-
-            case TYPE_INT:
-                return in.readInt();
-
-            case TYPE_LONG:
-                return in.readLong();
-
-            case TYPE_FLOAT:
-                return in.readFloat();
-
-            case TYPE_DOUBLE:
-                return in.readDouble();
-
-            case TYPE_CHAR:
-                return in.readChar();
-
-            case TYPE_BOOLEAN:
-                return in.readBoolean();
-
-            case TYPE_BYTE_ARR:
-                return in.readByteArray();
-
-            case TYPE_SHORT_ARR:
-                return in.readShortArray();
-
-            case TYPE_INT_ARR:
-                return in.readIntArray();
-
-            case TYPE_LONG_ARR:
-                return in.readLongArray();
-
-            case TYPE_FLOAT_ARR:
-                return in.readFloatArray();
-
-            case TYPE_DOUBLE_ARR:
-                return in.readDoubleArray();
-
-            case TYPE_CHAR_ARR:
-                return in.readCharArray();
-
-            case TYPE_BOOLEAN_ARR:
-                return in.readBooleanArray();
-
-            case TYPE_OBJ_ARR:
-                return in.readArray(Class.forName(in.readUTF(), false, in.classLoader()));
-
-            case TYPE_STR:
-                return in.readString();
-
-            case TYPE_ENUM:
+            case ENUM:
                 return enumVals[in.readInt()];
 
-            case TYPE_UUID:
-                return in.readUuid();
-
-            case TYPE_PROPS:
-                return in.readProperties();
-
-            case TYPE_ARRAY_LIST:
-                return in.readArrayList();
-
-            case TYPE_HASH_MAP:
-                return in.readHashMap(false);
-
-            case TYPE_HASH_SET:
-                return in.readHashSet(mapFieldOff);
-
-            case TYPE_LINKED_LIST:
-                return in.readLinkedList();
-
-            case TYPE_LINKED_HASH_MAP:
-                return in.readLinkedHashMap(false);
-
-            case TYPE_LINKED_HASH_SET:
-                return in.readLinkedHashSet(mapFieldOff);
-
-            case TYPE_DATE:
-                return in.readDate();
-
-            case TYPE_CLS:
-                return classDescriptor(in.readInt(), in.classLoader(), ctx, mapper).describedClass();
-
-            case TYPE_EXTERNALIZABLE:
+            case EXTERNALIZABLE:
                 verifyChecksum(in.readShort());
 
                 return in.readExternalizable(constructor, readResolveMtd);
 
-            case TYPE_SERIALIZABLE:
+            case SERIALIZABLE:
                 verifyChecksum(in.readShort());
 
                 return in.readSerializable(cls, readObjMtds, readResolveMtd, fields);
 
             default:
-                throw new IllegalStateException("Invalid class type: " + type);
+                assert false : "Unexpected type: " + type;
+
+                return null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
index 1c8d2f8..ff1967c 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.marshaller.optimized;
 
+import org.apache.ignite.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.marshaller.*;
@@ -35,20 +36,113 @@ import java.util.concurrent.*;
  * Miscellaneous utility methods to facilitate {@link OptimizedMarshaller}.
  */
 class OptimizedMarshallerUtils {
-    /** Unsafe. */
+    /** */
     private static final Unsafe UNSAFE = GridUnsafe.unsafe();
 
-    /** {@code Null} object reference. */
-    static final byte NULL = (byte)0x70;
+    /** */
+    static final long HASH_SET_MAP_OFF;
 
-    /** Handle reference. */
-    static final byte HANDLE = (byte)0x71;
+    /** */
+    static final byte JDK = -2;
 
-    /** Object reference. */
-    static final byte OBJECT = (byte)0x72;
+    /** */
+    static final byte HANDLE = -1;
 
-    /** Object marshalled with JDK marshaller. */
-    static final byte JDK = (byte)0x73;
+    /** */
+    static final byte NULL = 0;
+
+    /** */
+    static final byte BYTE = 1;
+
+    /** */
+    static final byte SHORT = 2;
+
+    /** */
+    static final byte INT = 3;
+
+    /** */
+    static final byte LONG = 4;
+
+    /** */
+    static final byte FLOAT = 5;
+
+    /** */
+    static final byte DOUBLE = 6;
+
+    /** */
+    static final byte CHAR = 7;
+
+    /** */
+    static final byte BOOLEAN = 8;
+
+    /** */
+    static final byte BYTE_ARR = 9;
+
+    /** */
+    static final byte SHORT_ARR = 10;
+
+    /** */
+    static final byte INT_ARR = 11;
+
+    /** */
+    static final byte LONG_ARR = 12;
+
+    /** */
+    static final byte FLOAT_ARR = 13;
+
+    /** */
+    static final byte DOUBLE_ARR = 14;
+
+    /** */
+    static final byte CHAR_ARR = 15;
+
+    /** */
+    static final byte BOOLEAN_ARR = 16;
+
+    /** */
+    static final byte OBJ_ARR = 17;
+
+    /** */
+    static final byte STR = 18;
+
+    /** */
+    static final byte UUID = 19;
+
+    /** */
+    static final byte PROPS = 20;
+
+    /** */
+    static final byte ARRAY_LIST = 21;
+
+    /** */
+    static final byte HASH_MAP = 22;
+
+    /** */
+    static final byte HASH_SET = 23;
+
+    /** */
+    static final byte LINKED_LIST = 24;
+
+    /** */
+    static final byte LINKED_HASH_MAP = 25;
+
+    /** */
+    static final byte LINKED_HASH_SET = 26;
+
+    /** */
+    static final byte DATE = 27;
+
+    /** */
+    static final byte CLS = 28;
+
+    /** */
+    static final byte ENUM = 100;
+
+    /** */
+    static final byte EXTERNALIZABLE = 101;
+
+    /** */
+    static final byte SERIALIZABLE = 102;
 
     /** UTF-8 character name. */
     static final Charset UTF_8 = Charset.forName("UTF-8");
@@ -59,6 +153,15 @@ class OptimizedMarshallerUtils {
     /** Class descriptors by class. */
     private static final ConcurrentMap<Class, OptimizedClassDescriptor> DESC_BY_CLS
= new ConcurrentHashMap8<>();
 
+    static {
+        try {
+            HASH_SET_MAP_OFF = UNSAFE.objectFieldOffset(HashSet.class.getDeclaredField("map"));
+        }
+        catch (NoSuchFieldException e) {
+            throw new IgniteException("Initialization failure.", e);
+        }
+    }
+
     /**
      */
     private OptimizedMarshallerUtils() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
index aaeffa1..c0def75 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
@@ -92,13 +92,6 @@ class OptimizedObjectInputStream extends ObjectInputStream {
     }
 
     /**
-     * @return Class loader.
-     */
-    ClassLoader classLoader() {
-        return clsLdr;
-    }
-
-    /**
      * @return Input.
      */
     public GridDataInput in() {
@@ -148,15 +141,6 @@ class OptimizedObjectInputStream extends ObjectInputStream {
             case HANDLE:
                 return handles.lookup(readInt());
 
-            case OBJECT:
-                int typeId = readInt();
-
-                OptimizedClassDescriptor desc = OptimizedMarshallerUtils.classDescriptor(typeId,
clsLdr, ctx, mapper);
-
-                curCls = desc.describedClass();
-
-                return desc.read(this);
-
             case JDK:
                 try {
                     return JDK_MARSH.unmarshal(this, clsLdr);
@@ -170,6 +154,101 @@ class OptimizedObjectInputStream extends ObjectInputStream {
                         throw new IOException("Failed to deserialize object with JDK marshaller.",
e);
                 }
 
+            case BYTE:
+                return readByte();
+
+            case SHORT:
+                return readShort();
+
+            case INT:
+                return readInt();
+
+            case LONG:
+                return readLong();
+
+            case FLOAT:
+                return readFloat();
+
+            case DOUBLE:
+                return readDouble();
+
+            case CHAR:
+                return readChar();
+
+            case BOOLEAN:
+                return readBoolean();
+
+            case BYTE_ARR:
+                return readByteArray();
+
+            case SHORT_ARR:
+                return readShortArray();
+
+            case INT_ARR:
+                return readIntArray();
+
+            case LONG_ARR:
+                return readLongArray();
+
+            case FLOAT_ARR:
+                return readFloatArray();
+
+            case DOUBLE_ARR:
+                return readDoubleArray();
+
+            case CHAR_ARR:
+                return readCharArray();
+
+            case BOOLEAN_ARR:
+                return readBooleanArray();
+
+            case OBJ_ARR:
+                return readArray(Class.forName(readUTF(), false, clsLdr));
+
+            case STR:
+                return readString();
+
+            case UUID:
+                return readUuid();
+
+            case PROPS:
+                return readProperties();
+
+            case ARRAY_LIST:
+                return readArrayList();
+
+            case HASH_MAP:
+                return readHashMap(false);
+
+            case HASH_SET:
+                return readHashSet(HASH_SET_MAP_OFF);
+
+            case LINKED_LIST:
+                return readLinkedList();
+
+            case LINKED_HASH_MAP:
+                return readLinkedHashMap(false);
+
+            case LINKED_HASH_SET:
+                return readLinkedHashSet(HASH_SET_MAP_OFF);
+
+            case DATE:
+                return readDate();
+
+            case CLS:
+                return classDescriptor(in.readInt(), clsLdr, ctx, mapper).describedClass();
+
+            case ENUM:
+            case EXTERNALIZABLE:
+            case SERIALIZABLE:
+                int typeId = readInt();
+
+                OptimizedClassDescriptor desc = OptimizedMarshallerUtils.classDescriptor(typeId,
clsLdr, ctx, mapper);
+
+                curCls = desc.describedClass();
+
+                return desc.read(this);
+
             default:
                 SB msg = new SB("Unexpected error occurred during unmarshalling");
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
index 9e392be..1faad50 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -200,12 +200,8 @@ class OptimizedObjectOutputStream extends ObjectOutputStream {
                     writeByte(HANDLE);
                     writeInt(handle);
                 }
-                else {
-                    writeByte(OBJECT);
-                    writeInt(desc.typeId());
-
+                else
                     desc.write(this, obj);
-                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
index 2cb1b2d..7d09070 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
@@ -84,7 +84,11 @@ public class OptimizedMarshallerSelfTest extends GridMarshallerAbstractTest
{
             log,
             new Callable<Object>() {
                 @Override public Object call() throws Exception {
-                    unmarshal(new byte[10]);
+                    byte[] arr = new byte[10];
+
+                    arr[0] = (byte)200;
+
+                    unmarshal(arr);
 
                     return null;
                 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b98e7e6a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
index c376195..5f63730 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
@@ -1082,7 +1082,8 @@ public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest
{
 
         /** {@inheritDoc} */
         @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeLong(0);
+            out.writeInt(0);
+            out.writeInt(200);
             out.writeObject("str");
         }
 


Mime
View raw message