Coordinated hooking mechanism for checkpointing virtual machines
Aspects of the invention include systems and methods configured to checkpoint an application executing on a virtual machine. Aspects include receiving from a first thread executing on a virtual machine a call to a checkpoint application program interface (API) and suspending, by the virtual machine, execution of all threads other than the first thread. Aspects also includes executing, by the virtual machine, all application checkpoint hooks and executing, by the virtual machine, all virtual machine checkpoint hooks. Aspects further include creating one or more checkpoint image files.
1 . A computer-implemented method for checkpointing an application executing on a virtual machine, the method comprising:
registering, with the virtual machine, application checkpoint hooks from the application, wherein the application checkpoint hooks are portions of code of the application that are configured to perform application level compensation tasks;
receiving, from a first thread executing on the virtual machine, a call to a checkpoint application program interface (API), wherein the virtual machine having virtual machine checkpoint hooks and virtual machine checkpoint hooks are portions of code of the virtual machine that are configured to perform virtual machine compensation tasks;
suspending, by the virtual machine, execution of all threads other than the first thread, including:
performing a global suspend operation which suspends the execution of all threads;
walking a virtual machine thread list to add a CHECKPOINT_HALT_FLAG to all application threads other than the first thread; and
performing a global resume operation which resumes operation of all threads that do not have a CHECKPOINT_HALT_FLAG, thereby placing the virtual machine into a single-threaded operating mode in which only the first thread continues execution;
while in the single-threaded operating mode, executing, by the virtual machine, all application checkpoint hooks;
while in the single-threaded operating mode, executing, by the virtual machine, all virtual machine checkpoint hooks; and
creating one or more checkpoint image files in response to executing the application checkpoint hooks and the virtual machine checkpoint hooks.
2 . The computer-implemented method of claim 1 , further comprising aborting checkpointing the application based on detecting an error executing one or more of the application checkpoint hooks and the virtual machine checkpoint hooks.
3 . The computer-implemented method of claim 1 , further comprising:
receiving a request to restore the application based on the one or more checkpoint image files;
executing, by the virtual machine, all application restore hooks;
executing, by the virtual machine, all virtual machine restore hooks; and
resuming a multi-threaded operating mode by resuming all suspended threads.
4 . The computer-implemented method of claim 3 , wherein resuming all suspended threads includes performing a global suspend operation which suspends execution of all threads, walking a virtual machine thread list to remove the CHECKPOINTHALTFLAG from all application threads, and performing a global resume operation which resumes operation of all threads.
5 . A computer program product for checkpointing an application executing on a virtual machine comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by one or more processors to cause the one or more processors to perform operations comprising:
registering, with the virtual machine, application checkpoint hooks from the application, wherein the application checkpoint hooks are portions of code of the application that are configured to perform application level compensation tasks;
receiving, from a first thread executing on the virtual machine, a call to a checkpoint application program interface (API), wherein the virtual machine having virtual machine checkpoint hooks and virtual machine checkpoint hooks are portions of code of the virtual machine that are configured to perform virtual machine compensation tasks;
suspending, by the virtual machine, execution of all threads other than the first thread, including:
performing a global suspend operation which suspends the execution of all threads;
walking a virtual machine thread list to add a CHECKPOINT_HALT_FLAG to all application threads other than the first thread; and
performing a global resume operation which resumes operation of all threads that do not have a CHECKPOINTHALTFLAG, thereby placing the virtual machine into a single-threaded operating mode in which only the first thread continues execution;
while in the single-threaded operating mode, executing, by the virtual machine, all application checkpoint hooks;
while in the single-threaded operating mode, executing, by the virtual machine, all virtual machine checkpoint hooks; and
creating one or more checkpoint image files in response to executing the application checkpoint hooks and the virtual machine checkpoint hooks.
6 . The computer program product of claim 5 , wherein the operations further comprise aborting checkpointing the application based on detecting an error executing one or more of the application checkpoint hooks and the virtual machine checkpoint hooks.
7 . The computer program product of claim 5 , wherein the operations further comprise:
receiving a request to restore the application based on the one or more checkpoint image files;
executing, by the virtual machine, all application restore hooks;
executing, by the virtual machine, all virtual machine restore hooks; and
resuming a multi-threaded operating mode by resuming all suspended threads.
8 . The computer program product of claim 7 , wherein resuming the multi-threaded operating mode includes performing a global suspend operation which suspends execution of all threads, walking a virtual machine thread list to remove the CHECKPOINTHALTFLAG from all application threads, and performing a global resume operation which resumes operation of all threads.
9 . A computer-implemented method for a-checkpointing an application in a managed runtime environment of a computing system, the computer-implemented process comprising:
registering, with the managed runtime environment, application checkpoint hooks from the application, wherein the application checkpoint hooks are portions of the code of the application that are configured to perform application level compensation tasks;
receiving, from a first thread executing on the managed runtime environment, a call to checkpoint application programming interface (API), wherein the managed runtime environment having a first set of managed runtime environment checkpoint hooks registered by a provider of the managed runtime environment and the first managed runtime environment checkpoint hooks are portions of code of the managed runtime environment that are configured to perform virtual machine compensation tasks;
suspending, by the managed runtime environment, execution of all threads other than the first thread, including:
performing a global suspend operation which suspends the execution of all threads,
walking a virtual machine thread list to add a CHECKPOINT_HALT_FLAG to all application threads other than the first thread, and
performing a global resume operation which resumes operation of all threads that do not have a CHECKPOINT_HALT_FLAG, thereby placing the managed runtime environment into a single-threaded operating mode in which only the first thread continues execution;
while in the single-threaded operating mode, executing, by the managed runtime environment, all application checkpoint hooks;
while in the single-threaded operating mode, executing, by the managed runtime environment, all managed runtime environment checkpoint hooks; and
creating, by the managed runtime environment, one or more checkpoint image files in response to executing the application checkpoint hooks and the managed runtime environment checkpoint hooks.
10 . The computer-implemented method of claim 9 , further comprising:
in response to receiving a request to restore the application, restoring the managed runtime environment to a state at a time of the checkpoint;
executing, by the managed runtime environment, a set of managed runtime environment restore hooks registered by the provider of the managed runtime environment;
executing, by the managed runtime environment, a set of application restore hooks registered by the application;
resuming a multi-threaded operating mode by resuming execution of the suspended threads by the managed runtime environment; and
completing return from the checkpoint application programming interface call.
11 . The computer-implemented method of claim 10 , wherein the set of application restore hooks are portions of code of the application that are configured to perform application level compensation tasks.
12 . The computer-implemented method of claim 10 , wherein the set of managed runtime environment restore hooks are portions of code of the managed runtime environment that are configured to perform virtual machine compensation tasks.