-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): count slice allocations before performing memory allocati…
…ons (#2781) <!-- please provide a detailed description of the changes made in this pull request. --> This is to fix the first issue mentioned in #2738. In short, when allocating and reallocating slices' underlying arrays, the VM was building the `TypedValue` slice before making the necessary VM allocations. It is important the VM allocations be done before the `TypedValue` allocations to ensure the values being allocated won't exceed the VM's limit. In extreme cases, unchecked allocations resulted in the VM hanging as it tried to allocate massive `TypedValue` slices in the go runtime. <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [x] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
- Loading branch information
Showing
5 changed files
with
120 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
loadpkg gno.land/r/alloc $WORK | ||
|
||
gnoland start | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/alloc -func DoAlloc -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stderr 'Data: allocation limit exceeded' | ||
|
||
-- alloc.gno -- | ||
package alloc | ||
|
||
var buffer interface{} | ||
|
||
func DoAlloc() { | ||
var arr [1_000_000_000_000_000]byte | ||
buffer = arr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
loadpkg gno.land/r/alloc $WORK | ||
|
||
gnoland start | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/alloc -func DoAlloc -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stderr 'Data: allocation limit exceeded' | ||
|
||
-- alloc.gno -- | ||
package alloc | ||
|
||
var buffer []byte | ||
|
||
func DoAlloc() { | ||
buffer := make([]byte, 1_000_000_000_000) | ||
buffer[1] = 'a' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
loadpkg gno.land/r/alloc $WORK | ||
|
||
gnoland start | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/alloc -func DoAlloc -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stderr 'Data: allocation limit exceeded' | ||
|
||
-- alloc.gno -- | ||
package alloc | ||
|
||
var buffer []int | ||
|
||
func DoAlloc() { | ||
buffer := make([]int, 1_000_000_000_000) | ||
buffer[1] = 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters