A method and apparatus which comprises, as part of compiling source code into
native
code, identifying a source code block in the source code to optimize using register
promotion, and optimizing the source code block using a register promotion transformation.
Thereafter, compensation native code is generated to update those memory locations
whose values were promoted using register promotion with the up-to-date values
from registers associated with the memory locations. As a result native code corresponding
to any existing source code exception handler associated with the source code block
will have access to the up-to-date memory locations during program execution.