diff --git a/opt/interdex/InterDex.cpp b/opt/interdex/InterDex.cpp index f465d05ccd..a95b13f2fd 100644 --- a/opt/interdex/InterDex.cpp +++ b/opt/interdex/InterDex.cpp @@ -698,17 +698,21 @@ void InterDex::init_cross_dex_ref_minimizer() { TRACE(IDEX, 2, "[dex ordering] Cross-dex-ref-minimizer active with method ref weight " "%" PRIu64 ", field ref weight %" PRIu64 ", type ref weight %" PRIu64 - ", string ref weight %" PRIu64 ", method seed weight %" PRIu64 + ", large string ref weight %" PRIu64 + ", small string ref weight %" PRIu64 ", method seed weight %" PRIu64 ", field seed weight %" PRIu64 ", type seed weight %" PRIu64 - ", string seed weight %" PRIu64 ".", + ", large string seed weight %" PRIu64 + ", small string seed weight %" PRIu64 ".", m_cross_dex_ref_minimizer.get_config().method_ref_weight, m_cross_dex_ref_minimizer.get_config().field_ref_weight, m_cross_dex_ref_minimizer.get_config().type_ref_weight, - m_cross_dex_ref_minimizer.get_config().string_ref_weight, + m_cross_dex_ref_minimizer.get_config().large_string_ref_weight, + m_cross_dex_ref_minimizer.get_config().small_string_ref_weight, m_cross_dex_ref_minimizer.get_config().method_seed_weight, m_cross_dex_ref_minimizer.get_config().field_seed_weight, m_cross_dex_ref_minimizer.get_config().type_seed_weight, - m_cross_dex_ref_minimizer.get_config().string_seed_weight); + m_cross_dex_ref_minimizer.get_config().large_string_seed_weight, + m_cross_dex_ref_minimizer.get_config().small_string_seed_weight); std::vector classes_to_insert; // Emit classes using some algorithm to group together classes which diff --git a/opt/interdex/InterDexPass.cpp b/opt/interdex/InterDexPass.cpp index bfa73c9304..d8eac3a7e2 100644 --- a/opt/interdex/InterDexPass.cpp +++ b/opt/interdex/InterDexPass.cpp @@ -71,9 +71,15 @@ void InterDexPass::bind_config() { bind("minimize_cross_dex_refs_type_ref_weight", m_minimize_cross_dex_refs_config.type_ref_weight, m_minimize_cross_dex_refs_config.type_ref_weight); - bind("minimize_cross_dex_refs_string_ref_weight", - m_minimize_cross_dex_refs_config.string_ref_weight, - m_minimize_cross_dex_refs_config.string_ref_weight); + bind("minimize_cross_dex_refs_large_string_ref_weight", + m_minimize_cross_dex_refs_config.large_string_ref_weight, + m_minimize_cross_dex_refs_config.large_string_ref_weight); + bind("minimize_cross_dex_refs_small_string_ref_weight", + m_minimize_cross_dex_refs_config.small_string_ref_weight, + m_minimize_cross_dex_refs_config.small_string_ref_weight); + bind("minimize_cross_dex_refs_min_large_string_size", + m_minimize_cross_dex_refs_config.min_large_string_size, + m_minimize_cross_dex_refs_config.min_large_string_size); bind("minimize_cross_dex_refs_method_seed_weight", m_minimize_cross_dex_refs_config.method_seed_weight, m_minimize_cross_dex_refs_config.method_seed_weight); @@ -83,9 +89,12 @@ void InterDexPass::bind_config() { bind("minimize_cross_dex_refs_type_seed_weight", m_minimize_cross_dex_refs_config.type_seed_weight, m_minimize_cross_dex_refs_config.type_seed_weight); - bind("minimize_cross_dex_refs_string_seed_weight", - m_minimize_cross_dex_refs_config.string_seed_weight, - m_minimize_cross_dex_refs_config.string_seed_weight); + bind("minimize_cross_dex_refs_large_string_seed_weight", + m_minimize_cross_dex_refs_config.large_string_seed_weight, + m_minimize_cross_dex_refs_config.large_string_seed_weight); + bind("minimize_cross_dex_refs_large_string_seed_weight", + m_minimize_cross_dex_refs_config.small_string_seed_weight, + m_minimize_cross_dex_refs_config.small_string_seed_weight); bind("minimize_cross_dex_refs_emit_json", false, m_minimize_cross_dex_refs_config.emit_json); bind("minimize_cross_dex_refs_explore_alternatives", 1, diff --git a/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.cpp b/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.cpp index 3d5e6c23b9..c5006f6bbd 100644 --- a/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.cpp +++ b/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.cpp @@ -222,7 +222,13 @@ void CrossDexRefMinimizer::insert(DexClass* cls) { add_weight(type, m_config.type_ref_weight, m_config.type_seed_weight); } for (auto string : cls_refs.strings) { - add_weight(string, m_config.string_ref_weight, m_config.string_seed_weight); + if (string->length() > m_config.min_large_string_size) { + add_weight(string, m_config.small_string_ref_weight, + m_config.large_string_seed_weight); + } else { + add_weight(string, m_config.large_string_ref_weight, + m_config.small_string_seed_weight); + } } for (auto fref : cls_refs.field_refs) { add_weight(fref, m_config.field_ref_weight, m_config.field_seed_weight); diff --git a/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.h b/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.h index 3d599ebddc..0e29abdeac 100644 --- a/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.h +++ b/service/cross-dex-ref-minimizer/CrossDexRefMinimizer.h @@ -41,13 +41,16 @@ struct CrossDexRefMinimizerConfig { uint64_t method_ref_weight{100}; uint64_t field_ref_weight{90}; uint64_t type_ref_weight{100}; - uint64_t string_ref_weight{90}; + uint64_t large_string_ref_weight{90}; + uint64_t small_string_ref_weight{90}; uint64_t method_seed_weight{100}; uint64_t field_seed_weight{20}; uint64_t type_seed_weight{30}; - uint64_t string_seed_weight{20}; + uint64_t large_string_seed_weight{20}; + uint64_t small_string_seed_weight{20}; + uint32_t min_large_string_size{50}; bool emit_json{false}; };