By Lifang Xia
Over the past three years, our team has undertaken the substantial task of porting Android 10 and Android 12 to the XuanTie C910 platform. During this period, we have also executed profound optimizations within the Android Runtime (ART). This journey of adaptation and enhancement was showcased at the 2023 North America RISC-V Summit last November, where we detailed our methodologies and achievements in advancing ART. This article aims to share insights into our work and the strides we have made.
Understanding ART
Before delving into the specifics of our optimization efforts, it is essential to grasp what ART entails. Within the Android ecosystem, all applications are developed in Java, with the Android SDK converting Java bytecode into the more platform-specific dex bytecode. This conversion underscores the pivotal role of the dex virtual machine in Android’s architecture. While Dalvik VM served this purpose until the Lollipop release, ART has been the standard since, introducing significant advancements.
ART Execution Overview
ART set itself apart from its predecessor by adopting the Ahead-Of-Time (AOT) compilation right from its inception with Lollipop. This approach compiles .dex bytecode into machine code during the application installation phase, allowing applications to run directly as machine code, markedly enhancing execution efficiency.
However, to mitigate the long installation times associated with pure AOT compilation, Android N introduced a hybrid model incorporating Just-In-Time (JIT) compilation. In this model, dex bytecode undergoes initial interpretation. When frequently invoked methods (hot methods) are identified, ART’s JIT compiler compiles these into machine code, which is used for subsequent executions, optimizing performance dynamically.
RISC-V Support in ART
Following an overview of ART’s foundational principles, we revisit our support initiatives for ART across two Android versions.
Android 10 Support
Our journey began in 2020 with the goal of enabling RISC-V support on Android 10. Initial phases focused on kernel and driver readiness, integration with the Clang compiler and build systems, Bionic library adaptations, and ensuring Shell launch capabilities.
Subsequent efforts on ART included implementing JNI calling conventions and runtime interface support, achieving Launcher initiation in approximately 20 minutes. By incorporating the RV64GC instruction set and optimizing both the Mterp assembly interpreter and JIT/AOT compilers, we significantly reduced Launcher startup times to 10 and 1 minute, respectively.
Android 12 Support
Building on our experiences, we extended our support to Android 12 in 2022. With a streamlined approach thanks to our prior endeavors, we introduced enhancements on a new hardware platform, TH1520, updated the Clang compiler to a Xuantie-optimized Clang 15 version, and made improvements to Bionic.
On ART for Android 12, we introduced the Nterp interpreter to streamline method invocation and integrated optimizations specific to the XuanTie extension instruction set, facilitated by Clang 15. These collective optimizations further reduced the Launcher startup time on TH1520 to 47 seconds, even with an increased number of services.
Community Contributions
Integral to our porting efforts has been our active contribution to the community, aiming to prevent redundant development efforts. Since September 2022, we have been consistently contributing porting changes to the AOSP community, amassing over 80 commits on ART. We’re grateful to Vladimir Mark, Ulya Trofimovich, and Santiago Aboy Solanes from Google for their detailed code reviews, ensuring the high-quality integration of our contributions.
XuanTie Extension Instruction Set Optimizations
Our latest optimization efforts have integrated support for the XuanTie extension instruction set within ART, covering integer computation, memory operations, bit manipulation, and the vector v0.7 instruction set. These enhancements span compiler optimizations, instruction generation, and runtime improvements, including assembly interpreters and Quick Entries. Furthermore, we have optimized the C and math libraries within Bionic using the XuanTie extension instruction set, achieving significant performance gains across various benchmarks.
XuanTie’s extended ISA brings about notable performance gains as compared to the RV64GC ISA:
- For Caffeine Mark, performance is improved by over 15% for the integer part and 4% for the floating-point part or method calling.
- For SCIMath2, performance is improved by over 15% in most use cases, with little impact in a small minority of SOR/Monte Carlo use cases.
- For a number of other programming languages, performance is dramatically improved, up to five times for the one that benefits most.
Conclusion
The adaptation of RISC-V on Android, particularly within ART, represents a nascent yet rapidly evolving endeavor. We are privileged to contribute to this historical development, collaborating with the global developer community to enhance Android’s compatibility with RISC-V. We encourage interested community members to engage with the RISC-V Android SIG and the Google RISCV64 community, fostering dialogue and contributions towards this collective goal.