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: eliminate write barrier for self-referencing pointer #15238

Open
randall77 opened this Issue Apr 11, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@randall77
Contributor

randall77 commented Apr 11, 2016

Go code often does something like:

type Buffer struct {
   buf []byte
   bootstrap [64]byte
}
var b *Buffer = ...
b.buf = b.bootstrap[:]

I don't think we need a write barrier when we write the slice pointer into b.buf, because the pointer always points from an object into (part of) itself.

But see the discussion in #14855 . Writing a pointer to the heap without a write barrier is tricky in the presence of races. Make sure the arguments in that issue don't apply here (I don't think they do, writing a self-pointer is like writing nil).

@aclements

@randall77 randall77 added this to the Unplanned milestone Apr 11, 2016

@aclements

This comment has been minimized.

Member

aclements commented Apr 11, 2016

How much do you think this would actually win? Rick and I just spent half an hour debating whether it was actually safe to ignore write barriers for writes of nil in the presence of concurrent stack rescanning (which we don't do yet, but are considering). We eventually decided it was, but things like that make me weary of subtle write barrier optimizations.

@randall77

This comment has been minimized.

Contributor

randall77 commented Apr 11, 2016

I'm not sure. The SSA compiler does it a lot (in cmd/compile/internal/ssa/value.go), but it is probably an outlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment