When attempting to understand Android Runtime, I came across the wikipedia page. The graphic shown there adds to my confusion. If .dex is getting converted entirely to ELF, why is ART needed anymore?

Once an application is compiled by using ART's on-device dex2oat utility, it is run solely from the compiled ELF executable; as a result, ART eliminates various application execution overheads associated with Dalvik's interpretation and trace-based JIT compilation

My understanding is that ART converts .dex to ELF and the code should run natively. With ELF, is a virtual machine still involved? With ART, does the android application stack look like -

Android Apps
ART (executing ELF)

Am I understanding this correctly? Should I see ART as an OS that provides services to the ELFed Android App?


2 Answers 2


While OAT file is an ELF file, it is not your usual executable ELF with everything in it including the entrypoint. It actually has a small number of symbols that are beginning and end of a binary blob which in turn contains the executable code of compiled methods. Now which methods should be called or when is all determined by runtime.

How it all works - a class is loaded. There is a C++ object that represents the Java object that is that class. Then an instance of that class is created. That's another C++ object. Than a method of that object is called. You find the object's class and find the method entrypoint (which is the compiled code). That code calls some other method - for that you will return back to runtime code, find another object and its class and call the new method again. There are no direct calls between methods (that I know of).

All this linking and resolution is actually done at each application start. Bootclasspath stuff is initialized once and then the process is forked so the children don't have to re-init bootclasspath (it's a bit more complex than that because of boot.art actually).

So the ART is still a JVM and OAT files are just some intermediate representation of some pre-compiled code. The fact that they are ELF files doesn't help much - could be something else.

P.S. Actually OAT file also contains all the DEX files which were used to create it. It is needed to construct the classes and methods. It is also possible to run application in interpreter mode when it actually executes DEX instructions directly.

  • Ah, okay, so even the method dispatch code is not inlined but part of the runtime? May 29, 2015 at 12:59
  • Each art method has an "entrypoint from compiled code" which in turn usually points directly to compiled code. It is possible that some method calls are inlined in the boot classpath because boot.oat is loaded to a fixed address unlike other oat files. This does interfere with step-by-step debugging thought and there was a commit somewhere that did fix this by reverting from "selective deoptimize" to "deoptimize everything" when debugging boot classpath things.
    – aragaer
    May 29, 2015 at 13:27
  • Interesting, thanks for the explanation. I never thought about what a design for a mostly static implementation for a mostly dynamic language ("dynamic" in the sense that all code loading, most method dispatch, and consequently all linking is dynamic) would look like. I'm only familiar with HotSpot, JRockit, J9, etc. which are mostly dynamic implementations and typical C++ implementations which are mostly static but for a mostly static language. ART is the first I have looked at which is mostly static for a mostly dynamic language. (Others are Excelsior.JET and GCJ, but I don't know them.) May 29, 2015 at 13:56

ART is the Android Runtime, and in addition to the (static) AOT compiler which compiles Dalvik bytecode to native machine code, it also contains all of the runtime services that an Android program needs: the memory allocator, garbage collector, reflection system, core classes and interfaces, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.