4

This might be a long shot of a question, but I have ran into a very complicated issue and I am unsure on how to solve it.

Long story short, we have a Java application running, it's currently using JDBC to pull in data from a MysQL Database on startup.

We have had a meltdown and that database is no longer active and has been lost forever and so has the data to go along with it which internally is very valuable.

However the data is still stored in the heap of the running JVM that pulled it in.

My only hope now is to somehow extract the data from the running JVM, in an ideal world i would be able to attach to it and have the flexibility to run code which could access the internal running classes..

So my questions today are:

  • Is my approach reasonable and possible?
  • If so how can I attach to the JVM and 'Inject' code

Thank you for reading

Deuce bigalow
  • 301
  • 1
  • 12
  • 1
    You know of the attach API? And of heap dumps? – Thorbjørn Ravn Andersen Feb 13 '16 at 09:26
  • 1
    See [How to get a thread and heap dump of a Java process on Windows that's not running in a console](http://stackoverflow.com/questions/407612/how-to-get-a-thread-and-heap-dump-of-a-java-process-on-windows-thats-not-runnin). –  Feb 13 '16 at 11:12

2 Answers2

0

It seems that what you want to use is the jmap command. jmap can be used to dump the heap of a running JVM into a file, which you can then analyze "off-line", using tools such as jhat or JVisualVM.

It allows you to do so without killing the JVM and/or injecting code into it, and since the heap dump file is "inert", you can analyze it at your leisure without fear of harming the running VM by probing it further. Admittedly, I haven't used it extensively, so I'm not sure exactly what its capabilities are, but theoretically, you could perhaps also use JVisualVM's OQL language to run automated sequences on data in the heap and dump it to files in a format you want.

See, for instance, this question for usage examples.

Community
  • 1
  • 1
Dolda2000
  • 25,216
  • 4
  • 51
  • 92
0

In a situation like this the Eclipse Memory Analyzer Tool can be a good solution. It works on heap dumps too and shows you which objects take up memory. In addition to this it can show the content of objects / memory locations.

I sometimes found MAT goes beyond what VisualVM does, but perhaps a view like this helps you find your data already:

enter image description here

(This is a screenshot of a made-up example where I create some custom objects in order to show them with their value in the heapdump)

Perhaps you can even attach Eclipse to the running application. There is a certain trick where you can run custom code in a breakpoint. This one could somehow dump your data to disk.

Marged
  • 10,577
  • 10
  • 57
  • 99