Volker Simonis (@volker_simonis)
Principal Software Engineer
AWS
org.crac
as a wrapper for:jdk.crac
/ javax.crac
/ -Dorg.crac.Core.Compat=..
import org.crac.Context;
import org.crac.Core;
import org.crac.Resource;
@Component
public class MyCheckpointRestoreListener implements Resource {
@Autowired
public MyCheckpointRestoreListener(...) {
Core.getGlobalContext().register(this);
logger.info("=> MyCheckpointRestoreListener: Registering in {}", Core.getGlobalContext());
}
@Override
public void beforeCheckpoint(Context<? extends Resource> context) {
logger.info("=> MyCheckpointRestoreListener: beforeCheckpoint");
}
@Override
public void afterRestore(Context<? extends Resource> context) {
logger.info("=> MyCheckpointRestoreListener: afterRestore");
}
}
org.crac
APIorg.crac
APIorg.crac
API-Dorg.crac.Core.Compat=io.simonis.crac
package io.simonis.crac.impl;
public class FirecrackerContext extends Context<Resource> {
private final ArrayList<WeakReference<Resource>> resources = new ArrayList<>();
@Override
public void register(Resource resource) {
resources.add(new WeakReference<Resource>(resource));
}
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws CheckpointException {
for (var iterator = resources.listIterator(resources.size()); iterator.hasPrevious();) {
Resource r = iterator.previous().get();
r.beforeCheckpoint(this);
...
@Override
public void afterRestore(Context<? extends Resource> context) throws RestoreException {
for (var iterator = resources.listIterator(); iterator.hasNext();) {
...
jint Java_io_simonis_SuspendResumeAgent_suspendThreads(JNIEnv *env, jclass cls) {
jint threads_count;
jthread *threads;
jvmti->GetAllThreads(&threads_count, &threads);
...
jvmtiError error = jvmti->SuspendThreadList(threads_count - 1, threads, errors);
jint Java_io_simonis_SuspendResumeAgent_resumeThreads(JNIEnv *env, jclass cls) {
jint threads_count;
jthread *threads;
jvmti->GetAllThreads(&threads_count, &threads);
...
jvmtiError error = jvmti->ResumeThreadList(threads_count, threads, errors);
jint Java_io_simonis_SuspendResumeAgent_forceGC(JNIEnv *env, jclass cls) {
jvmtiError error = jvmti->ForceGarbageCollection();
userfaultfd
ioctl()
) to:
mprotect()
/SIGSEGV
handler)userfaultfd
DEMO