Closer Look At Android Runtime: DVM vs ART




Before directly move to Android Runtime, we need to understand what runtime environment is and also understand some basic stuff i.e. the functioning of JVM and Dalvik VM.


What is runtime?

In a simplest term it is a system used by operating system which takes care of converting the code that you write in a high level language like Java to machine code and understand by CPU/Processor.
Runtime comprises of software instructions that execute when your program is running, even if they’re not essentially are a part of the code of that piece of software in particular.

CPUs or more general term our computers understand only machine language (binary codes) so to make it run on CPU, the code must be converted to machine code, which is done by translator.

So following are the generation of translator in a sequence-

1.    Assemblers :
It directly translate assembly codes to machine codes so it was very fast.

2.    Compilers :
It translates the code into assembly codes and then use assemblers to translate the code into binary. Using this compilation was slow but execution was fast. But the biggest problem with compiler is that the resulted machine code was platform dependent. In other words the code which runs on one machine may not run on different machine.

3.    Interpreters :
It translates the code while executing it. Since the translation happens at runtime, the execution was slow.


How JAVA code execution works?

To maintain the platform independency of the code, JAVA developed JVM i.e. Java Virtual Machine. It developed JVM specific to every platform means JVM is dependency on the platform. The Java compiler converts the .java files into .class files, which is called byte code. This byte code is given to the JVM which converts it into machine code.
This is faster than interpretation but slower than C++ compilation.


How Android code execution works?

In Android Java classes converted into DEX bytecode. The DEX bytecode format is translated to native machine code via either ART or the Dalvik runtimes.  Here DEX bytecode is independent of device architecture.
Dalvik is a JIT (Just in time) compilation based engine. There were drawbacks to use Dalvik hence from Android 4.4 (kitkat) ART was introduced as a runtime and from Android 5.0 (Lollipop) it has completely replaced Dalvik. Android 7.0 adds a just-in-time (JIT) compiler with code profiling to Android runtime (ART) that constantly improves the performance of Android apps as they run.

Key Point: Dalvik used JIT (Just in time) compilation whereas ART uses AOT (Ahead of time) compilation.

Below are the code snippet explaining the difference between Dalvik Virtual Machine and Java Virtual Machine.


Just In Time (JIT)

With the Dalvik JIT compiler, each time when the app is run, it dynamically translates a part of the Dalvik bytecode into machine code. As the execution progresses, more bytecode is compiled and cached. Since JIT compiles only a part of the code, it has a smaller memory footprint and uses less physical space on the device.


Ahead Of Time (AOT)

ART is equipped with an Ahead-of-Time compiler. During the app’s installation phase, it statically translates the DEX bytecode 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. With no need for JIT compilation, the code executes much faster.


As ART runs app machine code directly (native execution), it doesn't hit the CPU as hard as just-in-time code compiling on Dalvik. Because of less CPU usage results in less battery drain.


ART also uses same DEX bytecode as input for Dalvik. An application compiled using ART requires additional time for compilation when an application is installed and take up slightly larger amounts of space to store the compiled code.


Why Android use Virtual Machine?

Android makes use of a virtual machine as its runtime environment in order to run the APK files that constitute an Android application. Below are the advantages:

·       The application code is isolated from the core OS. So even if any code contains some malicious code won’t directly affect the system files. It makes the Android OS more stable and reliable.

·       It provides cross compatibility or platform independency. It meaning even if an app is compiled on platform such as a PC, it can still be executed on the mobile platform using the virtual machine.


Benefits of ART

·       Apps run faster as DEX bytecode translation done during installation.
·       Reduces startup time of applications as native code is directly executed.
·       Improves battery performance as power utilized to interpreted byte codes line by line is saved.
·       Improved garbage collector.
·       Improved developer tool.


Drawbacks of ART

·       App Installation takes more time because of DEX bytecodes conversion into machine code during installation.
·       As the native machine code generated on installation is stored in internal storage, more internal storage is required.


Conclusion

ART is written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed specially for Android that's optimized for minimal memory footprint. It makes the UI feel more responsive. That’s all from my side. For more details on ART and Dalvik you can go through official Android document.


To find more interesting topics on Software development follow me
Medium   Twitter   GitHub





Comments

  1. The Showbox HD app is a highly user friendly app the size of which is very small and adjustable
    apps like showbox

    ReplyDelete
  2. wow I like your way of explanation.All the details are explained in detail manner. Get more Java Training in Marathahalli
    Java Training in Bangalore

    ReplyDelete
  3. Thanks for this, it will be helpful while playing games like good craft on my android.

    ReplyDelete
  4. Really simple to understand
    And I understand very good.

    ReplyDelete
  5. Nowadays, most of the people showing interest to build mobile application in Android operating system, since it is flexible for developers to develop an app, If you are interested to build your own app, go here for Android Training | Android Training in Chennai

    ReplyDelete
  6. Thanks for sharing. Keep sharing

    ReplyDelete
  7. Thanks for sharing. Keep sharing

    ReplyDelete
  8. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    RPA Training in Bangalore

    ReplyDelete
  9. I just want to say that all the information you have given here is awesome. Thank you..
    Best Software Training Centre in Chennai | Software Training Centre in Chennai

    ReplyDelete
  10. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    rpa training in Chennai | rpa training in pune

    rpa training in tambaram | rpa training in sholinganallur

    rpa training in Chennai | rpa training in velachery

    rpa online training | rpa training in bangalore

    ReplyDelete
  11. UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
    ui path training in bangalore

    ReplyDelete
  12. If you ever want to take some of the load off, I’d like to write some material for your blog in exchange for a link back to mine. Please shoot me an email if interested. Thanks.
    safety course institute in chennai

    ReplyDelete
  13. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi

    ReplyDelete
  14. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Training in Chennai
    Selenium Training in Chennai
    Devops Training in Chennai

    ReplyDelete
  15. Great Article. This Blog Contain Good information about ERP Software. Thanks For sharing this blog. Can you please do more articles like this blog.

    cloud erp in chennai
    cloud based erp software in chennai
    top erp software solutions in chennai
    Robotic Process Automation Chennai

    ReplyDelete
  16. Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
    Java Training in Electronic City

    ReplyDelete

  17. Such a wonderful blog on Mean Stack .Your blog having almost full information about
    Mean Stack ..Your content covered full topics of Mean Stack ,that it cover from basic to higher level content of Mean Stack .Requesting you to please keep updating the data about Mean Stack in upcoming time if there is some addition.
    Thanks and Regards,
    Best institute for mean stack training in chennai
    Mean stack training fees in Chennai
    Mean stack training institute in Chennai
    Mean stack developer training in chennai
    Mean stack training fees in OMR, Chennai





    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Thanks for your article. It was really helpful in understanding DVM vs ART. I've also written an article on DVM vs ART but it also goes deep into JVM: https://ayusch.com/art-vs-dvm-in-android/

    Would be great if you could have a look and give your feedback :)

    Cheers!

    ReplyDelete
  20. Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Python Training In Chennai & get to know everything you want to about software trainings.

    ReplyDelete
  21. Learn Amazon Web Services for making your career as a shining sun with Infycle Technologies. Infycle Technologies is the best AWS training centre in Chennai, providing complete hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Python, AWS, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.Best AWS Training in Chennai

    ReplyDelete
  22. Reach to the best Data Science Training institute in Chennai for skyrocketing your career, Infycle Technologies. It is the best Software Training & Placement institutes in and around Chennai. that also gives the best placement training for personality tests, interview preparation, and mock interviews for leveling up the candidate's grades to a professional level.

    ReplyDelete
  23. Chennai's best software training institute, Infycle Technologies, offers the No.1 Oracle DBA training in Chennai for tech professionals & students along with other courses such as Python, Big Data, Selenium, Java, Hadoop, iOS, and Android development with 100% hands-on training. Once the completion of training, the students will be sent for placement interviews in the core MNC's. Call 7502633633 to get more info and a free demo.Top Oracle DBA Training in Chennai | Infycle Technologies

    ReplyDelete
  24. Infycle Technologies, the No.1 software training institute in Chennai offers the No.1 Data Science course in Chennai for tech professionals and students at the best offers. In addition to the Data Science course, other in-demand courses such as Python, Selenium, Oracle, Java, Python, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  25. Infycle Technologies, the best software training institute in Chennai offers the leading Data Science course in Chennai for tech professionals, freshers, and students at the best offers. In addition to the Data Science course, other in-demand courses such as Python, Cyber Security, Selenium, Oracle, Java, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  26. Infycle Technologies, the top software training institute and placement center in Chennai offers the Best Digital Marketing Course in Chennai | Infycle Technologies for freshers, students, and tech professionals at the best offers. In addition to Digital Marketing, other in-demand courses such as DevOps, Data Science, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete

Post a Comment

Popular posts from this blog

Android Performance: Avoid using ENUM on Android

Smart way to update RecyclerView using DiffUtil

Android O: Impact On Running Apps And Developer Viewpoint