Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
480a74a
Initial import of code from Databricks unsafe utils repo.
JoshRosen Apr 17, 2015
ab68e08
Begin merging the UTF8String implementations.
JoshRosen Apr 18, 2015
f03e9c1
Play around with Unsafe implementations of more string methods.
JoshRosen Apr 18, 2015
5d55cef
Add skeleton for Row implementation.
JoshRosen Apr 18, 2015
8a8f9df
Add skeleton for GeneratedAggregate integration.
JoshRosen Apr 18, 2015
1ff814d
Add reminder to free memory on iterator completion
JoshRosen Apr 18, 2015
53ba9b7
Start prototyping Java Row -> UnsafeRow converters
JoshRosen Apr 19, 2015
fc4c3a8
Sketch how the converters will be used in UnsafeGeneratedAggregate
JoshRosen Apr 19, 2015
1a483c5
First version that passes some aggregation tests:
JoshRosen Apr 19, 2015
079f1bf
Some clarification of the BytesToBytesMap.lookup() / set() contract.
JoshRosen Apr 19, 2015
f764d13
Simplify address + length calculation in Location.
JoshRosen Apr 19, 2015
c754ae1
Now that the store*() contract has been stregthened, we can remove an…
JoshRosen Apr 19, 2015
ae39694
Add finalizer as "cleanup method of last resort"
JoshRosen Apr 19, 2015
c7f0b56
Reuse UnsafeRow pointer in UnsafeRowConverter
JoshRosen Apr 20, 2015
62ab054
Optimize for fact that get() is only called on String columns.
JoshRosen Apr 20, 2015
c55bf66
Free buffer once iterator has been fully consumed.
JoshRosen Apr 20, 2015
738fa33
Add feature flag to guard UnsafeGeneratedAggregate
JoshRosen Apr 20, 2015
c1b3813
Fix bug in UnsafeMemoryAllocator.free():
JoshRosen Apr 20, 2015
7df6008
Optimizations related to zeroing out memory:
JoshRosen Apr 21, 2015
58ac393
Use UNSAFE allocator in GeneratedAggregate (TODO: make this configura…
JoshRosen Apr 21, 2015
d2bb986
Update to implement new Row methods added upstream
JoshRosen Apr 22, 2015
b3eaccd
Extract aggregation map into its own class.
JoshRosen Apr 22, 2015
bade966
Comment update (bumping to refresh GitHub cache...)
JoshRosen Apr 22, 2015
d85eeff
Add basic sanity test for UnsafeFixedWidthAggregationMap
JoshRosen Apr 22, 2015
1f4b716
Merge Unsafe code into the regular GeneratedAggregate, guarded by a
JoshRosen Apr 22, 2015
92d5a06
Address a number of minor code review comments.
JoshRosen Apr 23, 2015
628f936
Use ints intead of longs for indexing.
JoshRosen Apr 23, 2015
23a440a
Bump up default hash map size
JoshRosen Apr 23, 2015
765243d
Enable optional performance metrics for hash map.
JoshRosen Apr 23, 2015
b26f1d3
Fix bug in murmur hash implementation.
JoshRosen Apr 23, 2015
49aed30
More long -> int conversion.
JoshRosen Apr 23, 2015
29a7575
Remove debug logging
JoshRosen Apr 24, 2015
ef6b3d3
Fix a bunch of FindBugs and IntelliJ inspections
JoshRosen Apr 24, 2015
06e929d
More warning cleanup
JoshRosen Apr 24, 2015
854201a
Import and comment cleanup
JoshRosen Apr 24, 2015
f3dcbfe
More mod replacement
JoshRosen Apr 24, 2015
afe8dca
Some Javadoc cleanup
JoshRosen Apr 24, 2015
a95291e
Cleanups to string handling code
JoshRosen Apr 24, 2015
31eaabc
Lots of TODO and doc cleanup.
JoshRosen Apr 24, 2015
6ffdaa1
Null handling improvements in UnsafeRow.
JoshRosen Apr 24, 2015
9c19fc0
Add configuration options for heap vs. offheap
JoshRosen Apr 24, 2015
cde4132
Add missing pom.xml
JoshRosen Apr 26, 2015
0925847
Disable MiMa checks for new unsafe module
JoshRosen Apr 27, 2015
a8e4a3f
Introduce MemoryManager interface; add to SparkEnv.
JoshRosen Apr 28, 2015
b45f070
Don't redundantly store the offset from key to value, since we can co…
JoshRosen Apr 28, 2015
162caf7
Fix test compilation
JoshRosen Apr 28, 2015
3ca84b2
Only zero the used portion of groupingKeyConversionScratchSpace
JoshRosen Apr 28, 2015
529e571
Measure timeSpentResizing in nanoseconds instead of milliseconds.
JoshRosen Apr 28, 2015
ce3c565
More comments, formatting, and code cleanup.
JoshRosen Apr 28, 2015
78a5b84
Add logging to MemoryManager
JoshRosen Apr 28, 2015
a19e066
Rename unsafe Java test suites to match Scala test naming convention.
JoshRosen Apr 28, 2015
de5e001
Fix debug vs. trace in logging message.
JoshRosen Apr 28, 2015
6e4b192
Remove an unused method from ByteArrayMethods.
JoshRosen Apr 28, 2015
70a39e4
Split MemoryManager into ExecutorMemoryManager and TaskMemoryManager:
JoshRosen Apr 28, 2015
50e9671
Throw memory leak warning even in case of error; add warning about co…
JoshRosen Apr 29, 2015
017b2dc
Remove BytesToBytesMap.finalize()
JoshRosen Apr 29, 2015
1bc36cc
Refactor UnsafeRowConverter to avoid unnecessary boxing.
JoshRosen Apr 29, 2015
81f34f8
Follow 'place children last' convention for GeneratedAggregate
JoshRosen Apr 29, 2015
eeee512
Add converters for Null, Boolean, Byte, and Short columns.
JoshRosen Apr 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't redundantly store the offset from key to value, since we can co…
…mpute this from the key size.
  • Loading branch information
JoshRosen committed Apr 28, 2015
commit b45f0708733e5777fff01c69206d0f1b8efcb7e9
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public final class BytesToBytesMap {

private static final HashMapGrowthStrategy growthStrategy = HashMapGrowthStrategy.DOUBLING;

/** Bit mask for the lower 32 bits of a long */
private static final long MASK_LONG_LOWER_32_BITS = 0xFFFFFFFFL;

private final MemoryManager memoryManager;

/**
Expand Down Expand Up @@ -84,10 +81,18 @@ public final class BytesToBytesMap {
* A single array to store the key and value.
*
* Position {@code 2 * i} in the array is used to track a pointer to the key at index {@code i},
* while position {@code 2 * i + 1} in the array holds the upper bits of the key's hashcode plus
* the relative offset from the key pointer to the value at index {@code i}.
* while position {@code 2 * i + 1} in the array holds key's full 32-bit hashcode.
*/
private LongArray longArray;
// TODO: we're wasting 32 bits of space here; we can probably store fewer bits of the hashcode
// and exploit word-alignment to use fewer bits to hold the address. This might let us store
// only one long per map entry, increasing the chance that this array will fit in cache at the
// expense of maybe performing more lookups if we have hash collisions. Say that we stored only
// 27 bits of the hashcode and 37 bits of the address. 37 bits is enough to address 1 terabyte
// of RAM given word-alignment. If we use 13 bits of this for our page table, that gives us a
// maximum page size of 2^24 * 8 = ~134 megabytes per page. This change will require us to store
// full base addresses in the page table for off-heap mode so that we can reconstruct the full
// absolute memory addresses.

/**
* A {@link BitSet} used to track location of the map where the key is set.
Expand Down Expand Up @@ -222,7 +227,7 @@ public Location lookup(
return loc.with(pos, hashcode, false);
} else {
long stored = longArray.get(pos * 2 + 1);
if (((int) (stored & MASK_LONG_LOWER_32_BITS)) == hashcode) {
if ((int) (stored) == hashcode) {
// Full hash code matches. Let's compare the keys for equality.
loc.with(pos, hashcode, true);
if (loc.getKeyLength() == keyRowLengthBytes) {
Expand Down Expand Up @@ -270,14 +275,13 @@ public final class Location {
private int keyLength;
private int valueLength;

private void updateAddressesAndSizes(long fullKeyAddress, long offsetFromKeyToValue) {
private void updateAddressesAndSizes(long fullKeyAddress) {
final Object page = memoryManager.getPage(fullKeyAddress);
final long keyOffsetInPage = memoryManager.getOffsetInPage(fullKeyAddress);
keyMemoryLocation.setObjAndOffset(page, keyOffsetInPage + 8);
valueMemoryLocation.setObjAndOffset(page, keyOffsetInPage + 8 + offsetFromKeyToValue);
keyLength = (int) PlatformDependent.UNSAFE.getLong(page, keyOffsetInPage);
valueLength =
(int) PlatformDependent.UNSAFE.getLong(page, keyOffsetInPage + offsetFromKeyToValue);
valueMemoryLocation.setObjAndOffset(page, keyOffsetInPage + 8 + keyLength + 8);
valueLength = (int) PlatformDependent.UNSAFE.getLong(page, keyOffsetInPage + 8 + keyLength);
}

Location with(int pos, int keyHashcode, boolean isDefined) {
Expand All @@ -286,9 +290,7 @@ Location with(int pos, int keyHashcode, boolean isDefined) {
this.keyHashcode = keyHashcode;
if (isDefined) {
final long fullKeyAddress = longArray.get(pos * 2);
final long offsetFromKeyToValue =
(longArray.get(pos * 2 + 1) & ~MASK_LONG_LOWER_32_BITS) >>> 32;
updateAddressesAndSizes(fullKeyAddress, offsetFromKeyToValue);
updateAddressesAndSizes(fullKeyAddress);
}
return this;
}
Expand Down Expand Up @@ -399,8 +401,6 @@ public void putNewKey(
pageCursor += 8;
final long valueDataOffsetInPage = pageBaseOffset + pageCursor;
pageCursor += valueLengthBytes;
final long relativeOffsetFromKeyToValue = valueSizeOffsetInPage - keySizeOffsetInPage;
assert(relativeOffsetFromKeyToValue > 0);

// Copy the key
PlatformDependent.UNSAFE.putLong(pageBaseObject, keySizeOffsetInPage, keyLengthBytes);
Expand All @@ -414,10 +414,8 @@ public void putNewKey(
final long storedKeyAddress = memoryManager.encodePageNumberAndOffset(
currentDataPage, keySizeOffsetInPage);
longArray.set(pos * 2, storedKeyAddress);
final long storedValueOffsetAndKeyHashcode =
(relativeOffsetFromKeyToValue << 32) | (keyHashcode & MASK_LONG_LOWER_32_BITS);
longArray.set(pos * 2 + 1, storedValueOffsetAndKeyHashcode);
updateAddressesAndSizes(storedKeyAddress, relativeOffsetFromKeyToValue);
longArray.set(pos * 2 + 1, keyHashcode);
updateAddressesAndSizes(storedKeyAddress);
isDefined = true;
if (size > growthThreshold) {
growAndRehash();
Expand Down Expand Up @@ -518,8 +516,7 @@ private void growAndRehash() {
// Re-mask (we don't recompute the hashcode because we stored all 32 bits of it)
for (int pos = oldBitSet.nextSetBit(0); pos >= 0; pos = oldBitSet.nextSetBit(pos + 1)) {
final long keyPointer = oldLongArray.get(pos * 2);
final long valueOffsetPlusHashcode = oldLongArray.get(pos * 2 + 1);
final int hashcode = (int) (valueOffsetPlusHashcode & MASK_LONG_LOWER_32_BITS);
final int hashcode = (int) oldLongArray.get(pos * 2 + 1);
int newPos = hashcode & mask;
int step = 1;
boolean keepGoing = true;
Expand All @@ -530,7 +527,7 @@ private void growAndRehash() {
if (!bitset.isSet(newPos)) {
bitset.set(newPos);
longArray.set(newPos * 2, keyPointer);
longArray.set(newPos * 2 + 1, valueOffsetPlusHashcode);
longArray.set(newPos * 2 + 1, hashcode);
keepGoing = false;
} else {
newPos = (newPos + step) & mask;
Expand Down