service/method-inliner/MethodInliner.cpp
/**
 * Collect all non virtual methods and make all small methods candidates
 * for inlining.
 */
Collect all non virtual methods and make all small methods candidates
for inlining.
Collect all non virtual methods and make all small methods candidates for inlining .
std::unordered_set<DexMethod*> gather_non_virtual_methods(
    Scope& scope,
    const mog::Graph* method_override_graph,
    const std::unordered_set<DexType*>& no_devirtualize_anno) {
  size_t all_methods = 0;
  size_t direct_methods = 0;
  size_t direct_no_code = 0;
  size_t non_virtual_no_code = 0;
  size_t clinit = 0;
  size_t init = 0;
  size_t static_methods = 0;
  size_t private_methods = 0;
  size_t dont_strip = 0;
  size_t non_virt_dont_strip = 0;
  size_t non_virt_methods = 0;
  std::unordered_set<DexMethod*> methods;
  walk::methods(scope, [&](DexMethod* method) {
    all_methods++;
    if (method->is_virtual()) return;
    auto code = method->get_code();
    bool dont_inline = code == nullptr;
    direct_methods++;
    if (code == nullptr) direct_no_code++;
    if (method::is_constructor(method)) {
      (is_static(method)) ? clinit++ : init++;
      if (method::is_clinit(method)) {
        dont_inline = true;
      }
    } else {
      (is_static(method)) ? static_methods++ : private_methods++;
    }
    if (dont_inline) return;
    methods.insert(method);
  });
  if (method_override_graph) {
    auto non_virtual =
        mog::get_non_true_virtuals(*method_override_graph, scope);
    non_virt_methods = non_virtual.size();
    for (const auto& vmeth : non_virtual) {
      auto code = vmeth->get_code();
      if (code == nullptr) {
        non_virtual_no_code++;
        continue;
      }
      if (has_any_annotation(vmeth, no_devirtualize_anno)) {
        continue;
      }
      methods.insert(vmeth);
    }
  }
  TRACE(INLINE, 2, "All methods count: %ld", all_methods);
  TRACE(INLINE, 2, "Direct methods count: %ld", direct_methods);
  TRACE(INLINE, 2, "Virtual methods count: %ld", all_methods - direct_methods);
  TRACE(INLINE, 2, "Direct methods no code: %ld", direct_no_code);
  TRACE(INLINE, 2, "Direct methods with code: %ld",
        direct_methods - direct_no_code);
  TRACE(INLINE, 2, "Constructors with or without code: %ld", init);
  TRACE(INLINE, 2, "Static constructors: %ld", clinit);
  TRACE(INLINE, 2, "Static methods: %ld", static_methods);
  TRACE(INLINE, 2, "Private methods: %ld", private_methods);
  TRACE(INLINE, 2, "Virtual methods non virtual count: %ld", non_virt_methods);
  TRACE(INLINE, 2, "Non virtual no code count: %ld", non_virtual_no_code);
  TRACE(INLINE, 2, "Non virtual no strip count: %ld", non_virt_dont_strip);
  TRACE(INLINE, 2, "Don't strip inlinable methods count: %ld", dont_strip);
  return methods;
}
std :: unordered_set < DexMethod * > gather_non_virtual_methods ( Scope & scope , const mog :: Graph * method_override_graph , const std :: unordered_set < DexType * > & no_devirtualize_anno ) { size_t all_methods = 0 ; size_t direct_methods = 0 ; size_t direct_no_code = 0 ; size_t non_virtual_no_code = 0 ; size_t clinit = 0 ; size_t init = 0 ; size_t static_methods = 0 ; size_t private_methods = 0 ; size_t dont_strip = 0 ; size_t non_virt_dont_strip = 0 ; size_t non_virt_methods = 0 ; std :: unordered_set < DexMethod * > methods ; walk :: methods ( scope , [ & ] ( DexMethod * method ) { all_methods ++ ; if ( method -> is_virtual ( ) ) return ; auto code = method -> get_code ( ) ; bool dont_inline = code == nullptr ; direct_methods ++ ; if ( code == nullptr ) direct_no_code ++ ; if ( method :: is_constructor ( method ) ) { ( is_static ( method ) ) ? clinit ++ : init ++ ; if ( method :: is_clinit ( method ) ) { dont_inline = true ; } } else { ( is_static ( method ) ) ? static_methods ++ : private_methods ++ ; } if ( dont_inline ) return ; methods . insert ( method ) ; } ) ; if ( method_override_graph ) { auto non_virtual = mog :: get_non_true_virtuals ( * method_override_graph , scope ) ; non_virt_methods = non_virtual . size ( ) ; for ( const auto & vmeth : non_virtual ) { auto code = vmeth -> get_code ( ) ; if ( code == nullptr ) { non_virtual_no_code ++ ; continue ; } if ( has_any_annotation ( vmeth , no_devirtualize_anno ) ) { continue ; } methods . insert ( vmeth ) ; } } TRACE ( INLINE , 2 , " " , all_methods ) ; TRACE ( INLINE , 2 , " " , direct_methods ) ; TRACE ( INLINE , 2 , " " , all_methods - direct_methods ) ; TRACE ( INLINE , 2 , " " , direct_no_code ) ; TRACE ( INLINE , 2 , " " , direct_methods - direct_no_code ) ; TRACE ( INLINE , 2 , " " , init ) ; TRACE ( INLINE , 2 , " " , clinit ) ; TRACE ( INLINE , 2 , " " , static_methods ) ; TRACE ( INLINE , 2 , " " , private_methods ) ; TRACE ( INLINE , 2 , " " , non_virt_methods ) ; TRACE ( INLINE , 2 , " " , non_virtual_no_code ) ; TRACE ( INLINE , 2 , " " , non_virt_dont_strip ) ; TRACE ( INLINE , 2 , " " , dont_strip ) ; return methods ; }
Collect all non virtual methods and make all small methods candidates
 for inlining.
Collect all non virtual methods and make all small methods candidates for inlining .
// trace counter // collect all non virtual methods (dmethods and vmethods)