@@ -250,34 +250,37 @@ for(tmp_index = 0; tmp_index < dim_size; ++tmp_index)
250
250
251
251
\section java-bytecode-remove-exceptions Remove exceptions
252
252
253
- When ` remove_exceptions ` is called on the goto model , the goto model contains
254
- complex instructions such as ` CATCH-POP ` , ` CATCH-PUSH ` and ` THROW ` . In order to
255
- analyze the goto model, the instructions must be simplified to use more basic
256
- instructions - this is called "lowering". This class lowers the ` CATCH ` and
257
- ` THROW ` instructions.
253
+ When \ref remove_exceptions is called on the \ref goto_modelt , the
254
+ goto model contains complex instructions (\ref goto_program_instruction_typet)
255
+ such as ` CATCH-POP ` , ` CATCH-PUSH ` and ` THROW ` . In order to analyze the goto
256
+ model, the instructions must be simplified to use more basic instructions - this
257
+ is called "lowering". This class lowers the ` CATCH ` and ` THROW ` instructions.
258
258
259
- Exceptions that have been thrown, but not yet caught are stored the global
260
- ` @inflight_exception ` . When they have been caught, the global
261
- ` @inflight_exception ` is set back to null and ready for the next exception .
259
+ ` THROW ` instructions are replaced by assigning to ` @inflight_exception ` and a
260
+ goto to end of the function. ` CATCH ` instructions are replaced by a check of
261
+ the ` @inflight_exception ` and setting it to null.
262
262
263
- \subsection Throw
263
+ \subsection throw THROW
264
264
265
265
Consider a simple method ` testException(I)V ` :
266
266
267
267
``` java
268
- public void testException(int i) throws Exception {
269
- if (i < 0 ) {
270
- throw new Exception ();
268
+ public class TestExceptions {
269
+ int field;
270
+ public void testException (int i ) throws Exception {
271
+ if (i < 0 ) {
272
+ throw new Exception ();
273
+ }
274
+ field = i;
271
275
}
272
- field = i;
273
276
}
274
277
```
275
278
276
279
The goto for ` testException(I)V ` before ` remove_exceptions ` (removing comments
277
280
and replacing irrelevant parts with ` ... ` ) is:
278
281
279
282
```
280
- com.diffblue.regression. TestExceptions.testException(int) /* java::com.diffblue.regression. TestExceptions.testException:(I)V */
283
+ TestExceptions.testException(int) /* java::TestExceptions.testException:(I)V */
281
284
IF i >= 0 THEN GOTO 3
282
285
struct java.lang.Exception *new_tmp0;
283
286
new_tmp0 = new struct java.lang.Exception;
@@ -302,7 +305,7 @@ where there is a `THROW` instruction to be replaced.
302
305
After passing the goto model through ` remove_exceptions ` , it is:
303
306
304
307
```
305
- com.diffblue.regression. TestExceptions.testException(int) /* java::com.diffblue.regression. TestExceptions.testException:(I)V */
308
+ TestExceptions.testException(int) /* java::TestExceptions.testException:(I)V */
306
309
IF i >= 0 THEN GOTO 4
307
310
struct java.lang.Exception *new_tmp0;
308
311
new_tmp0 = new struct java.lang.Exception;
@@ -326,24 +329,34 @@ com.diffblue.regression.TestExceptions.testException(int) /* java::com.diffblue.
326
329
327
330
```
328
331
where now instead of the instruction ` THROW ` , the global variable
329
- ` @inflight_exception ` holds the thrown exception in ia separate goto statement.
332
+ ` @inflight_exception ` holds the thrown exception in a separate goto statement.
330
333
331
- \subsection Catch
334
+ \subsection catch CATCH-PUSH, CATCH-POP and EXCEPTION LANDING PAD
332
335
333
- Consider the method ` catchSomething(I)V ` that tries the above method ` testException(I)V ` and catches the exception:
336
+ Consider the method ` catchSomething(I)V ` that tries the above method
337
+ ` testException(I)V ` and catches the exception:
334
338
335
339
``` java
336
- public void catchSomething(int i) {
337
- try {
338
- testException(i);
339
- } catch (Exception e) {
340
+ public class TestExceptions {
341
+ int field;
342
+ public void testException (int i ) throws Exception {
343
+ if (i < 0 ) {
344
+ throw new Exception ();
345
+ }
346
+ field = i;
347
+ }
348
+ public void catchSomething (int i ) {
349
+ try {
350
+ testException(i);
351
+ } catch (Exception e) {
352
+ }
340
353
}
341
354
}
342
355
```
343
356
344
357
The goto model before ` remove_exceptions ` is:
345
358
```
346
- com.diffblue.regression. TestExceptions.catchSomething(int) /* java::com.diffblue.regression. TestExceptions.catchSomething:(I)V */
359
+ TestExceptions.catchSomething(int) /* java::TestExceptions.catchSomething:(I)V */
347
360
348
361
...
349
362
@@ -365,12 +378,14 @@ com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue
365
378
...
366
379
367
380
```
368
- which contains ` CATCH ` instructions that are intended to be replaced.
381
+ The ` CATCH-PUSH ` instruction signifies the start of the try block, the
382
+ ` CATCH-POP ` instruction signifies the end of the try block, and the `EXCEPTION
383
+ LANDING PAD` signifies beginning of the catch block.
369
384
370
385
After ` remove_exceptions ` the goto model is:
371
386
372
387
```
373
- com.diffblue.regression. TestExceptions.catchSomething(int) /* java::com.diffblue.regression. TestExceptions.catchSomething:(I)V */
388
+ TestExceptions.catchSomething(int) /* java::TestExceptions.catchSomething:(I)V */
374
389
375
390
...
376
391
@@ -401,7 +416,11 @@ com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue
401
416
5: ASSERT false // block 5
402
417
6: END_FUNCTION
403
418
```
404
- where the ` CATCH ` instructions have been replaced with new goto statements.
419
+ where the ` CATCH-PUSH ` has been replaced by a check on the ` @inflight_exception `
420
+ variable and goto statements, the ` CATCH-POP ` replaced by a check on the class
421
+ of the exception and a goto statement, and the ` EXCEPTION LANDING PAD ` replaced
422
+ by a section that assigns the exception to a local variable and sets the
423
+ ` @inflight_exception ` back to null.
405
424
406
425
\section java-bytecode-remove-instanceof Remove instanceof
407
426
0 commit comments