Skip to content

Commit 8b3035f

Browse files
author
Daniel Kroening
committed
manual: markdown in jbmc manual
1 parent a08649c commit 8b3035f

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

doc/cprover-manual/jbmc-user-manual.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
\ingroup module_hidden
2-
\page jbmc-user-manual JBMC User Manual
1+
[CPROVER Manual TOC](../)
32

3+
# Verifying Java with JBMC
44

5-
\section jbmc-manual-intro Introduction
5+
## Introduction
66

77
JBMC is a bounded model checking tool for the Java language. It follows the
88
same principles as CBMC, thus the existing
9-
[documentation for CBMC](http://www.cprover.org/cprover-manual/cbmc.html)
9+
[documentation for CBMC](../cbmc/tutorial/)
1010
largely applies to JBMC.
1111

12-
In brief, JBMC creates a model from Java Bytecode (given as input as a .class
13-
file or a .jar) and performs static analysis and symbolic execution which allow
14-
us to prove or refute properties. These properties are either automatically
15-
generated (runtime errors), or provided by the user in the form of assertions.
12+
In brief, JBMC creates a model from Java Bytecode (given as input as a
13+
`.class` file or a `.jar`) and performs static analysis and symbolic
14+
execution which allow us to prove or refute properties. These properties
15+
are either automatically generated (runtime errors), or provided by the user
16+
in the form of assertions.
1617

1718
Using examples, the following section will guide you through the basic
1819
features of JBMC.
1920

21+
## JBMC tutorial
2022

21-
\section jbmc-tutorial JBMC tutorial
22-
23-
\subsection jbmc-manual-auto-assert Automatic assertions
23+
### Automatic assertions
2424

2525
Consider the following simplistic `ExampleArray.java` file which we have
2626
compiled into `tutorial/ExampleArray.class` and which queries the array of
@@ -40,11 +40,12 @@ input arguments at index 3:
4040

4141
Now let's run the following command to let JBMC tell us about potential errors
4242
in our program.
43-
44-
$ jbmc tutorial/ExampleArray.class
43+
```
44+
$ jbmc tutorial/ExampleArray.class
45+
```
4546

4647
The output contains the following:
47-
```c
48+
```plaintext
4849
[java::tutorial.ExampleArray.main:([Ljava/lang/String;)V.null-pointer-exception.1] line 7 Null pointer check: SUCCESS
4950
[java::tutorial.ExampleArray.main:([Ljava/lang/String;)V.array-index-out-of-bounds-low.1] line 7 Array index should be >= 0: SUCCESS
5051
[java::tutorial.ExampleArray.main:([Ljava/lang/String;)V.array-index-out-of-bounds-high.1] line 7 Array index should be < length: FAILURE
@@ -75,20 +76,21 @@ safe as follows:
7576
13| }
7677
```
7778
then when running JBMC on that corrected version:
78-
79-
$ jbmc tutorial/ExampleArraySafe.class
79+
```
80+
$ jbmc tutorial/ExampleArraySafe.class
81+
```
8082

8183
all the automatic assertions become valid, meaning that there is no
8284
possible inputs (argument values) for which they can be violated:
83-
```c
85+
```plaintext
8486
[java::tutorial.ExampleArraySafe.main:([Ljava/lang/String;)V.1] line 7 no uncaught exception: SUCCESS
8587
[java::tutorial.ExampleArraySafe.main:([Ljava/lang/String;)V.null-pointer-exception.1] line 8 Null pointer check: SUCCESS
8688
[java::tutorial.ExampleArraySafe.main:([Ljava/lang/String;)V.null-pointer-exception.2] line 9 Null pointer check: SUCCESS
8789
[java::tutorial.ExampleArraySafe.main:([Ljava/lang/String;)V.array-index-out-of-bounds-low.1] line 9 Array index should be >= 0: SUCCESS
8890
[java::tutorial.ExampleArraySafe.main:([Ljava/lang/String;)V.array-index-out-of-bounds-high.1] line 9 Array index should be < length: SUCCESS
8991
```
9092

91-
\subsection jbmc-manual-unwind Loop unwinding
93+
## Loop unwinding
9294

9395
As CBMC, JBMC needs to unwind loops up to a given value. Consider the `isPrime`
9496
method in the code below. Without specifying an unwind limit, JBMC will not
@@ -120,49 +122,49 @@ depends on an input):
120122
```
121123
To limit the number of times the for-loop is unwound, we use the `--unwind N`
122124
options, in which case the following call to JBMC:
123-
124-
$ jbmc tutorial/ExampleUnwind.class --function tutorial.ExampleUnwind.isPrime --unwind 10
125-
125+
```
126+
$ jbmc tutorial/ExampleUnwind.class --function tutorial.ExampleUnwind.isPrime --unwind 10
127+
```
126128
will terminate correctly. In this case, we will see `VERIFICATION SUCCESSFUL`,
127129
as no automatic assertions are violated.
128130

129131
Note that in that example, there are is no main function, so we give specify
130132
the desired entry point via the `--function` option.
131133

132134

133-
\subsection jbmc-manual-user-assert User assertions
135+
## User assertions
134136

135137
Elaborating on the example above, users may provide their own assertions, that
136138
JBMC will try to refute. On line 7, we check the assertion that all odd
137139
numbers greater than 1 are prime. To be sure that this always holds, we run
138140
JBMC on the example, with a reasonable `unwind` value:
139-
140-
$ jbmc tutorial/ExampleUnwind.class --function tutorial.ExampleUnwind.doSomething --unwind 10
141-
141+
```
142+
$ jbmc tutorial/ExampleUnwind.class --function tutorial.ExampleUnwind.doSomething --unwind 10
143+
```
142144
Unsurprisingly JBMC doesn't agree, and prints an assertion failure
143145
(truncated here for readability):
144-
```c
146+
```plaintext
145147
[...doSomething:(I)V.assertion.1] line 7 assertion at file tutorial/ExampleUnwind.java: FAILURE
146148
```
147149

148150
Rerunning the analysis with the `--trace` option, the following line appears
149151
somewhere in the trace output and tells us which input value JBMC found to
150152
trigger the violation (note that to see the original parameter names in the
151153
trace output, the Java source must be compiled in debug mode: `javac -g`):
152-
```c
154+
```plaintext
153155
INPUT inputVal: 15
154156
```
155157
The value chosen by JBMC is arbitrary, and could as well be 9
156158
or 2084569161.
157159

158-
\subsection jbmc-manual-library Java Library support
160+
## Java Library support
159161

160162
The examples above only involve primitive types. In order to analyse code
161163
involving Java Library classes, the core models (located in the same
162164
repository) need to be added to the classpath:
163-
164-
--cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar
165-
165+
```
166+
--cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar
167+
```
166168

167169
The core models library simulate the behavior of the Java Library and
168170
contains some commonly used classes, such as Object, Class, String, Enum.
@@ -185,21 +187,21 @@ from `java.lang.String`, e.g.
185187
```
186188
The following command line (note that the current directory is also added to
187189
the classpath):
188-
189-
$ jbmc tutorial/ExampleModels.class --cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar:.
190-
190+
```
191+
$ jbmc tutorial/ExampleModels.class --cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar:.
192+
```
191193
will flag this violation (truncated):
192-
```c
194+
```plaintext
193195
[java::tutorial.ExampleModels.stringOp:()V.assertion.1] line 8 assertion: FAILURE
194196
```
195197

196198
Again, the trace (when re-running with `--trace`) shows the string violating
197199
the condition in the assertion:
198-
```c
200+
```plaintext
199201
dynamic_object2={ 'a', 'b', '$', 'c', 'd' }
200202
```
201203

202-
\subsection jbmc-manual-exceptions Exceptions
204+
## Exceptions
203205

204206
In its analysis, JBMC can take into account exceptions thrown by user code or
205207
library classes, as well as runtime exceptions such as NullPointerException.
@@ -220,13 +222,12 @@ Consider the following code:
220222
```
221223

222224
When given the `--throw-runtime-exceptions` options:
223-
224-
$ jbmc tutorial/ExampleExceptions --tutorial.ExampleExceptions.strLength --throw-runtime-exceptions
225-
225+
```
226+
$ jbmc tutorial/ExampleExceptions --tutorial.ExampleExceptions.strLength --throw-runtime-exceptions
227+
```
226228
JBMC will signal that the `str.length()` call may throw a runtime exception
227229
and that this exception is not caught.
228-
229-
```c
230+
```plaintext
230231
[java::tutorial.ExampleExceptions.strLength:(Ljava/lang/String;)I.1] line 6 no uncaught exception: FAILURE
231232
```
232233
This could be fixed by adding a try-catch statement, or else checking that
@@ -243,9 +244,9 @@ VERIFICATION SUCCESSFUL
243244
```
244245

245246
When analyzing this function without runtime exception support:
246-
247-
$ jbmc tutorial/ExampleExceptions
248-
247+
```
248+
$ jbmc tutorial/ExampleExceptions
249+
```
249250
JBMC only reports the error as a null pointer check failure:
250251
```
251252
[...null-pointer-exception.1] line 6 Null pointer check: FAILURE
@@ -258,11 +259,11 @@ on violation. This behavior can be replicated in JBMC by using the
258259
then be reported like any other uncaught exception.
259260

260261

261-
\subsection jbmc-manual-further-doc Further documentation
262+
## Further documentation
262263

263264
JBMC has a wealth of other options that can either constrain the model (to
264265
cope with complexity issues), or output more relevant information. The list
265266
of all available options is printed by running:
266-
267-
$ jbmc --help
268-
267+
```
268+
$ jbmc --help
269+
```

0 commit comments

Comments
 (0)