diff options
author | 2019-02-07 16:17:33 +0000 | |
---|---|---|
committer | 2019-02-08 17:19:20 +0000 | |
commit | 6c70224ebd667b52a862f850893f6528af63f3e8 (patch) | |
tree | 43e1ed17ee7fdfd7081cb07e11700b77c38a5a52 | |
parent | 8581e2a234b562880c1d6c6b5ad14d23f7b597ed (diff) |
Replace MergeSets() with std::set::merge().
And clear up ownership of the VerifierDeps being merged
by using std::unique_ptr<>.
Test: m test-art-host-gtest
Test: testrunner.py --host
Bug: 123750182
Change-Id: Id4ffa9f9fa1968fa762b9e825f25827240f6d45d
-rw-r--r-- | compiler/driver/compiler_driver.cc | 8 | ||||
-rw-r--r-- | dexlayout/dex_verify.cc | 2 | ||||
-rw-r--r-- | dexlayout/dexlayout.h | 2 | ||||
-rw-r--r-- | libartbase/base/stl_util.h | 7 | ||||
-rw-r--r-- | runtime/verifier/verifier_deps.cc | 20 | ||||
-rw-r--r-- | runtime/verifier/verifier_deps.h | 2 |
6 files changed, 19 insertions, 22 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 56333b6d45..d9c0bf3922 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -1928,10 +1928,10 @@ void CompilerDriver::Verify(jobject jclass_loader, // Merge all VerifierDeps into the main one. verifier::VerifierDeps* verifier_deps = Thread::Current()->GetVerifierDeps(); for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) { - verifier::VerifierDeps* thread_deps = worker->GetThread()->GetVerifierDeps(); - worker->GetThread()->SetVerifierDeps(nullptr); - verifier_deps->MergeWith(*thread_deps, GetCompilerOptions().GetDexFilesForOatFile()); - delete thread_deps; + std::unique_ptr<verifier::VerifierDeps> thread_deps(worker->GetThread()->GetVerifierDeps()); + worker->GetThread()->SetVerifierDeps(nullptr); // We just took ownership. + verifier_deps->MergeWith(std::move(thread_deps), + GetCompilerOptions().GetDexFilesForOatFile()); } Thread::Current()->SetVerifierDeps(nullptr); } diff --git a/dexlayout/dex_verify.cc b/dexlayout/dex_verify.cc index 718d66feaa..83a7c69d7d 100644 --- a/dexlayout/dex_verify.cc +++ b/dexlayout/dex_verify.cc @@ -22,6 +22,8 @@ #include <inttypes.h> +#include <set> + #include "android-base/stringprintf.h" namespace art { diff --git a/dexlayout/dexlayout.h b/dexlayout/dexlayout.h index 535f789f95..60076bf59f 100644 --- a/dexlayout/dexlayout.h +++ b/dexlayout/dexlayout.h @@ -25,6 +25,8 @@ #include <stdint.h> #include <stdio.h> + +#include <set> #include <unordered_map> #include "dex/compact_dex_level.h" diff --git a/libartbase/base/stl_util.h b/libartbase/base/stl_util.h index 9d944b1170..1e071cee23 100644 --- a/libartbase/base/stl_util.h +++ b/libartbase/base/stl_util.h @@ -18,7 +18,6 @@ #define ART_LIBARTBASE_BASE_STL_UTIL_H_ #include <algorithm> -#include <set> #include <sstream> #include <android-base/logging.h> @@ -136,12 +135,6 @@ struct FNVHash { } }; -// Merge `other` entries into `to_update`. -template <typename T> -static inline void MergeSets(std::set<T>& to_update, const std::set<T>& other) { - to_update.insert(other.begin(), other.end()); -} - // Returns a copy of the passed vector that doesn't memory-own its entries. template <typename T> static inline std::vector<T*> MakeNonOwningPointerVector(const std::vector<std::unique_ptr<T>>& src) { diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc index b758159923..375ca75d31 100644 --- a/runtime/verifier/verifier_deps.cc +++ b/runtime/verifier/verifier_deps.cc @@ -23,7 +23,6 @@ #include "base/indenter.h" #include "base/leb128.h" #include "base/mutex-inl.h" -#include "base/stl_util.h" #include "compiler_callbacks.h" #include "dex/dex_file-inl.h" #include "mirror/class-inl.h" @@ -46,21 +45,22 @@ VerifierDeps::VerifierDeps(const std::vector<const DexFile*>& dex_files, bool ou VerifierDeps::VerifierDeps(const std::vector<const DexFile*>& dex_files) : VerifierDeps(dex_files, /*output_only=*/ true) {} -void VerifierDeps::MergeWith(const VerifierDeps& other, +void VerifierDeps::MergeWith(std::unique_ptr<VerifierDeps> other, const std::vector<const DexFile*>& dex_files) { - DCHECK(dex_deps_.size() == other.dex_deps_.size()); + DCHECK(other != nullptr); + DCHECK_EQ(dex_deps_.size(), other->dex_deps_.size()); for (const DexFile* dex_file : dex_files) { DexFileDeps* my_deps = GetDexFileDeps(*dex_file); - const DexFileDeps& other_deps = *other.GetDexFileDeps(*dex_file); + DexFileDeps& other_deps = *other->GetDexFileDeps(*dex_file); // We currently collect extra strings only on the main `VerifierDeps`, // which should be the one passed as `this` in this method. DCHECK(other_deps.strings_.empty()); - MergeSets(my_deps->assignable_types_, other_deps.assignable_types_); - MergeSets(my_deps->unassignable_types_, other_deps.unassignable_types_); - MergeSets(my_deps->classes_, other_deps.classes_); - MergeSets(my_deps->fields_, other_deps.fields_); - MergeSets(my_deps->methods_, other_deps.methods_); - MergeSets(my_deps->unverified_classes_, other_deps.unverified_classes_); + my_deps->assignable_types_.merge(other_deps.assignable_types_); + my_deps->unassignable_types_.merge(other_deps.unassignable_types_); + my_deps->classes_.merge(other_deps.classes_); + my_deps->fields_.merge(other_deps.fields_); + my_deps->methods_.merge(other_deps.methods_); + my_deps->unverified_classes_.merge(other_deps.unverified_classes_); } } diff --git a/runtime/verifier/verifier_deps.h b/runtime/verifier/verifier_deps.h index dfd4a5c4fb..7f71c6d76a 100644 --- a/runtime/verifier/verifier_deps.h +++ b/runtime/verifier/verifier_deps.h @@ -63,7 +63,7 @@ class VerifierDeps { // Merge `other` into this `VerifierDeps`'. `other` and `this` must be for the // same set of dex files. - void MergeWith(const VerifierDeps& other, const std::vector<const DexFile*>& dex_files); + void MergeWith(std::unique_ptr<VerifierDeps> other, const std::vector<const DexFile*>& dex_files); // Record the verification status of the class at `type_idx`. static void MaybeRecordVerificationStatus(const DexFile& dex_file, |