Repository navigation
test: flush GraalPy's inline caches before checking a class is collectable (#1963) - #2013
Merged
Merged
Conversation
) test_cache_is_per_class_and_collectable failed on GraalPy 25.4.4 in sharded runs. The class is not freed late: graalpython's LookupAttributeInMRONode.SlowPath.lookupConstantMRO caches the receiver class strongly, up to AttributeAccessInlineCacheMaxDepth classes, until lookupCachedLen replaces it (graal-25.4.4). So a class measured while a node in the nested-type walk still has room stays reachable however long gc.collect is given. Unsharded runs passed because earlier tests had already overflowed those caches. On GraalPy only, when the first collection leaves the class alive, send throwaway classes of the same shape through the walk and collect again. The smallest flush that frees the class every time equals the option's value, measured at the default and a raised one; the constant is headroom. A reinstated module-level WeakKeyDictionary pin still fails on both interpreters. CPython runs the check unchanged.
JarryShaw
force-pushed
the
test/1963-graalpy-cache-collectable
branch
from
October 21, 2026 04:38
7e5d9ba to
00179a5
Compare
Owner
Author
|
GOOD TO GO at
It asked for a source for the inline-cache claim, and Measured:
The test file passes on CPython (14) and on GraalPy (14). |
Contributor
|
Coverage: 91.55% (unit tier, Python 3.15,
Per-file detail: the |
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.
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
test— tests onlyDescription of your pull request and other information
On GraalPy,
test_cache_is_per_class_and_collectablefailed in the sharded runs of #2012, but not in an unsharded run. The cause is not #2010's late finaliser.GraalPy's attribute and call nodes cache the classes they see, and hold them strongly until the node goes megamorphic. A plain class stays pinned by a
cls.mro()call alone, with no pcapkit code involved. Waiting does not free it: a class stayed alive through 30 s of repeatedgc.collect(). It was only released once more classes went through the same nodes. A shard reaches the test with those caches still holding classes, whereas an unsharded run has already filled them.On GraalPy only, if the class survives the first
gc.collect(), the test now pushesINLINE_CACHE_FLUSHthrowaway classes of the same shape throughinfo_finaland_nested_info_types, then collects again. The gate issys.implementation.name. On CPython the flush count is 0, so the check runs exactly as before.Reproduced on GraalPy 25.4.4: the test method run repeatedly in one process failed in 7 of 20 runs before, and passed 20 of 20 after (200 of 200 under
--vm.Xmx400m). The test still catches a real leak. With a class-pinningWeakKeyDictionaryre-added, it fails on both GraalPy and CPython.Part of #1963.