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

Issue 7513: stack overflow due to recursive GC marking and release #9040

Merged
merged 2 commits into from Apr 17, 2021

Conversation

rubidium42
Copy link
Contributor

@rubidium42 rubidium42 commented Apr 15, 2021

Motivation / Problem

Fixes #7513 which is a stack overflow due to recursive marking for garbage collection. Whacking that mole yields a stack overflow due to recursive releasing, so that's tackled here as well.

Description

The bug is solved by rewriting bits of code to go from a recursive marking and releasing to an approach that is more iterative, which is done by having a queue of objects that need to be processed and going through that queue iteratively. Whenever the iterative step on an object requires the same step to be taken on another object (release or GC marking), then that object is added to the queue so it will be processed at a later stage.

Limitations

Depending on the code, now you might hit out of memory issues instead of the game crashing due to a stack overflow. I intentionally tried to make a few changes to the rest of the squirrel code, so it's probably not all according to coding style. I rather leave the coding style fixes for Squirrel for another time, as not doing those makes it easier to see the differences between stock and our version of squirrel.
Freeing and GC marking can cause lags with such large amounts of elements, but that's inherent to such massive amounts of elements; millions in my test cases in debug builds. This makes both freeing and GC marking slightly slower, but the benefit is the game not crashing.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@rubidium42 rubidium42 changed the title Issue 7513 Issue 7513: stack overflow due to recursive GC marking and release Apr 15, 2021
@LordAro LordAro added the backport requested This PR should be backport to current release (RC / stable) label Apr 16, 2021
@LordAro
Copy link
Member

LordAro commented Apr 16, 2021

Some warnings that need fixing (override), other than that, looks good

@rubidium42 rubidium42 force-pushed the issue-7513 branch 2 times, most recently from 1677ecb to 26f5c6f Compare April 16, 2021 16:57
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

LGTM

@LordAro LordAro merged commit 44d1b96 into OpenTTD:master Apr 17, 2021
@rubidium42 rubidium42 deleted the issue-7513 branch April 17, 2021 18:48
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Squirrel can stack overflow when GCing deep structures, leading to crash
3 participants