SammyVimes commented on a change in pull request #530:
URL: https://github.com/apache/ignite-3/pull/530#discussion_r776609595



##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/BuiltInContainerMarshallers.java
##########
@@ -45,9 +44,9 @@
      * them eligible for a generic unmarshal algorithm: read length, create an 
empty collection, then read N elements
      * and add each of them into the collection.
      */
-    private final Map<Class<?>, IntFunction<? extends Collection<?>>> 
mutableBuiltInCollectionFactories = Map.of(
+    private final Map<Class<?>, Supplier<? extends Collection<?>>> 
mutableBuiltInCollectionFactories = Map.of(

Review comment:
       Instantiation with the pre-defined size seemed like a good thing, why 
did you remove it?

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/FieldAccessorImpl.java
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.network.serialization;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * {@link FieldAccessor} implementation.
+ */
+class FieldAccessorImpl implements FieldAccessor {
+    private final Field field;
+    private final VarHandle varHandle;

Review comment:
       I think we should use Unsafe to set the field's value as non-static 
VarHandles are slower even than the reflection (well, because reflection works 
on top of unsafe). Also, there will not be if branching for final fields (as 
unsafe can set a final field's value)

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/Cycles.java
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.network.serialization.marshal;
+
+import org.apache.ignite.internal.network.serialization.ClassDescriptor;
+
+/**
+ * Logic related to cycles in object graphs.
+ */
+class Cycles {
+    private final BuiltInNonContainerMarshallers 
builtInNonContainerMarshallers;
+
+    Cycles(BuiltInNonContainerMarshallers builtInNonContainerMarshallers) {
+        this.builtInNonContainerMarshallers = builtInNonContainerMarshallers;
+    }
+
+    /**
+     * Returns {@code true} if an instance of the type represented by the 
descriptor may actively form a cycle.
+     *
+     * @param descriptor    descriptor to check
+     * @return {@code true} if an instance of the type represented by the 
descriptor may actively form a cycle
+     */
+    boolean canParticipateInCycles(ClassDescriptor descriptor) {
+        return !builtInNonContainerMarshallers.supports(descriptor.clazz());

Review comment:
       So any non-builtin type is a type that can form a cycle, right?

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/Cycles.java
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.network.serialization.marshal;
+
+import org.apache.ignite.internal.network.serialization.ClassDescriptor;
+
+/**
+ * Logic related to cycles in object graphs.
+ */
+class Cycles {

Review comment:
       Seems like an overkill, a class (and also an object) for one method. 
Should it maybe be static?

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/FieldAccessorImpl.java
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.network.serialization;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * {@link FieldAccessor} implementation.
+ */
+class FieldAccessorImpl implements FieldAccessor {
+    private final Field field;
+    private final VarHandle varHandle;
+
+    FieldAccessorImpl(FieldDescriptor descriptor) {
+        field = findField(descriptor);
+        field.setAccessible(true);
+
+        varHandle = varHandleFrom(field);
+    }
+
+    private static Field findField(FieldDescriptor fieldDescriptor) {
+        try {
+            return 
fieldDescriptor.declaringClass().getDeclaredField(fieldDescriptor.name());
+        } catch (NoSuchFieldException e) {
+            throw new ReflectionException("Cannot find field", e);
+        }
+    }
+
+    private static VarHandle varHandleFrom(Field field) {
+        try {
+            MethodHandles.Lookup lookup = 
MethodHandles.privateLookupIn(field.getDeclaringClass(), 
MethodHandles.lookup());
+            return lookup.unreflectVarHandle(field);
+        } catch (ReflectiveOperationException e) {
+            throw new ReflectionException("Cannot get a field VarHandle", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Object get(Object target) {
+        return varHandle.get(target);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void set(Object target, Object fieldValue) {
+        if (isFieldFinal()) {

Review comment:
       Can be cached

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/serialization/FieldDescriptor.java
##########
@@ -27,38 +27,50 @@
     /**
      * Name of the field.
      */
-    @NotNull
     private final String name;
 
     /**
      * Type of the field.
      */
-    @NotNull
     private final Class<?> clazz;
 
     /**
      * Field type's descriptor id.
      */
     private final int typeDescriptorId;
 
+    /**
+     * The class in which the field is declared.
+     */
+    private final Class<?> declaringClass;

Review comment:
       Why do we need it?

##########
File path: 
modules/network/src/main/java/org/apache/ignite/internal/network/message/FieldDescriptorMessage.java
##########
@@ -39,4 +39,9 @@
      * Field's class name.
      */
     String className();
+
+    /**
+     * The name of The class in which this field is declared.
+     */
+    String declaringClassName();

Review comment:
       Do you think we really need this? Seems like this message is always 
inside of the class descriptor message, so we kinda have this information 
already




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to