You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by sa...@apache.org on 2017/10/25 16:04:18 UTC
spark git commit: [SPARK-22349] In on-heap mode,
when allocating memory from pool,
we should fill memory with `MEMORY_DEBUG_FILL_CLEAN_VALUE`
Repository: spark
Updated Branches:
refs/heads/master 1051ebec7 -> 3d43a9f93
[SPARK-22349] In on-heap mode, when allocating memory from pool,we should fill memory with `MEMORY_DEBUG_FILL_CLEAN_VALUE`
## What changes were proposed in this pull request?
In on-heap mode, when allocating memory from pool,we should fill memory with `MEMORY_DEBUG_FILL_CLEAN_VALUE`
## How was this patch tested?
added unit tests
Author: liuxian <li...@zte.com.cn>
Closes #19572 from 10110346/MEMORY_DEBUG.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/3d43a9f9
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/3d43a9f9
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/3d43a9f9
Branch: refs/heads/master
Commit: 3d43a9f939764ec265de945921d1ecf2323ca230
Parents: 1051ebe
Author: liuxian <li...@zte.com.cn>
Authored: Wed Oct 25 21:34:00 2017 +0530
Committer: Sameer Agarwal <sa...@b223.local>
Committed: Wed Oct 25 21:34:00 2017 +0530
----------------------------------------------------------------------
.../spark/unsafe/memory/HeapMemoryAllocator.java | 3 +++
.../org/apache/spark/unsafe/PlatformUtilSuite.java | 13 ++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/3d43a9f9/common/unsafe/src/main/java/org/apache/spark/unsafe/memory/HeapMemoryAllocator.java
----------------------------------------------------------------------
diff --git a/common/unsafe/src/main/java/org/apache/spark/unsafe/memory/HeapMemoryAllocator.java b/common/unsafe/src/main/java/org/apache/spark/unsafe/memory/HeapMemoryAllocator.java
index 3557482..cc9cc42 100644
--- a/common/unsafe/src/main/java/org/apache/spark/unsafe/memory/HeapMemoryAllocator.java
+++ b/common/unsafe/src/main/java/org/apache/spark/unsafe/memory/HeapMemoryAllocator.java
@@ -56,6 +56,9 @@ public class HeapMemoryAllocator implements MemoryAllocator {
final MemoryBlock memory = blockReference.get();
if (memory != null) {
assert (memory.size() == size);
+ if (MemoryAllocator.MEMORY_DEBUG_FILL_ENABLED) {
+ memory.fill(MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
+ }
return memory;
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/3d43a9f9/common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java
----------------------------------------------------------------------
diff --git a/common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java b/common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java
index 4ae49d8..4b14133 100644
--- a/common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java
+++ b/common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java
@@ -66,10 +66,21 @@ public class PlatformUtilSuite {
public void memoryDebugFillEnabledInTest() {
Assert.assertTrue(MemoryAllocator.MEMORY_DEBUG_FILL_ENABLED);
MemoryBlock onheap = MemoryAllocator.HEAP.allocate(1);
- MemoryBlock offheap = MemoryAllocator.UNSAFE.allocate(1);
Assert.assertEquals(
Platform.getByte(onheap.getBaseObject(), onheap.getBaseOffset()),
MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
+
+ MemoryBlock onheap1 = MemoryAllocator.HEAP.allocate(1024 * 1024);
+ MemoryAllocator.HEAP.free(onheap1);
+ Assert.assertEquals(
+ Platform.getByte(onheap1.getBaseObject(), onheap1.getBaseOffset()),
+ MemoryAllocator.MEMORY_DEBUG_FILL_FREED_VALUE);
+ MemoryBlock onheap2 = MemoryAllocator.HEAP.allocate(1024 * 1024);
+ Assert.assertEquals(
+ Platform.getByte(onheap2.getBaseObject(), onheap2.getBaseOffset()),
+ MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
+
+ MemoryBlock offheap = MemoryAllocator.UNSAFE.allocate(1);
Assert.assertEquals(
Platform.getByte(offheap.getBaseObject(), offheap.getBaseOffset()),
MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org