views:

372

answers:

4

I was wondering if something exists (in Java world) able to take an snapshot of the JVM current state with the following features:

  • Do it while an exception is being thrown.
  • Capture local variables, method's arguments, etc.
  • Put it in a handy file which can be used to extract or reproduce in a IDE the situation in your source code.

The two first features are required (third would be awesome). And it must be suitable for production use (so, there is no way about debuggers).

Before asking this I've searched through the WWW (as long as possible) and I found some pointers:

  • Cajoon Interceptor: As said in Dzone post, it's a passive JVM agent which fulfill the three requirements! But, it has two downsides: you must pay for it and the site is down (maybe there is no chance to pay anything).
  • AviCode Intercept Studio: Cajoon's .NET equivalent. Just to give some insight about.
  • JavaFrame: Ok, it's a tweet, but it points to a available SVN repo which have the source code (under MIT license) of a JVM agent which looks fine (I'm going to give a try to it).

So, maybe I'm looking for a non existent solution? It's not urgent, but I had this idea for a project and it would be great to explore this "unknown" (?) path and get something real.

It seems to be clear that it would be a JVM agent (exception event from JVMTI, for example).

At last, I would highlight the followin paragraph from Wikipedia's Exception Handling article:

In runtime engine environments such as Java or .NET, there exist tools that attach to the runtime engine and every time that an exception of interest occurs, they record debugging information that existed in memory at the time the exception was thrown (call stack and heap values). These tools are called Automated Exception Handling or Error Interception tools and provide 'root-cause' information for exceptions.

That's the idea. I hope somebody can give me some insight or maybe, in the future, somebody get inspired by this humble post :)

Thanks!

A: 

Not sure if this is viable in a production environment, but there's the Omniscient debugger:

What if your debugger could go "go backwards in time?" Would that make debugging easier? By simply recording all variable assignments, it is possible to do essentially this. This is the underlying idea for omniscient debugging. The amazing part is that significantly large programs can be debugged in this fashion -- Ant, JUnit, the debugger itself.

http://www.lambdacs.com/debugger/

bajafresh4life
I found it too, but I don't think it can be a suitable solution for a production environment, because it seems to need execute through it your program. Imagine it with a JBoss AS... Thanks anyway ;)
Dario
+1  A: 

You may want to look into the work that NetBeans has done regarding automated use logging: http://wiki.netbeans.org/UsageLoggingSpecification.

As for dumping out local variables, I would imagine that you could simply use a debugger, such as the one that bajafresh4life mentioned.

Zian Choy
Thanks, there is a way to call a debugger while handling an exception? The goal is get an image of the JVM state on-the-fly, just in the moment an exception raises.In this way, you would be able to look what values the local variables had, also static classes and method's arguments too.
Dario
+1  A: 

Maybe it could be done with AspectJ?

GvS
Maybe but no local variables dump available, I guess, because aspects have their own scope or context (maybe I'm wrong).
Dario
+1  A: 

I give a look to JavaFrame and it seems a good starting point. Just install Apache Ant, do ant in the javaframe directory and launch the test suite (inside test directory) with:

LD_LIBRARY_PATH=../build/native/ java -agentlib:frameintrospect -classpath ../build/classes/:. org.thobe.frame.Test

It does not get any local variable but it tries. So, as I said, it can be an starting point. I hope to get further about its usage, but no time and no documentation (there are lots of projects named JavaFrame) are bad circumstances.

Maybe some day it can be done again. Yes, again. There was Cajoon, it looked promising and shiny but its website is down and there is no trace of any downloadable jar to try.

Thanks to everybody!

PD.: Just for reference, some links I found while researching:

Dario