-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
runtime: run syscall/js finalizers on wasm without a manual GC #5545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
felipegenef
wants to merge
5
commits into
tinygo-org:dev
Choose a base branch
from
felipegenef:fix-syscall-js-finalizeref-pressure-gc
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
851d47e
runtime: run syscall/js finalizers on wasm without a manual GC
felipegenef 58898cd
runtime: address review feedback on finalizer idle GC
felipegenef ee59cd9
runtime: clear a finished task's args pointer so its arguments are co…
felipegenef d619b24
runtime: skip the finalizer scan with a per-block registration bit
felipegenef d456724
Merge remote-tracking branch 'upstream/dev' into fix-syscall-js-final…
felipegenef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,70 @@ | ||
| package compileopts | ||
|
|
||
| import ( | ||
| "go/build/constraint" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestFinalizerRunnerSchedulerCoverage checks that the build constraints on the | ||
| // gc_finalizer_sched*.go files define spawnFinalizerRunner for exactly one file | ||
| // per scheduler. The three constraints must partition the scheduler space: every | ||
| // scheduler matches exactly one file, so none can be left with the symbol | ||
| // undefined or defined twice. It iterates validSchedulerOptions as the source of | ||
| // truth, so a newly added scheduler is covered by this check automatically. | ||
| func TestFinalizerRunnerSchedulerCoverage(t *testing.T) { | ||
| files := []string{ | ||
| "gc_finalizer_sched.go", | ||
| "gc_finalizer_sched_none.go", | ||
| "gc_finalizer_sched_other.go", | ||
| } | ||
| exprs := make([]constraint.Expr, len(files)) | ||
| for i, name := range files { | ||
| exprs[i] = readBuildConstraint(t, filepath.Join("..", "src", "runtime", name)) | ||
| } | ||
|
|
||
| for _, sched := range validSchedulerOptions { | ||
| // The finalizer table exists under the block GCs; gc.conservative | ||
| // satisfies the "gc.conservative || gc.precise" half of every constraint. | ||
| tags := map[string]bool{ | ||
| "gc.conservative": true, | ||
| "scheduler." + sched: true, | ||
| } | ||
| var matched []string | ||
| for i, expr := range exprs { | ||
| if expr.Eval(func(tag string) bool { return tags[tag] }) { | ||
| matched = append(matched, files[i]) | ||
| } | ||
| } | ||
| if len(matched) != 1 { | ||
| t.Errorf("scheduler.%s: spawnFinalizerRunner defined in %d files %v, want exactly 1", | ||
| sched, len(matched), matched) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // readBuildConstraint returns the parsed //go:build expression of a Go file. | ||
| func readBuildConstraint(t *testing.T, path string) constraint.Expr { | ||
| t.Helper() | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for _, line := range strings.Split(string(data), "\n") { | ||
| line = strings.TrimSpace(line) | ||
| if constraint.IsGoBuild(line) { | ||
| expr, err := constraint.Parse(line) | ||
| if err != nil { | ||
| t.Fatalf("%s: %v", path, err) | ||
| } | ||
| return expr | ||
| } | ||
| if line != "" && !strings.HasPrefix(line, "//") { | ||
| break // reached code before any //go:build line | ||
| } | ||
| } | ||
| t.Fatalf("%s: no //go:build line found", path) | ||
| return nil | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| //go:build scheduler.tasks | ||
|
|
||
| package task | ||
|
|
||
| // MarkFinishing is a no-op for the stack-based scheduler. Zeroing a finished | ||
| // goroutine's stack to drop the stale pointers its returned frames leave behind | ||
| // is only implemented for the asyncify scheduler, whose goroutine stacks are | ||
| // heap buffers scanned conservatively (see the asyncify MarkFinishing and | ||
| // Resume). deadlock and goexit in the cooperative scheduler call this for both. | ||
| func MarkFinishing() {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might need
t.state.args = nil?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed. Added a testFinishedGoroutineArgs case in finalizeridle.go to cover it. Thanks!