rymurr commented on a change in pull request #7347: URL: https://github.com/apache/arrow/pull/7347#discussion_r440896771
########## File path: java/memory/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java ########## @@ -78,6 +77,55 @@ public Object run() { Field addressField = java.nio.Buffer.class.getDeclaredField("address"); addressField.setAccessible(true); BYTE_BUFFER_ADDRESS_OFFSET = UNSAFE.objectFieldOffset(addressField); + + Constructor<?> directBufferConstructor; + long address = -1; + final ByteBuffer direct = ByteBuffer.allocateDirect(1); + try { + + final Object maybeDirectBufferConstructor = + AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override + public Object run() { + try { + final Constructor<?> constructor = + direct.getClass().getDeclaredConstructor(long.class, int.class); + constructor.setAccessible(true); + return constructor; + } catch (NoSuchMethodException e) { + return e; + } catch (SecurityException e) { + return e; + } + } + }); + + if (maybeDirectBufferConstructor instanceof Constructor<?>) { + address = UNSAFE.allocateMemory(1); + // try to use the constructor now + try { + ((Constructor<?>) maybeDirectBufferConstructor).newInstance(address, 1); + directBufferConstructor = (Constructor<?>) maybeDirectBufferConstructor; + logger.debug("direct buffer constructor: available"); + } catch (InstantiationException e) { + directBufferConstructor = null; Review comment: sure, any suggestions where? Note: This is taken from PlatformDependent0 in netty (logs and all). ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org