Skip to content

Commit

Permalink
Remove usage of Unsafe.setMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed Apr 30, 2015
1 parent 96d41c9 commit 50230c0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
Expand Up @@ -429,7 +429,7 @@ public void putNewKey(
private void allocate(int capacity) {
capacity = Math.max((int) Math.min(Integer.MAX_VALUE, nextPowerOf2(capacity)), 64);
longArray = new LongArray(memoryManager.allocate(capacity * 8 * 2));
bitset = new BitSet(memoryManager.allocate(capacity / 8).zero());
bitset = new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]));

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

// Deallocate the old data structures.
memoryManager.free(oldLongArray.memoryBlock());
memoryManager.free(oldBitSet.memoryBlock());
if (enablePerfMetrics) {
timeSpentResizingNs += System.nanoTime() - resizeStartTime;
}
Expand Down
Expand Up @@ -46,14 +46,6 @@ public long size() {
return length;
}

/**
* Clear the contents of this memory block. Returns `this` to facilitate chaining.
*/
public MemoryBlock zero() {
PlatformDependent.UNSAFE.setMemory(obj, offset, length, (byte) 0);
return this;
}

/**
* Creates a memory block pointing to the memory used by the long array.
*/
Expand Down
Expand Up @@ -27,7 +27,7 @@ public class BitSetSuite {

private static BitSet createBitSet(int capacity) {
assert capacity % 64 == 0;
return new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]).zero());
return new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]));
}

@Test
Expand Down

0 comments on commit 50230c0

Please sign in to comment.