rymurr commented on a change in pull request #7347:
URL: https://github.com/apache/arrow/pull/7347#discussion_r446920388



##########
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);
+                  logger.debug("Constructor for direct buffer found and made 
accessible");
+                  return constructor;
+                } catch (NoSuchMethodException e) {
+                  logger.debug("Cannot get constructor for direct buffer 
allocation", e);
+                  return e;
+                } catch (SecurityException e) {
+                  logger.debug("Cannot get constructor for direct buffer 
allocation", 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 | IllegalAccessException | 
InvocationTargetException e) {
+            logger.debug("unable to instantiate a direct buffer via 
constructor", e);

Review comment:
       fixed




----------------------------------------------------------------
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


Reply via email to