Friday, 16 January 2015

Java Flight Recorder (JFR)

JFR is a Java profiler which will allow you to investigate the runtime characteristics of your code. Typically you will use a profiler to determine which parts of your code are causing  large amounts of memory allocation or causing excess CPU to be consumed.

There are plenty of products out there.  In the past I've used YourKit, OptimizeIt, JProfiler, NetBeans and others. Each has its benefits and it is largely a matter of personal preference as to which you choose. My current personal favourite is YourKit. It integrates nicely into IntelliJ has a relatively low overhead and presents its reports well.

The truth is that profiling is a very inexact science and it is often worth looking at more than one profiler to build up a clearer picture of what exactly is going on in your program. To my knowledge most of the profilers rely on the JVMP/JVMTI agents to probe the Java program. A major problem with this is safe points. This means your Java program can only be probed when it is at a safe point. This means that you will get a false picture of what is really going on in your program especially if much of the activity is between safe points. Also all profilers, to a varying degree add overhead.  Profiler overhead will change the characteristics of your program and may cause misleading results from your analysis. Much more information here.

Enter JFR.  JRF has been bundled with the JDK since release 7u40. JFR is built with direct access to the JVM. This not only means that there is a very low overhead (claimed to be less than 1% in nearly all cases) but also does not rely on safe points.  Have a look here at an example of how radically different an analysis from YourKit and JFR can look.

To run JFR you need to add these switches to your Java command line:

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder

JFR is located in Java Mission Control (JMC).  To launch JMC just type jmc in your command line and if you have the JDK in your path the JMC console will launch.  You should see your Java program in the left hand pane.  Right click on your program and then start flight recording.


You will be presented with a dialog box where you can just accept the defaults (sample for a minute) and then your results will be displayed.  It's worth paying around with the options to find how this will work best for you.  As with all good products this GUI is fairly intuitive.

As you can tell from the command line switches it is commercial feature.  I'm not exactly sure what that means but you can read more about that in the documentation here. Also you can run this from the command line, it's all in the documentation.

One problem I did find was when I downloaded the latest Java8 snapshot (at this time 1.8.0_40-ea) I was unable to launch my program and got the following message:

/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/
Error: Trying to use 'UnlockCommercialFeatures', but commercial features are not available in this VM.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

In summary, JFR is a great addition to any developers toolkit and as long as you are using JDK release 7u40 or above it's certainly worth trying it out on your code.

(I encourage you to have a look at a previous post First rule of performance optimisation in conjunction with JFR)

113 comments:

  1. Nowadays, most of the businesses rely on cloud based CRM tool to power their business process. They want to access the business from anywhere and anytime. In such scenarios, salesforce CRM will ensure massive advantage to the business owners.Cloud Computing Training in Chennai

    ReplyDelete
  2. INTERESTING TO KNOW ABOUT Java Flight Recorder (JFR)
    awesome post.. thanks for sharing. expecting much in future.

    Selenium Training in Chennai

    ReplyDelete
  3. Nice and usefull contents. thanks for sharing. expecting much in the future.

    RPA Training in Chennai

    ReplyDelete
  4. It is a great post. Keep sharing such kind of useful information.

    smarthrsolution
    Education

    ReplyDelete
  5. This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
    Android Training in Bangalore
    Android Institute in Bangalore
    Android Coaching in Bangalore
    Android Coaching Center in Bangalore
    Best Android Course in Bangalore

    ReplyDelete
  6. your blog informations are really creative and It contains full of new innovative ideas.thank you for sharing with us.please update more data.
    Salesforce Training in Perambur
    Salesforce Training in Mogappair
    Salesforce Training in Ashok Nagar
    Salesforce Training in Nungambakkam

    ReplyDelete
  7. Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing. AngularJS Training in Chennai | Best AngularJS Training Institute in Chennai

    ReplyDelete
  8. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

    machine learning training in Velachery
    machine learning training in Chennai
    Android training in Chennai
    PMP training in chennai

    ReplyDelete
  9. Thanks for your post. This is excellent information. The list of your blogs is very helpful for those who want to learn, It is amazing!!! You have been helping many application.
    best selenium training in chennai | best selenium training institute in chennai selenium training in chennai | best selenium training in chennai | selenium training in Velachery

    ReplyDelete
  10. Thank you so much for your information,its very useful and helful to me.Keep updating and sharing. Thank you.
    RPA training in chennai | UiPath training in chennai

    ReplyDelete
  11. Wow!! Really a nice Article. Thank you so much for your efforts. Definitely, it will be helpful for others. I would like to follow your blog. Share more like this. Thanks Again.
    iot training in Chennai | Best iot Training Institute in Chennai

    ReplyDelete
  12. This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
    JAVA Training in Chennai
    Android Training in Chennai
    German Classes in Chennai
    German Language Classes in Chennai

    ReplyDelete
  13. Learned a lot from your blog. Good creation and hats off to the creativity of your mind. Share more like this.
    Loadrunner Training in Chennai
    French Classes in Chennai
    iOS Training in Chennai

    ReplyDelete
  14. Make money on kasino online and do not regret anything gamble casino with us Make money on kaino online and do not regret anything.

    ReplyDelete
  15. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.



    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete
  16. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete
  17. Hello Admin!

    Thanks for the post. It was very interesting and meaningful. I really appreciate it! Keep updating stuffs like this. If you are looking for the Advertising Agency in Chennai | Printing in Chennai , Visit Inoventic Creative Agency Today..

    ReplyDelete
  18. Thank you for sharing this blog, it is very useful information....
    Java training bangalore

    ReplyDelete
  19. It's very useful article with inforamtive and insightful content and i had good experience with this information. We, at the CRS info solutions ,help candidates in acquiring certificates, master interview questions, and prepare brilliant resumes.Go through some helpful and rich content Salesforce Admin syllabus from learn in real time team. This Salesforce Development syllabus is 100% practical and highly worth reading. Recently i have gone through Salesforce Development syllabus and Salesforce Admin syllabus which includes Salesforce training in USA so practically designed.

    ReplyDelete
  20. it is really a great and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us informed like this. Thank you for sharing.
    china visa singapore

    ReplyDelete
  21. Amazing Article,Really useful information to all So, I hope you will share more information to be check and share here.thanks for sharing .
    Website: Vietnam Cycling Tours

    ReplyDelete
  22. Instead of relying only on the feedback or opinions from the Salesforce Consultants, it is desirable to check the discussion boards, user groups as well as other social media outlets in finding out what actually people are saying about the Consulting Company and its staffs and customer service. Salesforce training in Hyderabad

    ReplyDelete
  23. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Digital Marketing Course in Chennai
    Digital Marketing Courses in Bangalore
    Digital Marketing Course in Delhi
    Digital Marketing Online Course

    ReplyDelete
  24. This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
    DevOps Training in Chennai
    DevOps Training in Bangalore
    DevOps Online Training
    DevOps Training in Coimbatore

    ReplyDelete
  25. Great blog! This is really helpful for my reference. Do share more such posts and keep us updated. Looking forward to more informative blogs from you.
    Cloud Computing Training in Chennai
    Cloud Computing Courses in Chennai
    Cloud Computing Courses in Bangalore
    Cloud Computing Courses in Coimbatore

    ReplyDelete
  26. it is really a great and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us informed like this. Thank you for sharing.
    Website: Online punjab state lottery

    ReplyDelete
  27. Thanks for another great post. Where else could anyone get that kind of information in such a perfect way of writing? I've a presentation next week, and I'm on the look for such information.
    buy electronics online

    ReplyDelete
  28. Thank you for sharing. Excellent post...! It is a very great idea and unique content. Thank you so much.
    Renew malaysian passport online

    ReplyDelete
  29. Thank you for sharing. Excellent post...! It is a very great idea and unique content. Thank you so much.
    first copy mens watch omega

    ReplyDelete
  30. I read this article fully on the topic of the difference of most up-to-date and earlier technologies, it’s awesome article.
    Website: malaysian passport

    ReplyDelete
  31. Pretty! This was an extremely wonderful post. Thanks for providing this information.
    House wiring in Nagpur

    ReplyDelete
  32. This post is so interactive and informative.keep update more information...
    Selenium Training in Bangalore
    Selenium Training in Pune

    ReplyDelete
  33. Thank you for sharing so insightful article. Rozana.in has a far-reaching presence across various cities in India.
    Visit for more info discount grocery stores

    ReplyDelete
  34. Hello there, You have done a great job. As we all know how much Bill of Sale being used. This document is usually used for sale and purchase between two parties like Buyer & seller.
    Visit here IL Bill of sale

    ReplyDelete
  35. This post is so interactive and informative.keep update more information...
    AngularJS Training in Velachery
    Angularjs Training in Chennai

    ReplyDelete
  36. İnsan böyle şeyler görünce mutlu oluyor

    ReplyDelete
  37. Thanks for posting. Useful information.

    Introducing a new application named Engadoctor. Especially design with newly emerging technology for Online Doctor Consultation & Book Online Doctor Appointment.

    ReplyDelete
  38. This is great content for your readers. Thanks for sharing.
    sporrans

    ReplyDelete
  39. IVC-Services is a private Consulting Agency. Click here - india visa

    ReplyDelete