You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/01/02 04:28:24 UTC
[GitHub] srowen commented on a change in pull request #23424:
[SPARK-24421][CORE][FOLLOWUP] Use normal direct ByteBuffer allocation if
Cleaner can't be set
srowen commented on a change in pull request #23424: [SPARK-24421][CORE][FOLLOWUP] Use normal direct ByteBuffer allocation if Cleaner can't be set
URL: https://github.com/apache/spark/pull/23424#discussion_r244661628
##########
File path: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
##########
@@ -209,21 +209,25 @@ public static long reallocateMemory(long address, long oldSize, long newSize) {
}
/**
- * Uses internal JDK APIs to allocate a DirectByteBuffer while ignoring the JVM's
- * MaxDirectMemorySize limit (the default limit is too low and we do not want to require users
- * to increase it).
+ * Allocate a DirectByteBuffer, potentially bypassing the JVM's MaxDirectMemorySize limit.
*/
public static ByteBuffer allocateDirectBuffer(int size) {
try {
+ if (CLEANER_CREATE_METHOD == null) {
+ // Can't set a Cleaner (see comments on field), so need to allocate via normal Java APIs
+ return ByteBuffer.allocateDirect(size);
+ }
+ // Otherwise, use internal JDK APIs to allocate a DirectByteBuffer while ignoring the JVM's
+ // MaxDirectMemorySize limit (the default limit is too low and we do not want to
+ // require users to increase it).
long memory = allocateMemory(size);
ByteBuffer buffer = (ByteBuffer) DBB_CONSTRUCTOR.newInstance(memory, size);
- if (CLEANER_CREATE_METHOD != null) {
- try {
- DBB_CLEANER_FIELD.set(buffer,
- CLEANER_CREATE_METHOD.invoke(null, buffer, (Runnable) () -> freeMemory(memory)));
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new IllegalStateException(e);
- }
+ try {
+ DBB_CLEANER_FIELD.set(buffer,
+ CLEANER_CREATE_METHOD.invoke(null, buffer, (Runnable) () -> freeMemory(memory)));
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ freeMemory(memory);
Review comment:
Just to be totally safe, free the memory that was allocated but can't be used now in this case.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org