The invention is directed to a method of replacing code in an object oriented application program running on a
Virtual Machine (VM). The method comprises the steps of receiving at the
virtual machine a request to replace code; in response to
receipt of said request, examining each thread's
call stack to determine if any thread includes a method that will be made obsolete by a proposed code replacement; and, if it is determined that there are no threads that include such a method in their call stacks, performing the code replacement. However, for a thread whose
call stack is determined to include a method that will be made obsolete by the proposed code replacement, the method includes the step of allowing the thread to continue running until the thread unwinds past that method in its
call stack and then suspending said thread. This comprises a part of a process of determining a safe state for code replacement. The invention is also directed to a method of initializing new variables in such replacement code. The variable initialization method comprises the steps of identifying the replaced code and prior to resuming threads containing the replacement code, initializing new variables in the replacement code to values consistent with the application
semantics.