16

This question is related to android system. Dalvik VM uses JIT concept, it means that when you first run application Dalvik VM compiles it and loads into RAM as long as it could stay there. I understand that concept. But new virtual machine called ART, uses AOT method. ART compiles app after you install it(or when you are installing it?). What this means ? Apps compiled by ART are the same as already compiled apps(like C apps) but run in a separate processes separated from the rest of OS ? Can somebody explains me this concepts more thoroughly. I have to make some presentation, and this is mentioning there, but I don't understand this concept and I don't want to look dumb if somebody asks me something about that :) Sorry for bad English, it would be nice if somebody could edit question a bit.

N J
  • 27,217
  • 13
  • 76
  • 96
user2982390
  • 163
  • 1
  • 9

2 Answers2

11

I am not completely familier how Dalvik JIT on Android works in practice, because JIT have several options how can work.

First option is, that JIT translate all bytecode into CPU instructions on application launch. This option spent some time before application launches and after that application can run as native. Problem is, that translated application has to kept in memory during launch, which is not good.

Second option is, that JIT works as real Just-In-Time, which means that translate block of code when is about to launch. Whole application is not translated on launch, but only main function is translated on launch and then is translated during run, when certain block of code (function etc.) is used. This option consumes less memory, but application is much slower during run.

According to informations I found, Android uses first option. Application is translated on launch and after that it runs "almost" natively. And this "almost" makes main difference between JIT and AOT.

When you are about to launch some application, JIT have only limited time to compile all bytecode to CPU instructions to make launch-lag "acceptable" long. This means, it can perform only basic optimizations. However, when you install some application, you have usually more time to waste and you are doing it only once - not on every launch. This means that AOT compiler has much more time to find tricks how to optimize that application. Resulted code should be more "efficient". Second benefit is, that compiled application is stored to cache and only part of it can be loaded to memory on launch. That means that OS hadn't keep whole code in memory and can save it. And that is main differences.

And last part of your question - ART on Android will perform compilation on installation (after saving apk to /data/app/). However, if you wipe that cache, or switch from Dalvik to ART, it will compile all installed application on first boot, which can take 10 or even more minutes.

And sorry for my bad english too, I am Czech :-)

micropro.cz
  • 598
  • 4
  • 17
  • I do not' understand the thing about ART. All applications are compiled and saved to cache, right ? And they then run natively ? – user2982390 Nov 30 '13 at 16:41
  • Just don't try understart AOT (like Art) and JIT (like Dalvik) like completely different things. They are really very similar. AOT/JIT is mostly name for certain compiler behavior. In some point ART/JIT behavior can be choosed like option in settings (it's not case of Art/Dalvik, but there are hunders of compilers out there). AOT and JIT compiler can share 95% of core code with no problem. However, both can have their specific optimizations which are not interchangable between these two kinds of behavior, but there optimizations are optional. It is not thing which makes difference between them – micropro.cz Nov 30 '13 at 20:03
  • AOT compiling is way how is compiled most application these days. Delphi, C++, C# etc. uses this kind of compilation. It is exactly the same thing. But on android, applications are not shared via their source code, but with precompiled bytecode. It is something between source code and native app. Keywords, variables etc. are converted to symbolic bytes, reduntant informations which are irrelevant are stripped of (whitespaces, variable names or sometimes even class/function names). This makes bytecode much smaller than source code and changing it is more difficult, because readability is ... – micropro.cz Nov 30 '13 at 20:08
  • ... negatively affected by stripping comments, variable names etc. Launching or compiling bytecode is much faster than interpreting source code. Languages like PHP are converting source code to bytecode before launch too (it's called Zend Engine 2 OpCode if you are interested). Back to your question ... AOT and JIT are not using interpreting method, which means that both has to emit native code. Main difference is WHEN is this code emmited (JIT before or during runtime) and JIT has some overhead, because it usually runs during application run and analyzes/compiles it... – micropro.cz Nov 30 '13 at 20:12
  • And yes, AOT compiles all apps to native code and keep this native code in cache. This native code is usually bigger (Google says about 10-20% that cached bytecode used by Dalvik). – micropro.cz Nov 30 '13 at 20:13
0

Ahead Of Time(AOT) - Android Runtime(ART) - generates machine byte code during installation.

[JIT vs AOT]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205