Extract JVM uptime from binary heap dump

706 Views Asked by At

I am analyzing several heap dumps and am interested in a way that I can get the JVM uptime (or start time) from the heap dump. Using eclipse memory analyzer I can easy get the System Properties and class path but can't find a way to find uptime.

2

There are 2 best solutions below

2
The Rabbit of No Luck On BEST ANSWER

You can try to search for the sun.util.calendar.ZoneInfoFile class, it contains the long CURRT field. Its value matches with the JVM start time in VisualVM (in my case, at least, with the Oracle JVM):

Screenshot from MAT

Type|Name |Value
---------------------
long|CURRT|1578570465
---------------------

The epoch converter says it's 2020/1/9 6.47 am EST (GMT-5), the time I launched my Java application. Just in case, thehprof file was created few minutes later, at 7.03 am.

0
Forketyfork On

This may depend on the VM implementation, but at least on OpenJDK HotSpot VM start time and uptime are not being stored on the heap, instead they are implemented as native calls (see sun.management.VMManagementImpl#getStartupTime() and sun.management.VMManagementImpl#getUptime0()). This means that you won't find those values in an existing heap dump.

However, you could use ManagementFactory.getRuntimeMXBean().getUptime() or ManagementFactory.getRuntimeMXBean().getStartupTime() to get these values in a running VM and e.g. put them in system properties (System.getProperties().setProperty()) to be later analyzed as part of the dump.