Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool...
Transcript of Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool...
![Page 1: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/1.jpg)
Creating your own Debugging Tool with JDK Serviceability Technologies
Andrei PanginOdnoklassniki
![Page 2: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/2.jpg)
1
About us
• Andrei Pangin • Odnoklassniki (ok.ru)– Top 20 site (SimilarWeb)
– 50M DAU
– 1000 Gb/s
– 8000 servers
– 99% Java code
Lead developer
Specialist
![Page 3: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/3.jpg)
Troubleshooting
Bugs Performance Memory JVM crash
Debugger ProfilerMemory analyzer Crash dump
2
![Page 4: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/4.jpg)
3
Java
server
SSH
![Page 5: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/5.jpg)
JVM
ServiceabilityClass
Libraries
UIToolkits
JavaLanguage
Tools
Serviceability
4
Java Platform
![Page 6: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/6.jpg)
Serviceability
PerformanceCounters
DynamicAttach
ServAgent
JVM TI
Instrumentation
CustomTools
5
![Page 7: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/7.jpg)
6
Performance Counters
![Page 8: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/8.jpg)
7
Performance Counters
• 250+ variables
• Exported to /tmp/hsperfdata_user
• Free to read
• -XX:-UsePerfData
• jstatd
![Page 9: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/9.jpg)
8
Dynamic Attach
![Page 10: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/10.jpg)
9
Dynamic Attach
• Cooperative IPC
• Commands:– dump threads, dump heap, manage flags
– run GC, rotate logs, start JFR
– load agent lib
• -XX:+DisableAttachMechanism
![Page 11: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/11.jpg)
10
Serviceability Agent
• JVM internals Java API
• sa-jdi.jar
![Page 12: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/12.jpg)
11
Serviceability Agent
• Reads process memory / coredump
• Reflection-like API
• No cooperation from target JVM
• jsadebugd
![Page 13: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/13.jpg)
12
JVM Tool Interface
• Standard
• Native API
![Page 14: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/14.jpg)
13
JVM Tool Interface
• Native API for debuggers– threads, stack frames, local variables
– heap walking
– breakpoints, watchpoints
– event callbacks
• Capability-based
• java -agentpath
![Page 15: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/15.jpg)
14
Instrumentation API
• Standard Java API– java.lang.instrument
• Patch bytecode– redefineClasses
• -javaagent or
dynamic attach
![Page 16: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/16.jpg)
Serviceability
PerformanceCounters
DynamicAttach
ServAgent
JVM TI
Instrumentation
CustomTools
15
![Page 17: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...](https://reader031.fdocuments.in/reader031/viewer/2022020214/5acffc527f8b9a1d328dbe6b/html5/thumbnails/17.jpg)
16
Documentation
• Serviceability in HotSpot
– http://openjdk.java.net/groups/hotspot/docs/Serviceability.html
• Dynamic Attach
– https://docs.oracle.com/javase/8/docs/jdk/api/attach/spec/
• Serviceability Agent
– https://docs.oracle.com/javase/8/docs/serviceabilityagent/
• JVMTI
– http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html
– Demos and samples: ${JDK}/demo/jvmti