Commit c3f14925 authored by Cherry Zhang's avatar Cherry Zhang

cmd/internal/obj, runtime: use register map to mark unsafe points

Currently we use stack map index -2 to mark unsafe points, i.e.
PC ranges that is not safe for async preemption. This has a
problem: it cannot mark CALL instructions, because for stack scan
a valid stack map index is needed.

This CL switches to use register map index for marking unsafe
points instead, which does not conflict with stack scan and can
be applied on CALL instructions. This is necessary as next CL
will mark call to morestack nonpreemptible.

For #35470.

Change-Id: I357bf26c996e1fee1e7eebe4e6bb07d62930d3f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/207349Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 4a378d71
...@@ -215,12 +215,10 @@ func (ctxt *Link) StartUnsafePoint(p *Prog, newprog ProgAlloc) *Prog { ...@@ -215,12 +215,10 @@ func (ctxt *Link) StartUnsafePoint(p *Prog, newprog ProgAlloc) *Prog {
pcdata := Appendp(p, newprog) pcdata := Appendp(p, newprog)
pcdata.As = APCDATA pcdata.As = APCDATA
pcdata.From.Type = TYPE_CONST pcdata.From.Type = TYPE_CONST
pcdata.From.Offset = objabi.PCDATA_StackMapIndex pcdata.From.Offset = objabi.PCDATA_RegMapIndex
pcdata.To.Type = TYPE_CONST pcdata.To.Type = TYPE_CONST
pcdata.To.Offset = -2 // pcdata -2 marks unsafe point pcdata.To.Offset = -2 // pcdata -2 marks unsafe point
// TODO: register map?
return pcdata return pcdata
} }
...@@ -232,7 +230,7 @@ func (ctxt *Link) EndUnsafePoint(p *Prog, newprog ProgAlloc, oldval int64) *Prog ...@@ -232,7 +230,7 @@ func (ctxt *Link) EndUnsafePoint(p *Prog, newprog ProgAlloc, oldval int64) *Prog
pcdata := Appendp(p, newprog) pcdata := Appendp(p, newprog)
pcdata.As = APCDATA pcdata.As = APCDATA
pcdata.From.Type = TYPE_CONST pcdata.From.Type = TYPE_CONST
pcdata.From.Offset = objabi.PCDATA_StackMapIndex pcdata.From.Offset = objabi.PCDATA_RegMapIndex
pcdata.To.Type = TYPE_CONST pcdata.To.Type = TYPE_CONST
pcdata.To.Offset = oldval pcdata.To.Offset = oldval
...@@ -248,7 +246,7 @@ func MarkUnsafePoints(ctxt *Link, p0 *Prog, newprog ProgAlloc, isUnsafePoint fun ...@@ -248,7 +246,7 @@ func MarkUnsafePoints(ctxt *Link, p0 *Prog, newprog ProgAlloc, isUnsafePoint fun
prev := p0 prev := p0
oldval := int64(-1) // entry pcdata oldval := int64(-1) // entry pcdata
for p := prev.Link; p != nil; p, prev = p.Link, p { for p := prev.Link; p != nil; p, prev = p.Link, p {
if p.As == APCDATA && p.From.Offset == objabi.PCDATA_StackMapIndex { if p.As == APCDATA && p.From.Offset == objabi.PCDATA_RegMapIndex {
oldval = p.To.Offset oldval = p.To.Offset
continue continue
} }
......
...@@ -393,7 +393,7 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) bool { ...@@ -393,7 +393,7 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) bool {
// use the LR for unwinding, which will be bad. // use the LR for unwinding, which will be bad.
return false return false
} }
smi := pcdatavalue(f, _PCDATA_StackMapIndex, pc, nil) smi := pcdatavalue(f, _PCDATA_RegMapIndex, pc, nil)
if smi == -2 { if smi == -2 {
// Unsafe-point marked by compiler. This includes // Unsafe-point marked by compiler. This includes
// atomic sequences (e.g., write barrier) and nosplit // atomic sequences (e.g., write barrier) and nosplit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment