Skip to content

Commit 5254b7e

Browse files
committed
runtime: do not unmap work.spans until after checkmark phase
This is causing crashes. Change-Id: I1832f33d114bc29894e491dd2baac45d7ab3a50d Reviewed-on: https://go-review.googlesource.com/5330 Reviewed-by: Rick Hudson <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 6c4b54f commit 5254b7e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/runtime/mgc.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,24 +616,23 @@ func gc(start_time int64, eagersweep bool) {
616616
sweep.npausesweep = 0
617617
}
618618

619-
// See the comment in the beginning of this function as to why we need the following.
620-
// Even if this is still stop-the-world, a concurrent exitsyscall can allocate a stack from heap.
621-
lock(&mheap_.lock)
622-
// Free the old cached mark array if necessary.
623-
if work.spans != nil && &work.spans[0] != &h_allspans[0] {
624-
sysFree(unsafe.Pointer(&work.spans[0]), uintptr(len(work.spans))*unsafe.Sizeof(work.spans[0]), &memstats.other_sys)
625-
}
626-
627619
if debug.gccheckmark > 0 {
628620
if !checkmarkphase {
629621
// first half of two-pass; don't set up sweep
630-
unlock(&mheap_.lock)
631622
return
632623
}
633624
checkmarkphase = false // done checking marks
634625
clearCheckmarks()
635626
}
636627

628+
// See the comment in the beginning of this function as to why we need the following.
629+
// Even if this is still stop-the-world, a concurrent exitsyscall can allocate a stack from heap.
630+
lock(&mheap_.lock)
631+
// Free the old cached mark array if necessary.
632+
if work.spans != nil && &work.spans[0] != &h_allspans[0] {
633+
sysFree(unsafe.Pointer(&work.spans[0]), uintptr(len(work.spans))*unsafe.Sizeof(work.spans[0]), &memstats.other_sys)
634+
}
635+
637636
// Cache the current array for sweeping.
638637
mheap_.gcspans = mheap_.allspans
639638
mheap_.sweepgen += 2

0 commit comments

Comments
 (0)