Searching for a way to take a "snapshot" of a java application

J

Jack

Hi,
is there any way (jdk tools or commercial product) to take a "snapshot"
of a running java application, which can be used to restart a new
instance of the application, resuming the execution with the snapshot ?

Of course, i'm thinking about debugging...
 
M

mike.mainguy

Hi,
is there any way (jdk tools or commercial product) to take a "snapshot"
of a running java application, which can be used to restart a new
instance of the application, resuming the execution with the snapshot ?

Of course, i'm thinking about debugging...

Excellent question.
If you want a dump of all the current thread stacks and everything in
memory, yes, I know this can be done in IBM's J9 for sure, I'm not
sure about Sun or JRocket (although I suspect it can or can easily be
implemented).

If you want to load all that into another JVM and begin where you left
off.... that's a great idea, but I've never tried it or put much
thought into it. I can't think of any technical reasons why it can't
be done (certainly with virtualization software it's "easy") and
honestly I'm not sure why this isn't something people do on a
recurring basis. I may have to spend some time looking into this
because it seems plausible and I'm not sure why spending 15 minutes
building up a test scenario is acceptable if we could instantly
restart from a specific state in the JVM.

Of course if you have external dependencies (database, etc.) it might
make the problem more complicated than it seems on the surface.
s
 
J

Jack

(e-mail address removed) a écrit :
Excellent question.
If you want a dump of all the current thread stacks and everything in
memory, yes, I know this can be done in IBM's J9 for sure, I'm not
sure about Sun or JRocket (although I suspect it can or can easily be
implemented).

J9 seems to be only for pda.
If you want to load all that into another JVM and begin where you left
off.... that's a great idea, but I've never tried it or put much
thought into it. I can't think of any technical reasons why it can't
be done (certainly with virtualization software it's "easy") and
honestly I'm not sure why this isn't something people do on a
recurring basis. I may have to spend some time looking into this
because it seems plausible and I'm not sure why spending 15 minutes
building up a test scenario is acceptable if we could instantly
restart from a specific state in the JVM.

I agree. And it can be done in C with core dumps and gdb i think, so why
not Java ?
 
J

Jack

(e-mail address removed) a écrit :
Excellent question.
If you want a dump of all the current thread stacks and everything in
memory, yes, I know this can be done in IBM's J9 for sure, I'm not
sure about Sun or JRocket (although I suspect it can or can easily be
implemented).

from JRockit docs:
http://edocs.bea.com/jrockit/jrdocs/refman/intro.html

There is no way to save the runtime state of a running java application.
 
O

Owen Jacobson

Hi,
is there any way (jdk tools or commercial product) to take a "snapshot"
of a running java application, which can be used to restart a new
instance of the application, resuming the execution with the snapshot ?

Of course, i'm thinking about debugging...

Snapshotting and resurrecting a process is theoretically possible, but
it's fraught with peril. An application restored from a snapshot
would discover that all of its file handles, native GUI objects,
network connections, transactional state, and any other external state
it had established had suddenly disappeared. In theory this can
happen during normal operation, but in practice it's very rare for a
program to be prepared for it.

-o
 
J

Jack

Tim Smith a écrit :
What about state that isn't stored in the program, such as what your
input and output streams are connected to? Say I run a Java program:

java MyProgram > output.txt

If that is reloaded from a snapshot, how will the reloader know to
connect the output back up to output.txt?

Even trickier...suppose I'm using Java to write a console application
that plays around with terminal modes. It has just moved the cursor to
a specific line in the middle of the screen, and output the sequence
that switches the terminal to inverse video. A snapshot is taken.

When it is reloaded, how will the reloader know how to restore the
terminal state?

These are the things that make this kind of thing hard in general. You
have to (if you want to do a thorough job) have some OS-specific code
that can go and enumerate all the files and devices the program has
open, and record their current state, and the snapshot loader has to be
able to restore things from that, if possible.

If you were asking about a more general purpose language, like C or
Perl, rather than Java, then I'd also be pointing out things like
semaphores. If the program has a semaphore, and has used it to acquire
ownership of a resource, the snapshot loader had better be able to
acquire ownership of that resource before resuming the program. (This
is probably not a problem in Java, because Java programs tend to only
worry about synchronization issues with other code running in the JVM,
so tend to not have native system semaphores to worry about. However,
if I'm wrong about that, and there is a way to access native semaphores
reasonably in Java, then this would be an issue for a Java snapshot
system).

I almost forgot databases. What if the program has an open connection
to a database, and is in the middle of a transaction. The snapshot
taker will have to roll back the transaction (well, that will probably
happen automatically if the connection is closed after the snapshot is
taken). The snapshot loader would need to reconnect to the database,
begin the transaction, and issue the statements that are supposed to
have already been issued up to that point in the transaction.

Databases was mentioned before, but you are right. You think about a
generic snapshot tools wich would do all the work alone, but it can't be
done. Of course, the application would need to be designed to support
that feature. If you have tried to close some threads of ICQ (IIRC),
they are re-created, so some application are designed to be robusts.

But anyway it doesn't exist yet...
 
R

Roedy Green

is there any way (jdk tools or commercial product) to take a "snapshot"
of a running java application, which can be used to restart a new
instance of the application, resuming the execution with the snapshot ?

this is what I call "gespenstering" I implemented it for BBL Forth
and Abundance.

Basically you create a ram image. The catch is how to create the
relocatable tables so that if the program is reloaded somewhere else,
it will be appropriately adjusted.

To implement it in Java would require the careful co-operation of the
writers of the JVM.

see http://mindprod.com/jgloss/gespenstering.html

I did this back in the DOS days when TSRs made your load address
unstable. You might implement it today by just giving up if the load
address changes.

Saving the RAW ram image could be done with a bit of JNI and some
knowledge of the inner workings so you know what sections of RAM to
save. You then have to build an exe header.

I also implemented Jaunting (where I take stack snapshots). By
restoring the stack state, I can make a program jump backward in time
and pick up where it left off at some previous snapshot.

You would need in intimate knowledge of the JVM to pull this off.

However the difficult part implementing it for the JVM would be
reopening files that were open at the time of the snapshot, including
restoring the state (possibly even including OS buffers).

You might do gesperstering where it is not totally transparent to the
app. You leave it up to the app to close all files on snap and
reopen/restore them on restart.

I called for this as a way of creating instant start apps for Java.
See http://mindprod.com/project/gespenster.html

The closest I have seen was a now defunct Lotus project called Ensuite
that used serialisation to snap/restore system state.

The JET people are sneaking up on this. The latest release 6.4 in a
way simulates restoring a snapshot of the app just after it has
started. This allows programs to start as quickly as C++ programs.
see http://mindprod.com/jgloss/jet.html
 
L

ldv

Hi,
is there any way (jdk tools or commercial product) to take a "snapshot"
of a runningjavaapplication, which can be used to restart a new
instance of the application, resuming the execution with the snapshot ?

Of course, i'm thinking about debugging...

This is not possible in the general case, because the application may
depend on external resources (files, network connections) that may
become unavailable or change state upon resume, and events (user
input, network traffic). Say, you have a real-time network traffic
analyzer and took a snapshot of you app before it crashed. Unless you
can replay the network traffic, you may be unable to reproduce the
crash.

Otherwise, have a look at Replay Solutions (http://
www.replaysolutions.com/)

HTH,

LDV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top