Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Sep 29, 2024
1 parent 6f3ebce commit 34df31f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
6 changes: 3 additions & 3 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (vm *VMKeeper) Initialize(
baseStore := ms.GetStore(vm.baseKey)
iavlStore := ms.GetStore(vm.iavlKey)

alloc := gno.NewAllocator(maxAllocTx, 10000, gno.NewHeap())
alloc := gno.NewAllocator(maxAllocTx, gno.NewHeap())
vm.gnoStore = gno.NewStore(alloc, baseStore, iavlStore)
vm.gnoStore.SetNativeStore(stdlibs.NativeStore)

Expand Down Expand Up @@ -698,7 +698,7 @@ func (vm *VMKeeper) QueryFuncs(ctx sdk.Context, pkgPath string) (fsigs FunctionS
// TODO: modify query protocol to allow MsgEval.
// TODO: then, rename to "Eval".
func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res string, err error) {
alloc := gno.NewAllocator(maxAllocQuery, 10000, gno.NewHeap())
alloc := gno.NewAllocator(maxAllocQuery, gno.NewHeap())
gnostore := vm.newGnoTransactionStore(ctx) // throwaway (never committed)
pkgAddr := gno.DerivePkgAddr(pkgPath)
// Get Package.
Expand Down Expand Up @@ -765,7 +765,7 @@ func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res
// TODO: modify query protocol to allow MsgEval.
// TODO: then, rename to "EvalString".
func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string) (res string, err error) {
alloc := gno.NewAllocator(maxAllocQuery, 10000, gno.NewHeap())
alloc := gno.NewAllocator(maxAllocQuery, gno.NewHeap())
gnostore := vm.newGnoTransactionStore(ctx) // throwaway (never committed)
pkgAddr := gno.DerivePkgAddr(pkgPath)
// Get Package.
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func gnoTestPkg(
// XXX: make maxAllocTx configurable.
maxAllocTx := int64(50 * 1000 * 1000)

m.Alloc = gno.NewAllocator(maxAllocTx, 10000, gno.NewHeap())
m.Alloc = gno.NewAllocator(maxAllocTx, gno.NewHeap())
}
m.RunMemPackage(memPkg, true)
err := runTestFiles(m, tfiles, memPkg.Name, verbose, printRuntimeMetrics, runFlag, io)
Expand Down
21 changes: 5 additions & 16 deletions gnovm/pkg/gnolang/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
// (optionally?) condensed (objects to be GC'd will be discarded),
// but for now, allocations strictly increment across the whole tx.
type Allocator struct {
maxBytes int64
bytes int64
lastGcRun int64
minGcRun int64
heap *Heap
detonate bool
maxBytes int64
bytes int64
heap *Heap
detonate bool
}

// for gonative, which doesn't consider the allocator.
Expand Down Expand Up @@ -71,14 +69,13 @@ const (
allocHeapItem = _allocBase + _allocPointer + _allocTypedValue
)

func NewAllocator(maxBytes int64, minGcRun int64, heap *Heap) *Allocator {
func NewAllocator(maxBytes int64, heap *Heap) *Allocator {
if maxBytes == 0 {
return nil
}
return &Allocator{
maxBytes: maxBytes,
heap: heap,
minGcRun: minGcRun,
}
}

Expand Down Expand Up @@ -123,17 +120,9 @@ func (alloc *Allocator) Allocate(size int64) {
}
alloc.detonate = alloc.bytes > alloc.maxBytes
}
} else if alloc.ShouldRunGC() {
alloc.lastGcRun = alloc.bytes
deleted := alloc.heap.MarkAndSweep()
alloc.DeallocDeleted(deleted)
}
}

func (alloc *Allocator) ShouldRunGC() bool {
return false // return alloc.bytes >= 2*alloc.lastGcRun && alloc.bytes >= alloc.minGcRun
}

func (alloc *Allocator) DeallocDeleted(objs []*GcObj) {
for _, obj := range objs {
alloc.DeallocObj(obj.tv)
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func foo(b int) *Foo {
`
n := MustParseFile("main.go", c)
m.RunFiles(n)
m.Alloc = NewAllocator(22000, 3000, NewHeap())
m.Alloc = NewAllocator(22000, NewHeap())
m.RunMain()
}

Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func NewMachineWithOptions(opts MachineOptions) *Machine {
}
alloc := opts.Alloc
if alloc == nil {
alloc = NewAllocator(opts.MaxAllocBytes, 10000, NewHeap())
alloc = NewAllocator(opts.MaxAllocBytes, NewHeap())
}
store := opts.Store
if store == nil {
Expand Down

0 comments on commit 34df31f

Please sign in to comment.