4

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.

turbanoff
  • 2,439
  • 6
  • 42
  • 99
  • 2
    I don't think there's such a thing, but probably you could use something like here https://www.eclipse.org/forums/index.php/t/440489/. Although you will need to take new dumps. – Vladucu Voican Jan 09 '20 at 12:07
  • You can [extract the time when the heap dump has been created](https://stackoverflow.com/q/57116971/2711488) but that’s neither, uptime nor start time… – Holger Jan 09 '20 at 13:31

2 Answers2

2

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.

  • 1
    It seems this does not work in JDK 11 or earlier. Based on a quick test, "currt" (ignoring case) is present in heap dumps generated by 12.0.1 and 13-ea, but not 1.8.0_172 or 11.0.3. – Kaan Jan 09 '20 at 21:38
  • @kaan, actually I got this result on Oracle JDK 1.8.211 – The Rabbit of No Luck Jan 09 '20 at 21:39
1

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.

Forketyfork
  • 7,416
  • 1
  • 26
  • 33