View the assembly instructions for the Java code another weapon, Jitwatch.

Source: Internet
Author: User

Http://www.tuicool.com/articles/IRrIRb3time 2015-05-13 08:00:00 Liuxinglanyue ' s Blog Original http://javagoo.tk/java/jitwatch_code.html ThemeJDK

See the assembly instructions for the Java code another weapon, Jitwatch.

Error correction 2015

Then the previous article looked at the Java code corresponding assembly instructions, Hsdis. Jitwatch provides a better way to display, as well as a variety of charts, called another tool.

GitHub Address: Jitwatch

git clone git@github. Com:adoptopenjdk/jitwatch.gitcd jitwatchmvn clean install-dskiptests=true./launchui.sh 

We use a simple example to see how it is used (the example is slightly more complicated, in order to understand JDK8 's optimization of the Atomicinteger.getandincrement () method), the Getandincrement () method based on JDK8 (JDK7) implements different )

First give the Java code, Atomicinteger_jdk8.java

Import Java.util.concurrent.CountDownLatch;Import Java.util.concurrent.atomic.AtomicInteger;PublicClassATOMICINTEGER_JDK8 {PrivateFinalStaticint test_size =100000000;PrivateFinalStaticint thread_count =10;Private Countdownlatch CDL =New Countdownlatch (Thread_count +1);Private Atomicinteger AI =New Atomicinteger (0);PrivateLong StartTime;PublicvoidInit() {startTime = System.nanotime ();}PublicClassMyTaskImplementsRunnable {@OverridePublicvoidrun () {while ( true) {if (ai.getandincrement () = = Test_size) {System.out.println (System.nanotime ()-StartTime ); Cdl.countdown (); System.exit (0);}}} public static void main (string[] args) {atomicinteger_jdk8 at = Span class= "Hljs-keyword" >new atomicinteger_jdk8 (); At.init (); for (int n = 0; n < THREAD_COUNT; n + +) new Thread (at.new mytask ()). Start (); System.out.println ( "start"); At.cdl.countDown ();}}       

Compile execution, and output log (hint: Need Hsdis)

Javac Atomicinteger_jdk8.javajava-server-xx:+unlockdiagnosticvmoptions-xx:+traceclassloading  -  xx:+printassembly-xx:+logcompilation-xx:logfile=jit.log  atomicinteger_jdk8    

    1. Click Open Log to select the Jit.log file
    2. Click Start
    3. , right-click the run () method, and click Triview

The Atomicinteger.getandincrement () method corresponds to the assembly instruction Callq.

By Jitwatch Discovery, Getandaddint () has been compiled into a special machine directive Xadd (which is why JDK8 is faster than JDK7, readers can see for themselves what JDK7 is)

--------------------------------------------added the------------------------------------of JDK7

View the assembly instructions for the Java code another weapon, Jitwatch.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.