Repository navigation
Conversation
The CMC collector does not visit the declaring class of methods on the stack while compacting, and our malloc'd replacement ArtMethods are not in LinearAlloc, so their declaring_class_ goes stale before threads walk their stacks. Let MarkCompact::VisitRoots() update them on leave of CompactionPause(), while all threads are still suspended.
Author
|
I missed this when I opened this PR: #410 fixes the same root cause in a different way.
I tested #410 on the same device with the same repro. It fixes the crash too: 0/10 runs crashed with explicit GCs and 0/5 with allocation only, while main crashed 2/2 in each mode in the same session. The details are in my comment on #410. How the two approaches compare:
I'm fine with whichever approach you prefer. If you go with #410, I'll close this PR. |
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.
Refs #387, #394, frida/frida#3805
In my repro on Android 16 (CMC), the
DecodeGcMasksOnlycrash from #387 goes away with the access flags mask fix from 302a588, which is on main but not released yet. With that fix, the same repro hits the crash below. With both, the #387 symptom is gone in my repro.With the userfaultfd based CMC collector (used on this Android 16 device), the thread stack walk during compaction skips
VisitDeclaringClass(), because CMC updates ArtMethods in LinearAlloc separately. Replacement ArtMethods are malloc'd, so theirdeclaring_class_keeps the pre-compaction address whileThreadFlipVisitorwalks the stack. For a native frame, ART reads the shorty through that class and crashes inReferenceMapVisitor::VisitFrame(). The existing sync onHeap::CollectGarbageInternalleave runs after the flip, which is too late.Hook
MarkCompact::CompactionPause(), which runs with all threads suspended before any flip visitor. On leave, pass each replacement'sdeclaring_class_toMarkCompact::VisitRoots(), so the collector updates it to the post-compaction address.Tested on Samsung S24, Android 16 (BP4A.251205.006), arm64, Frida 17.25.2, with a stock-app repro. With explicit GCs, unpatched main crashed in 18 of 18 runs and this patch in 0 of 10. With allocation-driven (young) GCs only, main crashed in 5 of 5 runs and this patch in 0 of 5.
eslint libreports no problems.Not tested on a device running the CC collector. The CC sync hooks are unchanged, and
CompactionPause()only runs when MarkCompact is the active collector, so on CC the new hook is installed but never called.