Creating your own Debugging Tool with JDK Serviceability ... · Creating your own Debugging Tool...

Preview:

Citation preview

Creating your own Debugging Tool with JDK Serviceability Technologies

Andrei PanginOdnoklassniki

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

Troubleshooting

Bugs Performance Memory JVM crash

Debugger ProfilerMemory analyzer Crash dump

2

3

Java

server

SSH

JVM

ServiceabilityClass

Libraries

UIToolkits

JavaLanguage

Tools

Serviceability

4

Java Platform

Serviceability

PerformanceCounters

DynamicAttach

ServAgent

JVM TI

Instrumentation

CustomTools

5

6

Performance Counters

7

Performance Counters

• 250+ variables

• Exported to /tmp/hsperfdata_user

• Free to read

• -XX:-UsePerfData

• jstatd

8

Dynamic Attach

9

Dynamic Attach

• Cooperative IPC

• Commands:– dump threads, dump heap, manage flags

– run GC, rotate logs, start JFR

– load agent lib

• -XX:+DisableAttachMechanism

10

Serviceability Agent

• JVM internals Java API

• sa-jdi.jar

11

Serviceability Agent

• Reads process memory / coredump

• Reflection-like API

• No cooperation from target JVM

• jsadebugd

12

JVM Tool Interface

• Standard

• Native API

13

JVM Tool Interface

• Native API for debuggers– threads, stack frames, local variables

– heap walking

– breakpoints, watchpoints

– event callbacks

• Capability-based

• java -agentpath

14

Instrumentation API

• Standard Java API– java.lang.instrument

• Patch bytecode– redefineClasses

• -javaagent or

dynamic attach

Serviceability

PerformanceCounters

DynamicAttach

ServAgent

JVM TI

Instrumentation

CustomTools

15

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

Thank You

@AndreiPanginandrey.pangin@corp.mail.ru

https://github.com/odnoklassniki

Recommended