Skip to content

Commit 50230c0

Browse files
committed
Remove usage of Unsafe.setMemory
1 parent 96d41c9 commit 50230c0

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

unsafe/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public void putNewKey(
429429
private void allocate(int capacity) {
430430
capacity = Math.max((int) Math.min(Integer.MAX_VALUE, nextPowerOf2(capacity)), 64);
431431
longArray = new LongArray(memoryManager.allocate(capacity * 8 * 2));
432-
bitset = new BitSet(memoryManager.allocate(capacity / 8).zero());
432+
bitset = new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]));
433433

434434
this.growthThreshold = (int) (capacity * loadFactor);
435435
this.mask = capacity - 1;
@@ -447,7 +447,7 @@ public void free() {
447447
longArray = null;
448448
}
449449
if (bitset != null) {
450-
memoryManager.free(bitset.memoryBlock());
450+
// The bitset's heap memory isn't managed by a memory manager, so no need to free it here.
451451
bitset = null;
452452
}
453453
Iterator<MemoryBlock> dataPagesIterator = dataPages.iterator();
@@ -535,7 +535,6 @@ private void growAndRehash() {
535535

536536
// Deallocate the old data structures.
537537
memoryManager.free(oldLongArray.memoryBlock());
538-
memoryManager.free(oldBitSet.memoryBlock());
539538
if (enablePerfMetrics) {
540539
timeSpentResizingNs += System.nanoTime() - resizeStartTime;
541540
}

unsafe/src/main/java/org/apache/spark/unsafe/memory/MemoryBlock.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public long size() {
4646
return length;
4747
}
4848

49-
/**
50-
* Clear the contents of this memory block. Returns `this` to facilitate chaining.
51-
*/
52-
public MemoryBlock zero() {
53-
PlatformDependent.UNSAFE.setMemory(obj, offset, length, (byte) 0);
54-
return this;
55-
}
56-
5749
/**
5850
* Creates a memory block pointing to the memory used by the long array.
5951
*/

unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BitSetSuite {
2727

2828
private static BitSet createBitSet(int capacity) {
2929
assert capacity % 64 == 0;
30-
return new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]).zero());
30+
return new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]));
3131
}
3232

3333
@Test

0 commit comments

Comments
 (0)