Java CRaC resume from checkpoint with arguments

253 views Asked by At

I am experimenting with CRaC on Azul JVM. I have built a checkpoint of my program with

$JAVA_CMD -XX:CRaCCheckpointTo=cr -jar target/cractest-0.1.0-standalone.jar

And I can restore it successfully with

$JAVA_CMD -XX:CRaCRestoreFrom=cr

It works all right. In the next step, I want to pass arguments to the program on restore, so the program can pick it up, ideally just like the following:

$JAVA_CMD -XX:CRaCRestoreFrom=cr -- arg1 arg2 arg3

And normally I would access arg1 arg2 arg3 in the String[] args parameter of main, but since we are resuming a checkpoint, we don't have access to that array anymore.

How could I still access the parameters on checkpoint restore? Is it available in some context object during runtime?

2

There are 2 answers

0
antonkozlov On

In theory, you can build this functionallity by adding a Resource into your program, that will read arguments from a file and call some java code. And then, prior restore, write the parameters to the file.

It all looks general enough to be implemented in the JDK. So since https://github.com/openjdk/crac/pull/16, you can pass a class name and arguments to run on restore. Please check the supplied JavaCompilerCRaC.java.

Ability to run some java code is inteded to do some post-restore actions. For example, setting some parameters, etc. The command line looks like:

java -XX:CRaCRestoreFrom=cr ClassName arg1 arg2 ...

CRaC allows to set properties on restore by

java -XX:CRaCRestoreFrom=cr -DpropName=propValue

But you can implement it yourself:

public class Props {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < args.length; i += 2) {
            System.setProperty(args[i], args[i + 1]);
        }
        printProperties();
    }
}
java -XX:CRaCRestoreFrom=cr Props propName propValue

So the limit is what you can express with java code.

Feedback on this functionallity would be appreciated.

0
Speakjava On

This is not the way CRaC works. You need to think of it as a running application that has been paused. Just as you can't change the arguments to main() of a running application, you can't do this with CRaC.

What you could do is use the afterRestore() method of a class that implements the Resource interface and read new values from some source (e.g. a file).