-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: don't use maps in js note implementation
notes are used in sensitive locations in the runtime, such as those with write barriers forbidden. Maps aren't designed for this sort of internal use. Notably, newm -> notewakeup doesn't allow write barriers, but mapaccess1 -> panic contains write barriers. The js runtime only builds right now because the map access is optimized to mapaccess1_fast64, which happens to not have a panic call. The initial swisstable map implementation doesn't have a fast64 variant. While we could add one, it is a bad idea in general to use a map in such a fragile location. Simplify the implementation by storing the metadata directly in the note, and using a linked list for checkTimeouts. For #54766. Cq-Include-Trybots: luci.golang.try:gotip-js-wasm Change-Id: Ib9d39f064ae4ad32dcc873f799428717eb6c2d5a Reviewed-on: https://go-review.googlesource.com/c/go/+/595558 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
- Loading branch information
Showing
4 changed files
with
106 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package runtime | ||
|
||
// sleep and wakeup on one-time events. | ||
// before any calls to notesleep or notewakeup, | ||
// must call noteclear to initialize the Note. | ||
// then, exactly one thread can call notesleep | ||
// and exactly one thread can call notewakeup (once). | ||
// once notewakeup has been called, the notesleep | ||
// will return. future notesleep will return immediately. | ||
// subsequent noteclear must be called only after | ||
// previous notesleep has returned, e.g. it's disallowed | ||
// to call noteclear straight after notewakeup. | ||
// | ||
// notetsleep is like notesleep but wakes up after | ||
// a given number of nanoseconds even if the event | ||
// has not yet happened. if a goroutine uses notetsleep to | ||
// wake up early, it must wait to call noteclear until it | ||
// can be sure that no other goroutine is calling | ||
// notewakeup. | ||
// | ||
// notesleep/notetsleep are generally called on g0, | ||
// notetsleepg is similar to notetsleep but is called on user g. | ||
type note struct { | ||
status int32 | ||
|
||
// The G waiting on this note. | ||
gp *g | ||
|
||
// Deadline, if any. 0 indicates no timeout. | ||
deadline int64 | ||
|
||
// allprev and allnext are used to form the allDeadlineNotes linked | ||
// list. These are unused if there is no deadline. | ||
allprev *note | ||
allnext *note | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !js | ||
|
||
package runtime | ||
|
||
// sleep and wakeup on one-time events. | ||
// before any calls to notesleep or notewakeup, | ||
// must call noteclear to initialize the Note. | ||
// then, exactly one thread can call notesleep | ||
// and exactly one thread can call notewakeup (once). | ||
// once notewakeup has been called, the notesleep | ||
// will return. future notesleep will return immediately. | ||
// subsequent noteclear must be called only after | ||
// previous notesleep has returned, e.g. it's disallowed | ||
// to call noteclear straight after notewakeup. | ||
// | ||
// notetsleep is like notesleep but wakes up after | ||
// a given number of nanoseconds even if the event | ||
// has not yet happened. if a goroutine uses notetsleep to | ||
// wake up early, it must wait to call noteclear until it | ||
// can be sure that no other goroutine is calling | ||
// notewakeup. | ||
// | ||
// notesleep/notetsleep are generally called on g0, | ||
// notetsleepg is similar to notetsleep but is called on user g. | ||
type note struct { | ||
// Futex-based impl treats it as uint32 key, | ||
// while sema-based impl as M* waitm. | ||
key uintptr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters