Skip to content

Commit 2a34624

Browse files
Replace call to getMonitorCount by field access
1 parent 7f9e2eb commit 2a34624

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,37 @@ static void instrument_get_current_thread_id(
391391
code = code_assign;
392392
}
393393

394+
/// Transforms the codet stored in in \p f_code, which is a call to function
395+
/// CProver.getMonitorCount:(Ljava/lang/Object;)I into a
396+
/// code_assignt that assigns the cproverMonitorCount field of the
397+
/// java.lang.Object argument passed to getMonitorCount.
398+
///
399+
/// The resulting codet is stored in the output parameter \p code.
400+
///
401+
/// \param f_code: call to CProver.getMonitorCount:(Ljava/lang/Object;)I
402+
/// \param [out] code: resulting transformation
403+
/// \param symbol_table: a symbol table
404+
static void instrument_get_monitor_count(
405+
const code_function_callt &f_code,
406+
codet &code,
407+
symbol_tablet &symbol_table)
408+
{
409+
PRECONDITION(f_code.arguments().size() == 1);
410+
411+
const namespacet ns(symbol_table);
412+
const auto &followed_type =
413+
ns.follow(to_pointer_type(f_code.arguments()[0].type()).subtype());
414+
const auto &object_type = to_struct_type(followed_type);
415+
code_assignt code_assign(
416+
f_code.lhs(),
417+
member_exprt(
418+
dereference_exprt(f_code.arguments()[0]),
419+
object_type.get_component("cproverMonitorCount")));
420+
code_assign.add_source_location() = f_code.source_location();
421+
422+
code = code_assign;
423+
}
424+
394425
/// Iterate through the symbol table to find and appropriately instrument
395426
/// thread-blocks.
396427
///
@@ -501,6 +532,13 @@ void convert_threadblock(symbol_tablet &symbol_table)
501532
std::placeholders::_1,
502533
std::placeholders::_2,
503534
std::placeholders::_3);
535+
else if(
536+
f_name == "org.cprover.CProver.getMonitorCount:(Ljava/lang/Object;)I")
537+
cb = std::bind(
538+
&instrument_get_monitor_count,
539+
std::placeholders::_1,
540+
std::placeholders::_2,
541+
std::placeholders::_3);
504542

505543
if(cb)
506544
expr_replacement_map.insert({expr, cb});

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ const std::unordered_set<std::string> cprover_methods_to_ignore{
545545
"atomicEnd",
546546
"startThread",
547547
"endThread",
548-
"getCurrentThreadId"};
548+
"getCurrentThreadId",
549+
"getMonitorCount"};
549550

550551
/// \param type: type of new symbol
551552
/// \param basename_prefix: new symbol will be named

0 commit comments

Comments
 (0)