Exception Handling with Fail-Safe Semantics Phd Thesis
Total Page:16
File Type:pdf, Size:1020Kb
Exception Handling With Fail-Safe Semantics PhD Thesis Steven J. Drew B.App.Sci. (Computing) Hons. Date: 29th. November, 1996. Principal Supervisor: Prof.K.J.Gough School Of Computing Science Faculty Of Information Technology Queensland University Of Technology DEDICATION To my father for all his love and support, To my mother, I'm glad you saw the start of this, I'll tell you how it ended one day. QUT QUEENSLAND UNIVERSITY OF TECHNOLOGY DOCTOR OF PHILOSOPHY THESIS EXAMINATION CANDIDATE NAME Steven John Drew CENTRE/RESEARCH CONCENTRATION Programming Languages and Systems PRINCIPAL SUPERVISOR Professor John Gough ASSOCIATE SUPERVISOR(S) Dr John Hynd THESIS TITLE Exception Handling with Fail-Safe Semantics Under the requirements of PhD regulation 9.2, the above candidate was examined orally by the Faculty. The members of the panel set up for this examination recommend that the thesis be accepted by the University and forwarded to the appointed Committee for examination. Prof K J Gough Name ....................................................................... Panel Chairperson (Principal Supervisor) Name ...... ~?.';'.<?~.-:~.:.<?.~ .. ~.. -~-~XP.~:.E?~~ ......................... Panel Member Assoc Prof G Mohay Name ....................................................................... Panel Member Under the requirements of PhD regulation 9.15, it is hereby certified that the thesis of the above-named candidate has been examined. I recommend on behalf of the Thesis Examination Committee that the thesis be accepted in fulfilment of the conditions for the award of the degree of Doctor of Philosophy. Name .. :'9r.... Y~~~.. .zy~ • Date .. .<f. ..P~:'?.~ .. Chair of Examiners (Thesis Examination Comrilittee) Keywords Exception handling, programming languages, fail-safety, fail-safe semantics, software fault tolerance, program complexity, program comprehensibility, Modula-2. Abstract Computer architectures are becoming increasingly complex and are being used to solve problems of similarly increasing complexity. Unmastered complexity is the major source. of design and implementation faults which, appearing as 'exceptions' during the execution of a program, often have deleterious or unexpected effects. There is a growing need for facilities to help reduce and handle the effects of program complexity, and to help produce programs which are robust, reliable and correct. A properly designed exception handling mechanism can be an invaluable tool for dealing with faults, errors and other unusual events detected during the execution of a program. A desirable property for an exception handling mechanism is for it to be able to ensure 'safe', if not correct, results under any circumstances. Such an exception handling mechanism may be termed 'fail-safe' if it handles exceptions from any source, without masking any exception occurrence, and if it signals its failure to the operating environment. This thesis presents a taxonomy for exception handling models and explains the consequences of different model characteristics on the appearance and performance of computer programs. The property of 'fail-safety' is explored and its definition refined to apply to systems employing exception handling. The principle is extended to investigate how fail-safety might be imbued into a system of multiple concurrent processes. To provide information for the ISO standardisation of the Modula-2 language, a number of fail-safe exception handling mechanisms were implemented by this author. Details of different model designs and implementations related in this thesis include an implementation which supplies exception handling with zero or low overhead to programs not suffering an exception. The consequences of exception handling are explored with respect to program performance and compiler design, including the levels of optimisation which may be safely provided. Several program characteristics have been found to influence the perceived complexity and comprehensibility of program code. Evaluation of the implemented Modula-2 exception handling models revealed one which exhibited characteristics which should improve program comprehensibility. An experiment was designed and executed to test such a hypothesis; a detailed discussion of the method and results are presented. The final draft of the ISO Modula-2language standard described an exception handling mechanism which did not promote fail-safety and which exhibited features offering no improvement to program comprehensibility. An alternative design for a more comprehensible and fail safe ISO Modula-2language is presented for comparison. lllustrations Figure 1 Pattern of research for PhD Page 8. Figure 2 A dynamic chain. Page 20. Figure 3 Guarded regions. Page 21. Figure 4 Full backward error recovery. Page 22. Figure 5 Mixed backward and forward error recovery. Page 23. Figure 6 Full forward error recovery. Page 24. Figure 7 Exception handler responses. Page 25. Figure 8 The set of all input states. Page 75. Figure 9 Fail-safe responses with Hoare-like notation. Page 82. Figure 10 GPM compiler. Page 106. Figure 11 GPM builder utility. Page 107. Figure 12 Module initialisation and fmalisation. Page 109. Figure 13 Data structures for exception handling. Page 113. Figure 14 Catching an exception during normal code execution. Page 116. Figure 15 Catching an exception in exception handler code. Page 117. Figure 16 Control paths and procedure structure. Page 139. Figure 17 Procedure descriptor table in assembler file. Page 142. Figure 18 Procedures, handlers and control flow. Page 148. Figure 19 Blind robot navigation. Page 280. Figure 20 Trapped. Page 281. Statement of original authorship The work contained in this thesis has not been previously submitted for a degree of diploma at any other higher education institution. To the best of my knowledge and belief, the thesis contains no material previously published or written by another person except where due reference is made. Date: Table Of Contents Chapter 1. An introduction to a Ph.D............................................. 1 1.1. Complexity, software and the role of exception handling . 1 1.2. Exceptions in programs . 2 1.3. Exception handling .............................................. 3 1.4. Exception handling and program fmalisation . 4 1.5. System 'level' and consequences of exception handling ................... 5 1.6. Exception handling and structured programming ........................ 6 1.7. Program fail-safety .............................................. 7 1.8. Extent of research . 8 1.8.1. Implementation of exception handling models for ISO Modula-2 .... 9 1.8.2. Fail-safety . 11 1.8.3. Exception handling and program complexity ................... 12 1.9. Limitations of research .......................................... 14 Chapter 2. Building a taxonomy for exception handling models ........................ 15 2.1. Features distinguishing exception handling models . 15 2.2. Representation of an exception . 16 2.3. Range of exception sources ....................................... 16 2.4. Appearance . 17 2.5. Association of guarded region and handler code ....................... 18 2.6. Visibility of program data objects to handler code . 21 2. 7. Semantics of exception handling . 22 2. 7 .1. Error recovery mechanisms . 22 2. 7 .2. Handler response semantics . 25 2.7.2.1. Resumption .................................... 26 2.7.2.2. Termination .................................... 26 2. 7 .2.2.1. Retrial . 26 2.7.2.2.2. Propagation ............................. 27 2.7.2.2.3. Transfer or Strict Termination ............... 28 2. 7 .2.2.4 Return . 28 2.8. Minor conclusions .............................................. 29 Chapter 3. Exception handling literature review . 32 3.1. Introduction to fault tolerant computing ............................. 32 3.2. Early exception handling models ................................... 35 3.2.1. Parnas [PARN72] ....................................... 35 3.2.2. Homing, Lauer, Melliar-Smith and Randell [HORN74] . 37 3.2.3. Randell [RAND75] ...................................... 39 3.2.4. Lampson, Mitchell and Satterthwaite [LAMP74] ............... 40 3.2.5. Goodenough [GOOD75a,b] ............................... 41 3.2.6. Levin [LEVI77] ........................................ 43 3.2.7. Cocco and Dulli [COCC82] ............................... 45 3.2.8. Knudsen [KNUD84] [KNUD87] ........................... 45 3.2.9. Cristian [CRIS82] ...................................... 47 3.2.10. Campbell and Randell [CAMP86] .......................... 48 3.2.11. Anido and Kramer [ANID87] ............................. 49 3.3. Contemporary exception handling models ............................ 49 3.3.1. CLU: Atkinson, Liskov and Sheifler [ATKI78] ................. 49 3.3.2. C language: Allman and Been [ALLM85] ..................... 51 3.3.3. Algol68: Yemini and Berry [YEMI85] . 52 3.3.4. Modula-2+: P.Rovner [ROVN86] ........................... 55 3.3.5. Numerical Turing: Hull, Cohen, Sawchuk and Wortman [HULL88] . 56 3.3.6. Eiffel: B.Meyer [MEYE88] . 56 3.3.7. Ada: ISOIIEC DIS 1994 [ADAI94] ......................... 58 3.3.8. Modula-3: Cardelli et al. [CARD89] . 60 3.3.9. Exceptional C: N.Gehani [GEHA90] ........................ 61 3.3.10. C++: Koenig and Stroustrup [KOEN90a&b] ................. 63 3.4. Exception handling, software engineering and formal methods ............. 66 3.4.1. Luckham and Polak [LUCK80] ............................. 66 3.4.2. Best and Cristian [BEST81] ............................... 66 3.4.3. Gogolla,