ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/3] ignite git commit: IGNITE-1418: Finalization.
Date Mon, 02 Nov 2015 13:38:10 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1814-debug 2c0ee0e1a -> 0fa9fb945


IGNITE-1418: Finalization.


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

Branch: refs/heads/ignite-1814-debug
Commit: b90ba5aca62fe39026b3510cd4afe4cabedaf2a7
Parents: 2c0ee0e
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Nov 2 16:14:46 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Nov 2 16:14:46 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableFieldImpl.java    |  3 +-
 .../internal/portable/PortableObjectEx.java     |  2 +-
 .../internal/portable/PortableObjectImpl.java   | 46 ++++------
 .../portable/PortableObjectOffheapImpl.java     | 91 ++++++++++++++++++--
 .../internal/portable/PortableReaderExImpl.java | 12 +--
 5 files changed, 111 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b90ba5ac/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
index 2ba2bf9..12be55c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
@@ -55,8 +55,7 @@ public class PortableFieldImpl implements PortableField {
 
         int order = fieldOrder(obj0);
 
-        // TODO: Fix me!
-        return order != 0 ? (T)obj0.fieldByOffset(order * 8 + 4) : null;
+        return order != 0 ? (T)obj0.fieldByOrder(order) : null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/b90ba5ac/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
index 42c973b..d6d7f50 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
@@ -72,7 +72,7 @@ public abstract class PortableObjectEx implements PortableObject {
      * @param fieldOffset Field offset.
      * @return Field value.
      */
-    @Nullable protected abstract <F> F fieldByOffset(int fieldOffset);
+    @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
 
     /**
      * @param ctx Reader context.

http://git-wip-us.apache.org/repos/asf/ignite/blob/b90ba5ac/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
index a1272d0..4895551 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
@@ -256,11 +256,25 @@ public final class PortableObjectImpl extends PortableObjectEx implements
Extern
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F fieldByOffset(int fieldOffset) {
+    @Nullable @Override protected <F> F fieldByOrder(int order) {
         Object val;
 
+        // Calculate field position.
         int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-        int fieldPos = PortablePrimitives.readInt(arr, start + schemaOffset + fieldOffset);
+
+        short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
+        int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+
+        int fieldPos;
+
+        if (fieldOffsetSize == PortableUtils.OFFSET_1)
+            fieldPos = (int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF;
+        else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+            fieldPos = (int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF;
+        else
+            fieldPos = PortablePrimitives.readInt(arr, fieldOffsetPos);
 
         // Read header and try performing fast lookup for well-known types (the most common
types go first).
         byte hdr = PortablePrimitives.readByte(arr, fieldPos);
@@ -306,36 +320,12 @@ public final class PortableObjectImpl extends PortableObjectEx implements
Extern
 
                 break;
 
-//            case DECIMAL:
-//                val = doReadDecimal();
-//
-//                break;
-//
-//            case STRING:
-//                val = doReadString();
-//
-//                break;
-//
-//            case UUID:
-//                val = doReadUuid();
-//
-//                break;
-//
-//            case DATE:
-//                val = doReadDate();
-//
-//                break;
-//
-//            case TIMESTAMP:
-//                val = doReadTimestamp();
-//
-//                break;
+            // TODO: Support other types: DECIMAL, STRING, UUID, DATE, TIMESTAMP.
 
             default: {
-                // TODO: Pass absolute offset, not relative.
                 PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
 
-                val = reader.unmarshalFieldByOffset(fieldOffset);
+                val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b90ba5ac/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
index f023f2e..fade602 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
@@ -37,6 +37,15 @@ import org.apache.ignite.portable.PortableObject;
 import org.jetbrains.annotations.Nullable;
 import sun.misc.Unsafe;
 
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+
 /**
  *  Portable object implementation over offheap memory
  */
@@ -179,13 +188,83 @@ public class PortableObjectOffheapImpl extends PortableObjectEx implements
Exter
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F fieldByOffset(int fieldOffset) {
-        PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
-            new PortableOffheapInputStream(ptr, size, false),
-            start,
-            null);
+    @Nullable @Override protected <F> F fieldByOrder(int order) {
+        Object val;
+
+        // Calculate field position.
+        int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+        short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
+        int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+
+        int fieldPos;
+
+        if (fieldOffsetSize == PortableUtils.OFFSET_1)
+            fieldPos = (int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF;
+        else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+            fieldPos = (int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF;
+        else
+            fieldPos = PortablePrimitives.readInt(ptr, fieldOffsetPos);
+
+        // Read header and try performing fast lookup for well-known types (the most common
types go first).
+        byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
+
+        switch (hdr) {
+            case INT:
+                val = PortablePrimitives.readInt(ptr, fieldPos + 1);
+
+                break;
+
+            case LONG:
+                val = PortablePrimitives.readLong(ptr, fieldPos + 1);
+
+                break;
+
+            case BOOLEAN:
+                val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
+
+                break;
+
+            case SHORT:
+                val = PortablePrimitives.readShort(ptr, fieldPos + 1);
+
+                break;
+
+            case BYTE:
+                val = PortablePrimitives.readByte(ptr, fieldPos + 1);
+
+                break;
+
+            case CHAR:
+                val = PortablePrimitives.readChar(ptr, fieldPos + 1);
+
+                break;
+
+            case FLOAT:
+                val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
+
+                break;
+
+            case DOUBLE:
+                val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
+
+                break;
+
+            // TODO: Support other types: DECIMAL, STRING, UUID, DATE, TIMESTAMP.
+
+            default: {
+                PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
+                    new PortableOffheapInputStream(ptr, size, false),
+                    start,
+                    null);
+
+                val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
+            }
+        }
 
-        return (F)reader.unmarshalFieldByOffset(fieldOffset);
+        return (F)val;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b90ba5ac/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index 91e1ae5..061a9fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -312,16 +312,16 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     }
 
     /**
-     * @param fieldOffset Field offset.
-     * @return Unmarshalled value.
+     * Unmarshal field by absolute position.
+     *
+     * @param pos Absolute position.
+     * @return Field value.
      * @throws PortableException In case of error.
      */
-    @Nullable Object unmarshalFieldByOffset(int fieldOffset) throws PortableException {
-        assert fieldOffset != 0;
-
+    @Nullable Object unmarshalFieldByAbsolutePosition(int pos) throws PortableException {
         parseHeaderIfNeeded();
 
-        in.position(start + in.readIntPositioned(footerStart + fieldOffset));
+        in.position(pos);
 
         return unmarshal();
     }


Mime
View raw message