Top Banner
Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin Odnoklassniki
18

Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...

Apr 13, 2018

Download

Documents

dodien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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 ...

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

Page 18: Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool with JDK Serviceability Technologies Andrei Pangin ... •JVM internals Java API ...

Thank You

@[email protected]

https://github.com/odnoklassniki