21

Everyone knows that a heap dump can be obtained from a running JVM. Is the other way possible? Can we start a JVM using a heap dump?

I have been having this question in mind for a long time now. If this is possible it would solve a lot of time and make thinks easy for a support engineer. It helps big time in cases where if we have to recreate some the rare problems our customer face. [Just imagine that the underlying hardware and Java runtime are the same and also all the supporting files are also present in the respective location in file system].

Added note: The intention of doing this is not when OOM occurs but at any given point after JVM starts.

Siva
  • 219
  • 1
  • 5

3 Answers3

2

No you can't. You would need things like the current position in each open file. That affects what data is returned on a simple sequential read. The restorer would need to open each file and get it to the correct position. That may not be possible for non-seekable streams.

Program specific serialization is a much more feasible path, then setup the program from there.

Also, as Heap Dumps are usually from OutOfMemory situtaions, recreating JVM from same would again throw OutOfMemoryException. If you are taking heap dump in between, then serialize your objects and restore them when you bring up jvm.

(contents copied from comments of this question, Authors almas-shaikh and patricia-shanahan)

Community
  • 1
  • 1
Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
  • A heap dump is created when you get an out of memory error, but this is not the only method of getting one. This answer makes an assumption about the intent of the author. just because a -> b doesn't mean b -> a – Joeblade Dec 09 '14 at 10:56
  • 1
    Point is you didn't answer their question. (or rather your first line is correct but you didn't list why / what. instead you discuss a specific circumstance that generates dump that would not be useful to restore from). The second paragraph I think is on point but the first isn't. – Joeblade Dec 09 '14 at 15:24
  • Could you expand on "current position in each open file", "sequential read" and "non-seekable streams"? What exaclty are you referring to? I dont understand in what context these things live. Assume I'm a moron. – veidelis Jun 15 '22 at 19:33
1

I think you are looking for tools like Java Mission Control and Chronon DVR (commercial). These help you incident analysis, event collection and profiling, time travel debugging (as phrased by chronon)

As per their documentation:

Java Mission Control

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving. Java Mission Control is an advanced set of tools that enables efficient and detailed analysis of the extensive of data collected by Java Flight Recorder. The tool chain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments.Starting with the release of Oracle JDK 7 Update 40 (7u40)

Some key features of Chronon Recording Server which will be useful in your case:

The Recording Server is specifically designed for long running, server side applications that run for weeks or months at a time. The Recording Server will take care of splitting the recording if it get too large and flushing out old recordings.

Get rid of the need to look at long sparsely detailed log files to debug your program. Just play back the entire execution and see exactly what took place in your program. The Recording Server makes it share recordings on different machines among team members or across multiple teams.

Laksitha Ranasingha
  • 4,321
  • 1
  • 28
  • 33
1

To create a heap dump from a running JVM you can also use jhat, or jcmd (with the GC.heap_dump command), both exist in the JDK/bin folder. MAT is one way of analyzing the contents of the dump. Java Mission Control has a tool called JOverflow that analyzes heap dumps, but only to look at memory waste patterns.

I have never heard of any way to restart a JVM from sort of image, a heap dump would not be enough at all, since it only contains the Java objects, and not the compiled code and other things.

Klara
  • 2,935
  • 22
  • 19