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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org