From e039617e0042c4f8f17dc4251bb61fe626c9a9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Wed, 19 Jul 2023 16:32:09 -0400 Subject: [PATCH 1/6] fix(lib/runtime): update `MaxPossibleAllocation` to `2^25 bytes, 32 MiB`` --- lib/runtime/allocator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/allocator.go b/lib/runtime/allocator.go index 5b05935f45..abdbb81989 100644 --- a/lib/runtime/allocator.go +++ b/lib/runtime/allocator.go @@ -23,7 +23,7 @@ const alignment uint32 = 8 const HeadsQty = 22 // MaxPossibleAllocation 2^24 bytes -const MaxPossibleAllocation = (1 << 24) +const MaxPossibleAllocation = (1 << 25) // FreeingBumpHeapAllocator struct type FreeingBumpHeapAllocator struct { From d149b919fb4ed8e9da28e3e98d483d08882967a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Wed, 19 Jul 2023 16:39:29 -0400 Subject: [PATCH 2/6] update `MaxPossibleAllocation` comment --- lib/runtime/allocator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/allocator.go b/lib/runtime/allocator.go index abdbb81989..8f82170172 100644 --- a/lib/runtime/allocator.go +++ b/lib/runtime/allocator.go @@ -22,7 +22,7 @@ const alignment uint32 = 8 // HeadsQty 22 const HeadsQty = 22 -// MaxPossibleAllocation 2^24 bytes +// MaxPossibleAllocation 2^25 bytes, 32 MiB const MaxPossibleAllocation = (1 << 25) // FreeingBumpHeapAllocator struct From b32343516ce1654563f654ba419f6bccfeda374d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Wed, 19 Jul 2023 17:19:49 -0400 Subject: [PATCH 3/6] change `HeadsQty` to `23` --- lib/runtime/allocator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/allocator.go b/lib/runtime/allocator.go index 8f82170172..5f642280f7 100644 --- a/lib/runtime/allocator.go +++ b/lib/runtime/allocator.go @@ -20,7 +20,7 @@ const DefaultHeapBase = uint32(1469576) const alignment uint32 = 8 // HeadsQty 22 -const HeadsQty = 22 +const HeadsQty = 23 // MaxPossibleAllocation 2^25 bytes, 32 MiB const MaxPossibleAllocation = (1 << 25) From d612436df1b590dac508681259223f2275022112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Wed, 19 Jul 2023 17:20:04 -0400 Subject: [PATCH 4/6] change comment --- lib/runtime/allocator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/allocator.go b/lib/runtime/allocator.go index 5f642280f7..c550b77478 100644 --- a/lib/runtime/allocator.go +++ b/lib/runtime/allocator.go @@ -19,7 +19,7 @@ const DefaultHeapBase = uint32(1469576) // The pointers need to be aligned to 8 bytes const alignment uint32 = 8 -// HeadsQty 22 +// HeadsQty 23 const HeadsQty = 23 // MaxPossibleAllocation 2^25 bytes, 32 MiB From c5336e1b53dc8ecef9e1606b5328e965d00ebf35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Thu, 20 Jul 2023 10:36:34 -0400 Subject: [PATCH 5/6] change `allocator_test` to use `[HeadsQty]{}` --- lib/runtime/allocator_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/runtime/allocator_test.go b/lib/runtime/allocator_test.go index 9efdbbc3a7..9d6c38bce8 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}}, } From 70012a1f54fec995355dc23e07d42d3147898883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Thu, 20 Jul 2023 13:50:00 -0400 Subject: [PATCH 6/6] update `TestShouldGetMaxFromIndex` test --- lib/runtime/allocator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/allocator_test.go b/lib/runtime/allocator_test.go index 9d6c38bce8..ceeda29b3f 100644 --- a/lib/runtime/allocator_test.go +++ b/lib/runtime/allocator_test.go @@ -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)