Improve and cleanup post-compaction synchronization with mutators

Earlier we used to separate counters: one for synchronizing only
moving-space operations during moving-space compaction by gc-thread, and
another for overall SIGBUS handler, which covered both linear-alloc
space as well. Also, we first stopped mutators from doing anything in
SIGBUS handler, and then the GC-thread would unregister userfaultfd.
Given the lower priority of GC-thread, it could cause priority inversion.

However, after some recent changes related to ioctl batching, there is a
possibility to reduce the complexity and avoid the priority inversion.
We still use two counters but both in SIGBUS handler. The first counter
is used during compaction. Afterwards we switch to the second counter
before unregistering the spaces from userfaultfd. This way we let the
mutators map pages (mostly zero-pages) if and when the GC-thread falls
behind (due to lower priority). After both the counters are passed, it
is safe to clear the spaces and data-structures.

Bug: 320478828
Test: art/test/testrunner/testrunner.py --host
Change-Id: Ibd7f4306b007e1965567ae667288e60852f6da53
2 files changed