-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Remove the interface function fullCollectNoStack from the gcinterface #16401
Merged
thewilsonator
merged 4 commits into
dlang:master
from
schveiguy:removeFullCollectNoStack
Apr 23, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,38 @@ | ||
Remove all `collectNoStack` functions and API from druntime. | ||
|
||
The function `collectNoStack` in the D garbage collector performed a | ||
collection, without using any roots from thread stacks or thread-local-storage. | ||
The danger of running this mechanism is that any blocks of memory which only | ||
have a reference from a thread might be collected, while the thread is still | ||
running and possibly using the memory. | ||
|
||
The only time this function was called was at GC termination. At GC | ||
termination, the GC is about to be destroyed, and so we want to run as many | ||
destructors as possible. However, if some thread is using GC-allocated memory, | ||
cleaning up that memory isn't going to help matters. Either it will crash after | ||
the GC cleans the memory, or it will crash after the GC is destroyed. | ||
|
||
The original purpose of this function (from D1) was to ensure simple uses of | ||
the GC were cleaned up in small test programs, as this mechanism was only used | ||
on single-threaded programs (and of course, at program exit). Also note at the | ||
time, D1 was 32-bit, and false pointers where much more common. Avoiding | ||
scanning stacks would aid in avoiding seemingly random behavior in cleanup. | ||
However, as shown below, there are more deterministic ways to ensure data is | ||
always cleaned up. | ||
|
||
Today, the dangers are much greater that such a function is even callable -- | ||
any call to such a function would immediately start use-after-free memory | ||
corruption in any thread that is still running. Therefore, we are removing the | ||
functionality entirely, and simply doing a standard GC cleanup (scanning stacks | ||
and all). One less footgun is the benefit for having less guaranteed GC clean | ||
up at program exit. | ||
|
||
In addition, the GC today is a bit smarter about where the valid stack is, so | ||
there is even less of a chance of leaving blocks unfinalized. | ||
|
||
As always, the GC is *not* guaranteed to clean up any block at the end of | ||
runtime. Any change in behavior with code that had blocks clean up before, but | ||
no longer are cleaned up is still within specification. And if you want the | ||
behavior that absolutely cleans all blocks, you can use the | ||
`--DRT-gcopt=cleanup:finalize` druntime configuration option, which will clean | ||
up all blocks without even scanning. |
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
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 |
---|---|---|
|
@@ -79,10 +79,6 @@ class ManualGC : GC | |
{ | ||
} | ||
|
||
void collectNoStack() nothrow | ||
{ | ||
} | ||
|
||
void minimize() nothrow | ||
{ | ||
} | ||
|
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 |
---|---|---|
|
@@ -76,10 +76,6 @@ class ProtoGC : GC | |
{ | ||
} | ||
|
||
void collectNoStack() nothrow | ||
{ | ||
} | ||
|
||
void minimize() nothrow | ||
{ | ||
} | ||
|
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 |
---|---|---|
|
@@ -8,5 +8,6 @@ struct S | |
|
||
void main() | ||
{ | ||
new S; | ||
foreach(i; 0 .. 100) | ||
new S; | ||
} |
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
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.
maybe add a
GC.collect();
here to force a collection then?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'm not seeing why we have to force one when it's going to collect at the end of the program anyway. The goal here is to make sure there is at least one piece of garbage that will trigger the error, and making 100 of them means at least one of those won't be referred to in stack/registers.
Probably could be 2, but 100 is cheap...