aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorL. Pereira <[email protected]>2024-07-08 16:34:40 -0700
committerGitHub <[email protected]>2024-07-08 16:34:40 -0700
commitd150badf33d6087bdad8da5eb6a680e13dafe6ff (patch)
tree9b36dcbacccc2d459e9a658d862111b7906abc21
parent2d85fc6a6435f3bbdb8edaba6d41e6ec014f57f2 (diff)
downloadtinygo-d150badf33d6087bdad8da5eb6a680e13dafe6ff.tar.gz
tinygo-d150badf33d6087bdad8da5eb6a680e13dafe6ff.zip
gc_leaking: Don't zero out new allocations in some targets (#4302)
Wasm linear memory is always initialized to zero by definition, so there's no need to waste time zeroing out this allocation. This is the case for freshly-obtained memory from mmap(). Signed-off-by: L. Pereira <[email protected]>
-rw-r--r--src/runtime/gc_leaking.go2
-rw-r--r--src/runtime/zero_new_alloc.go12
-rw-r--r--src/runtime/zero_new_alloc_noop.go14
3 files changed, 27 insertions, 1 deletions
diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go
index 26b012bdb..5c9594277 100644
--- a/src/runtime/gc_leaking.go
+++ b/src/runtime/gc_leaking.go
@@ -44,7 +44,7 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
runtimePanic("out of memory")
}
pointer := unsafe.Pointer(addr)
- memzero(pointer, size)
+ zero_new_alloc(pointer, size)
return pointer
}
diff --git a/src/runtime/zero_new_alloc.go b/src/runtime/zero_new_alloc.go
new file mode 100644
index 000000000..b94190ae0
--- /dev/null
+++ b/src/runtime/zero_new_alloc.go
@@ -0,0 +1,12 @@
+//go:build gc.leaking && (baremetal || nintendoswitch)
+
+package runtime
+
+import (
+ "unsafe"
+)
+
+//go:inline
+func zero_new_alloc(ptr unsafe.Pointer, size uintptr) {
+ memzero(ptr, size)
+}
diff --git a/src/runtime/zero_new_alloc_noop.go b/src/runtime/zero_new_alloc_noop.go
new file mode 100644
index 000000000..79fefc199
--- /dev/null
+++ b/src/runtime/zero_new_alloc_noop.go
@@ -0,0 +1,14 @@
+//go:build gc.leaking && !baremetal && !nintendoswitch
+
+package runtime
+
+import (
+ "unsafe"
+)
+
+//go:inline
+func zero_new_alloc(ptr unsafe.Pointer, size uintptr) {
+ // Wasm linear memory is initialized to zero by default, so
+ // there's no need to do anything. This is also the case for
+ // fresh-allocated memory from an mmap() system call.
+}