Repository navigation
Mark only what the collector made from a default closure - #476
Merged
Merged
Conversation
A class's __register copies its vtable from an instance it makes on the stack, and that instance's constructor gives each dynamic function a default closure holding it. The closure is garbage at once, but a stale word a stack scan finds can still reach it, and marking it followed the stack address as if it were an object: it wrote a mark byte there, and faulted in a marking thread where the line marks it then read were not mapped. Whether it faults depends on the stack's layout. Making a thread's scratch buffer only at API level 500 changed that layout, and the release telemetry test, which uses haxe.Timer and its dynamic run, crashed on Windows x64 every run; stock hxcpp crashes the same way. The default closure now marks and visits its instance only when hx::IsCollectedAlloc finds it in memory the collector manages, which holds while it collects. Test: DefaultFuncForeignThis makes such an instance in zeroed memory outside the heap and keeps its default closure. Before the change a collection wrote 1 byte there, after it none, at 32 and 64 bits and with HXCPP_GC_MOVING, GENERATIONAL and DEBUG_ALWAYS_MOVE. The telemetry test passes 12 of 12, where it crashed 10 of 10. The GC, thread and Cppia regressions (100), test/haxe, the fuzz replay and the cppia suite pass on Windows x64.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The main run on the merge of #449 failed in Haxe 4.3.7 / Windows 64 / gc and telemetry: the release telemetry test segfaulted, and it does so locally every run.
The cause is older than #449. A class's
__registercopies its vtable from an instance it makes on the stack, and that instance's constructor gives each dynamic function a default closure holding it. The closure is garbage at once, but a stale word a stack scan finds can still reach it, and marking it followed the stack address as if it were an object, writing a mark byte into the stack and faulting in a marking thread where the line marks it then read were not mapped. Whether it faults depends on the stack's layout: making a thread's scratch buffer only at API level 500 (in #449) changed that layout, and the telemetry test, which useshaxe.Timerand its dynamicrun, crashed from then on. Old main with only that change crashes the same way, and so does stock hxcpp.The default closure now marks and visits its instance only when
hx::IsCollectedAllocfinds it in memory the collector manages.Tests:
DefaultFuncForeignThismakes such an instance in zeroed memory outside the heap and keeps its default closure. Before the change a collection wrote 1 byte there, after it none, at 32 and 64 bits and with HXCPP_GC_MOVING, HXCPP_GC_GENERATIONAL and HXCPP_GC_DEBUG_ALWAYS_MOVE.This blocks 6.0.0-rc.3, whose release workflow needs main green.