Skip to content

Commit

Permalink
fix(lib/runtime): update MaxPossibleAllocation to 2^25 (#3393)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Jul 20, 2023
1 parent 4ea3361 commit 91eabdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/runtime/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions lib/runtime/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
}

Expand All @@ -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},
Expand Down Expand Up @@ -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}},
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}},
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 91eabdc

Please sign in to comment.