Skip to content

Commit 364ced6

Browse files
committed
runtime: tweak js and plan9 to avoid/disable write barrier & gc problems
runtime code for js contains possible write barriers that fail the nowritebarrierrec check when internal local package naming conventions are changed. The problem was there all already; this allows the code to compile, and it seems to work anyway in the (single-threaded) js/wasm environment. The offending operations are noted with TODO, which is an improvement. runtime code for plan9 contained an apparent allocation that was not really an allocation; rewrite to remove the potential allocation to avoid nowritebarrierrec problems. This CL is a prerequisite for a pending code cleanup, https://go-review.googlesource.com/c/go/+/393715 Updates #51734. Change-Id: I93f31831ff9b92632137dd7b0055eaa721c81556 Reviewed-on: https://go-review.googlesource.com/c/go/+/405901 Run-TryBot: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 540f8c2 commit 364ced6

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/runtime/lock_js.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ func notetsleepg(n *note, ns int64) bool {
144144
}
145145

146146
// checkTimeouts resumes goroutines that are waiting on a note which has reached its deadline.
147+
// TODO(drchase): need to understand if write barriers are really okay in this context.
148+
//
149+
//go:yeswritebarrierrec
147150
func checkTimeouts() {
148151
now := nanotime()
152+
// TODO: map iteration has the write barriers in it; is that okay?
149153
for n, nt := range notesWithTimeout {
150154
if n.key == note_cleared && now >= nt.deadline {
151155
n.key = note_timeout
@@ -175,6 +179,9 @@ var idleID int32
175179
// If an event handler returned, we resume it and it will pause the execution.
176180
// beforeIdle either returns the specific goroutine to schedule next or
177181
// indicates with otherReady that some goroutine became ready.
182+
// TODO(drchase): need to understand if write barriers are really okay in this context.
183+
//
184+
//go:yeswritebarrierrec
178185
func beforeIdle(now, pollUntil int64) (gp *g, otherReady bool) {
179186
delay := int64(-1)
180187
if pollUntil != 0 {
@@ -196,6 +203,7 @@ func beforeIdle(now, pollUntil int64) (gp *g, otherReady bool) {
196203
}
197204

198205
if len(events) == 0 {
206+
// TODO: this is the line that requires the yeswritebarrierrec
199207
go handleAsyncEvent()
200208
return nil, true
201209
}

src/runtime/os_js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func initsig(preinit bool) {
129129
//
130130
//go:nowritebarrier
131131
func newosproc(mp *m) {
132-
panic("newosproc: not implemented")
132+
throw("newosproc: not implemented")
133133
}
134134

135135
func setProcessCPUProfiler(hz int32) {}

src/runtime/os_plan9.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ func exit(e int32) {
437437
} else {
438438
// build error string
439439
var tmp [32]byte
440-
status = append(itoa(tmp[:len(tmp)-1], uint64(e)), 0)
440+
sl := itoa(tmp[:len(tmp)-1], uint64(e))
441+
// Don't append, rely on the existing data being zero.
442+
status = tmp[:len(sl)+1]
441443
}
442444
goexitsall(&status[0])
443445
exits(&status[0])

0 commit comments

Comments
 (0)