diff --git a/runtime/criusupport/criusupport.cpp b/runtime/criusupport/criusupport.cpp index 75d99fc3e66..6e2b485d629 100644 --- a/runtime/criusupport/criusupport.cpp +++ b/runtime/criusupport/criusupport.cpp @@ -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); @@ -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; @@ -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; @@ -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); @@ -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; @@ -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; @@ -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; @@ -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) */ } diff --git a/runtime/oti/VMHelpers.hpp b/runtime/oti/VMHelpers.hpp index ade870a69c8..72526cfc958 100644 --- a/runtime/oti/VMHelpers.hpp +++ b/runtime/oti/VMHelpers.hpp @@ -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_ */ diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index 313be96f8d7..5bc90d6b9e9 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -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 diff --git a/runtime/vm/BytecodeInterpreter.hpp b/runtime/vm/BytecodeInterpreter.hpp index 8e13d223289..423e7fb9334 100644 --- a/runtime/vm/BytecodeInterpreter.hpp +++ b/runtime/vm/BytecodeInterpreter.hpp @@ -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)) { @@ -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; } @@ -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 */ @@ -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; @@ -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 */