简体   繁体   中英

Extract JVM uptime from binary heap dump

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.

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 ):

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, the hprof file was created few minutes later, at 7.03 am .

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 eg put them in system properties ( System.getProperties().setProperty() ) to be later analyzed as part of the dump.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM