]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: tweak js and plan9 to avoid/disable write barrier & gc problems
authorDavid Chase <drchase@google.com>
Fri, 13 May 2022 17:16:58 +0000 (13:16 -0400)
committerDavid Chase <drchase@google.com>
Fri, 13 May 2022 19:51:37 +0000 (19:51 +0000)
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 <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/runtime/lock_js.go
src/runtime/os_js.go
src/runtime/os_plan9.go

index 80ee50da3513cf71541e358392e0358c250ea323..f71e7a2b4a59cddcc36999761b2170e98329fe9d 100644 (file)
@@ -144,8 +144,12 @@ func notetsleepg(n *note, ns int64) bool {
 }
 
 // checkTimeouts resumes goroutines that are waiting on a note which has reached its deadline.
+// TODO(drchase): need to understand if write barriers are really okay in this context.
+//
+//go:yeswritebarrierrec
 func checkTimeouts() {
        now := nanotime()
+       // TODO: map iteration has the write barriers in it; is that okay?
        for n, nt := range notesWithTimeout {
                if n.key == note_cleared && now >= nt.deadline {
                        n.key = note_timeout
@@ -175,6 +179,9 @@ var idleID int32
 // If an event handler returned, we resume it and it will pause the execution.
 // beforeIdle either returns the specific goroutine to schedule next or
 // indicates with otherReady that some goroutine became ready.
+// TODO(drchase): need to understand if write barriers are really okay in this context.
+//
+//go:yeswritebarrierrec
 func beforeIdle(now, pollUntil int64) (gp *g, otherReady bool) {
        delay := int64(-1)
        if pollUntil != 0 {
@@ -196,6 +203,7 @@ func beforeIdle(now, pollUntil int64) (gp *g, otherReady bool) {
        }
 
        if len(events) == 0 {
+               // TODO: this is the line that requires the yeswritebarrierrec
                go handleAsyncEvent()
                return nil, true
        }
index 7ec1210b73c681cc9055b7f20dd3ce31e5103996..34cc0271f050b70a77549016cad91ce770b87b3a 100644 (file)
@@ -129,7 +129,7 @@ func initsig(preinit bool) {
 //
 //go:nowritebarrier
 func newosproc(mp *m) {
-       panic("newosproc: not implemented")
+       throw("newosproc: not implemented")
 }
 
 func setProcessCPUProfiler(hz int32) {}
index 1a0c0e9363e1a767af465a31e621104fea1bf5af..13bc3be4abfa92ee16b2f8274817267493b65b40 100644 (file)
@@ -437,7 +437,9 @@ func exit(e int32) {
        } else {
                // build error string
                var tmp [32]byte
-               status = append(itoa(tmp[:len(tmp)-1], uint64(e)), 0)
+               sl := itoa(tmp[:len(tmp)-1], uint64(e))
+               // Don't append, rely on the existing data being zero.
+               status = tmp[:len(sl)+1]
        }
        goexitsall(&status[0])
        exits(&status[0])