Skip to content

Commit

Permalink
Add an option to skip merging anonymous classes
Browse files Browse the repository at this point in the history
Summary:
## Context

In previous AB tests, we enabled merging more anonymous classes in IntraDexClassMerging while making sure that we emit the correct method profile for the merged symbols. As the next step, we want to

Reviewed By: wsanville

Differential Revision: D70356894

fbshipit-source-id: 3b8d21d0658778c20d6356d4d87cda6e43393379
  • Loading branch information
Wei Zhang (Devinfra) authored and facebook-github-bot committed Feb 28, 2025
1 parent ad3ac5e commit 5efe6cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions opt/class-merging/ClassMergingPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ void ClassMergingPass::bind_config() {
trait(Traits::Pass::unique, true);
bool use_stable_shape_names;
bind("use_stable_shape_names", false, use_stable_shape_names);
bool skip_anonymous_classes;
bind("skip_anonymous_classes", false, skip_anonymous_classes);

// load model specifications
std::vector<Json::Value> models;
Expand Down Expand Up @@ -247,6 +249,7 @@ void ClassMergingPass::bind_config() {
model.process_method_meta = process_method_meta;
model.max_num_dispatch_target = m_max_num_dispatch_target;
model.use_stable_shape_names = use_stable_shape_names;
model.skip_anonymous_classes = skip_anonymous_classes;
// Assume config based models are all generated code.
model_spec.get("is_generated_code", true, model.is_generated_code);

Expand Down
18 changes: 16 additions & 2 deletions service/class-merging/ClassMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ void load_roots_subtypes_as_merging_targets(const TypeSystem& type_system,
const auto& implementors = type_system.get_implementors(*root);
for (auto impl_type : implementors) {
auto impl_cls = type_class(impl_type);
// Note: Bellow is to simply make the logic unchange after the
if (spec->skip_anonymous_classes &&
klass::maybe_anonymous_class(impl_cls)) {
continue;
}
// Note: Below is to simply make the logic unchange after the
// refactoring.
// Find the first internal class at the top of the type
// hierarchy of the impl_cls. if it extends java.lang.Object and
Expand All @@ -86,7 +90,17 @@ void load_roots_subtypes_as_merging_targets(const TypeSystem& type_system,
}
root = spec->roots.erase(root);
} else {
type_system.get_all_children(*root, merging_targets_set);
TypeSet children;
type_system.get_all_children(*root, children);

for (const auto* child : children) {
const auto* child_cls = type_class(child);
if (spec->skip_anonymous_classes &&
klass::maybe_anonymous_class(child_cls)) {
continue;
}
merging_targets_set.insert(child);
}
root++;
}
}
Expand Down
2 changes: 2 additions & 0 deletions service/class-merging/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ struct ModelSpec {
bool use_stable_shape_names{false};

bool mergeability_checks_use_of_const_class{false};

bool skip_anonymous_classes{false};
};

struct ModelStats {
Expand Down

0 comments on commit 5efe6cb

Please sign in to comment.