runtime: replace traceBuf slice with index
runtime: replace traceBuf slice with index

Currently traceBuf keeps track of where it is in the trace buffer by
also maintaining a slice that points in to this buffer with an initial
length of 0 and a cap of the length of the array. All writes to this
buffer are done by appending to the slice (as long as the bounds
checks are right, it will never overflow and the append won't allocate
a new slice).

Each of these appends generates a write barrier. As long as we never
overflow the buffer, this write barrier won't fire, but this wreaks
havoc with eliminating write barriers from the tracing code. If we
were to overflow the buffer, this would both allocate and invoke a
write barrier, both things that are dicey at best to do in many of the
contexts tracing happens. It also wastes space in the traceBuf and
leads to more complex code and more complex generated code.

Replace this slice trick with keeping track of a simple array
position.

Updates #10600.

Change-Id: I0a63eecec1992e195449f414ed47653f66318d0e
Reviewed-on: https://go-review.googlesource.com/16814
Run-TryBot: Austin Clements <7ea35d812706d9213868749011af1ed4fa2f6aa0@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Dmitry Vyukov <05e8181be3150e47da8fe2e1f18d381c75496ff4@google.com>

polyverse-security/go,rachtsingh/gogojuice,4ad/go,deft-code/go,mwhudson/go,linux-on-ibm-z/go,rachtsingh/gogojuice,cloudflare/go,mwhudson/go,odeke-em/go,polyverse-security/go,suncycheng/go,ganboing/go-esx,cyberroadie/go,linux-on-ibm-z/go,codestation/go,theif519/go,goodlang/good,Cofyc/go,derekmarcotte/go,Samurais/go,sndnvaps/go,kim-racktop/go,4ad/go,vsekhar/elastic-go,CAFxX/go,Endika/go,ImJasonH/go,vanloswang/go,CAFxX/go,mwhudson/go,linux-on-ibm-z/go,deft-code/go,suncycheng/go,codestation/go,nawawi/go,miolini/go,theif519/go,theif519/go,cyberroadie/go,miolini/go,CAFxX/go,fjballest/golang,cyberroadie/go,vsekhar/elastic-go,cloudflare/go,odeke-em/go,josharian/go,4ad/go,akutz/go,polyverse-security/go,deft-code/go,Cofyc/go,ImJasonH/go,binarycrusader/go,ganboing/go-esx,suncycheng/go,ganboing/go-esx,4ad/go,binarycrusader/go,binarycrusader/go,Samurais/go,miolini/go,akutz/go,rachtsingh/gogojuice,4ad/go,4ad/go,Cofyc/go,suncycheng/go,linux-on-ibm-z/go,miolini/go,josharian/go,deft-code/go,theif519/go,kim-racktop/go,theif519/go,deft-code/go,Endika/go,rachtsingh/gogojuice,cyberroadie/go,momchil-velikov/go,nawawi/go,Samurais/go,Cofyc/go,odeke-em/go,josharian/go,fjballest/golang,linux-on-ibm-z/go,odeke-em/go,nawawi/go,vanloswang/go,golang/go,Cofyc/go,Endika/go,Jordanzuo/go,nawawi/go,suncycheng/go,codestation/go,Jordanzuo/go,Endika/go,vanloswang/go,Jordanzuo/go,cloudflare/go,deft-code/go,sndnvaps/go,akutz/go,momchil-velikov/go,miolini/go,akutz/go,golang/go,derekmarcotte/go,goodlang/good,goodlang/good,josharian/go,sndnvaps/go,CAFxX/go,rachtsingh/gogojuice,deft-code/go,cyberroadie/go,vanloswang/go,polyverse-security/go,nawawi/go,Cofyc/go,codestation/go,ganboing/go-esx,ganboing/go-esx,cloudflare/go,ImJasonH/go,golang/go,cloudflare/go,roth1002/go,Jordanzuo/go,goodlang/good,binarycrusader/go,vsekhar/elastic-go,mwhudson/go,codestation/go,Jordanzuo/go,roth1002/go,roth1002/go,sndnvaps/go,Jordanzuo/go,goodlang/good,Cofyc/go,vanloswang/go,binarycrusader/go,vsekhar/elastic-go,sndnvaps/go,roth1002/go,derekmarcotte/go,linux-on-ibm-z/go,theif519/go,akutz/go,golang/go,vsekhar/elastic-go,cyberroadie/go,cloudflare/go,codestation/go,rachtsingh/gogojuice,miolini/go,vsekhar/elastic-go,christopher-henderson/Go,kim-racktop/go,codestation/go,odeke-em/go,miolini/go,Samurais/go,mwhudson/go,polyverse-security/go,derekmarcotte/go,akutz/go,golang/go,derekmarcotte/go,ImJasonH/go,vanloswang/go,4ad/go,sndnvaps/go,goodlang/good,odeke-em/go,vsekhar/elastic-go,Samurais/go,CAFxX/go,josharian/go,theif519/go,akutz/go,cloudflare/go,cyberroadie/go,binarycrusader/go,Jordanzuo/go,binarycrusader/go,codestation/go,ImJasonH/go,vanloswang/go,momchil-velikov/go,ImJasonH/go,Samurais/go,roth1002/go,josharian/go,CAFxX/go,goodlang/good,binarycrusader/go,momchil-velikov/go,momchil-velikov/go,polyverse-security/go,CAFxX/go,cloudflare/go,derekmarcotte/go,roth1002/go,kim-racktop/go,ganboing/go-esx,ImJasonH/go,Endika/go,sndnvaps/go,ImJasonH/go,Endika/go,ganboing/go-esx,fjballest/golang,sndnvaps/go,derekmarcotte/go,derekmarcotte/go,kim-racktop/go,vsekhar/elastic-go,linux-on-ibm-z/go,goodlang/good,mwhudson/go,4ad/go,mwhudson/go,vanloswang/go,Cofyc/go,rachtsingh/gogojuice,fjballest/golang,Samurais/go,polyverse-security/go,cyberroadie/go,josharian/go,Jordanzuo/go,polyverse-security/go,deft-code/go,theif519/go,Endika/go,fjballest/golang,miolini/go,akutz/go,momchil-velikov/go,roth1002/go,momchil-velikov/go,linux-on-ibm-z/go,nawawi/go,odeke-em/go,roth1002/go,fjballest/golang,ganboing/go-esx,fjballest/golang,momchil-velikov/go,golang/go,nawawi/go,suncycheng/go,suncycheng/go,Samurais/go,rachtsingh/gogojuice,kim-racktop/go,nawawi/go,golang/go,kim-racktop/go,Endika/go,golang/go,mwhudson/go,odeke-em/go,CAFxX/go,suncycheng/go,fjballest/golang,kim-racktop/go,josharian/go