Skip to content

Commit 94bbbba

Browse files
committed
Added new cmd option to jbmc, 'java-threading'
Setting this option will enable support for analysing multi-threaded java programs. For now, this means that a thread-safe version of clinit_wrapper is generated. This was made opt-in instead of opt-out as the inclusion of thread-safe clinit wrapper has negative implications for performance. Commit also adds appropriate regression tests that use this flag to test the resulting modifications to the clinit_wrapper
1 parent 48914be commit 94bbbba

File tree

10 files changed

+215
-60
lines changed

10 files changed

+215
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
static_init.class
3+
--function static_init.main --java-threading
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
static_init.class
3+
--function static_init.main --java-threading
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
static_init_order.class
3+
--function static_init_order.test1 --trace --java-threading
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
static_init_order.class
3+
--function static_init_order.test2 --java-threading
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--

src/java_bytecode/java_bytecode_language.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
6969
else
7070
lazy_methods_mode=LAZY_METHODS_MODE_EAGER;
7171

72+
if(cmd.isset("java-threading"))
73+
threading_support = true;
74+
else
75+
threading_support = false;
76+
7277
if(cmd.isset("java-throw-runtime-exceptions"))
7378
{
7479
throw_runtime_exceptions = true;
@@ -701,7 +706,8 @@ bool java_bytecode_languaget::typecheck(
701706
// For each class that will require a static initializer wrapper, create a
702707
// function named package.classname::clinit_wrapper, and a corresponding
703708
// global tracking whether it has run or not:
704-
create_static_initializer_wrappers(symbol_table, synthetic_methods);
709+
create_static_initializer_wrappers(
710+
symbol_table, synthetic_methods, threading_support);
705711

706712
// Now incrementally elaborate methods
707713
// that are reachable from this entry point.
@@ -961,7 +967,11 @@ bool java_bytecode_languaget::convert_single_method(
961967
switch(synthetic_method_it->second)
962968
{
963969
case synthetic_method_typet::STATIC_INITIALIZER_WRAPPER:
964-
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
970+
if(threading_support)
971+
symbol.value = get_thread_safe_clinit_wrapper_body(
972+
function_id, symbol_table);
973+
else
974+
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
965975
break;
966976
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
967977
symbol.value =

src/java_bytecode/java_bytecode_language.h

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class java_bytecode_languaget:public languaget
159159
irep_idt main_class;
160160
std::vector<irep_idt> main_jar_classes;
161161
java_class_loadert java_class_loader;
162+
bool threading_support;
162163
bool assume_inputs_non_null; // assume inputs variables to be non-null
163164
object_factory_parameterst object_factory_parameters;
164165
size_t max_user_array_length; // max size for user code created arrays

0 commit comments

Comments
 (0)