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

Discussion in 'Java' started by Jack, Jun 18, 2008.

  1. Jack

    Jack Guest

    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...
    Jack, Jun 18, 2008
    #1
    1. Advertising

  2. Jack

    Guest

    On Jun 18, 6:55 am, Jack <> wrote:
    > 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
    , Jun 19, 2008
    #2
    1. Advertising

  3. Jack

    Jack Guest

    a écrit :
    > On Jun 18, 6:55 am, Jack <> wrote:
    >> 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).


    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 ?
    Jack, Jun 19, 2008
    #3
  4. Jack

    Jack Guest

    a écrit :
    > On Jun 18, 6:55 am, Jack <> wrote:
    >> 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).


    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.
    Jack, Jun 19, 2008
    #4
  5. On Jun 18, 7:55 am, Jack <> wrote:
    > 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
    Owen Jacobson, Jun 19, 2008
    #5
  6. Jack

    Jack Guest

    Tim Smith a écrit :
    > In article <485a1374$0$855$>,
    > Jack <> wrote:
    >>> 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 ?

    >
    > 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...
    Jack, Jun 20, 2008
    #6
  7. Jack

    Roedy Green Guest

    On Wed, 18 Jun 2008 13:55:04 +0200, Jack <> wrote,
    quoted or indirectly quoted someone who said :

    >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


    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jun 20, 2008
    #7
  8. Jack

    Guest

    On Jun 18, 6:55 pm, Jack <> wrote:
    > 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
    , Jun 26, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Thomas

    How to open a Snapshot file from ASP.NET

    Steven Thomas, Nov 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    846
    Eliahu
    Nov 19, 2004
  2. Mickey Segal
    Replies:
    1
    Views:
    309
    Thomas Hawtin
    May 19, 2006
  3. markspace

    Java 8 Lambda binary snapshot

    markspace, Nov 11, 2011, in forum: Java
    Replies:
    39
    Views:
    1,441
  4. stumblng.tumblr
    Replies:
    1
    Views:
    204
    stumblng.tumblr
    Feb 4, 2008
  5. Mr. X.
    Replies:
    0
    Views:
    341
    Mr. X.
    Jan 11, 2013
Loading...

Share This Page