Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: allocation escapes to heap with "non-constant size" with constant size >= 64K #41635

Closed
kipply opened this issue Sep 26, 2020 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kipply
Copy link

kipply commented Sep 26, 2020

What version of Go are you using (go version)?

go version go1.14.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

// skipping

What did you do?

package main

func main() {
  thing := make([]byte, 65536) // also ran with 65535, which is < 64KiB 
}

Ran with go run -gcflags '-m -m' alloc.go

What did you expect to see?

message should say it escapes to heap because of a max value (not sure if this is an escape analysis impl determined value, or more related to my architecture or setup of the stack, or a mix of those)

What did you see instead?

./alloc.go:7:13: make([]byte, 65537) escapes to heap:
./alloc.go:7:13:   flow: {heap} = &{storage for make([]byte, 65537)}:
./alloc.go:7:13:     from make([]byte, 65537) (non-constant size) at ./alloc.go:7:13

it will not escape when I use 65535 instead of 65536.

@ALTree ALTree changed the title allocation escapes to heap with "non-constant size" with constant size >= 64K cmd/compile: allocation escapes to heap with "non-constant size" with constant size >= 64K Sep 26, 2020
@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 26, 2020
@ALTree ALTree added this to the Go1.16 milestone Sep 26, 2020
@ALTree ALTree self-assigned this Sep 26, 2020
@ALTree
Copy link
Member

ALTree commented Sep 26, 2020

Thanks for reporting this. The problem is at the following check in escape.go:

why := "too large for stack"
if n.Op == OMAKESLICE && (!Isconst(n.Left, CTINT) || !Isconst(n.Right, CTINT)) {
	why = "non-constant size"
}

In OMAKESLICE nodes, n.Left is the length and n.Right is the capacity. In a call with implied capacity like make([]byte, 65536), n.Right will be nil, so Isconst(n.Right, CTINT) will return false, and we print non-constant size instead of the correct message.

@gopherbot
Copy link

Change https://golang.org/cl/257641 mentions this issue: cmd/compile: fix escape reason for MAKESLICE with no cap

@golang golang locked and limited conversation to collaborators Sep 28, 2021
@rsc rsc unassigned ALTree Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants