Weitere ähnliche Inhalte Ähnlich wie JFokus Java 9 contended locking performance (20) Mehr von Monica Beckwith (7) Kürzlich hochgeladen (20) JFokus Java 9 contended locking performance2. 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
3. Agenda
• Setting the stage
• A quick glance at JDK 9 JEPs
• Building a problem statement
• Studying JEP 143 – Improve contended locking
©2017 CodeKaram2
4. Agenda
• Quick overview of top-down and bottom-up performance
approaches
• Choosing the right approach!
• Building our arsenal!
©2017 CodeKaram3
5. Agenda
• Observing the targeted improvements
• Demo comparing JDK 9 with JDK 8
• Summarizing the observations
©2017 CodeKaram4
7. JEPs in JDK 9
©2017 CodeKaram6
There are 89 total JEPs in JDK 9
8. JEPs in JDK 9
…and contended locking performanceimprovement (JEP143) is
one of them J
©2017 CodeKaram7
9. 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.
11. Summary of JEP 143
©2017 CodeKaram10
“Improve the performance of contended Java object monitors”
17. 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
22. Top Down Approach - Process
•Step 1Monitor
•Step 2 Profile
•Step 3Analyze
•Step 4 Tune +
Apply
26. Bottom Up Approach - Process
•Step 1Monitor
•Step 2 Profile
•Step 3Analyze
•Step 4 Tune +
Apply
32. Where to Start?
©2017 CodeKaram31
• Know what you are stressing
• Get/ write the appropriate workload/ application
• Get/write the appropriate tools
36. 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.
37. 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;
}
}
38. 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;
}
}
39. Where to Next?
©2017 CodeKaram38
Ensure that you are in fact measuring contended object monitor
performance!
40. How DoWe DoThat?
©2017 CodeKaram39
Bypass biased locking: Use -XX:-UseBiasedLocking
Bypass stack based locking: Use -XX:+UseHeavyMonitors
43. 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
49. ©2017 CodeKaram48
JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name
0.400 0.941 os::PlatformEvent::unpark()
Unpark
51. ©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
53. ©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