Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/6159#discussion_r30558817
--- Diff:
unsafe/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java ---
@@ -427,7 +496,9 @@ public void putNewKey(
* @param capacity the new map capacity
*/
private void allocate(int capacity) {
- capacity = Math.max((int) Math.min(Integer.MAX_VALUE,
nextPowerOf2(capacity)), 64);
+ assert (capacity >= 0);
+ // The capacity needs to be divisible by 64 so that our bit set can be
sized properly
+ capacity = Math.max((int) Math.min(MAX_CAPACITY,
nextPowerOf2(capacity)), 64);
longArray = new LongArray(memoryManager.allocate(capacity * 8 * 2));
--- End diff --
`capacity * 8 * 2` should be `capacity * 8L * 2` to avoid overflow. And if
you change it to `capacity * 8L * 2` and `capacity` is `(1 << 30)`, you will
see the following error:
```
java.lang.NegativeArraySizeException
at
org.apache.spark.unsafe.memory.HeapMemoryAllocator.allocate(HeapMemoryAllocator.java:28)
at
org.apache.spark.unsafe.memory.ExecutorMemoryManager.allocate(ExecutorMemoryManager.java:51)
at
org.apache.spark.unsafe.memory.TaskMemoryManager.allocate(TaskMemoryManager.java:162)
at
org.apache.spark.unsafe.map.BytesToBytesMap.allocate(BytesToBytesMap.java:504)
at
org.apache.spark.unsafe.map.BytesToBytesMap.<init>(BytesToBytesMap.java:165)
at
org.apache.spark.unsafe.map.BytesToBytesMap.<init>(BytesToBytesMap.java:169)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]