Refactoring android Java code for on-demand computation offloading

Ying Zhang, Gang Huang, Xuanzhe Liu, Wei Zhang, Hong Mei, Shunxiang Yang

TL;DR

This paper introduces DPartner, an automatic tool that refactors existing Android applications to enable on-demand computation offloading. By analyzing bytecode and intelligently rewriting it, DPartner allows computationally intensive parts of an app to run on a remote server, significantly reducing execution time and battery consumption on the smartphone.

What Problem Does This Paper Address?

Modern smartphones are powerful, but their capabilities are limited by battery life and the diversity of hardware configurations. As Android applications become increasingly complex, they push these limits, leading to slow performance and rapid battery drain. Developers face significant challenges in implementing computation offloading: they must identify which code can run remotely (correctness), ensure offloading actually speeds things up (effectiveness), and handle dynamic changes in user needs and environments (adaptability). Crucially, existing solutions often require developers to manually modify their code or use specialized frameworks, making them impractical for the vast number of legacy Android applications.

Methods

The core of this work is the DPartner tool, which automates the process of refactoring Android applications for computation offloading. DPartner employs a four-step approach:

  1. Detect Movable Classes: It analyzes bytecode to classify classes as either "anchored" (must run on the phone due to reliance on device-specific sensors or UI) or "movable" (can run either on the phone or server). This classification can be customized by developers.
  2. Generate Proxies and Transform Classes: For movable classes, DPartner generates proxy classes that mimic the original class's behavior but forward method calls to a remote endpoint. It also transforms the app's classes to use these proxies and handles specific Java features like arrays and static methods.
  3. Cluster App Classes: To optimize runtime decision-making, DPartner clusters frequently interacting movable classes. This allows entire groups of related classes to be offloaded together, reducing inter-class communication overhead. The clustering algorithm combines call graph analysis with semantic similarity of class names and content.
  4. Package Deployable Files: Finally, DPartner generates two artifacts: a refactored .apk file for the smartphone and a .jar file containing the offloadable components for the server.

The system also includes an "endpoint" component on the server that manages the actual offloading and communication, dynamically deciding which computations to offload based on performance and energy consumption models.

Datasets

The paper evaluates DPartner on three real-world Android applications:

  • Linpack: A benchmark for numerical linear algebra computations.
  • Chess Game (Andgoid): An interactive chess application where the AI player's computations are computationally intensive.
  • 3D Car Game (XRace): A game that relies heavily on gravity sensor input and complex collision detection logic.

These apps were chosen because they are computation-intensive and representative of categories like entertainment, games, and media.

Key Insights and Ideas

  • Automatic Refactoring is Key: The most significant contribution is the automation of computation offloading for existing Android apps. This bypasses the need for manual code modification, making offloading accessible to a much wider range of applications.
  • Class-Level Offloading is Practical: By refactoring at the class and object level, the approach is well-suited for object-oriented programming paradigms common in Android development.
  • Clustering for Efficiency: Grouping related classes for offloading is crucial. It not only reduces the overhead of individual class offloading decisions but also minimizes inter-class communication, which can be a major bottleneck.
  • On-Demand Adaptation is Essential: The system's ability to dynamically adjust offloading based on network conditions (RTT, packet loss) is vital for real-world usability. When offloading becomes detrimental, computations are seamlessly brought back to the phone.
  • Network Quality Matters Greatly: The performance gains are highly dependent on network latency. While Wi-Fi offers good results, 3G networks, despite slower speeds, can still yield significant benefits, especially for computation-intensive tasks with low data exchange.

Key Results

  • Execution Time Reduction: Offloaded apps showed significant reductions in execution time, ranging from 46% to 97%.
  • Battery Power Reduction: Battery power consumption was reduced by 27% to 83%.
  • Refactoring Overhead: The refactoring process itself increases app size and takes time, but this is considered acceptable as it's a one-time, pre-runtime cost. The increase in app size was generally manageable.
  • Network Impact: Performance degrades with increasing Round Trip Time (RTT). Offloading only the most computation-intensive class (without considering clusters) can sometimes lead to worse performance than running entirely on the phone due to network overhead.
  • 3G Performance: Even with slower 3G networks (around 360ms RTT), significant performance improvements (e.g., 82.2% reduction in execution time for the chess game) were observed, though power consumption increased compared to Wi-Fi.

Limitations and Future Work

  • Obfuscated Code: DPartner's current bytecode refactoring libraries (Dexmaker, ASM) have limitations in fully supporting obfuscated bytecode, which is common in commercial Android apps.
  • Measurement Tools: The authors suggest using more accurate external current meters for power consumption measurements and dedicated routers for network traffic analysis.
  • Algorithm Refinement: Further exploration of rules and algorithms for deciding which classes to offload is planned.
  • 3G Network Testing: More extensive experiments on 3G networks are needed.
  • Server Performance: The performance of the offloaded app is heavily influenced by the server's processing power.
  • Dynamic Adaptation: While the system adapts to network conditions, further research into more sophisticated prediction algorithms for offloading decisions is suggested.

Summary updated

Abstract

Computation offloading is a promising way to improve the performance as well as reducing the battery power consumption of a smartphone application by executing some parts of the application on a remote server. Supporting such capability is not easy for smartphone application developers due to (1) correctness: some code, e.g., that for GPS, gravity, and other sensors, can run only on the smartphone so that developers have to identify which parts of the application cannot be offloaded; (2) effectiveness: the reduced execution time must be greater than the network delay caused by computation offloading so that developers need to calculate which parts are worth offloading; (3) adaptability: smartphone applications often face changes of user requirements and runtime environments so that developers need to implement the adaptation on offloading. More importantly, considering the large number of today's smartphone applications, solutions applicable for legacy applications will be much more valuable. In this paper, we present a tool, named DPartner, that automatically refactors Android applications to be the ones with computation offloading capability. For a given Android application, DPartner first analyzes its bytecode for discovering the parts worth offloading, then rewrites the bytecode to implement a special program structure supporting on-demand offloading, and finally generates two artifacts to be deployed onto an Android phone and the server, respectively. We evaluated DPartner on three real-world Android applications, demonstrating the reduction of execution time by 46%-97% and battery power consumption by 27%-83%.
BibTeX
@inproceedings{zhang2012refactoring,
  author = {Ying Zhang and Gang Huang and Xuanzhe Liu and Wei Zhang and Hong Mei and Shunxiang Yang},
  title = {{Refactoring android Java code for on-demand computation offloading}},
  booktitle = {OOPSLA},
  year = {2012},
  doi = {10.1145/2384616.2384634},
}

Loading related content...

Figure