diff --git a/lib/runtime/allocator.go b/lib/runtime/allocator.go index 5b05935f45..c550b77478 100644 --- a/lib/runtime/allocator.go +++ b/lib/runtime/allocator.go @@ -19,11 +19,11 @@ const DefaultHeapBase = uint32(1469576) // The pointers need to be aligned to 8 bytes const alignment uint32 = 8 -// HeadsQty 22 -const HeadsQty = 22 +// HeadsQty 23 +const HeadsQty = 23 -// MaxPossibleAllocation 2^24 bytes -const MaxPossibleAllocation = (1 << 24) +// MaxPossibleAllocation 2^25 bytes, 32 MiB +const MaxPossibleAllocation = (1 << 25) // FreeingBumpHeapAllocator struct type FreeingBumpHeapAllocator struct { diff --git a/lib/runtime/allocator_test.go b/lib/runtime/allocator_test.go index 9efdbbc3a7..ceeda29b3f 100644 --- a/lib/runtime/allocator_test.go +++ b/lib/runtime/allocator_test.go @@ -90,7 +90,7 @@ var allocateFreeTest = []testSet{ totalSize: 40}}, {test: &freeTest{ptr: 24}, // address of second allocation state: allocatorState{bumper: 40, - heads: [22]uint32{0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, totalSize: 16}}, } @@ -108,7 +108,7 @@ var allocateDeallocateReallocateWithOffset = []testSet{ totalSize: 40}}, {test: &freeTest{ptr: 40}, // address of second allocation state: allocatorState{bumper: 40, - heads: [22]uint32{0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, ptrOffset: 16, totalSize: 16}}, {test: &allocateTest{size: 9}, @@ -141,18 +141,18 @@ var allocateShouldBuildFreeList = []testSet{ // free second allocation {test: &freeTest{ptr: 24}, // address of second allocation state: allocatorState{bumper: 48, - heads: [22]uint32{16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, totalSize: 16}}, // free third allocation {test: &freeTest{ptr: 40}, // address of third allocation state: allocatorState{bumper: 48, - heads: [22]uint32{32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, totalSize: 0}}, // allocate 8 bytes {test: &allocateTest{size: 8}, output: uint32(40), state: allocatorState{bumper: 48, - heads: [22]uint32{16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, totalSize: 16}}, } @@ -200,7 +200,7 @@ var heapShouldBeZeroAfterFreeWithOffsetFiveTimes = []testSet{ // second free {test: &freeTest{ptr: 104}, state: allocatorState{bumper: 144, - heads: [22]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, ptrOffset: 24, totalSize: 0}}, // third alloc @@ -212,7 +212,7 @@ var heapShouldBeZeroAfterFreeWithOffsetFiveTimes = []testSet{ // third free {test: &freeTest{ptr: 104}, state: allocatorState{bumper: 144, - heads: [22]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, ptrOffset: 24, totalSize: 0}}, // forth alloc @@ -224,7 +224,7 @@ var heapShouldBeZeroAfterFreeWithOffsetFiveTimes = []testSet{ // forth free {test: &freeTest{ptr: 104}, state: allocatorState{bumper: 144, - heads: [22]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, ptrOffset: 24, totalSize: 0}}, // fifth alloc @@ -236,7 +236,7 @@ var heapShouldBeZeroAfterFreeWithOffsetFiveTimes = []testSet{ // fifth free {test: &freeTest{ptr: 104}, state: allocatorState{bumper: 144, - heads: [22]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + heads: [HeadsQty]uint32{0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, ptrOffset: 24, totalSize: 0}}, } @@ -484,7 +484,7 @@ func TestShouldGetItemFromIndex(t *testing.T) { // that that getItemSizeFromIndex method gets expected item size from index // max index position func TestShouldGetMaxFromIndex(t *testing.T) { - index := uint(21) + index := uint(HeadsQty - 1) itemSize := getItemSizeFromIndex(index) if itemSize != MaxPossibleAllocation { t.Errorf("item_size should be %d, got item_size: %d", MaxPossibleAllocation, itemSize)