Search code examples
androidgarbage-collectionjvm

Why Android VM not use G1 Garbage Collector


linked to https://developer.android.com/topic/performance/memory-overview#gc, android current gc seems to be CMS.

with g1 benefit, why android not use g1?


Solution

  • Your question is based on a number of false premises:

    1. Android does NOT use the OpenJDK CMS collector. It has its own garbage collector.

    2. The page that you linked to does NOT mention OpenJDK or CMS:

      • It does say that the Android GC is generational, but many, many collectors are generational.
      • It does NOT say that the Android collector is concurrent, which is one of the important characteristics of CMS and G1.
    3. Android is NOT based on the OpenJDK codebase. Therefore, the OpenJDK garbage collectors would not work in Android without (probably) a complete rewrite.

    4. OpenJDK is covered by GPLv2 with the classpath extension, so the source code would technically be available to be ported. However, the copyright remains with Oracle. I cannot imagine Google wanting to incorporate any Oracle copyright code into the Android codebase. (Especially given Oracle's unpleasant history of using litigation to gain a competitive advantage.)

    5. The platform requirements for Android and OpenJDK are significantly different. For example, OpenJDK is optimized for running services rather than apps. The characteristics that make G1 attractive on a typical enterprise server are not necessarily a good match for an "app" running on someone's mobile phone, where (for example) there is less RAM and fewer cores, and power consumption / battery life are critical concerns.

    In short, it doesn't make much sense for Android to support the G1 collector. And it is unlikely that it will ever happen.