Skip to content

Commit 376d2f2

Browse files
Add an assume-no-exceptions-thrown option
This is to specify that we want to replace all throw instructions by assume false. This is useful mainly for performance reasons as it simplifies conditions for symex, while retaining the non-exceptional behaviour of the program.
1 parent 4538920 commit 376d2f2

5 files changed

+31
-11
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,9 +2344,10 @@ void java_bytecode_convert_methodt::convert_athrow(
23442344
exprt::operandst &results) const
23452345
{
23462346
if(
2347-
!throw_assertion_error &&
2348-
uncaught_exceptions_domaint::get_exception_type(op[0].type()) ==
2349-
"java::java.lang.AssertionError")
2347+
assume_no_exceptions_thrown ||
2348+
((uncaught_exceptions_domaint::get_exception_type(op[0].type()) ==
2349+
"java::java.lang.AssertionError") &&
2350+
!throw_assertion_error))
23502351
{
23512352
// we translate athrow into
23522353
// ASSERT false;
@@ -3184,7 +3185,8 @@ void java_bytecode_convert_method(
31843185
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
31853186
java_string_library_preprocesst &string_preprocess,
31863187
const class_hierarchyt &class_hierarchy,
3187-
bool threading_support)
3188+
bool threading_support,
3189+
bool assume_no_exceptions_thrown)
31883190

31893191
{
31903192
java_bytecode_convert_methodt java_bytecode_convert_method(
@@ -3195,7 +3197,8 @@ void java_bytecode_convert_method(
31953197
needed_lazy_methods,
31963198
string_preprocess,
31973199
class_hierarchy,
3198-
threading_support);
3200+
threading_support,
3201+
assume_no_exceptions_thrown);
31993202

32003203
java_bytecode_convert_method(class_symbol, method);
32013204
}

jbmc/src/java_bytecode/java_bytecode_convert_method.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void java_bytecode_convert_method(
3737
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
3838
java_string_library_preprocesst &string_preprocess,
3939
const class_hierarchyt &class_hierarchy,
40-
bool threading_support);
40+
bool threading_support,
41+
bool assume_no_exceptions_thrown);
4142

4243
void create_method_stub_symbol(
4344
const irep_idt &identifier,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ class java_bytecode_convert_methodt:public messaget
4040
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
4141
java_string_library_preprocesst &_string_preprocess,
4242
const class_hierarchyt &class_hierarchy,
43-
bool threading_support)
43+
bool threading_support,
44+
bool assume_no_exceptions_thrown)
4445
: messaget(_message_handler),
4546
symbol_table(symbol_table),
4647
ns(symbol_table),
4748
max_array_length(_max_array_length),
4849
throw_assertion_error(throw_assertion_error),
50+
assume_no_exceptions_thrown(assume_no_exceptions_thrown),
4951
threading_support(threading_support),
5052
needed_lazy_methods(std::move(needed_lazy_methods)),
5153
string_preprocess(_string_preprocess),
@@ -73,6 +75,7 @@ class java_bytecode_convert_methodt:public messaget
7375
namespacet ns;
7476
const size_t max_array_length;
7577
const bool throw_assertion_error;
78+
const bool assume_no_exceptions_thrown;
7679
const bool threading_support;
7780
optionalt<ci_lazy_methods_neededt> needed_lazy_methods;
7881

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void parse_java_language_options(const cmdlinet &cmd, optionst &options)
5959
"uncaught-exception-check", !cmd.isset("disable-uncaught-exception-check"));
6060
options.set_option(
6161
"throw-assertion-error", cmd.isset("throw-assertion-error"));
62+
options.set_option(
63+
"assume-no-exceptions-thrown", cmd.isset("assume-no-exceptions-thrown"));
6264
options.set_option("java-threading", cmd.isset("java-threading"));
6365

6466
if(cmd.isset("java-max-vla-length"))
@@ -144,6 +146,8 @@ java_bytecode_language_optionst::java_bytecode_language_optionst(
144146
assert_uncaught_exceptions =
145147
options.get_bool_option("uncaught-exception-check");
146148
throw_assertion_error = options.get_bool_option("throw-assertion-error");
149+
assume_no_exceptions_thrown =
150+
options.get_bool_option("assume-no-exceptions-thrown");
147151
threading_support = options.get_bool_option("java-threading");
148152
max_user_array_length =
149153
options.get_unsigned_int_option("java-max-vla-length");
@@ -1328,7 +1332,8 @@ bool java_bytecode_languaget::convert_single_method(
13281332
std::move(needed_lazy_methods),
13291333
string_preprocess,
13301334
class_hierarchy,
1331-
language_options->threading_support);
1335+
language_options->threading_support,
1336+
language_options->assume_no_exceptions_thrown);
13321337
INVARIANT(declaring_class(symbol), "Method must have a declaring class.");
13331338
return false;
13341339
}
@@ -1359,7 +1364,7 @@ bool java_bytecode_languaget::convert_single_method(
13591364

13601365
bool java_bytecode_languaget::final(symbol_table_baset &)
13611366
{
1362-
PRECONDITION(language_options_initialized);
1367+
PRECONDITION(language_options.has_value());
13631368
return false;
13641369
}
13651370

jbmc/src/java_bytecode/java_bytecode_language.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Author: Daniel Kroening, [email protected]
3232
#define JAVA_BYTECODE_LANGUAGE_OPTIONS /*NOLINT*/ \
3333
"(disable-uncaught-exception-check)" \
3434
"(throw-assertion-error)" \
35+
"(assume-no-exceptions-thrown)" \
3536
"(java-assume-inputs-non-null)" \
3637
"(java-assume-inputs-interval):" \
3738
"(java-assume-inputs-integral)" \
@@ -56,6 +57,9 @@ Author: Daniel Kroening, [email protected]
5657
" assert statements instead of failing\n" \
5758
" at the location of the assert statement\n" \
5859
" --throw-runtime-exceptions make implicit runtime exceptions explicit\n" \
60+
" --assume-no-exceptions-thrown\n"\
61+
" transform `throw` instructions into `assert FALSE`\n"/* NOLINT(*) */ \
62+
" followed by `assume FALSE`.\n" \
5963
" --max-nondet-array-length N limit nondet (e.g. input) array size to <= N\n" /* NOLINT(*) */ \
6064
" --max-nondet-tree-depth N limit size of nondet (e.g. input) object tree;\n" /* NOLINT(*) */ \
6165
" at level N references are set to null\n" /* NOLINT(*) */ \
@@ -110,9 +114,9 @@ Author: Daniel Kroening, [email protected]
110114
" (clinit) method.\n" \
111115
" The argument can be a relative or absolute path to\n"/* NOLINT(*) */ \
112116
" the file.\n"
113-
// clang-format on
117+
// clang-format on
114118

115-
class symbolt;
119+
class symbolt;
116120

117121
enum lazy_methods_modet
118122
{
@@ -164,6 +168,10 @@ struct java_bytecode_language_optionst
164168
bool nondet_static = false;
165169
bool ignore_manifest_main_class = false;
166170

171+
/// Transform `athrow` bytecode instructions into `assert FALSE` followed
172+
/// by `assume FALSE`.
173+
bool assume_no_exceptions_thrown = false;
174+
167175
/// max size for user code created arrays
168176
size_t max_user_array_length = 0;
169177
lazy_methods_modet lazy_methods_mode =

0 commit comments

Comments
 (0)