The present invention generally relates to recovery from errors in computer programs, and more particularly to using alternative code to recover execution of a failed computer program.
Certain types of software errors are fatal to program execution. For example, a reference to a memory address that is beyond the address domain of a program will likely result in a fatal error. Certain timing or other transient conditions may also trigger fatal errors. While certain errors may be within the control of the software developer, the developer may be unable to guard against certain other errors in developing the software.
Program errors that are transient or timing-related are problematic to both the program user and to the program developer. From the user's point of view, failure of the program not only interrupts the task at hand, but may also result in lost work product. Reporting such transient errors is also difficult since the conditions required to reproduce the problem are likely to be unknown.
From the developer's point of view, much time may be spent trying to find the root cause of a problem where the root cause is external to the program. Furthermore, tracing the root cause of the problem may be difficult and time-consuming if there is there is scant information available for reproducing the problem.
A method and apparatus that address the aforementioned problems, as well as other related problems, are therefore desirable.
In various embodiments, a computer implemented method is provided for recovery from fatal program errors. A program is compiled using two compilers to generate first and second sets of object code. Checkpoints are identified in the program, and checkpoint code is generated for execution at the checkpoints. If execution of the first set of object code fails, checkpoint data is recovered and execution of the program is resumed using either the first or second set of object code. In one embodiment, the first set of object code is re-executed before trying the second set of object code. In another embodiment, the second set of object code automatically executed upon failure of the first set of object code.
It will be appreciated that various other embodiments are set forth in the Detailed Description and Claims which follow.
Various aspects and advantages of the invention will become apparent upon review of the following detailed description and upon reference to the drawings in which:
In various embodiments, the present invention provides a method and apparatus for generating alternative code that supports recovery from a fatal program error.
At steps 202 and 204, the program source code is compiled using two different compilers, and two sets of object code that are functionally equivalent are created from the compilation. For example, the compilers may be different versions of the same compiler or compilers from different vendors. For making the two sets of object code interchangeable, checkpoints are identified and checkpoint code is generated for the two sets of object code at step 206. Known computer platforms allow multiple compilers to coexist and also allow inter-operation at the function/procedure call level.
In one embodiment, the checkpoints are identified and the code generated as described in the co-pending patent application entitled, “Compiler-based Checkpointing for Support of Error Recovery” by Ziegler et al. and filed on Oct. 30, 2000, which has patent/application Ser. No. 09/702,590 is commonly assigned to the assignee of the present invention, and the contents of which are incorporated herein by reference. Each segment of code is delineated by a checkpoint, as determined by the compiler. The checkpoints are points in the code when the state of the program stored so that execution can be recovered at the point in the program following the checkpoint. For example, convenient places for checkpoints are procedure boundaries.
At step 208, the code that performs the checkpointing is generated and combined with the intermediate code that was generated from the user's source code. Along with the checkpointing code, a data structure is created for storage of the checkpoint data at step 208.
Checkpoint data are alternately stored in checkpoint data sets 260a and 260b for consecutive checkpoints. For example, at time t1, checkpoint data set 260a references checkpoint 262 and checkpoint data set 260b references checkpoint 264. At time t2 after program execution completes checkpoint 266, checkpoint data set 260a references checkpoint 266, and checkpoint data set 260b references checkpoint 264.
Timestamps or commit flags may be used in alternative embodiments to indicate which of the checkpoint data sets is to be used in recovery. The timestamp scheme involves writing a timestamp to a checkpoint data set when the storage of state information in the checkpoint data set is complete. Thus, the later of the two timestamps indicates which of checkpoint data sets 260a or 260b is to be used in recovery. The commit flag scheme involves a flag that indicates which of checkpoint data sets 260a or 206b is to be used in recovery.
Compilation of the program source code results in program object code 104 that includes two sets of object segments, object segments 1-n and object segments 1-n′. The object segments in each set correspond to the source segments of program source code 102.
Each set of object segments is code that is generated in compiling the source code with different compilers or code generators. In other words, object segments 1′-n′ are generated by a first compiler, and object segments 1′-n′ are generated by a different compiler. If the program fails during execution of segment i, for example, then the state of the checkpoint data can be recovered from checkpoint that precedes segment i and execution can resume at segment i′.
The process begins when a program error has been detected by the operating system, for example. At step 304, checkpoint data is restored, and at step 306 the program counter is reset to the selected checkpoint. The segment of object code from the first set of segments is re-executed at step 308. If the program executes the segment without error, decision step 310 and step 312 illustrate that the program continues with execution of the segments from the first set.
If an error recurs in executing the segment of code from the first set, control is directed to decision step 314, which determines whether the alternative code should be tried. In one embodiment, the first set of segments of code may be re-executed a selected number of times before trying execution of the alternative code. Control is directed to step 316 when the decision is made to execute the alternative code.
At step 316, checkpoint data is restored, and at step 318, the address of the segment of object code from the second set is selected for execution. That is, the program counter is loaded with a program address of a segment in the second set. At step 320, the alternative segment of object code is executed, and execution of the segments of code from the second set continues at step 322.
Returning now to decision step 314, if the decision is made to not execute the alternative code, control is directed to decision step 324. Decision step 324 tests whether execution of the segment from the first set of segments should be attempted again. If so, control is returned to stop 304 to restore the checkpoint data and try again. Otherwise, the program is exited with an error.
The present invention is believed to be applicable to compilers for a variety of programming languages. Other aspects and embodiments of the present invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. It is intended that the specification and illustrated embodiments be considered as examples only, with a true scope and spirit of the invention being indicated by the following claims.
Number | Name | Date | Kind |
---|---|---|---|
5590277 | Fuchs et al. | Dec 1996 | A |
5621885 | Del Vigna, Jr. | Apr 1997 | A |
5630047 | Wang | May 1997 | A |
5737514 | Stiffler | Apr 1998 | A |
5907673 | Hirayama et al. | May 1999 | A |
5923832 | Shirakihara et al. | Jul 1999 | A |
5958070 | Stiffler | Sep 1999 | A |
6044475 | Chung et al. | Mar 2000 | A |
6154877 | Ramkumar et al. | Nov 2000 | A |
6161193 | Garg et al. | Dec 2000 | A |
6161196 | Tsai | Dec 2000 | A |
6332200 | Meth et al. | Dec 2001 | B1 |
6401216 | Meth et al. | Jun 2002 | B1 |