@@ -118,11 +118,6 @@ public final class BytesToBytesMap extends MemoryConsumer {
118118 // full base addresses in the page table for off-heap mode so that we can reconstruct the full
119119 // absolute memory addresses.
120120
121- /**
122- * Whether or not the longArray can grow. We will not insert more elements if it's false.
123- */
124- private boolean canGrowArray = true ;
125-
126121 private final double loadFactor ;
127122
128123 /**
@@ -695,11 +690,16 @@ public boolean append(Object kbase, long koff, int klen, Object vbase, long voff
695690 assert (vlen % 8 == 0 );
696691 assert (longArray != null );
697692
698- if (numKeys == MAX_CAPACITY
699- // The map could be reused from last spill (because of no enough memory to grow),
700- // then we don't try to grow again if hit the `growthThreshold`.
701- || !canGrowArray && numKeys >= growthThreshold ) {
702- return false ;
693+ if (numKeys >= growthThreshold ) {
694+ if (longArray .size () / 2 == MAX_CAPACITY ) {
695+ // Should not grow beyond the max capacity
696+ return false ;
697+ }
698+ try {
699+ growAndRehash ();
700+ } catch (OutOfMemoryError oom ) {
701+ return false ;
702+ }
703703 }
704704
705705 // Here, we'll copy the data into our data pages. Because we only store a relative offset from
@@ -741,14 +741,6 @@ public boolean append(Object kbase, long koff, int klen, Object vbase, long voff
741741 numKeys ++;
742742 longArray .set (pos * 2 + 1 , keyHashcode );
743743 isDefined = true ;
744-
745- if (numKeys >= growthThreshold && longArray .size () < MAX_CAPACITY ) {
746- try {
747- growAndRehash ();
748- } catch (OutOfMemoryError oom ) {
749- canGrowArray = false ;
750- }
751- }
752744 }
753745 return true ;
754746 }
0 commit comments