How Java Executes and Performs Better _ Javalobby
-
Upload
faizanahmed963 -
Category
Documents
-
view
18 -
download
0
description
Transcript of How Java Executes and Performs Better _ Javalobby
-
2/22/2015 HowJavaExecutesandPerformsBetter|Javalobby
http://java.dzone.com/articles/howjavaexecutesandperforms 1/3
Search
LINKS REFCARDZ GUIDES ABOUT POST LOG IN or JOIN
Working on Android, iOS or Windows Phone apps? Check out our Mobile Zone
How Java Executes and Performs Better09.22.2014 | 12586 VIEWS | Tweet 12
ThePerformance ZoneispresentedbyAppDynamics.AppDynamicsisaleadersintheAPMspacewithmassive cost reductionsforusers.
Please bear with my attempt to inform you a little regarding the execution of Java code.
Javas code is compiled into byte code, which Javas virtual machine executes. This output is an
intermediate language (IL) that is neither human readable nor machine-executable. Only the virtual
machine understands it. To execute this output, the virtual machine uses a Just in Time (JIT) compiler
to interpret the byte code so is Java an interpreted language as some people describe it, or is Java
a compiled language? The answer: Java is both. Its source code is compiled with a static compiler
into byte code and then, the JIT interprets the compilers output.
From the previous description, one might be tempted to conclude that the JIT hurts performance, as it
compiles during execution, a design that would seem to cause Java to run slowly. This conclusion,
while intuitive, is incorrect. The JIT actually performs quite well. At run time, it compiles byte code
into machine code, which is later run by the CPU. When Java executes, it executes machine code just
as native code does so it should run discounting the JITs compilation costs as fast as native
code does.
However, C/C++ is generally regarded as providing better performance than Java does. The on-the-fly
nature of Javas execution lends credence to this thinking. Compiling a piece of code into machine
code takes a non-trivial amount of time. If a language executes similar machine instructions but does
not need compilation prior to the execution of them, then one can assume that the language in
question runs faster than Java does even when Javas machine code output is maximally
optimized. However, Java isnt maximally optimized, but C++ is not maximally optimized either. No
compiler can match the performance of a top-notch assembly programmer who is an expert at
manipulating the targeted hardware so both Java and C++ can never be maximally optimized.
Making matters worse, both languages have inherent issues. Java must bear the reality that at least
some of its code has to be compiled every time that it runs, and C++ is, when it must be generic,
often not fully tailored to its hardware, as Java always is. Even with the aforementioned handicap, one
still expects Javas compilation cost to give C++ an edge in every scenario outside of very poorly
coded or compiled C++.
However, appearances are deceiving; the JVM is a very intelligent environment and the JIT an
ZONES: AGILE BIG DATA CLOUD DEVOPS ECLIPSE INTEGRATION IOT JAVA MOBILE NOSQL PERFORMANCE WEB DEV
Performance Zone is brought to you in partnership with:
A. N. M. BAZLUR RAHMAN Bio Website @bazlur_rahman
20Like SHARE 29
Publish an Article Share a Tip
Connect with DZone
RELATED MICROZONE RESOURCES
How to Improve Quality Mobile ApplicationDelivery
Top 10 Java Performance Problems
5 Reasons You Need To Monitor
Performance in the Enterprise: A SurvivalGuide
APM Customer gets his life back with usingAppDynamics
DZONES GUIDE TO
CONTINUOUSDELIVERYDiscover many areas ofDevOps implementation andmanagement, and the bestpractices of ContinuousDelivery.
Download the Guide
http://dzone.com/mz/mobilehttp://www.linkedin.com/groups?gid=696877&trk=hb_side_ghttp://dzone.com/corporate/abouthttp://java.dzone.com/www.bazlur.comhttp://www.dzone.com/links/index.htmlhttp://txt.couchware.com/medias/jump?hid=3249&cid=491&mid=1355http://adclick.g.doubleclick.net/aclk?sa=L&ai=BPI8biarpVLjlFsL58gOT64GQA8bC5fECAAAAEAEg4tPyBjgAWI6S5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIeLzI5MTYwNzAvem9uZXNfdG9wYmx1cmJfNjUweDYx-AL_0R6AAwGQA_wHmAOkA6gDAeAEAaAGFtgHAA&num=0&sig=AOD64_2LhoywI0hKv5RkcdvrNBQtvDeLfw&client=ca-pub-3945085396033279&adurl=/mz/high-performancehttp://dzone.com/page/researchhttp://java.dzone.com/users/bazlurrahmanmailto:[email protected]://txt.couchware.com/medias/jump?hid=3253&cid=491&mid=1359javascript:void(0);http://dzone.com/mz/cloudhttp://java.dzone.com/user/register?clean=truehttp://www.facebook.com/home.php?#/pages/DZone/259639764711?ref=sgmhttp://dzone.com/mz/devopshttp://www.github.com/https://github.com/rokon12http://twitter.com/dzonehttp://java.dzone.com/userhttp://adclick.g.doubleclick.net/aclk%253Fsa%253DL%2526ai%253DBRyQjiKrpVObiKoOB8QPB9YHgB_7Y77IGAAAAEAEg4tPyBjgAWMaUneO_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIcLzI5MTYwNzAvem9uZXNfdGV4dGFkXzgwMHgyMPgC_9EekAP8B5gDpAOoAwHQBJBO4AQBoAYW2AcA%2526num%253D0%2526sig%253DAOD64_36jW3qDojsgZfvvUngoTCFTKtq8w%2526client%253Dca-pub-3945085396033279%2526adurl%253Dhttp://dzone.com/mz/mobile?utm_source=dzone&utm_medium=textad&utm_campaign=Androidhttps://plus.google.com/+dzone/postshttp://java.dzone.com/http://dzone.com/mz/big-datahttp://feeds.dzone.com/dzone/frontpagehttp://txt.couchware.com/medias/jump?hid=3247&cid=491&mid=1353http://dzone.com/mz/enterprise-integrationhttp://refcardz.dzone.com/http://eclipse.dzone.com/http://adclick.g.doubleclick.net/aclk%253Fsa%253DL%2526ai%253DBPI8biarpVLjlFsL58gOT64GQA8bC5fECAAAAEAEg4tPyBjgAWI6S5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIeLzI5MTYwNzAvem9uZXNfdG9wYmx1cmJfNjUweDYx-AL_0R6AAwGQA_wHmAOkA6gDAeAEAaAGFtgHAA%2526num%253D0%2526sig%253DAOD64_2LhoywI0hKv5RkcdvrNBQtvDeLfw%2526client%253Dca-pub-3945085396033279%2526adurl%253Dhttp://www.appdynamics.comhttp://dzone.com/mz/nosqlhttp://www.dzone.com/links/index.htmlhttp://dzone.com/mz/iothttp://dzone.com/mz/agilehttp://www.facebook.com/rokonoidhttp://dzone.com/mz/html5http://txt.couchware.com/medias/jump?hid=2997&cid=491&mid=1105http://dzone.com/node/addhttps://twitter.com/bazlur_rahmanhttp://txt.couchware.com/medias/jump?hid=2995&cid=491&mid=1103mailto:[email protected]://adclick.g.doubleclick.net/aclk%253Fsa%253DL%2526ai%253DBPI8biarpVLjlFsL58gOT64GQA8bC5fECAAAAEAEg4tPyBjgAWI6S5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIeLzI5MTYwNzAvem9uZXNfdG9wYmx1cmJfNjUweDYx-AL_0R6AAwGQA_wHmAOkA6gDAeAEAaAGFtgHAA%2526num%253D0%2526sig%253DAOD64_2LhoywI0hKv5RkcdvrNBQtvDeLfw%2526client%253Dca-pub-3945085396033279%2526adurl%253Dhttp://txt.couchware.com/medias/jump?hid=2991&cid=491&mid=1099http://java.dzone.com/node/addhttp://dzone.com/mz/performancehttp://www.linkedin.com/in/bazlur
-
2/22/2015 HowJavaExecutesandPerformsBetter|Javalobby
http://java.dzone.com/articles/howjavaexecutesandperforms 2/3
intelligence compiler. For example, the JVM knows which methods are called frequently, as it
maintains a count of each methods calls. When this count exceeds a certain threshold, the methods
machine code is kept, so that the JIT does not have to compile the method when it is called again a
decision that greatly reduces the cost of translating byte code into machine code. Furthering this
performance improvement, the JIT optimizes the most frequently used code. The JIT collects statistics
to determine which parts of code fit this mold. Intelligent optimization of this ilk can, as Research
indicates, yield big gains. Most research states that 80% of execution time is spent executing 20% of
the code (hot code) so optimizing these sections of code can yield sizeable performance benefits.
The JIT optimizes hot code. It executes these sections in a highly optimized way directly on the
operating system. To achieve this goal, the JIT uses statistics to identify the hot code. In fact, Java
performs even more optimization than efficiently executing hot code. It identifies the code that it
executes the most and recompiles to run more efficiently than it previously did. These optimizations
allow Java to achieve, in certain situations, better performance than C++ gives, without the need to
resort to dangerous compiler settings or to dangerous optimization techniques.
Published at DZone with permission of its author, A. N. M. Bazlur Rahman. (source)
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)
Tags: compilation execution Java java jit performance Tips and Tricks
Performance
ThePerformance ZoneispresentedbyAppDynamics.Scalabilityandbetterperformanceareconstantconcernsforthedeveloperandoperationsmanager.TryAppDynamics'fully-featuredperformance tool for Java, .NET, & PHP.
AROUND THE DZONE NETWORK
ARCHITECTS
Top Posts of 2013: BigData BeyondMapReduce: Goog...
JAVALOBBY
Top Posts of 2013: ThePrinciples of JavaApplicat...
ARCHITECTS
5 Things a JavaDeveloper ShouldConsider This Yea...
JAVALOBBY
Top Posts of 2013:There Are Only 2 Rolesof Code
JAVALOBBY
Singleton DesignPattern AnIntrospection w/ B...
SERVER
Best Best PracticesEver
Save settings
Comments
Comment viewing options
Flatlistexpanded Dateoldestfirst 30commentsperpage
Select your preferred way to display the comments and click "Save settings" to
activate your changes.
Advait Trivedi replied on Thu, 2014/09/25 - 11:18pm
Hi Rahman,
Well written article.. short and simple.
Login or register to post comments
A. N. M. Bazlur... replied on Sun, 2014/10/19 - 12:33am
Thanks
Login or register to post comments
in response to: Advait Trivedi
My Most Frequent CodeReview Comment
We Can't MeasureProgrammer Productivity orCan We?
DevNexus Conference:Gearing up for DEVolution
An Exhaustive List ofDeveloper Topic Newsletters
Spotlight Features
http://java.dzone.com/click/191565/1http://java.dzone.com/category/content-form/tips-and-trickshttp://java.dzone.com/user/register?destination=node%2F177103%23comment-formhttp://java.dzone.com/http://architects.dzone.com/http://java.dzone.com/click/189383/1http://java.dzone.com/user/login?destination=node%2F177103%23comment-formhttp://java.dzone.com/click/189199/1http://adclick.g.doubleclick.net/aclk%253Fsa%253DL%2526ai%253DB67YqjqrpVOPVM8Oa8wOpm4GICMbC5fECAAAAEAEg4tPyBjgAWIaT5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIiLzI5MTYwNzAvem9uZXNfYm90dG9tYmx1cmJfNjUweDEyMvgC_9EegAMBkAP8B5gDpAOoAwHgBAGgBhbYBwA%2526num%253D0%2526sig%253DAOD64_1TmScCP-kQKY_0YbByuXTpLjXF4Q%2526client%253Dca-pub-3945085396033279%2526adurl%253Dhttps://portal.appdynamics.com/account/signupB/signupForm/?utm_expid=67797221-32.8-Uo8xToReOtBY4c7ksr7A.1&utm_source=dzone&utm_medium=display&utm_campaign=zone%20co-sponsorship%20q3%202013%20&utm_content=free%20appdynamics%20pro%20tool&utm_term=blog_sponsor_linkhttp://adclick.g.doubleclick.net/aclk%253Fsa%253DL%2526ai%253DB67YqjqrpVOPVM8Oa8wOpm4GICMbC5fECAAAAEAEg4tPyBjgAWIaT5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIiLzI5MTYwNzAvem9uZXNfYm90dG9tYmx1cmJfNjUweDEyMvgC_9EegAMBkAP8B5gDpAOoAwHgBAGgBhbYBwA%2526num%253D0%2526sig%253DAOD64_1TmScCP-kQKY_0YbByuXTpLjXF4Q%2526client%253Dca-pub-3945085396033279%2526adurl%253Dhttp://www.appdynamics.comhttp://server.dzone.com/http://java.dzone.com/click/189199/1http://java.dzone.com/articles/principles-java-applicationhttp://java.dzone.com/category/tags/compilationhttp://architects.dzone.com/http://java.dzone.com/click/190407/1http://java.dzone.com/articles/singleton-design-pattern-%E2%80%93http://java.dzone.com/category/tags/executionhttp://java.dzone.com/articles/there-are-only-2-roles-codehttp://architects.dzone.com/articles/5-things-java-developer-shouldhttp://server.dzone.com/articles/best-best-practices-everhttp://java.dzone.com/http://java.dzone.com/click/190407/1http://java.dzone.com/click/189383/1http://java.dzone.com/taxonomy/term/66http://java.dzone.com/category/tags/performancehttp://bazlur.quora.com/How-the-java-executes-and-performs-betterhttp://java.dzone.com/category/tags/jithttp://java.dzone.com/user/login?destination=node%2F177103%23comment-formhttp://java.dzone.com/http://java.dzone.com/user/register?destination=node%2F177103%23comment-formhttp://java.dzone.com/users/bazlurrahmanhttp://java.dzone.com/click/191565/1http://java.dzone.com/category/dzone-taxonomy/javahttp://adclick.g.doubleclick.net/aclk?sa=L&ai=B67YqjqrpVOPVM8Oa8wOpm4GICMbC5fECAAAAEAEg4tPyBjgAWIaT5sC_AWDL1LQFsgEOamF2YS5kem9uZS5jb226AQlnZnBfaW1hZ2XIAQnaAT1odHRwOi8vamF2YS5kem9uZS5jb20vYXJ0aWNsZXMvaG93LWphdmEtZXhlY3V0ZXMtYW5kLXBlcmZvcm1zwAIC4AIA6gIiLzI5MTYwNzAvem9uZXNfYm90dG9tYmx1cmJfNjUweDEyMvgC_9EegAMBkAP8B5gDpAOoAwHgBAGgBhbYBwA&num=0&sig=AOD64_1TmScCP-kQKY_0YbByuXTpLjXF4Q&client=ca-pub-3945085396033279&adurl=/mz/high-performancehttp://architects.dzone.com/articles/big-data-beyond-mapreducehttp://java.dzone.com/category/dzone-taxonomy/java/performance
-
2/22/2015 HowJavaExecutesandPerformsBetter|Javalobby
http://java.dzone.com/articles/howjavaexecutesandperforms 3/3
Code Golf: Fibonacci's Sequence
11 Mistakes that Come Back to Bite Experience Java Developers
An Exhaustive List of Developer Topic Newsletters
"NoSQL Injection" - What 40000 Unsecured MongoDB Databases Mean for ourIndustry
Geek Reading February 13, 2015
You Need Feature Teams to Produce Features
How do you estimate that which you've never done?
Testing AngularJS Applications
What Development & Test Managers do in Agile Organizations
Thread Magic Tricks: 5 Things You Never Knew You Can Do with Java Threads
Required Reading: Iron Clad Java
Docker and Its Challenges for Enterprise IT
The Best of DZone: Feb. 11 - Feb. 18
What Are the Leading Trends in Cloud Computing?
Diary of Scrum: Something More Chaotic
YOU MIGHT ALSO LIKE
Search
Refcardz Book ReviewsTech Library IT QuestionsSnippets My ProfileAbout DZone AdvertiseTools & Buttons Send Feedback
DZone
HTML5 Windows PhoneCloud Mobile.NET JavaPHP EclipsePerformance Big DataAgile DevOps
Topics
Google +
Facebook
LinkedIn
Twitter
Follow Us
PithyAdviceforProgrammers
"Startingfromscratch"isseductivebutdiseaseridden
POPULAR ON JAVALOBBY
Spring Batch - Hello World
Is Hibernate the best choice?
How to Create Visual Applications inJava?
9 Programming Languages To WatchIn 2011
Introduction to Oracle's ADF FacesRich Client Framework
Interview: John De Goes Introduces aNewly Free Source Code Editor
Lucene's FuzzyQuery is 100 timesfaster in 4.0
Time Slider: OpenSolaris 2008.11Killer Feature
LATEST ARTICLES
Thinking Fast and Slow with SoftwareDevelopment
How you can collaborate with yourenemies
The rise of social gaming
SpringOne2GX 2014 Replay: RESTfulGrails 2
Another Reason Natural LogarithmsAre Natural
I Dropped a Large Binary Object inGit... Now What?
SpringOne2GX 2014 Replay: TestingJava, Groovy, Spring and WebApplications with Spock
Crap tech industry metaphors
SPOTLIGHT RESOURCES
EssentialCouchbase APIs:Open SourceNoSQL DataAccess fromJava, Ruby, and.NET
Practical DNS:ManagingDomains forSafety,Reliability, andSpeed
Camel EssentialComponentsDZone's 170thRefcard is anessential reference toCamel, an open-source, lightweight,integration library.This Refcard isauthored by...
Advertising - Terms of Service - Privacy - 1997-2014, DZone, Inc.
http://www.dzone.com/links/buttons.jsphttp://dzone.com/mz/performancehttp://java.dzone.com/page/privacyhttp://ask.dzone.com/index.htmlhttp://mobile.dzone.com/http://books.dzone.com/http://java.dzone.com/articles/springone2gx-2014-replay-20http://library.dzone.com/http://www.dzone.com/corporate/advertisehttp://server.dzone.com/articles/geek-reading-february-13-2015http://java.dzone.com/news/9-programming-languages-watchhttp://server.dzone.com/articles/code-golf-fibonaccis-sequencehttp://java.dzone.com/http://snippets.dzone.com/http://itquestions.com/index.htmlhttp://java.dzone.com/news/killer-feature-opensolaris-200http://www.dzone.com/links/about.jsphttp://server.dzone.com/articles/what-development-test-managershttp://www.linkedin.com/groups/DZone-696877http://dzone.com/http://server.dzone.com/articles/required-reading-iron-cladhttp://server.dzone.com/articles/docker-and-its-challengeshttp://java.dzone.com/articles/thinking-fast-and-slowhttp://server.dzone.com/articles/11-mistakes-come-back-bitehttp://dzone.com/mz/html5http://java.dzone.com/news/introduction-oracles-adf-faceshttp://java.dzone.com/articles/how-you-can-collaborate-yourhttp://dzone.com/mz/html5http://server.dzone.com/articles/nosql-injection-what-40000http://java.dzone.com/page/advertisehttp://java.dzone.com/news/hibernate-best-choicehttp://refcardz.dzone.com/refcardz/couchbase-apishttp://server.dzone.com/articles/you-need-feature-teams-producehttp://www.dzone.com/mz/big-datahttp://java.dzone.com/news/lucenes-fuzzyquery-100-timeshttp://server.dzone.com/articles/linksheet-exhaustive-listhttp://java.dzone.com/articles/i-dropped-large-binary-objecthttp://server.dzone.com/articles/diary-scrum-something-morehttps://plus.google.com/+dzone/postshttp://agile.dzone.com/http://refcardz.dzone.com/refcardz/dnshttp://java.dzone.com/page/toshttp://refcardz.dzone.com/http://server.dzone.com/articles/best-dzone-feb-11-feb-18http://dzone.com/mz/devopshttp://www.facebook.com/pages/DZone/259639764711http://java.dzone.com/articles/rise-social-gaminghttp://php.dzone.com/http://dzone.com/mz/windowsphone7http://java.dzone.com/articles/another-reason-naturalhttp://java.dzone.com/articles/crap-tech-industry-metaphorshttp://server.dzone.com/articles/what-are-leading-trends-cloudhttp://dzone.com/mz/dotnethttp://server.dzone.com/articles/how-do-you-estimate-whichhttp://server.dzone.com/articles/thread-magic-tricks-5-thingshttp://java.dzone.com/articles/springone2gx-2014-replay-21http://dzone.com/userhttp://cloud.dzone.com/https://twitter.com/#!/Dzonehttp://java.dzone.com/news/interview-john-de-goes-free-unhttp://java.dzone.com/news/how-create-visual-applicationshttp://eclipse.dzone.com/http://refcardz.dzone.com/refcardz/essential-camel-componentshttp://java.dzone.com/news/spring-batch-hello-world-1http://server.dzone.com/articles/testing-angularjs-applications