Method and apparatus for handling exceptions during binding to native code
Abstract
A method of handling exceptions during native binding under program code conversion from subject code ( 17 ) executable by a subject computing architecture to target code ( 21 ) executable by a target computing architecture. Performing native binding executes a portion of native code ( 28 ) in place of translating a portion of the subject code ( 17 ) into the target code ( 21 ). When an exception occurs during the portion of native code ( 28 ), the method comprises saving a target state (T′) which represents a current point of execution in the target computing architecture for the portion of native code ( 28 ), and creating a subject state (S′) which represents an emulated point of execution in the subject computing architecture. The exception is handled through a subject exception handler ( 170, 170 ′) with reference to the subject state (S′), such that, upon resuming execution from the exception using the provided subject state (S′), the saved target state (T′) is restored to resume execution in the section of portion of native code ( 28 ). In one embodiment, the subject state (S′) links to the saved target state (T′) through a recovery unit ( 192 ).
Claims
exact text as granted — not AI-modified1 . A method of handling an exception, comprising the steps of:
(a) performing program code conversion to convert subject code executable by a subject computing architecture into target code executable by a target computing architecture; (b) executing a portion of native code which is native to the target computing architecture in substitution for translating a portion of the subject code into the target code; (c) in response to an exception arising during execution of the portion of native code, performing the steps of:
(i) saving a target state which represents a current point of execution in the target computing architecture with respect to the native code portion;
(ii) generating a subject state which represents an emulated point of execution in the subject computing architecture; and
(iii) handling the exception with reference to the subject state; and
(d) resuming execution from the exception by using the subject state to restore the target state, and then using the target state to resume execution of the native code portion.
2 . The method of claim 1 , wherein the subject state comprises a link to the target state.
3 . The method of claim 1 , wherein the step (d) comprises executing a recovery routine to restore the target state.
4 . The method of claim 1 , wherein the subject state includes a modified subject program counter and the method further comprises passing execution control to the modified subject program counter thereby executing a recovery routine to load the target state and return execution control to the portion of native code.
5 . The method of claim 4 , wherein the modified subject program counter has a predetermined value and the method further comprises detecting the predetermined value and redirecting execution control to execute the recovery routine.
6 . The method of claim 1 , wherein the subject state includes a modified subject program counter, and the method further comprises providing a reserved location to be treated as a portion of the subject code at an address identified by the modified subject program counter.
7 . The method of claim 6 , wherein the reserved location contains subject code instructions and the method comprises translating and executing the subject code instructions as target code, thereby to recover the target state and resume execution of the portion of native code.
8 . The method of claim 6 , wherein the reserved location contains special case instructions which do not fall within an instruction set architecture of the subject computing architecture, and the method comprises detecting the special case instructions and in response executing a recovery routine to recover the saved target state and resume execution of the portion of native code.
9 . The method of claim 6 , comprising using the modified subject program counter as a return address after handling the exception, when attempting to restart execution of the subject code at a point where the exception occurred, such that execution control passes to the reserved location.
10 . The method of claim 1 , further comprising the steps of:
converting a caller portion of the subject code into target code and forming a first subject state including at least a subject program counter; calling the portion of native code from the caller portion of target code; and copying and modifying the first subject state to form the subject state.
11 . The method of claim 1 , further comprising providing a subject stack data structure in a memory of in the target computing architecture for emulating execution of the subject code on the subject computing architecture, and executing the portion of native code using the subject stack.
12 . The method of claim 1 , further comprising providing a subject stack in the target computing architecture for emulating execution of the subject code on the subject computing architecture, and storing the subject state on the subject stack prior to handling the exception whereby the stored subject state is available from the subject stack after handling the exception.
13 . The method of claim 1 , further comprising providing a subject stack in the target computing architecture for emulating execution of the subject code on the subject computing architecture, and saving the target state on the subject stack prior to handling the exception whereby the target state is available from the subject stack after handling the exception.
14 . The method of claim 13 , wherein the step of saving the target state comprises saving values of a set of registers of a target processor of the target computing architecture onto the subject stack, and the method further comprises restoring the target state including loading the saved values from the subject stack into the set of registers.
15 . The method of claim 1 , further comprising handling the exception and determining to resume execution of the subject code at a point where the exception occurred using the subject state, or to resume execution of the subject program at another point in the subject code by altering a subject program counter in the subject state.
16 . A method of handling an exception, comprising the steps of:
converting subject code executable by a subject computing platform into target code executable by a target computing platform, including converting a caller portion of subject code into a caller portion of target code; executing the caller portion of target code thereby generating on the target computing platform a first target state relating to execution of the target code and emulating a first subject state representing execution of the caller portion of subject code on the subject computing platform; calling from the caller portion of target code to a portion of native code which is native to the target computing platform; executing the portion of native code on the target computing platform thereby generating a second target state and, where an exception occurs during execution of the portion of native code, saving the second target state and generating a second subject state based on the first subject state wherein the second subject state comprises a link to the second target state; and handling the exception with reference to the second subject state and using the second subject state to link to the second target state to thereby resume execution in the portion of native 7 code.
17 . The method of claim 16 , further comprising the step of executing of a recovery routine to restore the second target state when resuming execution from the exception.
18 . The method of claim 16 , wherein the second subject state comprises a modified subject program counter and the method further comprises passing execution control to the modified subject program counter, loading a recovery routine to load the saved second target state, and thereby returning execution control to the portion of native code.
19 . The method of claim 18 , wherein the modified subject program counter has a predetermined value and the method further comprises detecting the predetermined value and redirecting execution control to the recovery routine.
20 . The method of claim 16 , wherein the second subject state comprises a modified subject program counter, and the method further comprises providing a reserved location treated as a portion of the subject code at an address identified by the modified subject program counter.
21 . The method of claim 20 , wherein the reserved location contains subject code instructions and the method comprises converting and executing the subject code instructions as target code thereby causing recovery of the saved target state whereby the portion of native code resumes execution.
22 . The method of claim 20 , wherein the reserved location contains special case instructions which do not fall within an instruction set architecture of the subject computing platform, and the method comprises detecting the special case instructions and in response executing a recovery routine to recover the saved second target state thereby enable execution of the portion of native code to resume.
23 . The method of claim 20 , comprising using the modified subject program counter as a return address after handling the exception, when attempting to restart execution at a point where the exception occurred, whereby execution control passes to the reserved location.
24 . The method of claim 16 , wherein the first subject state comprises at least a subject program counter, and wherein generating the second subject state comprises copying the first subject state to form the subject state and modifying the subject program counter to a modified value.
25 . The method of claim 16 , further comprising providing a subject stack data structure in the target computing platform for emulating execution of the subject code on the subject computing platform, and executing the portion of native code with reference to the subject stack.
26 . The method of claim 16 , further comprising providing a subject stack in the target computing platform for emulating execution of the subject code on the subject computing platform, and storing at least the second subject state on the subject stack prior to handling the exception, such that the stored second subject state is available from the subject stack after handling the exception.
27 . The method of claim 16 , further comprising providing a subject stack in the target computing platform for emulating execution of the subject code on the subject computing platform, and saving at least the second target state on the subject stack prior to handling the exception, such that the saved second target state is available from the subject stack after handling the exception.
28 . The method of claim 27 , wherein the step of saving the second target state comprises saving values of a set of target registers of a target processor of the target computing platform onto the subject stack, and the method further comprises restoring the second target state including loading the saved values from the subject stack into the set of target registers.
29 . The method of claim 16 , further comprising handling the exception and determining to resume execution at a point where the exception occurred using the subject state, or to resume execution of the subject program at another point in the subject code by altering a subject program counter in the subject state.
30 . A target computing platform arranged to handle exceptions during binding to native code, comprising:
a translator unit arranged to translate subject code executable by a subject computing platform into target code executable by the target computing platform, and arranged to substitute a portion of native code which is native to the target computing platform instead of translating a portion of the subject code into the target code; an execution unit arranged to execute the target code and the native code, and to raise an exception signal when an exception occurs; an exception handler unit arranged to detect the exception signal raised by the execution unit during execution of the native code, cause the saving of a target state which represents a current point of execution in the execution unit for the native code, provide a subject state which represents an emulated point of execution in the subject computing platform, and handle the exception with reference to the subject state; and a recovery unit arranged to restore the saved target state by linking from the subject state and thereby resume execution of the native code in the execution unit using the saved target state.
31 . A translator apparatus arranged to handle exceptions during binding to native code, comprising:
a translator unit arranged to convert subject code executable by a subject computing platform into target code executable by a target computing platform, and arranged to cause the target computing platform to execute a portion of native code which is native to the target computing platform in substitution for converting a portion of the subject code into the target code, and further wherein the translator unit is arranged to convert caller subject code into caller target code for execution by the target computing platform to provide a first target state and a first subject state and to cause at least the first subject state to be saved when calling into a portion of the native code from the caller target code; an exception handler unit arranged to detect an exception signal raised during execution of the native code, cause the saving of a second target state which represents a current point of execution in the target computing platform for the native code, and provide a second subject state, wherein the second subject state comprises a link to the second target state; a subject exception handler unit arranged to handle the exception with reference to the second subject state; and a recovery unit arranged to cause the target computing platform to resume execution of the native code by linking to the second target state from the second subject state.
32 . A computer-readable medium having recorded thereon instructions implementable by a computer to perform a method of handling an exception, comprising the steps of:
(a) performing program code conversion to convert subject code executable by a subject computing architecture into target code executable by a target computing architecture; (b) executing a portion of native code which is native to the target computing architecture in substitution for translating a portion of the subject code into the target code; (c) in response to an exception arising during execution of the portion of native code, performing the steps of:
(i) saving a target state which represents a current point of execution in the target computing architecture with respect to the native code portion;
(ii) generating a subject state which represents an emulated point of execution in the subject computing architecture; and
(iii) handling the exception with reference to the subject state; and
(d) resuming execution from the exception by using the subject state to restore the target state, and then using the target state to resume execution of the native code portion.
33 . A computer-readable medium having recorded thereon instructions implementable by a computer to perform a method of handling an exception, comprising the steps of:
converting subject code executable by a subject computing platform into target code executable by a target computing platform, including converting a caller portion of subject code into a caller portion of target code; executing the caller portion of target code thereby generating on the target computing platform a first target state relating to execution of the target code and emulating a first subject state representing execution of the caller portion of subject code on the subject computing platform; calling from the caller portion of target code to a portion of native code which is native to the target computing platform; executing the portion of native code on the target computing platform thereby generating a second target state and, where an exception occurs during execution of the portion of native code, saving the second target state and generating a second subject state based on the first subject state wherein the second subject state comprises a link to the second target state; and handling the exception with reference to the second subject state and using the second subject state to link to the second target state to thereby resume execution in the portion of native code.Cited by (0)
No later patents cite this yet.
References (0)
No backward citations on record.