Go to the documentation of this file.
41 const bool is_thread_local,
42 const bool is_static_lifetime)
44 const symbolt *psymbol =
nullptr;
47 if(psymbol !=
nullptr)
50 new_symbol.
name = name;
53 new_symbol.
type = type;
54 new_symbol.
value = value;
59 new_symbol.
mode = ID_java;
60 symbol_table.
add(new_symbol);
109 is_enter ?
"java::java.lang.Object.monitorenter:(Ljava/lang/Object;)V"
110 :
"java::java.lang.Object.monitorexit:(Ljava/lang/Object;)V";
112 auto it = symbol_table.
symbols.find(symbol);
124 if(it == symbol_table.
symbols.end())
138 if(statement == ID_return)
144 statement == ID_label || statement == ID_block ||
145 statement == ID_decl_block)
211 const exprt &sync_object)
224 irep_idt handler(
"pc-synchronized-catch");
228 exception_list.push_back(
237 "caught-synchronized-exception",
244 codet catch_instruction = catch_statement;
247 catch_block.
add(catch_instruction);
248 catch_block.
add(monitorexit);
259 code =
code_blockt({monitorenter, catch_push, code, catch_pop, catch_label});
292 const symbolt ¤t_symbol =
313 codet tmp_a(ID_start_thread);
314 tmp_a.
set(ID_destination, lbl1);
325 codet(ID_atomic_begin),
328 codet(ID_atomic_end)});
358 codet tmp_a(ID_end_thread);
382 const symbolt& current_symbol =
414 const auto &followed_type =
421 object_type.get_component(
"cproverMonitorCount")));
489 using instrument_callbackt =
491 using expr_replacement_mapt =
492 std::unordered_map<const exprt, instrument_callbackt, irep_hash>;
496 for(
const auto &entry : symbol_table)
498 expr_replacement_mapt expr_replacement_map;
499 const symbolt &symbol = entry.second;
507 instrument_callbackt cb;
509 const exprt &expr = *it;
510 if(expr.
id() != ID_code)
519 if(f_name ==
"org.cprover.CProver.startThread:(I)V")
522 std::placeholders::_1,
523 std::placeholders::_2,
524 std::placeholders::_3);
525 else if(f_name ==
"org.cprover.CProver.endThread:(I)V")
528 std::placeholders::_1,
529 std::placeholders::_2,
530 std::placeholders::_3);
531 else if(f_name ==
"org.cprover.CProver.getCurrentThreadId:()I")
534 std::placeholders::_1,
535 std::placeholders::_2,
536 std::placeholders::_3);
538 f_name ==
"org.cprover.CProver.getMonitorCount:(Ljava/lang/Object;)I")
541 std::placeholders::_1,
542 std::placeholders::_2,
543 std::placeholders::_3);
546 expr_replacement_map.insert({expr, cb});
549 if(!expr_replacement_map.empty())
551 symbolt &w_symbol = symbol_table.get_writeable_ref(entry.first);
558 expr_replacement_mapt::iterator m_it = expr_replacement_map.find(*it);
559 if(m_it != expr_replacement_map.end())
563 m_it->second(f_code, code, symbol_table);
564 it.next_sibling_or_parent();
566 expr_replacement_map.erase(m_it);
567 if(expr_replacement_map.empty())
610 for(
const auto &entry : symbol_table)
612 const symbolt &symbol = entry.second;
614 if(symbol.
type.
id() != ID_code)
624 message.
warning() <<
"Java method '" << entry.first
625 <<
"' is static and synchronized."
626 <<
" This is unsupported, the synchronized keyword"
627 <<
" will be ignored."
634 exprt this_expr(this_id);
636 auto it = symbol_table.symbols.find(this_id);
638 if(it == symbol_table.symbols.end())
643 symbolt &w_symbol = symbol_table.get_writeable_ref(entry.first);
Class that provides messages with a built-in verbosity 'level'.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A codet representing sequential composition of program statements.
void convert_synchronized_methods(symbol_tablet &symbol_table, message_handlert &message_handler)
Iterate through the symbol table to find and instrument synchronized methods.
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
static const std::string get_thread_block_identifier(const code_function_callt &f_code)
Retrieves a thread block identifier from a function call to CProver.startThread:(I)V or CProver....
depth_iteratort depth_end()
#define Forall_operands(it, expr)
reference_typet java_reference_type(const typet &subtype)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const std::string thread_id
The type of an expression, extends irept.
static symbolt add_or_get_symbol(symbol_tablet &symbol_table, const irep_idt &name, const irep_idt &base_name, const typet &type, const exprt &value, const bool is_thread_local, const bool is_static_lifetime)
Adds a new symbol to the symbol table if it doesn't exist.
typet type
Type of symbol.
Operator to dereference a pointer.
static void monitor_exits(codet &code, const codet &monitorexit)
Introduces a monitorexit before every return recursively.
The plus expression Associativity is not specified.
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
Pushes an exception handler, of the form: exception_tag1 -> label1 exception_tag2 -> label2 ....
A struct tag type, i.e., struct_typet with an identifier.
void convert_threadblock(symbol_tablet &symbol_table)
Iterate through the symbol table to find and appropriately instrument thread-blocks.
static const std::string get_first_label_id(const std::string &id)
Retrieve the first label identifier.
Expression to hold a symbol (variable)
Pops an exception handler from the stack of active handlers (i.e.
irep_idt pretty_name
Language-specific display name.
static void instrument_end_thread(const code_function_callt &f_code, codet &code, const symbol_tablet &symbol_table)
Transforms the codet stored in in f_code, which is a call to function CProver.endThread:(I)V into a b...
static void instrument_get_monitor_count(const code_function_callt &f_code, codet &code, symbol_tablet &symbol_table)
Transforms the codet stored in in f_code, which is a call to function CProver.getMonitorCount:(Ljava/...
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const codet & to_code(const exprt &expr)
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
goto_instruction_codet representation of a function call statement.
irep_idt mode
Language mode.
const std::string & id2string(const irep_idt &d)
const std::string next_thread_id
void set(const irep_idt &name, const irep_idt &value)
codet representation of a goto statement.
codet representation of a label for branch targets.
#define PRECONDITION(CONDITION)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
exception_listt & exception_list()
static const std::string get_second_label_id(const std::string &id)
Retrieve the second label identifier.
const irep_idt & id() const
static codet get_monitor_call(const symbol_tablet &symbol_table, bool is_enter, const exprt &object)
Creates a monitorenter/monitorexit code_function_callt for the given synchronization object.
void add(const codet &code)
signedbv_typet java_int_type()
symbolt & fresh_java_symbol(const typet &type, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &function_name, symbol_table_baset &symbol_table)
namespacet ns
Initialized just before symbolic execution begins, to point to both outer_symbol_table and the symbol...
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Extract member of struct or union.
exprt value
Initial value of symbol.
A codet representing a skip statement.
A statement that catches an exception, assigning the exception in flight to an expression (e....
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
depth_iteratort depth_begin()
std::vector< exception_list_entryt > exception_listt
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const typet & base_type() const
The type of the data what we point to.
std::string expr2java(const exprt &expr, const namespacet &ns)
static void instrument_start_thread(const code_function_callt &f_code, codet &code, symbol_tablet &symbol_table)
Transforms the codet stored in in f_code, which is a call to function CProver.startThread:(I)V into a...
A side_effect_exprt representation of a side effect that throws an exception.
const code_blockt & to_code_block(const codet &code)
There are a large number of kinds of tree structured or tree-like data in CPROVER.
source_locationt & add_source_location()
A goto_instruction_codet representing an assignment in the program.
const irep_idt & get_statement() const
mstreamt & warning() const
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
static void instrument_synchronized_code(symbol_tablet &symbol_table, symbolt &symbol, const exprt &sync_object)
Transforms the codet stored in symbol.value.
const source_locationt & source_location() const
static void instrument_get_current_thread_id(const code_function_callt &f_code, codet &code, symbol_tablet &symbol_table)
Transforms the codet stored in in f_code, which is a call to function CProver.getCurrentThreadId:()I ...
irep_idt name
The unique identifier.
bool get_bool(const irep_idt &name) const
codet representation of an expression statement.
Data structure for representing an arbitrary statement in a program.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const std::string integer2string(const mp_integer &n, unsigned base)