Skip to content

Commit

Permalink
Merge pull request diffblue#350 from diffblue/owen-jones-diffblue/ski…
Browse files Browse the repository at this point in the history
…p-duplicate-callsites-in-lazy-methods

SEC-266: Speed up resolution of virtual callsites in lazy loading
  • Loading branch information
owen-jones-diffblue authored Mar 9, 2018
2 parents 73fb488 + fd76555 commit 3d8423c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/java_bytecode/ci_lazy_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ bool ci_lazy_methodst::operator()(
<< " callsites)"
<< eom;

for(const auto &callsite : virtual_callsites)
std::unordered_set<exprt, irep_hash> unique_functions;
for(const code_function_callt *virtual_callsite : virtual_callsites)
unique_functions.insert(virtual_callsite->function());

for(const exprt &function : unique_functions)
{
// This will also create a stub if a virtual callsite has no targets.
get_virtual_method_targets(
*callsite,
function,
needed_classes,
method_worklist2,
symbol_table);
Expand Down Expand Up @@ -397,21 +400,20 @@ void ci_lazy_methodst::gather_virtual_callsites(

/// Find possible callees, excluding types that are not known to be
/// instantiated.
/// \param c: function call whose potential target functions should
/// be determined.
/// \param called_function: virtual function call whose concrete function calls
/// should be determined.
/// \param needed_classes: set of classes that can be instantiated. Any
/// potential callee not in this set will be ignored.
/// \param symbol_table: global symbol table
/// \param [out] needed_methods: Populated with all possible `c` callees, taking
/// `needed_classes` into account (virtual function overrides defined on
/// classes that are not 'needed' are ignored)
void ci_lazy_methodst::get_virtual_method_targets(
const code_function_callt &c,
const exprt &called_function,
const std::set<irep_idt> &needed_classes,
std::vector<irep_idt> &needed_methods,
symbol_tablet &symbol_table)
{
const auto &called_function=c.function();
PRECONDITION(called_function.id()==ID_virtual_function);

const auto &call_class=called_function.get(ID_C_class);
Expand Down Expand Up @@ -453,7 +455,7 @@ void ci_lazy_methodst::get_virtual_method_targets(
symbolt symbol;
symbol.name=stubname;
symbol.base_name=call_basename;
symbol.type=c.function().type();
symbol.type=called_function.type();
symbol.value.make_nil();
symbol.mode=ID_java;
symbol_table.add(symbol);
Expand Down
2 changes: 1 addition & 1 deletion src/java_bytecode/ci_lazy_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ci_lazy_methodst:public messaget
std::vector<const code_function_callt *> &result);

void get_virtual_method_targets(
const code_function_callt &c,
const exprt &called_function,
const std::set<irep_idt> &needed_classes,
std::vector<irep_idt> &needed_methods,
symbol_tablet &symbol_table);
Expand Down

0 comments on commit 3d8423c

Please sign in to comment.