1. A method comprising: calculating an exit-enter time (EET) to exit and enter a context and a save-restore time (SRT) to save and restore a machine state; executing a selective algorithm that saves and restores the machine state on selected context changes and accumulating statistics for an expected value for EET overhead and an expected value for SRT overhead while executing the selective algorithm; computing a cost of the selective algorithm using the expected value for EET overhead and the expected value for SRT overhead; comparing the cost of the selective algorithm to two times SRT which is the cost of an unconditional algorithm that always saves and restores the machine state on context changes; and selecting one of the selective algorithm or the unconditional algorithm having the least cost as a virtualization algorithm to virtualize context changes.