Skip to content

Commit 9d8422a

Browse files
fixup! reviewer comments
1 parent 4b478dd commit 9d8422a

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

jbmc/src/java_bytecode/README.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,34 +250,37 @@ for(tmp_index = 0; tmp_index < dim_size; ++tmp_index)
250250

251251
\section java-bytecode-remove-exceptions Remove exceptions
252252

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.
258258

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.
262262

263-
\subsection Throw
263+
\subsection throw THROW
264264

265265
Consider a simple method `testException(I)V`:
266266

267267
```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;
271275
}
272-
field = i;
273276
}
274277
```
275278

276279
The goto for `testException(I)V` before `remove_exceptions` (removing comments
277280
and replacing irrelevant parts with `...`) is:
278281

279282
```
280-
com.diffblue.regression.TestExceptions.testException(int) /* java::com.diffblue.regression.TestExceptions.testException:(I)V */
283+
TestExceptions.testException(int) /* java::TestExceptions.testException:(I)V */
281284
IF i >= 0 THEN GOTO 3
282285
struct java.lang.Exception *new_tmp0;
283286
new_tmp0 = new struct java.lang.Exception;
@@ -302,7 +305,7 @@ where there is a `THROW` instruction to be replaced.
302305
After passing the goto model through `remove_exceptions`, it is:
303306

304307
```
305-
com.diffblue.regression.TestExceptions.testException(int) /* java::com.diffblue.regression.TestExceptions.testException:(I)V */
308+
TestExceptions.testException(int) /* java::TestExceptions.testException:(I)V */
306309
IF i >= 0 THEN GOTO 4
307310
struct java.lang.Exception *new_tmp0;
308311
new_tmp0 = new struct java.lang.Exception;
@@ -326,24 +329,34 @@ com.diffblue.regression.TestExceptions.testException(int) /* java::com.diffblue.
326329
327330
```
328331
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.
330333

331-
\subsection Catch
334+
\subsection catch CATCH-PUSH, CATCH-POP and EXCEPTION LANDING PAD
332335

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:
334338

335339
```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+
}
340353
}
341354
}
342355
```
343356

344357
The goto model before `remove_exceptions` is:
345358
```
346-
com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue.regression.TestExceptions.catchSomething:(I)V */
359+
TestExceptions.catchSomething(int) /* java::TestExceptions.catchSomething:(I)V */
347360
348361
...
349362
@@ -365,12 +378,14 @@ com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue
365378
...
366379
367380
```
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.
369384

370385
After `remove_exceptions` the goto model is:
371386

372387
```
373-
com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue.regression.TestExceptions.catchSomething:(I)V */
388+
TestExceptions.catchSomething(int) /* java::TestExceptions.catchSomething:(I)V */
374389
375390
...
376391
@@ -401,7 +416,11 @@ com.diffblue.regression.TestExceptions.catchSomething(int) /* java::com.diffblue
401416
5: ASSERT false // block 5
402417
6: END_FUNCTION
403418
```
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.
405424

406425
\section java-bytecode-remove-instanceof Remove instanceof
407426

0 commit comments

Comments
 (0)