summaryrefslogtreecommitdiff
path: root/runtime/cha.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/cha.cc')
-rw-r--r--runtime/cha.cc61
1 files changed, 23 insertions, 38 deletions
diff --git a/runtime/cha.cc b/runtime/cha.cc
index 7948c29e5d..e6bdb84d4c 100644
--- a/runtime/cha.cc
+++ b/runtime/cha.cc
@@ -31,34 +31,24 @@ namespace art {
void ClassHierarchyAnalysis::AddDependency(ArtMethod* method,
ArtMethod* dependent_method,
OatQuickMethodHeader* dependent_header) {
- auto it = cha_dependency_map_.find(method);
- if (it == cha_dependency_map_.end()) {
- cha_dependency_map_[method] =
- new std::vector<std::pair<art::ArtMethod*, art::OatQuickMethodHeader*>>();
- it = cha_dependency_map_.find(method);
- } else {
- DCHECK(it->second != nullptr);
- }
- it->second->push_back(std::make_pair(dependent_method, dependent_header));
+ const auto it = cha_dependency_map_.insert(
+ decltype(cha_dependency_map_)::value_type(method, ListOfDependentPairs())).first;
+ it->second.push_back({dependent_method, dependent_header});
}
-std::vector<std::pair<ArtMethod*, OatQuickMethodHeader*>>*
- ClassHierarchyAnalysis::GetDependents(ArtMethod* method) {
+static const ClassHierarchyAnalysis::ListOfDependentPairs s_empty_vector;
+
+const ClassHierarchyAnalysis::ListOfDependentPairs& ClassHierarchyAnalysis::GetDependents(
+ ArtMethod* method) {
auto it = cha_dependency_map_.find(method);
if (it != cha_dependency_map_.end()) {
- DCHECK(it->second != nullptr);
return it->second;
}
- return nullptr;
+ return s_empty_vector;
}
-void ClassHierarchyAnalysis::RemoveDependencyFor(ArtMethod* method) {
- auto it = cha_dependency_map_.find(method);
- if (it != cha_dependency_map_.end()) {
- auto dependents = it->second;
- cha_dependency_map_.erase(it);
- delete dependents;
- }
+void ClassHierarchyAnalysis::RemoveAllDependenciesFor(ArtMethod* method) {
+ cha_dependency_map_.erase(method);
}
void ClassHierarchyAnalysis::RemoveDependentsWithMethodHeaders(
@@ -66,20 +56,19 @@ void ClassHierarchyAnalysis::RemoveDependentsWithMethodHeaders(
// Iterate through all entries in the dependency map and remove any entry that
// contains one of those in method_headers.
for (auto map_it = cha_dependency_map_.begin(); map_it != cha_dependency_map_.end(); ) {
- auto dependents = map_it->second;
- for (auto vec_it = dependents->begin(); vec_it != dependents->end(); ) {
- OatQuickMethodHeader* method_header = vec_it->second;
- auto it = std::find(method_headers.begin(), method_headers.end(), method_header);
- if (it != method_headers.end()) {
- vec_it = dependents->erase(vec_it);
- } else {
- vec_it++;
- }
- }
+ ListOfDependentPairs& dependents = map_it->second;
+ dependents.erase(
+ std::remove_if(
+ dependents.begin(),
+ dependents.end(),
+ [&method_headers](MethodAndMethodHeaderPair& dependent) {
+ return method_headers.find(dependent.second) != method_headers.end();
+ }),
+ dependents.end());
+
// Remove the map entry if there are no more dependents.
- if (dependents->empty()) {
+ if (dependents.empty()) {
map_it = cha_dependency_map_.erase(map_it);
- delete dependents;
} else {
map_it++;
}
@@ -554,11 +543,7 @@ void ClassHierarchyAnalysis::InvalidateSingleImplementationMethods(
}
// Invalidate all dependents.
- auto dependents = GetDependents(invalidated);
- if (dependents == nullptr) {
- continue;
- }
- for (const auto& dependent : *dependents) {
+ for (const auto& dependent : GetDependents(invalidated)) {
ArtMethod* method = dependent.first;;
OatQuickMethodHeader* method_header = dependent.second;
VLOG(class_linker) << "CHA invalidated compiled code for " << method->PrettyMethod();
@@ -567,7 +552,7 @@ void ClassHierarchyAnalysis::InvalidateSingleImplementationMethods(
method, method_header);
dependent_method_headers.insert(method_header);
}
- RemoveDependencyFor(invalidated);
+ RemoveAllDependenciesFor(invalidated);
}
}