void RemoveInterfacePass::remove_inheritance(const Scope& scope, const TypeSystem& type_system, const TypeSet& interfaces) { for (const auto intf : interfaces) { always_assert(is_leaf(type_system, intf)); auto impls = type_system.get_implementors(intf); for (const auto impl : impls) { TRACE(RM_INTF, 5, "Remove inheritance for %s on %s\n", SHOW(intf), SHOW(impl)); auto new_impl_list = get_new_impl_list(impl, intf); type_class(impl)->set_interfaces(new_impl_list); } type_class(intf)->set_interfaces(DexTypeList::make_type_list({})); } }
TypeSet RemoveInterfacePass::remove_leaf_interfaces( const Scope& scope, const DexType* root, const TypeSet& interfaces, const TypeSystem& type_system) { TypeSet leaf_interfaces; for (const auto intf : interfaces) { if (is_leaf(type_system, intf)) { leaf_interfaces.insert(intf); } } std::unordered_map<DexMethod*, DexMethod*> intf_meth_to_dispatch; for (const auto intf : leaf_interfaces) { TRACE(RM_INTF, 5, "Found leaf interface %s\n", SHOW(intf)); auto implementors = type_system.get_implementors(intf); auto intf_methods = type_class(intf)->get_vmethods(); for (const auto meth : intf_methods) { TRACE(RM_INTF, 5, "Finding virt scope for %s\n", SHOW(meth)); auto intf_scope = type_system.find_interface_scope(meth); MethodOrderedSet found_targets = find_dispatch_targets(type_system, intf_scope, implementors); std::vector<DexMethod*> dispatch_targets(found_targets.begin(), found_targets.end()); auto replacement_type = get_replacement_type(type_system, intf, root); auto dispatch = generate_dispatch(replacement_type, dispatch_targets, meth, m_keep_debug_info, m_interface_dispatch_anno); m_dispatch_stats[dispatch_targets.size()]++; intf_meth_to_dispatch[meth] = dispatch; } } update_interface_calls(scope, intf_meth_to_dispatch); remove_inheritance(scope, type_system, leaf_interfaces); m_num_interface_removed += leaf_interfaces.size(); return leaf_interfaces; }