ART GC overview
ART has a few different GC plans that consist of running different garbage collectors. Starting with Android 8 (Oreo), the default plan is Concurrent Copying (CC). The other GC plan is Concurrent Mark Sweep (CMS).
Some of the main characterstics of Concurrent Copying GC are:
- CC enables use of a bump-pointer allocator called RegionTLAB. This allocates a thread-local allocation buffer (TLAB) to each app thread, which can then allocate objects out of its TLAB by bumping the “top” pointer, without any synchronization.
- CC performs heap defragmentation by concurrently copying objects without pausing app threads. This is achieved with the help of a read-barrier which intercepts reference reads from the heap, without the need of any intervention from the app developer.
- GC only has one small pause, which is constant in time with regards to the heap size.
- CC extends to be a generational GC in Android 10 and higher. It enables collecting young objects, which often become unreachable fairly quickly, with little effort. This helps by increasing GC throughput and considerably delaying the need to perform a full-heap GC.
The other GC that ART still supports is CMS. This GC also supports compaction, but not concurrently. Compaction is avoided until the app goes into the background, at which time the app threads are paused to perform compaction. Compaction also becomes necessary when an object allocation fails due to fragmentation. In this case the app may potentially become unresponsive for some time.
Since CMS rarely compacts, and thus free objects may not be contiguous, it uses a free-list-based allocator called RosAlloc. It has a higher allocation cost as compared to RegionTLAB. Finally, because of internal fragmentation the memory usage for the Java heap can be higher for CMS than CC.
AOSP Documentation
Changing the GC type
By default, the CC collector runs in generational mode in Android 10 and higher. To disable generational mode, perform below steps.
Add Below lines in device mk file and build firmware image.
# Convert GC type to non-generational
PRODUCT_PROPERTY_OVERRIDES += \
dalvik.vm.gctype=nogenerational_cc
# Convert GC type to non-generational
PRODUCT_ART_USE_READ_BARRIER := false



Leave a Reply