Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add criu vmstates #15867

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions runtime/criusupport/criusupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
BOOLEAN syslogFlagNone = TRUE;
char *syslogOptions = NULL;
I_32 syslogBufferSize = 0;
UDATA oldVMState = VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_START);

vmFuncs->internalEnterVMFromJNI(currentThread);

Expand Down Expand Up @@ -484,6 +485,8 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,

releaseSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_JAVA_HOOKS);

if (FALSE == vmFuncs->jvmCheckpointHooks(currentThread)) {
/* throw the pending exception */
goto wakeJavaThreads;
Expand All @@ -496,6 +499,8 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,

acquireSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_INTERNAL_HOOKS);

/* Run internal checkpoint hooks, after iterating heap objects */
if (FALSE == vmFuncs->runInternalJVMCheckpointHooks(currentThread)) {
currentExceptionClass = vm->criuJVMCheckpointExceptionClass;
Expand Down Expand Up @@ -536,7 +541,9 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
syslogFlagNone = FALSE;
}

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_END);
systemReturnCode = criu_dump();
VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_START);
if (!syslogFlagNone) {
/* Re-open the system logger, and set options with saved string value. */
j9port_control(J9PORT_CTLDATA_SYSLOG_OPEN, 0);
Expand Down Expand Up @@ -585,6 +592,8 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
/* We can only end up here if the CRIU restore was successful */
isAfterCheckpoint = TRUE;

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_JAVA_HOOKS);

/* Run internal restore hooks, and cleanup */
if (FALSE == vmFuncs->runInternalJVMRestoreHooks(currentThread)) {
currentExceptionClass = vm->criuRestoreExceptionClass;
Expand All @@ -595,6 +604,8 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,

releaseSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_INTERNAL_HOOKS);

if (FALSE == vmFuncs->jvmRestoreHooks(currentThread)) {
/* throw the pending exception */
goto wakeJavaThreads;
Expand All @@ -617,6 +628,8 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
toggleSuspendOnJavaThreads(currentThread, FALSE);

releaseSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_END);
closeWorkDirFD:
if ((0 != close(workDirFD)) && (NULL == currentExceptionClass)) {
systemReturnCode = errno;
Expand Down Expand Up @@ -650,6 +663,7 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
j9mem_free_memory(directoryChars);
}

VM_VMHelpers::setVMState(currentThread, oldVMState);
vmFuncs->internalExitVMToJNI(currentThread);
#endif /* defined(LINUX) */
}
Expand Down
9 changes: 9 additions & 0 deletions runtime/oti/VMHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,15 @@ class VM_VMHelpers
vmThread->javaVM->internalVMFunctions->freeContinuation(vmThread, objectPtr);
#endif /* JAVA_SPEC_VERSION >= 19 */
}

static VMINLINE UDATA
setVMState(J9VMThread *currentThread, UDATA newState)
{
UDATA oldState = currentThread->omrVMThread->vmState;
currentThread->omrVMThread->vmState = newState;
return oldState;
}

};

#endif /* VMHELPERS_HPP_ */
8 changes: 8 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5285,6 +5285,14 @@ typedef struct J9VMThread {
#define J9VMSTATE_ATTACHEDDATA_FIND 0x8000B
#define J9VMSTATE_ATTACHEDDATA_UPDATE 0x8000C
#define J9VMSTATE_SNW_STACK_VALIDATE 0x110000
#define J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_START 0x200000
#define J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_JAVA_HOOKS 0x200001
#define J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_INTERNAL_HOOKS 0x200002
#define J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_END 0x200003
#define J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_START 0x400000
#define J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_JAVA_HOOKS 0x400004
#define J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_INTERNAL_HOOKS 0x400005
#define J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_END 0x400006
#define J9VMSTATE_GP 0xFFFF0000
#define J9VMTHREAD_OBJECT_MONITOR_CACHE_SIZE J9VM_OBJECT_MONITOR_CACHE_SIZE

Expand Down
26 changes: 8 additions & 18 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ class INTERPRETER_CLASS
UDATA *bp = buildMethodFrame(REGISTER_ARGS, _sendMethod, J9_SSF_JIT_NATIVE_TRANSITION_FRAME);
updateVMStruct(REGISTER_ARGS);
/* this call cannot change bp as no java code is run */
UDATA oldState = pushVMState(REGISTER_ARGS, J9VMSTATE_JIT);
UDATA oldState = VM_VMHelpers::setVMState(_currentThread, J9VMSTATE_JIT);
J9JITConfig *jitConfig = _vm->jitConfig;
jitConfig->entryPoint(jitConfig, _currentThread, _sendMethod, 0);
popVMState(REGISTER_ARGS, oldState);
VM_VMHelpers::setVMState(_currentThread, oldState);
VMStructHasBeenUpdated(REGISTER_ARGS);
restoreSpecialStackFrameLeavingArgs(REGISTER_ARGS, bp);
if (MASK_PC(_pc) != MASK_PC(_literals)) {
Expand Down Expand Up @@ -1895,16 +1895,6 @@ class INTERPRETER_CLASS
return EXECUTE_BYTECODE;
}

VMINLINE UDATA
pushVMState(REGISTER_ARGS_LIST, UDATA newState)
{
UDATA oldState = _currentThread->omrVMThread->vmState;
_currentThread->omrVMThread->vmState = newState;
return oldState;
}

VMINLINE void popVMState(REGISTER_ARGS_LIST, UDATA oldState) { _currentThread->omrVMThread->vmState = oldState; }

VMINLINE bool startAddressIsCompiled(UDATA extra) { return J9_ARE_NO_BITS_SET(extra, J9_STARTPC_NOT_TRANSLATED); }
VMINLINE bool methodIsCompiled(J9Method *method) { return startAddressIsCompiled((UDATA)method->extra); }
VMINLINE bool singleStepEnabled() { return 0 != _vm->jitConfig->singleStepCount; }
Expand Down Expand Up @@ -1935,10 +1925,10 @@ class INTERPRETER_CLASS
UDATA *bp = buildMethodFrame(REGISTER_ARGS, _sendMethod, 0);
updateVMStruct(REGISTER_ARGS);
/* this call cannot change bp as no java code is run */
UDATA oldState = pushVMState(REGISTER_ARGS, J9VMSTATE_JIT);
UDATA oldState = VM_VMHelpers::setVMState(_currentThread, J9VMSTATE_JIT);
J9JITConfig *jitConfig = _vm->jitConfig;
jitConfig->entryPoint(jitConfig, _currentThread, _sendMethod, 0);
popVMState(REGISTER_ARGS, oldState);
VM_VMHelpers::setVMState(_currentThread, oldState);
VMStructHasBeenUpdated(REGISTER_ARGS);
restoreSpecialStackFrameLeavingArgs(REGISTER_ARGS, bp);
/* If the method is now compiled, run it compiled, otherwise run it bytecoded */
Expand Down Expand Up @@ -2108,10 +2098,10 @@ class INTERPRETER_CLASS
UDATA *bp = buildMethodFrame(REGISTER_ARGS, _sendMethod, jitStackFrameFlags(REGISTER_ARGS, 0));
updateVMStruct(REGISTER_ARGS);
/* this call cannot change bp as no java code is run */
UDATA oldState = pushVMState(REGISTER_ARGS, J9VMSTATE_JIT);
UDATA oldState = VM_VMHelpers::setVMState(_currentThread, J9VMSTATE_JIT);
J9JITConfig *jitConfig = _vm->jitConfig;
jitConfig->entryPoint(jitConfig, _currentThread, _sendMethod, 0);
popVMState(REGISTER_ARGS, oldState);
VM_VMHelpers::setVMState(_currentThread, oldState);
VMStructHasBeenUpdated(REGISTER_ARGS);
J9SFMethodFrame *methodFrame = (J9SFMethodFrame*)_sp;
_currentThread->jitStackFrameFlags = methodFrame->specialFrameFlags & J9_SSF_JIT_NATIVE_TRANSITION_FRAME;
Expand Down Expand Up @@ -2326,9 +2316,9 @@ class INTERPRETER_CLASS
jniMethodStartAddress = (void*)CEEJNIWrapper;
}
#endif /* J9VM_PORT_ZOS_CEEHDLRSUPPORT */
UDATA oldVMState = pushVMState(REGISTER_ARGS, J9VMSTATE_JNI);
UDATA oldVMState = VM_VMHelpers::setVMState(_currentThread, J9VMSTATE_JNI);
FFI_Return result = cJNICallout(REGISTER_ARGS, receiverAddress, javaArgs, returnType, &(_currentThread->returnValue), jniMethodStartAddress, isStatic);
popVMState(REGISTER_ARGS, oldVMState);
VM_VMHelpers::setVMState(_currentThread, oldVMState);
#if defined(J9VM_PORT_ZOS_CEEHDLRSUPPORT)
if (J9_ARE_ANY_BITS_SET(_vm->sigFlags, J9_SIG_ZOS_CEEHDLR)) {
/* verify that the native didn't resume execution after an LE condition and illegally return to Java */
Expand Down