This repository allows MMTk to work with the Android Runtime (ART).
This repository hosts the MMTk-side of the binding. Our ART fork hosts the ART-side of the binding as well as any changes required to ART to allow MMTk to work. Our MMTk fork hosts changes to MMTk that are required to allow MMTk to work with ART.
We support the NoGC
, SemiSpace
, Immix
, StickyImmix
, GenImmix
, and GenCopy
plans in MMTk core.
We can run headless ART builds both on target and host and for both x86_64 and aarch64 devices.
NoGC
is only supported for headless ART builds.
We have allocation fast-paths implemented for all architectures.
We can boot an AOSP build on an x86_64 Cuttlefish VM with the SemiSpace
, Immix
, and StickyImmix
plans.
We can boot an AOSP build on an actual arm64 device with the SemiSpace
, Immix
, and StickyImmix
plans.
Since we had to add/change repositories to get MMTk to build with ART, we maintain our own repo
manifest file.
It is based off the master-art
manifest file.
We lock all versions of dependencies to ensure we can always build MMTk.
The ART fork is based on commit 451cfcf9d09515ef60d76bd8551fc68c6e3bf621
.
$ mkdir android-mmtk
$ cd android-mmtk
$ repo init -u https://github.com/k-sareen/mmtk-art-manifest -b mmtk-art
Set up the environment and build target.
$ source build/envsetup.sh
$ export VARIANT="eng"
$ lunch silvermont-trunk_staging-${VARIANT} # For Linux x86_64 host builds
OR for aarch64 device target:
$ lunch armv8-trunk_staging-${VARIANT} # For device target builds
If you want a release/performance build set the VARIANT
environment variable to userdebug
or user
.
Note: If you want MMTk to build in release mode as well, then you will have to comment out the debug build flags in
mmtk-core/Android.bp
and uncomment the release build flags inmmtk-core/Android.bp
as well asmmtk-art/Android.bp
.
To build MMTk ART with Immix
:
$ RUST_BACKTRACE=1 ART_USE_MMTK=true ART_USE_READ_BARRIER=false ART_USE_WRITE_BARRIER=false ART_DEFAULT_GC_TYPE=SS ./art/tools/buildbot-build.sh --{host,target} --installclean --skip-run-tests-build
To build MMTk ART with StickyImmix
:
$ RUST_BACKTRACE=1 ART_USE_MMTK=true ART_USE_READ_BARRIER=false ART_USE_WRITE_BARRIER=true ART_DEFAULT_GC_TYPE=SS ./art/tools/buildbot-build.sh --{host,target} --installclean --skip-run-tests-build
Set up the environment and build target.
$ source build/envsetup.sh
$ export VARIANT="eng"
$ banchan com.android.art ${VARIANT} x86_64 # For x86_64 target builds
OR for aarch64 device target:
$ banchan com.android.art ${VARIANT} arm64 # For arm64 target builds
See above if you want a release/performance build.
To build MMTk ART with Immix
:
$ RUST_BACKTRACE=1 ART_USE_MMTK=1 ART_USE_READ_BARRIER=false ART_USE_WRITE_BARRIER=false ART_DEFAULT_GC_TYPE=SS m apps_only dist
To build MMTk ART with StickyImmix
:
$ RUST_BACKTRACE=1 ART_USE_MMTK=1 ART_USE_READ_BARRIER=false ART_USE_WRITE_BARRIER=true ART_DEFAULT_GC_TYPE=SS m apps_only dist
MMTk core does not use any inline
attributes to avoid second guessing the compiler.
We've found that (ab)using inline
attributes can lead to performance degradation as well.
To that end, we use profile guided optimization (PGO) to inform the inlining decisions of the compiler.
We provide PGO profiles under the profiles/
directory for the supported plans for both headless and APEX builds.
If you want to enable PGO builds, you will have to add the profile file to the build command in the Android.bp
file.
Note that unfortunately due to how Android invokes rustc
and a Rust compiler bug, we can't use the -C linker-plugin-lto
flag as it triggers the bug.
We have currently disabled it for our PGO builds.
We use Cuttlefish images from this Android CI build.
We run the Cuttlefish VM like so:
$ HOME=$PWD taskset -c 0-3 ./bin/launch_cvd -report_anonymous_usage_stats=n --daemon --gpu_mode=guest_swiftshader -vm_manager=qemu_cli -cpus=4
QEMU was used since crosvm
was crashing on our development machines.
It is likely MMTk works with crosvm
but it is untested.
Install ART with adb
like so:
$ adb install /path/to/android/root/out/dist/com.android.art.apex
$ adb reboot
If everything is fine then you should boot into the Android lock screen.
You can check if you are using MMTk if it is printing logs in logcat like so:
$ adb logcat | grep "mmtk-art"
[...]
08-01 12:18:58.734 1025 1251 I mmtk-art64: mmtk::util::heap::gc_trigger: [POLL] immix: Triggering collection (7722/7721 pages)
08-01 12:18:58.736 1025 1039 I mmtk-art64: mmtk::plan::sticky::immix::global: Full heap GC
08-01 12:18:58.818 1025 1039 I mmtk-art64: mmtk::scheduler::scheduler: End of GC (7328/7991 pages, took 81 ms)
08-01 12:22:49.812 1025 1063 I mmtk-art64: mmtk::util::heap::gc_trigger: [POLL] immix: Triggering collection (7994/7991 pages)
08-01 12:22:49.814 1025 1040 I mmtk-art64: mmtk::plan::sticky::immix::global: Nursery GC
08-01 12:22:49.838 1025 1040 I mmtk-art64: mmtk::scheduler::scheduler: End of GC (7385/7991 pages, took 24 ms)
[...]
From the generational plans, only StickyImmix
is currently supported for APEX builds as the others do not have support for the ZygoteSpace
yet.
We've temporarily disabled loading app images at run-time since we currently do not have a way to remove image spaces inside MMTk. Once we have this functionality, we will enable this feature and register app images with MMTk.
The port has not been performance tuned at all. For example, currently the write barrier is a full call into MMTk even for the fast-path.