Skip to content

Making the instrumented clinit_wrapper function thread-safe #2145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions regression/cbmc-java/static_init1/test1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
static_init.class
--function static_init.main --java-threading
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
8 changes: 8 additions & 0 deletions regression/cbmc-java/static_init2/test1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
static_init.class
--function static_init.main --java-threading
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
7 changes: 7 additions & 0 deletions regression/cbmc-java/static_init_order/test3.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
static_init_order.class
--function static_init_order.test1 --trace --java-threading
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
7 changes: 7 additions & 0 deletions regression/cbmc-java/static_init_order/test4.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
static_init_order.class
--function static_init_order.test2 --java-threading
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
14 changes: 12 additions & 2 deletions src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
else
lazy_methods_mode=LAZY_METHODS_MODE_EAGER;

if(cmd.isset("java-threading"))
threading_support = true;
else
threading_support = false;

if(cmd.isset("java-throw-runtime-exceptions"))
{
throw_runtime_exceptions = true;
Expand Down Expand Up @@ -701,7 +706,8 @@ bool java_bytecode_languaget::typecheck(
// For each class that will require a static initializer wrapper, create a
// function named package.classname::clinit_wrapper, and a corresponding
// global tracking whether it has run or not:
create_static_initializer_wrappers(symbol_table, synthetic_methods);
create_static_initializer_wrappers(
symbol_table, synthetic_methods, threading_support);

// Now incrementally elaborate methods
// that are reachable from this entry point.
Expand Down Expand Up @@ -961,7 +967,11 @@ bool java_bytecode_languaget::convert_single_method(
switch(synthetic_method_it->second)
{
case synthetic_method_typet::STATIC_INITIALIZER_WRAPPER:
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
if(threading_support)
symbol.value = get_thread_safe_clinit_wrapper_body(
function_id, symbol_table);
else
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
break;
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
symbol.value =
Expand Down
1 change: 1 addition & 0 deletions src/java_bytecode/java_bytecode_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class java_bytecode_languaget:public languaget
irep_idt main_class;
std::vector<irep_idt> main_jar_classes;
java_class_loadert java_class_loader;
bool threading_support;
bool assume_inputs_non_null; // assume inputs variables to be non-null
object_factory_parameterst object_factory_parameters;
size_t max_user_array_length; // max size for user code created arrays
Expand Down
Loading