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

Lazily spawn finalisation thread #17

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

jacob-hughes
Copy link

This ensures that the synchronisation cost of spawning the finalisation thread is only spent when a) the program contains finalisers, and b) dead objects become finalisable candidates.

This is the canonical place for globals and ensures that they are
included in the right object files.
fnlz_mlc.c Outdated
pthread_t t;
pthread_create(&t, NULL, init_finalize_thread, NULL /* arg */);
GC_finalizer_thread_exists = 1;

Copy link
Member

Choose a reason for hiding this comment

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

Extraneous blank line.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed here c1d312d

@@ -2069,9 +2069,11 @@ GC_API void GC_CALL GC_enable(void)
LOCK();
GC_ASSERT(GC_dont_gc != 0); /* ensure no counter underflow */
GC_dont_gc--;
#ifndef BUFFERED_FINALIZATION
Copy link
Member

Choose a reason for hiding this comment

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

Why is this #ifndefed?

Copy link
Author

Choose a reason for hiding this comment

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

When we allocate the pages for the finaliser buffer, we do so from within the STW pause which can cause the heap to grow if lots of objects are enqueued for finalisation in a single GC. This WARN prints to stderr anytime the heap grows, and in alloy tests this can cause spurious output which causes a test to fail because stderr does not match.

I probably should have made this a separate commit, happy for me to do so when I squash?

Copy link
Member

Choose a reason for hiding this comment

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

I probably should have made this a separate commit, happy for me to do so when I squash?

Works for me!

@ltratt
Copy link
Member

ltratt commented Apr 16, 2024

Please squash.

This ensures that the synchronisation cost of spawning the finalisation
thread is only spent when a) the program contains finalisers, and b)
dead objects become finalisable candidates.
The allocation of pages for the finaliser buffer is done from within the
STW pause. This can cause the heap to grow if lots of objects are
enqueued for finalisation in a single GC and can cause spurious warnings
to be printed to stderr.
@jacob-hughes
Copy link
Author

Squashed

@ltratt ltratt added this pull request to the merge queue Apr 17, 2024
Merged via the queue into softdevteam:master with commit 9bfdaa2 Apr 17, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants