introduction to troubleshooting in jdk 9€¦ · 48 case5: native memory leak? copyright©2016 ntt...

63
Copyright©2016 NTT corp. and NTT COMWARE corp. Introduction to Troubleshooting in JDK 9 Serviceability Tools are Your Friends Yuji KUBOTA (@sugarlife) Yasumasa Suenaga (@YaSuenag) Shinji Takao

Upload: others

Post on 14-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Copyright©2016 NTT corp. and NTT COMWARE corp.

Introduction to Troubleshooting in JDK 9

Serviceability Tools are Your Friends

Yuji KUBOTA (@sugarlife)

Yasumasa Suenaga (@YaSuenag)

Shinji Takao

Page 2: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

2

Who we are

Copyright©2016 NTT corp. and NTT COMWARE corp.

KUBOTA Yuji (@sugarlife), hard-of-hearing

Senior Expert in NTT

OpenJDK Author (ykubota)IcedTea Committer

Shinji Takao

Senior Expert in NTT

IcedTea Committer

Yasumasa Suenaga (@YaSuenag)

Senior Expert in NTT COMWARE

OpenJDK Committer (ysuenaga)IcedTea Committer

Page 3: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

3

#CON3733

Questions on twitter would begreatly appreciated!

Questions and comments

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 4: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

4

•Serviceability technology in Java 9

•Serviceability Tools• jhsdb

• jcmd

•HeapStats•Runtime monitoring tool powered by JVMTI

Topics:

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 5: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Serviceability Technology

Copyright©2016 NTT corp. and NTT COMWARE corp.

5

Page 6: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

http://openjdk.java.net/groups/serviceability/

jcmd

jhsdb

jcmd

Today’s topics

Copyright©2016 NTT corp. and NTT COMWARE corp.

6

Page 7: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•HotSpot collects data requested by serviceability tools•Serviceability tools

• Use methods implemented at sun.tools.attach.HotSpotVirtualMachine

•HotSpot• Request is received/processed on AttachListener

Dynamic Attach

Copyright©2016 NTT corp. and NTT COMWARE corp.

7

Page 8: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Dynamic Attach (on Linux)

1. Send SIGQUIT

2. Start

AttachListener

thread

4. Processing

3. Send request

5. Receive response

Unix domain socketServiceability

Tool

Target

JVM

process

Copyright©2016 NTT corp. and NTT COMWARE corp.

8

Page 9: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•aka PerfCounter

•Binaries of all statistics in HotSpot• /tmp/hsperfdata_<username>/<PID>

• jstat and jcmd refer to this file

jvmstat Performance Counters

Copyright©2016 NTT corp. and NTT COMWARE corp.

9

Page 10: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Library for collecting data from native layer• Like a native debugger (e.g. GDB)

•Debug symbol is required• debuginfo needs when you use OpenJDK on Linux

•SA can collect data from:•Memory dump (core file)

•Hung process

Serviceability Agent (SA)

Copyright©2016 NTT corp. and NTT COMWARE corp.

10

Page 11: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

http://docs.oracle.com/javase/8/docs/serviceabilityagent/index.html

Empty…

Copyright©2016 NTT corp. and NTT COMWARE corp.

11

Page 12: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Available via jhsdb ONLY•No –F option

SA in Java 9

JDK-8155091: Remove SA related functions from tmtools

Copyright©2016 NTT corp. and NTT COMWARE corp.

12

$ jstack -F 999Error: -F option usedCannot connect to core dump or remote debug server. Use jhsdb jstack instead

Page 13: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

13

Serviceability Tools

• jhsdb

• jcmd

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 14: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

jhsdbSA launcher in Java 9

Copyright©2016 NTT corp. and NTT COMWARE corp.

14

Page 15: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•New troubleshooting tool in Java 9• Launcher for all SA tools

•Enables hangs and crashes to be analyzed

jhsdb

JDK-8059038: Create new launcher for SA tools

Copyright©2016 NTT corp. and NTT COMWARE corp.

15

Page 16: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Mode of jhsdb

Mode

(1st argument)

Previous tool Abstract

clhsdb sa-jdi.jar HotSpot command-line debugger

hsdb sa-jdi.jar HotSpot GUI debugger

debugd jsadebugd SA debug server

jstack jstack Prints Java thread stack

jmap jmap Collects memory details

jinfo jinfo Prints VM information

jsnap sa-jdi.jar Dumps PerfCounter

Copyright©2016 NTT corp. and NTT COMWARE corp.

16

Page 17: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case 1: Obtain thread dump

Copyright©2016 NTT corp. and NTT COMWARE corp.

17

$ jhsdb jstack --pid 999Attaching to process ID 999, please wait...Debugger attached successfully.Server compiler detected.JVM version is 9-internal+0-2016-08-16-100008.ysuenaga.hsDeadlock Detection:

No deadlocks found.

Thread 18083: (state = BLOCKED)- java.lang.Object.wait(long) @bci=0 (Interpreted frame)

:

Page 18: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case 2: Obtain class histogram

Copyright©2016 NTT corp. and NTT COMWARE corp.

18

$ jhsdb jmap --pid 999 --histoAttaching to process ID 999, please wait...Debugger attached successfully.Server compiler detected.JVM version is 9-internal+0-2016-08-03-150733.ysuenaga.hsIterating over heap. This may take a while...Object Histogram:

num #instances #bytes Class description--------------------------------------------------------------------------1: 3075 153392 byte[]2: 3530 112960 java.util.HashMap$Node

:

Page 19: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case 3: Obtain heap dump

Copyright©2016 NTT corp. and NTT COMWARE corp.

19

$ jhsdb jmap --pid 999 --binaryheap --dumpfile heapdump.hprofAttaching to process ID 999, please wait...Debugger attached successfully.Server compiler detected.JVM version is 9-internal+0-2016-08-03-150733.ysuenaga.hsheap written to heapdump.hprof

Page 20: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case 4: Obtain VM information

Copyright©2016 NTT corp. and NTT COMWARE corp.

20

$ jhsdb jinfo --pid 999Attaching to process ID 999, please wait...

:Java System Properties:

awt.toolkit = sun.awt.X11.XToolkitjava.specification.version = 9sun.management.compiler = HotSpot 64-Bit Tiered Compilers

:VM Flags:Non-default VM flags: -XX:CICompilerCount=3 -XX:ConcGCThreads=1

:Command line: -Xlog:gc=debug -XX:+HeapDumpOnOutOfMemoryError

Page 21: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case 5: Attach to memory dump

Copyright©2016 NTT corp. and NTT COMWARE corp.

21

$ jhsdb jstack --exe /path/to/java/executable ¥--core /path/to/memory/dump/core.999

Attaching to core core.999 from executable /path/to/java/executable, please wait...Debugger attached successfully.Server compiler detected.

:

Page 22: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

HSDBDo you want to analyze in more details?

Copyright©2016 NTT corp. and NTT COMWARE corp.

22

Page 23: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•GUI HotSpot Debugger•CLHSDB: Command Line HotSpot Debugger

•You can attach HSDB and CLHSDB to:• live process

•memory dump

• remote debug server (jsadebugd)

HSDB

Copyright©2016 NTT corp. and NTT COMWARE corp.

23

Page 24: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Windows Error Reporting (WER) enabled:•You have to set Full dump to DumpType

• https://msdn.microsoft.com/en-us/library/bb787181.aspx

•You have to pass -XX:+UseOSErrorReporting

•WER disabled:• If you do NOT run app on Windows Server, you have to pass -XX:+CreateCoredumpOnCrash

NOTE: for Windows

Copyright©2016 NTT corp. and NTT COMWARE corp.

24

Page 25: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Find crashed thread

Click!

Crash thread name

Copyright©2016 NTT corp. and NTT COMWARE corp.

25

Page 26: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Show call stacks

1. Choose

2. Click!

3. Call stack

4. Byte Codes

Copyright©2016 NTT corp. and NTT COMWARE corp.

26

Page 27: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Show class histogram

Copyright©2016 NTT corp. and NTT COMWARE corp.

27

Page 28: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Show VM Settings

Copyright©2016 NTT corp. and NTT COMWARE corp.

28

Page 29: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

See also:https://bitbucket.org/javamagazine/magdownloads/downloads/2012-07-JavaMag-ServiceabilityAgent.pdf

Copyright©2016 NTT corp. and NTT COMWARE corp.

29

Page 30: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

30

jcmdNearly the ultimate serviceability tool

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 31: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

31

•Recommend tool for diagnosing problems

jcmd

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 32: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

32

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 33: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

33

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 34: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

34

• jcmd [-l | -h | -help]• -h | -help: prints help

• -l | no argument: lists JVM processes on local

• jcmd target command• JVM process id | main class

•Domain.suffix[ options] | -f file• -f file: executes command from the file

Basic usage

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 35: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

35

• jcmd -help•Prints basic usage

• jcmd target help• Lists available commands

•Depends on JVM version of target, not jcmd

• jcmd target help command•Prints command help

Help

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 36: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

36

Command: Domain.suffix (Java 8)

Copyright©2016 NTT corp. and NTT COMWARE corp.

DomainNum.

suffixAbstract

PerfCounter 1 Performance Counter

ManagementAgent 3 JMX agent

Thread 1 Thread dump

GC 7 Heap / GC / Finalization

VM 7 Runtime info. (log/native mem/flag/etc.)

Page 37: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

37

Command: Domain.suffix (Java 9)

Copyright©2016 NTT corp. and NTT COMWARE corp.

DomainNum.

suffixAbstract

PerfCounter 1 - Performance Counter

ManagementAgent 4 +1 JMX agent

Thread 1 - Thread dump

GC 8 +2

-1

Heap / GC / Finalization

VM 15 +8 Runtime info. (log/native mem/flag/etc.)

Compiler 7 - JIT Compiler

JVMTI 2 - JVMTI agent

Removed GC.rotate_log

Page 38: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

38

Copyright©2016 NTT corp. and NTT COMWARE corp.

Traditional tool jcmd command Abstracts

jps -l Lists JVM Process

jstat PerfCounter.print Prints JVM statistics

jstack Thread.print Prints full thread dump

jmap -dump:file=file

jmap -histo:live

GC.heap_dump file

GC.class_histogram

Dumps the Java heap

Prints a histogram of the heap

jinfo

jinfo -flag

jinfo -flags

jinfo -sysprops

PerfCounter.print

VM.set_flag

VM.flags

VM.system_properties

Prints VM information

Sets JVM flag

Lists configured JVM flags

Lists system properties

Alternatives to traditional tools

Page 39: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

39

• jcmd 999 VM.log [options]

Case1: Oops, I forgot to set GC.log!

Copyright©2016 NTT corp. and NTT COMWARE corp.

Options Description

output The name or index (#<index>) of output to configure.

output_options Options for the output

what Configures what tags to log

decorators Configures which decorators to use

disable Clears all configurations and turns off all loggings

list Lists current log configurations

rotate Rotate all logs (instead of GC.log_rotate in Java 8)

Page 40: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

40

Case1: Oops, I forgot to set GC.log!

Copyright©2016 NTT corp. and NTT COMWARE corp.

•Confirms current loggings

$ jcmd 999 VM.log list999:Available log levels: off, trace, debug, info, warning, errorAvailable log decorators: time (t), uptime (u), timemillis (tm), …Available log tags: add, age, alloc, arguments, annotation, barrier, …:Described tag combinations:logging: Logging for the log framework itself

Log output configuration:#0: stdout all=warning uptime,level,tags#1: stderr all=off uptime,level,tags

default configurations

Page 41: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

41

Case1: Oops, I forgot to set GC.log!

Copyright©2016 NTT corp. and NTT COMWARE corp.

•Turns on a new logging: GC.log$ jcmd 999 VM.log output="file=gc.log"

output_options="filecount=5,filesize=10m"what="gc=debug" decorators="time,level"

999:Command executed successfully$ jcmd 999 VM.log list999:: Log output configuration:#0: stdout all=warning uptime,level,tags#1: stderr all=off uptime,level,tags#2: gc.log gc=debug time,level added a new logging

tag=log_level

name or path

options (log rotate)

Page 42: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

42

Case1: Oops, I forgot to set GC.log!

Copyright©2016 NTT corp. and NTT COMWARE corp.

•Turns off all existing loggings

• If you want to turn off #2 only• jcmd 999 VM.log output="#2" what="all=off"

$ jcmd 999 VM.log disable999:Command executed successfully$ jcmd 999 VM.log list999::

Log output configuration:#0: stdout all=off uptime,level,tags#1: stderr all=off uptime,level,tags

set all=off at stdout / stderr, and removed

the other configuration(s) such as #2

output nothing

Page 43: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

43

• jcmd 999 VM.log rotate

•Rotates logs satisfying the following1. Configured ‘output’ as file

2. Configured ‘filecount’ (by ‘output_option’)

Case2: Force logrotate manually

Copyright©2016 NTT corp. and NTT COMWARE corp.

$ jcmd 999 VM.log list:Log output configuration:#0: stdout all=warning uptime,level,tags#1: stderr all=off uptime,level,tags#2: gc.log gc=debug filecount=5,filesize=20M level,tags

#2 will be rotated,

not #0 and #1

Obsoleted GC.rotate_log

Page 44: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

44

•Use ManagementAgent domain• jcmd 999 ManagementAgent.start [jmxremote.*]

Case3: Control JMX after goes live

Copyright©2016 NTT corp. and NTT COMWARE corp.

suffix Description

status Prints JMX agent’s status

start Enables remote JMX access

start_local Enables local JMX access

stop Disables remote JMX access (not local)

Page 45: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

45

Case3: Control JMX after goes live

Copyright©2016 NTT corp. and NTT COMWARE corp.

$ jcmd 999 ManagementAgent.start jmxremote.port=777 jmxremote.ssl=true999:Commandexecuted successfully$ jcmd 999 ManagementAgent.statusAgent: enabled

Connection Type: remoteProtocol : rmiHost : fedora24.novalocalURL : service:jmx:rmi://XXX…XXXProperties :

com.sun.management.jmxremote.authenticate = true [default]com.sun.management.jmxremote.ssl.need.client.auth = false [default]com.sun.management.jmxremote.ssl = true [default]:com.sun.management.jmxremote.port = 8070

You can set these

properties by option

Page 46: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

46

•Use DiagnosticCommandMBean with jconsole / jvisualvm

Case4: Can I run jcmd to remote?

Copyright©2016 NTT corp. and NTT COMWARE corp.

same as jcmd

commands

click then run jcmd

VM.system_properties

result

Page 47: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

47

•Use VM.native_memory command1. Run Java with -XX:NativeMemoryTracking=summary

2. jcmd 999 VM.native_memory baseline

3. jcmd 999 VM.native_memory summary.diff

• More details by using ‘detail’ instead of ‘summary’

•NativeMemoryTracking was available since Java 8• https://docs.oracle.com/javase/8/docs/technotes/

guides/troubleshoot/tooldescr007.html

Case5: Native memory leak?

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 48: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

48

Case5: Native memory leak?

Copyright©2016 NTT corp. and NTT COMWARE corp.

$ jcmd 999 VM.native_memory baseline999:Baseline succeeded# --- Run process/method which wants to check the memory consumption ---$ jcmd 999 VM.native_memory summary.diff999:Native Memory Tracking:Total: reserved=5664359KB -36096KB, committed=371555KB -36096KB- Java Heap (reserved=4108288KB, committed=258048KB)

(mmap: reserved=4108288KB, committed=258048KB)- Class (reserved=1056953KB +15KB, committed=5433KB +15KB)

(classes #767 +3)(malloc=185KB +3KB #741 -4)(mmap: reserved=1056768KB, committed=5248KB)

- Thread (reserved=36128KB -112KB, committed=36128KB -112KB)(thread #36 +1)(stack: reserved=35980KB +325KB, committed=35980KB+325KB)(malloc=107KB +2KB #197 +4)(arena=41KB -130KB #70 +2)

:

Case5: Native memory leak?

±n shows diff from baseline

Page 49: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

49

• jcmd 999 VM.info•prints a fatal error log that includes …

Case6: Get unified info. at once!

Copyright©2016 NTT corp. and NTT COMWARE corp.

includes information

Version and configuration

Threads list and their state

Heap summary, JVM internal events (e.g.: GC, JIT, safepoint, etc…)

Memory map with loaded native libraries

VM arguments and environment variables

Details about the operation system and hardware

Thread dump and heap dump

are NOT included

Page 50: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Use JVMTI domain

Case7: Operates JVMTI agent

suffix Description

agent_load <library_path> <option> Attach JVMTI agent of library path

data_dump Fire DataDumpRequest JVMTI

event

Copyright©2016 NTT corp. and NTT COMWARE corp.

50

Page 51: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Ex: Attach JVMTI agent to JShell

Case7: Operates JVMTI agent

Copyright©2016 NTT corp. and NTT COMWARE corp.

51

Page 52: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

Case7: Operates JVMTI agent

Copyright©2016 NTT corp. and NTT COMWARE corp.

52

Page 53: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

•Pros•Can configure JVM after it goes live

•Can print / dump various JVM information

•Can analyze hung process / Memory Dump

•By only two serviceability tools jhsdb and jcmd

•Cons• Insufficient time series information

Serviceability technology overview

Copyright©2016 NTT corp. and NTT COMWARE corp.

53

Page 54: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

54

HeapStatsLightweight JVMTI agent

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 55: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

55

•Gathers runtime information continuously, then draws up time-series graphs

•Lightweight agent to run on the production systems

•New solution to troubleshooting for OpenJDK users.

HeapStats

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 56: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

56

SPECjvm2008 Composite Result

Copyright©2016 NTT corp. and NTT COMWARE corp.

467.59 461.43

0

50

100

150

200

250

300

350

400

450

500

Without HeapStats With HeapStats

(ops/m)

1.32 %

Overhead Rate

Page 57: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

57

Copyright©2016 NTT corp. and NTT COMWARE corp.

$ jcmd 999 JVMTI.agent_load libheapstats.so999:Commandexecuted successfully

or

java.lang.OutOfMemoryError: Java heap space

$ java –jar heapstats-analyzer.jar

$ rpm -ivh heapstats-2.0.1-0.*.rpm$ java -agentpath:heapstats … Your_Application

then

How to use HeapStats

Page 58: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

58

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 59: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

59

Copyright©2016 NTT corp. and NTT COMWARE corp.

byte[]byte[]

Page 60: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

60

Copyright©2016 NTT corp. and NTT COMWARE corp.

byte[]

Most doubtful class which has many references to byte[]

Page 61: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

61

Copyright©2016 NTT corp. and NTT COMWARE corp.

Monitor wait

RunSleep

Legend

Page 62: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

62

•https://github.com/HeapStats/heapstats

•http://icedtea.classpath.org/wiki/HeapStats

Your contributions are welcome!

Copyright©2016 NTT corp. and NTT COMWARE corp.

Page 63: Introduction to Troubleshooting in JDK 9€¦ · 48 Case5: Native memory leak? Copyright©2016 NTT corp. and NTT COMWARE corp. $ jcmd 999 VM.native_memory baseline 999: Baseline succeeded

63

•New troubleshooting for java 9•Can configure JVM after it goes live

•Can print / dump various JVM information

•Can profile hung JVM process

•By only two serviceability tools: jhsdb and jcmd

•HeapStats•Useful time series info. for after-the-fact analysis

Conclusion

Copyright©2016 NTT corp. and NTT COMWARE corp.