kevin liu
kevin liu

Reputation: 53

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?

Upvotes: 1

Views: 369

Answers (2)

Stephen C
Stephen C

Reputation: 719109

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.

Upvotes: 1

nanofarad
nanofarad

Reputation: 41281

The G1 garbage collector is a feature of the Oracle JVM, but Android does not use the Oracle JVM. Furthermore, the G1 GC is unsuitable for mobile devices from a design standpoint which is likely a factor for why a similar algorithm wasn't implemented in the Android or Dalvik runtimes. From this page:

The Garbage-First (G1) collector is a server-style garbage collector, targeted for multi-processor machines with large memories.

Further, its memory overhead is higher, which is problematic for resource-constrained mobile devices:

If you migrate from the ... CMS collector to G1, you will likely see a larger JVM process size. This is largely related to "accounting" data structures such as Remembered Sets and Collection Sets.

Upvotes: 1

Related Questions