private void addSlab ( int minimumSize ) { int nextSlabSize ; if ( bytesUsed == 0 ) { nextSlabSize = initialSlabSize ; } else if ( bytesUsed > maxCapacityHint / 5 ) { // to avoid an overhead of up to twice the needed size, we get linear when approaching target page size nextSlabSize = maxCapacityHint / 5 ; } else { // double the size every time nextSlabSize = bytesUsed ; } if ( nextSlabSize < minimumSize ) { LOG . debug ( "slab size {} too small for value of size {}. Bumping up slab size" , nextSlabSize , minimumSize ) ; nextSlabSize = minimumSize ; } LOG . debug ( "used {} slabs, adding new slab of size {}" , slabs . size ( ) , nextSlabSize ) ; this . currentSlab = allocator . allocate ( nextSlabSize ) ; this . slabs . add ( currentSlab ) ; this . bytesAllocated += nextSlabSize ; this . currentSlabIndex = 0 ; }
the new slab is guaranteed to be at least minimumSize