Repository navigation
Clear the stack before CppiaAdoptInstances counts what a module keeps - #507
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
CppiaAdoptInstances failed once in the ASan job on Linux, on a pull request whose changes were all in the build tool, with "the old module keeps only what stayed: Reshaped x1, closures x2" in the JIT pass, where one closure stays. The next count, after the old values are dropped, was right, so nothing leaked. The census collection that counts what a released module keeps scans the frames it runs in for pointers, and a slot that nothing has written yet still holds what an earlier call left there. When that is the address of an object freed since, whose memory a closure of the old module now uses, the census counts the closure. Running every script call on a joined worker (cce2fed) kept the workers' values off the main thread's stack, but not the main thread's own leftovers. Planting the address of a dropped closure of the old module across the stack below main's frame before the count reproduces the line exactly, in both passes. main now clears 64 KB of stack below its frame before each count, so the frames the census scans start from zeros. main's own frame is scanned at every collection, so what it points to is never freed and cannot become a closure. Tests: on Windows x64 with MSVC 14.50 and Haxe 4.3.7, CppiaAdoptInstances matches stdout.txt in 40 runs, and in 25 under -D HXCPP_SANITIZE=address, where the old test also passed 25 times. With the dropped closure's address planted below main's frame, the old test prints closures x2 and the new one matches. Keeping a second closure of the old module for real still fails it, with closures x2 and the module not freed. The Linux ASan job has not run it yet.
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.
test/regression/CppiaAdoptInstancesfailed once in the ASan job on Linux, on #505, whose changes are all in the build tool:stdout.txtexpectsclosures x1, the bound method that stays. The next line,and is freed once they go: "", was right, so nothing leaked. The same runtime passed that job on other runs, including one at b6981ce.Why
The census collection behind
__scriptable_cppia_retainedscans the frames it runs in for pointers, as every collection does. A slot that nothing has written yet still holds what an earlier call left there. When that is the address of an object freed since, whose memory a closure of the old module now uses, the census counts the closure. cce2fed runs every script call on a joined worker, so the workers' values never reach the main thread's stack, but the main thread's own leftovers below its frame can still sit underretained()'s frames.Planting the address of a dropped closure of the old module across 64 KB of stack below
main's frame, just before the count, reproduces the CI line exactly, in both the interpreted and the JIT pass.The change
mainclears 64 KB of stack below its frame before each count, so every frame the census scans starts from zeros.main's own frame is scanned at every collection, so what it points to is never freed and cannot turn into a closure. Counting on a fresh worker instead would not do: glibc hands out the stacks of earlier threads from its cache without clearing them, and those threads ran the script code. Test only, so noChanges.mdline.Tests
On Windows x64 with MSVC 14.50 and Haxe 4.3.7:
stdout.txtin 40 runs, and in 25 under-D HXCPP_SANITIZE=address. The old test also passed 25 times under ASan here, as Windows lays the stack out differently, so the Linux ASan job is the real check.main's frame, the old test printsclosures x2, and this one matchesstdout.txt.closures x2andand is freed once they go: "Reshaped x1, closures x1".