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
:
- Click Open Log to select the Jit.log file
- Click Start
- , 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.