Skip to content
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

fix(swingset,xsnap): add gcAndFinalize, tests #3136

Merged
merged 2 commits into from
May 21, 2021
Merged

Conversation

warner
Copy link
Member

@warner warner commented May 20, 2021

This adds a platform-specific gcAndFinalize() function, which returns a
Promise that resolves when GC has been provoked and FinalizationRegistry
callbacks have had a chance to run.

On Node.js, the application must be run with --expose-gc . On xsnap, a
small change was made to the run loop to let finalizers run before after the
promise queue is empty and before timer events run.

refs #2660

@warner warner added the SwingSet package: SwingSet label May 20, 2021
@warner warner requested a review from dckc May 20, 2021 06:07
@warner warner self-assigned this May 20, 2021
@warner warner force-pushed the 2660-gc-and-finalize branch 3 times, most recently from b5dc16c to feca9cf Compare May 20, 2021 07:37
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good.

Since changelogs for SwingSet and xsnap are built from conventional commits, I suggest (but don't require) two commits:

  1. The xsnap.c change would go in:
    - fix: let finalizers run after empty promise queue, before timer events
  2. The rest would go in:
    - feat: gcAndFinalize: garbage collect and wait for FinalizationRegistry callbacks

The xsnap.c change might even be a feature, depending on which way you want to look at it.

The xsnap.c change would ideally come with a test in that package since, for example, the whole package is likely to move to endojs, where someone might look at it and wonder "why is this extra loop in here?"

@dckc dckc added the xsnap the XS execution tool label May 20, 2021
@warner warner force-pushed the 2660-gc-and-finalize branch 2 times, most recently from 1e750e1 to 9b6fbbe Compare May 20, 2021 20:56
@warner warner requested a review from dckc May 20, 2021 20:56
@warner
Copy link
Member Author

warner commented May 20, 2021

Done.. please take another look and see if I missed anything.

@dckc
Copy link
Member

dckc commented May 20, 2021

Looks good.

The test in xsnap looks a little verbose, but seems ok.

This changes the xsnap.c run loop to give finalizers a chance to run just
after the promise queue drains.

With this change, userspace can do a combination of `gc()` and `setImmediate`
that lets it provoke a full GC sweep, and wait until finalizers have run.
SwingSet will use this during a crank, after userspace has become idle, and
before end-of-crank GC processing takes place.

This combination is implemented in a function named `gcAndFinalize()`. We
copy this function from its normal home in SwingSet so the xsnap.c behavior
it depends upon can be tested locally.

refs #2660
This adds a platform-specific `gcAndFinalize()` function, which returns a
Promise that resolves when GC has been provoked and FinalizationRegistry
callbacks have had a chance to run.

On Node.js, the application must be run with --expose-gc .

refs #2660
@warner warner merged commit 6a8833b into master May 21, 2021
@warner warner deleted the 2660-gc-and-finalize branch May 21, 2021 06:04
warner added a commit that referenced this pull request May 24, 2021
I added this to SwingSet/package.json in commit
d4bc617 (PR #3136). However I overlooked the
fact that #3100 had already landed, which changed the top-level `yarn test`
from one that just did a (sequential) `yarn workspaces test`, testing one
package at a time with whatever the local `package.json` said to do, to one
that does a (parallel) `ava` invocation, which does all packages at the same
time but ignores the local `package.json` settings.

We need to include `--expose-gc` in the `nodeArguments` in the top-level
package.json to make sure the parallel form give the correct arguments when
SwingSet's turn comes around (as well as other packages which benefit from
enabling GC but don't have tests which directly assert that it can be done).
warner added a commit that referenced this pull request May 25, 2021
I added this to SwingSet/package.json in commit
d4bc617 (PR #3136). However I overlooked the
fact that #3100 had already landed, which changed the top-level `yarn test`
from one that just did a (sequential) `yarn workspaces test`, testing one
package at a time with whatever the local `package.json` said to do, to one
that does a (parallel) `ava` invocation, which does all packages at the same
time but ignores the local `package.json` settings.

We need to include `--expose-gc` in the `nodeArguments` in the top-level
package.json to make sure the parallel form give the correct arguments when
SwingSet's turn comes around (as well as other packages which benefit from
enabling GC but don't have tests which directly assert that it can be done).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwingSet package: SwingSet xsnap the XS execution tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants