Skip to content

Commit 3d8423c

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#350 from diffblue/owen-jones-diffblue/skip-duplicate-callsites-in-lazy-methods
SEC-266: Speed up resolution of virtual callsites in lazy loading
2 parents 73fb488 + fd76555 commit 3d8423c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ bool ci_lazy_methodst::operator()(
169169
<< " callsites)"
170170
<< eom;
171171

172-
for(const auto &callsite : virtual_callsites)
172+
std::unordered_set<exprt, irep_hash> unique_functions;
173+
for(const code_function_callt *virtual_callsite : virtual_callsites)
174+
unique_functions.insert(virtual_callsite->function());
175+
176+
for(const exprt &function : unique_functions)
173177
{
174-
// This will also create a stub if a virtual callsite has no targets.
175178
get_virtual_method_targets(
176-
*callsite,
179+
function,
177180
needed_classes,
178181
method_worklist2,
179182
symbol_table);
@@ -397,21 +400,20 @@ void ci_lazy_methodst::gather_virtual_callsites(
397400

398401
/// Find possible callees, excluding types that are not known to be
399402
/// instantiated.
400-
/// \param c: function call whose potential target functions should
401-
/// be determined.
403+
/// \param called_function: virtual function call whose concrete function calls
404+
/// should be determined.
402405
/// \param needed_classes: set of classes that can be instantiated. Any
403406
/// potential callee not in this set will be ignored.
404407
/// \param symbol_table: global symbol table
405408
/// \param [out] needed_methods: Populated with all possible `c` callees, taking
406409
/// `needed_classes` into account (virtual function overrides defined on
407410
/// classes that are not 'needed' are ignored)
408411
void ci_lazy_methodst::get_virtual_method_targets(
409-
const code_function_callt &c,
412+
const exprt &called_function,
410413
const std::set<irep_idt> &needed_classes,
411414
std::vector<irep_idt> &needed_methods,
412415
symbol_tablet &symbol_table)
413416
{
414-
const auto &called_function=c.function();
415417
PRECONDITION(called_function.id()==ID_virtual_function);
416418

417419
const auto &call_class=called_function.get(ID_C_class);
@@ -453,7 +455,7 @@ void ci_lazy_methodst::get_virtual_method_targets(
453455
symbolt symbol;
454456
symbol.name=stubname;
455457
symbol.base_name=call_basename;
456-
symbol.type=c.function().type();
458+
symbol.type=called_function.type();
457459
symbol.value.make_nil();
458460
symbol.mode=ID_java;
459461
symbol_table.add(symbol);

src/java_bytecode/ci_lazy_methods.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ci_lazy_methodst:public messaget
134134
std::vector<const code_function_callt *> &result);
135135

136136
void get_virtual_method_targets(
137-
const code_function_callt &c,
137+
const exprt &called_function,
138138
const std::set<irep_idt> &needed_classes,
139139
std::vector<irep_idt> &needed_methods,
140140
symbol_tablet &symbol_table);

0 commit comments

Comments
 (0)