ART: Android Run Time

Android apps are deployed in Dalvik bytecode, which is portable, unlike native code. In order to be able to run the app on a device, the code has to be compiled to machine code.

Every Android app runs on its own Virtual Machine which is called Dalvik.

Android Applications are compiled to bytecode(using java compiler) for the Java virtual machine, which is then translated to Dalvik bytecode (using dx compiler) and stored in .dex (Dalvik Executable) and .odex (Optimized Dalvik Executable) files;

Android apps are in .apk format, Java compiler converts applications written using java into DEX byte code format which is independent of device architecture and this DEX byte code needs to be converted to native code to run on the devices. Dalvik and ART will do this job.

Android Run Time(ART) was introduced in Kit kat on experimental basis.In Android Lollipop ART replaces Dalvik as a platform default.

Some of the major new features are:
  • Ahead-of-time (AOT) compilation
  • Improved garbage collection (GC)
  • Improved debugging support
To maintain backward compatibility, ART uses the same input bytecode as Dalvik.

Dalvik is based on JIT(Just In Time) compilation: 

  • Each time when the app is run, dalvik dynamically translates parts of byte code into machine code.
  • JIT requires extra memory for app cache data.
  • As you go through the app, additional code is going to be compiled and cached, so that the system can reuse the code while the app is running. Since JIT compiles only a part of the code, it has a smaller memory footprint and uses less physical space on the device.

ART is based on AOT( Ahead Of Time) compilation: 
  • New Run time in Android Lollipop.
  • AOT compilation eliminates compiling byte code to machine code at launch and instead performs this step at installation time. When the app is installed the runtime will convert the DEX and ODEX files to OAT (ART) files using the dex2oat tool.
  • During the app’s installation, ART compiler statically translates the DEX byte code into machine code and stores in the device’s storage. This is a one-time event which happens when the app is installed on the device.
  • DEX byte code is translated to machine code during installation, no extra time is needed to compile it during the run time.
  • ART compiler takes longer time to install app on device.

No comments:

Post a Comment