srowen commented on a change in pull request #22993: [SPARK-24421][BUILD][CORE] 
Accessing sun.misc.Cleaner in JDK11
URL: https://github.com/apache/spark/pull/22993#discussion_r244661604
 
 

 ##########
 File path: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
 ##########
 @@ -159,18 +213,18 @@ public static long reallocateMemory(long address, long 
oldSize, long newSize) {
    * MaxDirectMemorySize limit (the default limit is too low and we do not 
want to require users
    * to increase it).
    */
-  @SuppressWarnings("unchecked")
   public static ByteBuffer allocateDirectBuffer(int size) {
     try {
-      Class<?> cls = Class.forName("java.nio.DirectByteBuffer");
-      Constructor<?> constructor = cls.getDeclaredConstructor(Long.TYPE, 
Integer.TYPE);
-      constructor.setAccessible(true);
-      Field cleanerField = cls.getDeclaredField("cleaner");
-      cleanerField.setAccessible(true);
       long memory = allocateMemory(size);
-      ByteBuffer buffer = (ByteBuffer) constructor.newInstance(memory, size);
-      Cleaner cleaner = Cleaner.create(buffer, () -> freeMemory(memory));
-      cleanerField.set(buffer, cleaner);
+      ByteBuffer buffer = (ByteBuffer) DBB_CONSTRUCTOR.newInstance(memory, 
size);
+      if (CLEANER_CREATE_METHOD != null) {
 
 Review comment:
   See https://github.com/apache/spark/pull/23424 ; I now think this was an 
error.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to