You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ibessonov (via GitHub)" <gi...@apache.org> on 2025/05/02 12:35:48 UTC

[PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

ibessonov opened a new pull request, #5741:
URL: https://github.com/apache/ignite-3/pull/5741

   https://issues.apache.org/jira/browse/IGNITE-25284
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2073476330


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   have a static field, like `private static final Function<Long, Int, ByteBuffer>` and assign a correct method reference inside the static block



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2073421549


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;

Review Comment:
   Please add some javadocs about what these method handles correspond to



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {
+        if (DIRECT_BUF_MTD != null && JAVA_NIO_ACCESS_OBJ != null) {
+            return wrapPointerJavaNio(ptr, len);
+        } else if (DIRECT_BUF_CTOR_INT != null) {
+            return wrapPointerDirectBufferConstructor(ptr, len);
+        } else if (DIRECT_BUF_CTOR_LONG != null) {
+            return wrapPointerDirectBufferConstructor(ptr, (long) len);
+        } else {
+            throw new RuntimeException(
+                    "All alternatives for a new DirectByteBuffer() creation failed: " + FeatureChecker.JAVA_STARTUP_PARAMS_WARN);
+        }
+    }
+
+    /**
+     * Returns {@code JavaNioAccess} instance from private API for corresponding Java version.
+     *
+     * @return {@code JavaNioAccess} instance for corresponding Java version.
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static Object javaNioAccessObject() {
+        Class<?> cls;
+        try {
+            cls = Class.forName("jdk.internal.access.SharedSecrets");
+        } catch (ClassNotFoundException e) {
+            try {
+                cls = Class.forName("jdk.internal.misc.SharedSecrets");
+            } catch (ClassNotFoundException e1) {
+                throw new RuntimeException("Neither jdk.internal.access.SharedSecrets nor jdk.internal.misc.SharedSecrets are unavailable."
+                        + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+            }
+        }
+        try {
+            Method mth = cls.getMethod("getJavaNioAccess");
+
+            return mth.invoke(null);
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException(cls.getName() + " class is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+    /**
+     * Returns reference to {@code JavaNioAccess.newDirectByteBuffer} method from private API for corresponding Java version.
+     *
+     * @param nioAccessObj Java NIO access object.
+     * @return Reference to {@code JavaNioAccess.newDirectByteBuffer} method
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static MethodHandle newDirectBufferMethodHandle(Object nioAccessObj) {
+        try {
+            Class<?> cls = nioAccessObj.getClass();
+
+            Method mtd = cls.getMethod("newDirectByteBuffer", long.class, int.class, Object.class);
+
+            AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
+                mtd.setAccessible(true);
+
+                return null;
+            });
+
+            MethodType mtdType = MethodType.methodType(
+                    ByteBuffer.class,
+                    Object.class,
+                    long.class,
+                    int.class,
+                    Object.class
+            );
+
+            return MethodHandles.lookup()
+                    .unreflect(mtd)
+                    .asType(mtdType);
+        } catch (ReflectiveOperationException | PrivilegedActionException e) {
+            throw new RuntimeException(nioAccessObj.getClass().getName() + "#newDirectByteBuffer() method is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+
+    /**
+     * Creates and tests contructor for Direct ByteBuffer. Test is wrapping one-byte unsafe memory into a buffer.
+     *
+     * @param lengthType Type of the length parameter.
+     * @return constructor for creating direct ByteBuffers.
+     */
+    private static MethodHandle createAndTestNewDirectBufferCtor(Class<?> lengthType) {
+        assert lengthType == int.class || lengthType == long.class : "Unsupported type of length: " + lengthType;
+
+        MethodHandle ctorCandidate = createNewDirectBufferCtor(lengthType);
+
+        int l = 1;
+        long ptr = UNSAFE.allocateMemory(l);
+
+        try {
+            ByteBuffer buf = lengthType == int.class
+                    ? (ByteBuffer) ctorCandidate.invokeExact(ptr, l)
+                    : (ByteBuffer) ctorCandidate.invokeExact(ptr, (long) l);
+
+            if (!buf.isDirect()) {
+                throw new IllegalArgumentException("Buffer expected to be direct, internal error during #wrapPointerDirectBufCtor()");
+            }
+        } catch (Throwable t) {
+            throw new RuntimeException(t);
+        } finally {
+            UNSAFE.freeMemory(ptr);
+        }
+
+        return ctorCandidate;
+    }
+
+
+    /**
+     * Simply create some instance of direct Byte Buffer and try to get it's class declared constructor.
+     *
+     * @param lengthType Type of the length parameter.
+     * @return constructor for creating direct ByteBuffers.
+     */
+    private static MethodHandle createNewDirectBufferCtor(Class<?> lengthType) {
+        try {
+            ByteBuffer buf = ByteBuffer.allocateDirect(1).order(NATIVE_BYTE_ORDER);
+
+            Constructor<?> ctor = buf.getClass().getDeclaredConstructor(long.class, lengthType);
+
+            AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
+                ctor.setAccessible(true);
+
+                return null;
+            });
+
+            MethodType mtdType = MethodType.methodType(
+                    ByteBuffer.class,
+                    long.class,
+                    lengthType
+            );
+
+            return MethodHandles.lookup()
+                    .unreflectConstructor(ctor)
+                    .asType(mtdType);
+        } catch (ReflectiveOperationException | PrivilegedActionException e) {
+            throw new RuntimeException("Unable to set up byte buffer creation using reflection :" + e.getMessage(), e);
+        }
+    }
+
+

Review Comment:
   ```suggestion
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD

Review Comment:
   Why do we need this?



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   Can we implement this as a reference to a method that will be computed in the static block? Or will it bring the same performance penalties?



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {
+        if (DIRECT_BUF_MTD != null && JAVA_NIO_ACCESS_OBJ != null) {
+            return wrapPointerJavaNio(ptr, len);
+        } else if (DIRECT_BUF_CTOR_INT != null) {
+            return wrapPointerDirectBufferConstructor(ptr, len);
+        } else if (DIRECT_BUF_CTOR_LONG != null) {
+            return wrapPointerDirectBufferConstructor(ptr, (long) len);
+        } else {
+            throw new RuntimeException(
+                    "All alternatives for a new DirectByteBuffer() creation failed: " + FeatureChecker.JAVA_STARTUP_PARAMS_WARN);
+        }
+    }
+
+    /**
+     * Returns {@code JavaNioAccess} instance from private API for corresponding Java version.
+     *
+     * @return {@code JavaNioAccess} instance for corresponding Java version.
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static Object javaNioAccessObject() {
+        Class<?> cls;
+        try {
+            cls = Class.forName("jdk.internal.access.SharedSecrets");
+        } catch (ClassNotFoundException e) {
+            try {
+                cls = Class.forName("jdk.internal.misc.SharedSecrets");
+            } catch (ClassNotFoundException e1) {
+                throw new RuntimeException("Neither jdk.internal.access.SharedSecrets nor jdk.internal.misc.SharedSecrets are unavailable."
+                        + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+            }
+        }
+        try {
+            Method mth = cls.getMethod("getJavaNioAccess");
+
+            return mth.invoke(null);
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException(cls.getName() + " class is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+    /**
+     * Returns reference to {@code JavaNioAccess.newDirectByteBuffer} method from private API for corresponding Java version.
+     *
+     * @param nioAccessObj Java NIO access object.
+     * @return Reference to {@code JavaNioAccess.newDirectByteBuffer} method
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static MethodHandle newDirectBufferMethodHandle(Object nioAccessObj) {
+        try {
+            Class<?> cls = nioAccessObj.getClass();
+
+            Method mtd = cls.getMethod("newDirectByteBuffer", long.class, int.class, Object.class);
+
+            AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
+                mtd.setAccessible(true);
+
+                return null;
+            });
+
+            MethodType mtdType = MethodType.methodType(
+                    ByteBuffer.class,
+                    Object.class,
+                    long.class,
+                    int.class,
+                    Object.class
+            );
+
+            return MethodHandles.lookup()
+                    .unreflect(mtd)
+                    .asType(mtdType);
+        } catch (ReflectiveOperationException | PrivilegedActionException e) {
+            throw new RuntimeException(nioAccessObj.getClass().getName() + "#newDirectByteBuffer() method is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+
+    /**
+     * Creates and tests contructor for Direct ByteBuffer. Test is wrapping one-byte unsafe memory into a buffer.
+     *
+     * @param lengthType Type of the length parameter.
+     * @return constructor for creating direct ByteBuffers.
+     */
+    private static MethodHandle createAndTestNewDirectBufferCtor(Class<?> lengthType) {
+        assert lengthType == int.class || lengthType == long.class : "Unsupported type of length: " + lengthType;
+
+        MethodHandle ctorCandidate = createNewDirectBufferCtor(lengthType);
+
+        int l = 1;
+        long ptr = UNSAFE.allocateMemory(l);
+
+        try {
+            ByteBuffer buf = lengthType == int.class
+                    ? (ByteBuffer) ctorCandidate.invokeExact(ptr, l)
+                    : (ByteBuffer) ctorCandidate.invokeExact(ptr, (long) l);
+
+            if (!buf.isDirect()) {
+                throw new IllegalArgumentException("Buffer expected to be direct, internal error during #wrapPointerDirectBufCtor()");
+            }
+        } catch (Throwable t) {
+            throw new RuntimeException(t);
+        } finally {
+            UNSAFE.freeMemory(ptr);
+        }
+
+        return ctorCandidate;
+    }
+
+

Review Comment:
   ```suggestion
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {
+        if (DIRECT_BUF_MTD != null && JAVA_NIO_ACCESS_OBJ != null) {
+            return wrapPointerJavaNio(ptr, len);
+        } else if (DIRECT_BUF_CTOR_INT != null) {
+            return wrapPointerDirectBufferConstructor(ptr, len);
+        } else if (DIRECT_BUF_CTOR_LONG != null) {
+            return wrapPointerDirectBufferConstructor(ptr, (long) len);
+        } else {
+            throw new RuntimeException(
+                    "All alternatives for a new DirectByteBuffer() creation failed: " + FeatureChecker.JAVA_STARTUP_PARAMS_WARN);
+        }
+    }
+
+    /**
+     * Returns {@code JavaNioAccess} instance from private API for corresponding Java version.
+     *
+     * @return {@code JavaNioAccess} instance for corresponding Java version.
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static Object javaNioAccessObject() {
+        Class<?> cls;
+        try {
+            cls = Class.forName("jdk.internal.access.SharedSecrets");
+        } catch (ClassNotFoundException e) {
+            try {
+                cls = Class.forName("jdk.internal.misc.SharedSecrets");
+            } catch (ClassNotFoundException e1) {
+                throw new RuntimeException("Neither jdk.internal.access.SharedSecrets nor jdk.internal.misc.SharedSecrets are unavailable."
+                        + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+            }
+        }
+        try {
+            Method mth = cls.getMethod("getJavaNioAccess");
+
+            return mth.invoke(null);
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException(cls.getName() + " class is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+    /**
+     * Returns reference to {@code JavaNioAccess.newDirectByteBuffer} method from private API for corresponding Java version.
+     *
+     * @param nioAccessObj Java NIO access object.
+     * @return Reference to {@code JavaNioAccess.newDirectByteBuffer} method
+     * @throws RuntimeException If getting access to the private API is failed.
+     */
+    private static MethodHandle newDirectBufferMethodHandle(Object nioAccessObj) {
+        try {
+            Class<?> cls = nioAccessObj.getClass();
+
+            Method mtd = cls.getMethod("newDirectByteBuffer", long.class, int.class, Object.class);
+
+            AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
+                mtd.setAccessible(true);
+
+                return null;
+            });
+
+            MethodType mtdType = MethodType.methodType(
+                    ByteBuffer.class,
+                    Object.class,
+                    long.class,
+                    int.class,
+                    Object.class
+            );
+
+            return MethodHandles.lookup()
+                    .unreflect(mtd)
+                    .asType(mtdType);
+        } catch (ReflectiveOperationException | PrivilegedActionException e) {
+            throw new RuntimeException(nioAccessObj.getClass().getName() + "#newDirectByteBuffer() method is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+
+    /**
+     * Creates and tests contructor for Direct ByteBuffer. Test is wrapping one-byte unsafe memory into a buffer.
+     *
+     * @param lengthType Type of the length parameter.
+     * @return constructor for creating direct ByteBuffers.
+     */
+    private static MethodHandle createAndTestNewDirectBufferCtor(Class<?> lengthType) {
+        assert lengthType == int.class || lengthType == long.class : "Unsupported type of length: " + lengthType;
+
+        MethodHandle ctorCandidate = createNewDirectBufferCtor(lengthType);
+
+        int l = 1;
+        long ptr = UNSAFE.allocateMemory(l);
+
+        try {
+            ByteBuffer buf = lengthType == int.class
+                    ? (ByteBuffer) ctorCandidate.invokeExact(ptr, l)
+                    : (ByteBuffer) ctorCandidate.invokeExact(ptr, (long) l);
+
+            if (!buf.isDirect()) {
+                throw new IllegalArgumentException("Buffer expected to be direct, internal error during #wrapPointerDirectBufCtor()");
+            }
+        } catch (Throwable t) {
+            throw new RuntimeException(t);
+        } finally {
+            UNSAFE.freeMemory(ptr);
+        }
+
+        return ctorCandidate;
+    }
+
+
+    /**
+     * Simply create some instance of direct Byte Buffer and try to get it's class declared constructor.
+     *
+     * @param lengthType Type of the length parameter.
+     * @return constructor for creating direct ByteBuffers.
+     */
+    private static MethodHandle createNewDirectBufferCtor(Class<?> lengthType) {
+        try {
+            ByteBuffer buf = ByteBuffer.allocateDirect(1).order(NATIVE_BYTE_ORDER);
+
+            Constructor<?> ctor = buf.getClass().getDeclaredConstructor(long.class, lengthType);
+
+            AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
+                ctor.setAccessible(true);
+
+                return null;
+            });
+
+            MethodType mtdType = MethodType.methodType(
+                    ByteBuffer.class,
+                    long.class,
+                    lengthType
+            );
+
+            return MethodHandles.lookup()
+                    .unreflectConstructor(ctor)
+                    .asType(mtdType);
+        } catch (ReflectiveOperationException | PrivilegedActionException e) {
+            throw new RuntimeException("Unable to set up byte buffer creation using reflection :" + e.getMessage(), e);
+        }
+    }
+
+
+    private static ByteBuffer wrapPointerJavaNio(long ptr, int len) {
+        try {
+            ByteBuffer buf = (ByteBuffer) DIRECT_BUF_MTD.invokeExact(JAVA_NIO_ACCESS_OBJ, ptr, len, NULL_OBJ);
+
+            assert buf.isDirect() : "ptr=" + ptr + ", len=" + len;
+
+            buf.order(NATIVE_BYTE_ORDER);
+
+            return buf;
+        } catch (Throwable e) {
+            throw new RuntimeException("JavaNioAccess#newDirectByteBuffer() method is unavailable."
+                    + FeatureChecker.JAVA_STARTUP_PARAMS_WARN, e);
+        }
+    }
+
+    /**
+     * Wraps a pointer to unmanaged memory into a direct byte buffer. Uses the constructor of the direct byte buffer.
+     *
+     * @param ptr         Pointer to wrap.

Review Comment:
   Please remove the alignments



##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.

Review Comment:
   This comment is weird, why do we need it?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074797873


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   > Don't do it without having benchmarks and guaranteeing that performance won't suffer.
   
   Having this sentence without having the initial benchmarks yourself is kind of hypocritical



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074776988


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD

Review Comment:
   I think we don't



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074824410


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   I am in the process of committing that benchmark, don't worry



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2073460430


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   I don't think I understood your proposal



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074824946


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   Results are not as good as I saw in naive "for loop" tests, unfortunately



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074825431


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   Results are in Jira



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074830028


##########
modules/core/src/test/java/org/apache/ignite/internal/util/WrapPointerBenchmark.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.util;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * Benchmark for {@link GridUnsafe#wrapPointer(long, int)}.
+ */
+@State(Scope.Benchmark)
+@Fork(1)
+@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+public class WrapPointerBenchmark {
+    private static final int SIZE = 1024;
+
+    private long addr;
+
+    @Setup
+    public void setup() {
+        addr = GridUnsafe.allocateMemory(SIZE);
+    }
+
+    @Benchmark
+    public ByteBuffer benchmarkWrapPointer() {
+        return GridUnsafe.wrapPointer(addr, SIZE);
+    }
+
+    /**
+     * Benchmark's entry point.
+     */
+    public static void main(String[] args) throws RunnerException {
+        Options opt = new OptionsBuilder()
+                .include(".*" + WrapPointerBenchmark.class.getSimpleName() + ".*")
+                .build();
+
+        new Runner(opt).run();
+    }
+}

Review Comment:
   I think it did fail



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074779408


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;
+    private static final MethodHandle DIRECT_BUF_CTOR_INT;
+    private static final MethodHandle DIRECT_BUF_CTOR_LONG;
+
+    private static final Object JAVA_NIO_ACCESS_OBJ;
+
+    static {
+        Object nioAccessObj = null;
+
+        MethodHandle directBufMtd = null;
+        MethodHandle directBufCtorWithIntLen = null;
+        MethodHandle directBufCtorWithLongLen = null;
+
+        try {
+            directBufCtorWithIntLen = createAndTestNewDirectBufferCtor(int.class);
+        } catch (Exception e) {
+            try {
+                directBufCtorWithLongLen = createAndTestNewDirectBufferCtor(long.class);
+            } catch (Exception e2) {
+                try {
+                    nioAccessObj = javaNioAccessObject();
+                    directBufMtd = newDirectBufferMethodHandle(nioAccessObj);
+                } catch (Exception exFallback) {
+                    //noinspection CallToPrintStackTrace
+                    exFallback.printStackTrace(); // NOPMD
+
+                    e.addSuppressed(exFallback);
+
+                    throw e; // Fallback to shared secrets failed.
+                }
+
+                if (nioAccessObj == null || directBufMtd == null) {
+                    throw e;
+                }
+            }
+        }
+
+        DIRECT_BUF_MTD = directBufMtd;
+        DIRECT_BUF_CTOR_INT = directBufCtorWithIntLen;
+        DIRECT_BUF_CTOR_LONG = directBufCtorWithLongLen;
+
+        JAVA_NIO_ACCESS_OBJ = nioAccessObj;
+    }
+
     /**
      * Wraps a pointer to unmanaged memory into a direct byte buffer.
      *
      * @param ptr Pointer to wrap.
      * @param len Memory location length.
      * @return Byte buffer wrapping the given memory.
      */
-    ByteBuffer wrapPointer(long ptr, int len);
+    static ByteBuffer wrapPointer(long ptr, int len) {

Review Comment:
   I see now. `static` with the combination of `if` makes the invoke of target MH completely static, which is the most optimal way of doing it. I'll add a comment



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov merged PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074791583


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;

Review Comment:
   I just noticed that `JavaNioAccess` can be used directly in the code, because `jdk.internal.misc` is exported to compiler. That's funny, but I'll leave the old code just in case.
   
   Or should I refactor it?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074793210


##########
modules/core/src/main/java/org/apache/ignite/internal/util/PointerWrapping.java:
##########
@@ -17,19 +17,268 @@
 
 package org.apache.ignite.internal.util;
 
+import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
+import static org.apache.ignite.internal.util.GridUnsafe.UNSAFE;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * Wraps a pointer to unmanaged memory into a direct byte buffer.
  */
-@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
-interface PointerWrapping {
+abstract class PointerWrapping {
+    /** Null object. */
+    private static final Object NULL_OBJ = null;
+
+    private static final MethodHandle DIRECT_BUF_MTD;

Review Comment:
   Up to you



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25284 Remove polymorphism from "wrapPointer" [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5741:
URL: https://github.com/apache/ignite-3/pull/5741#discussion_r2074829015


##########
modules/core/src/test/java/org/apache/ignite/internal/util/WrapPointerBenchmark.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.util;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * Benchmark for {@link GridUnsafe#wrapPointer(long, int)}.
+ */
+@State(Scope.Benchmark)
+@Fork(1)
+@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+public class WrapPointerBenchmark {
+    private static final int SIZE = 1024;
+
+    private long addr;
+
+    @Setup
+    public void setup() {
+        addr = GridUnsafe.allocateMemory(SIZE);
+    }
+
+    @Benchmark
+    public ByteBuffer benchmarkWrapPointer() {
+        return GridUnsafe.wrapPointer(addr, SIZE);
+    }
+
+    /**
+     * Benchmark's entry point.
+     */
+    public static void main(String[] args) throws RunnerException {
+        Options opt = new OptionsBuilder()
+                .include(".*" + WrapPointerBenchmark.class.getSimpleName() + ".*")
+                .build();
+
+        new Runner(opt).run();
+    }
+}

Review Comment:
   Please check your IDEA settings. Also, why didn't checkstyle fail?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org