Android N 取消了AOT(Ahead of Time)编译,回归到了JIT(Just in Time)和AOT混合的编译模式。
同时采用Profile Guided Compilation

JIT记录程序运行的profile,在手机charge和idle时,会进行AOT编译

程序被解释运行时,JIT会kick in,周期性生成profile文件,当手机空闲时,profile guided compilation开始工作,生成二进制文件,取代原来的app code。

profile记录的信息包括
-
hot methods: 执行次数,是否在UI线程上执行
-
影响启动的class
-
code是否被其他应用share(full compilation)

系统启动时会启动AOT compilation daemon,当Device idle时会进行相应的编译

不同的场景有不同编译策略

AOT编译时,会将启动时使用类编译成pre-initialized class,然后生成Application image,在ClassLoader创建时加载进内存。
Android N里,unreachable classloader 和 class可以被GC。之前的版本是会一直驻留在程序内存中。
网友评论