From e68035acfd6997ed97eb32aec4f277f3b6858550 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 17 Aug 2019 23:43:08 +0000 Subject: compiler, runtime: allocate defer records on the stack When a defer is executed at most once in a function body, we can allocate the defer record for it on the stack instead of on the heap. This should make defers like this (which are very common) faster. This is a port of CL 171758 from the gc repo. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/190410 From-SVN: r274613 --- libgo/go/runtime/mgcmark.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libgo/go/runtime/mgcmark.go') diff --git a/libgo/go/runtime/mgcmark.go b/libgo/go/runtime/mgcmark.go index 1b8a7a3ddd7..2463a48d428 100644 --- a/libgo/go/runtime/mgcmark.go +++ b/libgo/go/runtime/mgcmark.go @@ -657,6 +657,11 @@ func scanstack(gp *g, gcw *gcWork) { scanstackblock(uintptr(unsafe.Pointer(&gp.context)), unsafe.Sizeof(gp.context), gcw) } + // Note: in the gc runtime scanstack also scans defer records. + // This is necessary as it uses stack objects (a.k.a. stack tracing). + // We don't (yet) do stack objects, and regular stack/heap scan + // will take care of defer records just fine. + gp.gcscanvalid = true } -- cgit v1.2.3