From 6eab1600a22b825d6366b00398bc1208a41bef82 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 13 Mar 2018 09:02:40 +0000 Subject: [PATCH] Speed up resolution of virtual callsites in lazy loading v1 We removed duplicates from the list of virtual callsites by using an unordered set. This gave a large speed up on at least one use case. There is scope for further optimisation. --- src/java_bytecode/ci_lazy_methods.cpp | 18 +++++++++--------- src/java_bytecode/ci_lazy_methods.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/java_bytecode/ci_lazy_methods.cpp b/src/java_bytecode/ci_lazy_methods.cpp index aedbf364d28..32344f24b2a 100644 --- a/src/java_bytecode/ci_lazy_methods.cpp +++ b/src/java_bytecode/ci_lazy_methods.cpp @@ -170,14 +170,15 @@ bool ci_lazy_methodst::operator()( << " callsites)" << eom; - for(const auto &callsite : virtual_callsites) + std::unordered_set 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, - instantiated_classes, - method_worklist2, - symbol_table); + function, instantiated_classes, method_worklist2, symbol_table); } } while(any_new_methods); @@ -403,8 +404,8 @@ 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 instantiated_classes: set of classes that can be instantiated. Any /// potential callee not in this set will be ignored. /// \param symbol_table: global symbol table @@ -412,12 +413,11 @@ void ci_lazy_methodst::gather_virtual_callsites( /// taking `instantiated_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 &instantiated_classes, std::vector &callable_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); diff --git a/src/java_bytecode/ci_lazy_methods.h b/src/java_bytecode/ci_lazy_methods.h index d69eb57f89b..f78414c44be 100644 --- a/src/java_bytecode/ci_lazy_methods.h +++ b/src/java_bytecode/ci_lazy_methods.h @@ -134,7 +134,7 @@ class ci_lazy_methodst:public messaget std::vector &result); void get_virtual_method_targets( - const code_function_callt &c, + const exprt &called_function, const std::set &instantiated_classes, std::vector &callable_methods, symbol_tablet &symbol_table);