The _FixedStack will finally assign to variable s, the stack in func stackpoolalloc.
Where to increase the stack size?
I know the answer is pretty clear, but let’s find them in the assembly.
Give this example code:
We use dlv debug example.go and type disass -l main.main. And we can see following output:
In jbe 0x1054c29, jbe is “jump if below or equal (unsigned)” and if the jump is taken, the instruction in 0x1054c29 would be called, which is call $runtime.morestack_noctxt. The cmp would set CF flag for jbe when ptr [rcx+0x10] is below or equal to rsp. Which means “the stack is not enough”.
Why put $runtime.morestack_noctxt at the end of the function?
The main reason is for static branch prediction. Which implies that this conditional jump will not be taken that frequently. The critial instructions can be tightened and executed fluently by CPU which impoves performance.