mirror of
https://github.com/golang/go
synced 2025-02-23 03:56:14 +00:00
This is a two-pronged approach. First, try to keep large objects off the stack frame. Second, if they do manage to appear anyway, use straight bitmasks instead of gc programs. Generally probably a good idea to keep large objects out of stack frames. But particularly keeping gc programs off the stack simplifies runtime code a bit. This CL sets the limit of most stack objects to 131072 bytes (on 64-bit archs). There can still be large objects if allocated by a late pass, like order, or they are required to be on the stack, like function arguments. But the size for the bitmasks for these objects isn't a huge deal, as we have already have (probably several) bitmasks for the frame liveness map itself. Change-Id: I6d2bed0e9aa9ac7499955562c6154f9264061359 Reviewed-on: https://go-review.googlesource.com/c/go/+/542815 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
39 lines
768 B
Go
39 lines
768 B
Go
// errorcheck -0 -m -l
|
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package p
|
|
|
|
type t [20000]*int
|
|
|
|
func (t) f() {
|
|
}
|
|
|
|
func x() {
|
|
x := t{}.f // ERROR "t{}.f escapes to heap"
|
|
x()
|
|
}
|
|
|
|
func y() {
|
|
var i int // ERROR "moved to heap: i"
|
|
y := (&t{&i}).f // ERROR "\(&t{...}\).f escapes to heap" "&t{...} escapes to heap"
|
|
y()
|
|
}
|
|
|
|
func z() {
|
|
var i int // ERROR "moved to heap: i"
|
|
z := t{&i}.f // ERROR "t{...}.f escapes to heap"
|
|
z()
|
|
}
|
|
|
|
// Should match cmd/compile/internal/ir/cfg.go:MaxStackVarSize.
|
|
const maxStack = 128 * 1024
|
|
|
|
func w(i int) byte {
|
|
var x [maxStack]byte
|
|
var y [maxStack + 1]byte // ERROR "moved to heap: y"
|
|
return x[i] + y[i]
|
|
}
|