Using Image Compression on Checkpoint
CRaC has built-in compression for checkpoints. You can use this approach in case you need to save some space in return for a relatively small increase in time on restore.
To enable image compression, you must start the JVM with the additional option -XX:CRaCEngineOptions=compression=true
, for example:
java -XX:CRaCCheckpointTo=cr-dir -XX:CRaCEngineOptions=compression=true -jar my_app.jar
A checkpoint created with this additional option, can be restored without the need for additional options:
java -XX:CRaCRestoreFrom=cr-dir
Example With Compression
You can use the following test application to compare the impact of the compression:
public class TestCracCompression {
static public void main(String[] args) throws InterruptedException {
int cnt = 0;
while (true) {
System.out.println(cnt++);
Thread.sleep(1000);
}
}
}
Compile to code to a class file to use it easily in the next steps:
javac TestCracCompression.java
This is the output of the checkpoint creation without compression:
# Start the application in the first terminal
$ java -XX:CRaCCheckpointTo=cr TestCracCompression
0
1
...
# Open a second terminal and create the checkpoint
$ jcmd TestCracCompression JDK.checkpoint
52794:
Command executed successfully
# In the first terminal, the application is stopped
15
16
Jun 13, 2025 10:28:31 AM jdk.internal.crac.LoggerContainer info
INFO: Starting checkpoint
[16,097s][info][crac] Checkpoint ...
Killed
# Check the size of the checkpoint
$ ls -sh cr/pages-1.img
25M cr/pages-1.img
# Restart from the checkpoint
$ java -XX:CRaCRestoreFrom=cr
17
18
...
This is the output of the checkpoint creation with compression:
# Start the application in the first terminal with an extra command line option
$ java -XX:CRaCCheckpointTo=cr -XX:CRaCEngineOptions=compression=true TestCracCompression
# Repeat the same steps to create the checkpoint
# Check the size of the checkpoint
$ ls -sh cr/pages-1.comp.img
5,8M cr/pages-1.comp.img
As you can see in the output above, the size of the checkpoint for this test application reduces from 25MB to 6MB.