Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JFokus Java 9 contended locking performance

965 views

Published on

At JavaOne keynote this year, Mark Reinhold talked about how Java 9 was much bigger than Jigsaw. To put that in numbers - 80+ JEPs bigger! Yes, we see more presentations on Jigsaw since it brings about modularity to the once monolithic JDK. But what about those other JEPs?! One of those "other" JEPs, is JEP 143 - 'Improve Contended Locking'. Monica will apply her performance engineering approach and talk about JEP 143 and Oracle's Studio Analyzer Performance Tool. The crux of the presentation will entail comparing performance of contended locks in JDK 9 to JDK 8.

Published in: Software
  • Be the first to comment

JFokus Java 9 contended locking performance

  1. 1. About Me Java/JVM/GC performance person Current Life: Consultant who solves Managed Runtime performance issues Past Life: Worked with Oracle, Sun,AMD… ©2017 CodeKaram1
  2. 2. Agenda • Setting the stage • A quick glance at JDK 9 JEPs • Building a problem statement • Studying JEP 143 – Improve contended locking ©2017 CodeKaram2
  3. 3. Agenda • Quick overview of top-down and bottom-up performance approaches • Choosing the right approach! • Building our arsenal! ©2017 CodeKaram3
  4. 4. Agenda • Observing the targeted improvements • Demo comparing JDK 9 with JDK 8 • Summarizing the observations ©2017 CodeKaram4
  5. 5. Setting The Stage ©2017 CodeKaram5
  6. 6. JEPs in JDK 9 ©2017 CodeKaram6 There are 89 total JEPs in JDK 9
  7. 7. JEPs in JDK 9 …and contended locking performanceimprovement (JEP143) is one of them J ©2017 CodeKaram7
  8. 8. What is JEP 143? ©2017 CodeKaram8 JEP 143 brings about improvements to contended locks* *In the past (Java 6) we have alreadyseen improvements to uncontendedlocksusing BiasedLockingtechnique.
  9. 9. Building A Problem Statement ©2017 CodeKaram9
  10. 10. Summary of JEP 143 ©2017 CodeKaram10 “Improve the performance of contended Java object monitors”
  11. 11. ©2017 CodeKaram11 “Improve the performance of contended Java object monitors” Summary of JEP 143
  12. 12. Uncontended Locks ©2017 CodeKaram12 A single thread ‘t’ is executing a synchronized method
  13. 13. Contended Locks ©2017 CodeKaram13 A different thread ‘u’ wants to enter the synchronized method that is already locked by thread ‘t’
  14. 14. Contended Locks ©2017 CodeKaram14 This is a heavy weight lock also known as inflated lock Object Monitor maintains “WaitSet” for threads waiting for the contended lock
  15. 15. Java Monitors ©2017 CodeKaram15 Wait Q Object Monitor Enter Exit Q
  16. 16. Wait Set ©2017 CodeKaram16 • A set of threads • At creation – empty set of threads • Can be manipulated only by: • Object.wait, Object.notify, Object.notifyAll
  17. 17. Java Monitors ©2017 CodeKaram17 Wait Q Object Monitor Enter Exit Q Wait Notify
  18. 18. Top-Down Performance Approach ©2017 CodeKaram18
  19. 19. What areYouTrying to Achieve? ©2017 CodeKaram19 Improve application?
  20. 20. Top-Down Approach ©2017 CodeKaram20 OS Hardware Application Ecosystem Application JRE JVM
  21. 21. Top Down Approach - Process •Step 1Monitor •Step 2 Profile •Step 3Analyze •Step 4 Tune + Apply
  22. 22. Bottom-Up Performance Approach ©2017 CodeKaram22
  23. 23. What areYouTrying to Achieve? ©2017 CodeKaram23 Improve the platform?
  24. 24. Bottom-Up Approach ©2017 CodeKaram24 OS Hardware Application Ecosystem Application JRE JVM
  25. 25. Bottom Up Approach - Process •Step 1Monitor •Step 2 Profile •Step 3Analyze •Step 4 Tune + Apply
  26. 26. Choosing The Right Approach … ©2017 CodeKaram26
  27. 27. Improve the JVM What AreWeTryingTo Do? ©2017 CodeKaram27
  28. 28. The Bottom-Up Approach HenceWeChoose… ©2017 CodeKaram28
  29. 29. Bottom Up Approach ©2017 CodeKaram29 I NEED the power!! … to stress the platform
  30. 30. Setting Up For Benchmarking ©2017 CodeKaram30
  31. 31. Where to Start? ©2017 CodeKaram31 • Know what you are stressing • Get/ write the appropriate workload/ application • Get/write the appropriate tools
  32. 32. Know What You’re Stressing… ©2017 CodeKaram32
  33. 33. Speed UpTargets ©2017 CodeKaram33 • PlatformEvent::unpark() • Java monitor enter operations • Java monitor exit operations • Java monitor notify/notifyAll operations
  34. 34. Get/Write The Appropriate Workload/Application … ©2017 CodeKaram34
  35. 35. FromThe JEP … ©2017 CodeKaram35 LockLoops-JSR166-Doug-Sept2009 (was LockLoops): The benchmark compares multiple locking techniques For our purpose, we just need to test the contended locks.
  36. 36. Contended Locking Test ©2017 CodeKaram36 private static class BuiltinLockLoop extends LockLoop { final int loop(int n) { int sum = 0; while (n-- > 0) { synchronized (this) { v = LoopHelpers.compute1(v); } sum += LoopHelpers.compute2(v); } return sum; } }
  37. 37. Contended Locking Test ©2017 CodeKaram37 private static class BuiltinLockLoop extends LockLoop { final int loop(int n) { int sum = 0; while (n-- > 0) { synchronized (this) { v = LoopHelpers.compute1(v); } sum += LoopHelpers.compute2(v); } return sum; } }
  38. 38. Where to Next? ©2017 CodeKaram38 Ensure that you are in fact measuring contended object monitor performance!
  39. 39. How DoWe DoThat? ©2017 CodeKaram39 Bypass biased locking: Use -XX:-UseBiasedLocking Bypass stack based locking: Use -XX:+UseHeavyMonitors
  40. 40. Get/Write The Appropriate Tools … ©2017 CodeKaram40
  41. 41. Oracle Developer Studio Performance Tool ©2017 CodeKaram41
  42. 42. Profiling with ‘collect’ ©2017 CodeKaram42 • -j on: default for when target is Java • -p on: default clock-profiling rate of ~100 samples/second • -H on: heap tracing • -t <duration>: time over which to record data • -h <ctr_def>…: specify HW counter profiling
  43. 43. Observing The Targeted Improvements ©2017 CodeKaram43
  44. 44. Speed UpTargets ©2017 CodeKaram44 • PlatformEvent::unpark() • Java monitor enter operations • Java monitor exit operations • Java monitor notify/notifyAll operations
  45. 45. Demo - Comparing Contended Locking in JDK 9 to JDK 8 ©2017 CodeKaram45
  46. 46. Summarizing the Observations ©2017 CodeKaram46
  47. 47. Speed UpTargets ©2017 CodeKaram47 •PlatformEvent::unpark() • Java monitor enter operations • Java monitor exit operations • Java monitor notify/notifyAll operations
  48. 48. ©2017 CodeKaram48 JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name 0.400 0.941 os::PlatformEvent::unpark() Unpark
  49. 49. ImprovementTargets ©2017 CodeKaram49 • PlatformEvent::unpark() •Java monitor enter operations • Java monitor exit operations • Java monitor notify/notifyAll operations
  50. 50. ©2017 CodeKaram50 JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name 97.678 187.001 ObjectMonitor::enter(Thread*) 2.462 3.432 ObjectMonitor::EnterI(Thread*) Monitor Enter
  51. 51. Speed UpTargets ©2017 CodeKaram51 • PlatformEvent::unpark() • Java monitor enter operations •Java monitor exit operations • Java monitor notify/notifyAll operations
  52. 52. ©2017 CodeKaram52 JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name 2.302 2.352 ObjectMonitor::exit(bool,…) 0.000 0.961 ObjectMonitor::ExitEpilog(Thread* ,…) Monitor Exit
  53. 53. Speed UpTargets ©2017 CodeKaram53 • PlatformEvent::unpark() • Java monitor enter operations • Java monitor exit operations •Java monitor notify/notifyAll operations
  54. 54. ©2017 CodeKaram54 I’ll leave that as a take-home exercise for you all! J Notify/ NotifyAll
  55. 55. Further Reading ©2017 CodeKaram55
  56. 56. http://openjdk.java.net/jeps/143 https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html https://wiki.openjdk.java.net/display/HotSpot/Synchronization https://blogs.oracle.com/dave/entry/biased_locking_in_hotspot http://extremeperformance.expert ©2017 CodeKaram56

×