1. A method for optimizing handling of guest code in a Virtual Machine, comprising: identifying, in the guest code, a predetermined pattern that includes unsafe instructions and an instruction that causes an event; executing the guest code in a native mode; upon encountering the instruction that raises an exception, transferring control to a Virtual Machine Monitor; in the Virtual Machine Monitor, detecting the pattern; and rolling back effects of privileged but unsafe instructions and any intervening instructions to ensure correct guest OS (Operating System) code context.