@@ -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});
0 commit comments