Skip to content

Commit d83bf8c

Browse files
cxzl25dongjoon-hyun
authored andcommitted
[SPARK-49509][CORE] Use Platform.allocateDirectBuffer instead of ByteBuffer.allocateDirect
This PR aims to use `Platform.allocateDirectBuffer` instead of `ByteBuffer.allocateDirect`. #47733 (review) Allocating off-heap memory should use the `allocateDirectBuffer` API provided `by Platform`. No GA No Closes #47987 from cxzl25/SPARK-49509. Authored-by: sychen <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 2ed6c3e) Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 7718777 commit d83bf8c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

core/src/main/java/org/apache/spark/io/NioBufferedFileInputStream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.apache.spark.io;
1515

1616
import org.apache.spark.storage.StorageUtils;
17+
import org.apache.spark.unsafe.Platform;
1718

1819
import java.io.File;
1920
import java.io.IOException;
@@ -39,7 +40,7 @@ public final class NioBufferedFileInputStream extends InputStream {
3940
private final FileChannel fileChannel;
4041

4142
public NioBufferedFileInputStream(File file, int bufferSizeInBytes) throws IOException {
42-
byteBuffer = ByteBuffer.allocateDirect(bufferSizeInBytes);
43+
byteBuffer = Platform.allocateDirectBuffer(bufferSizeInBytes);
4344
fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
4445
byteBuffer.flip();
4546
}

core/src/main/scala/org/apache/spark/storage/DiskStore.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.apache.spark.internal.{config, Logging}
3434
import org.apache.spark.network.buffer.ManagedBuffer
3535
import org.apache.spark.network.util.{AbstractFileRegion, JavaUtils}
3636
import org.apache.spark.security.CryptoStreamUtils
37+
import org.apache.spark.unsafe.Platform
3738
import org.apache.spark.unsafe.array.ByteArrayMethods
3839
import org.apache.spark.util.Utils
3940
import org.apache.spark.util.io.ChunkedByteBuffer
@@ -309,7 +310,7 @@ private class ReadableChannelFileRegion(source: ReadableByteChannel, blockSize:
309310

310311
private var _transferred = 0L
311312

312-
private val buffer = ByteBuffer.allocateDirect(64 * 1024)
313+
private val buffer = Platform.allocateDirectBuffer(64 * 1024)
313314
buffer.flip()
314315

315316
override def count(): Long = blockSize

0 commit comments

Comments
 (0)