diff options
author | Andreas Gampe <agampe@google.com> | 2015-04-21 03:59:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-21 03:59:33 +0000 |
commit | 2fb1639a4bd836f6426cc0d4b8d21c59d2648527 (patch) | |
tree | 605389efc1479fa58b85481c4c291bc072ba0d78 | |
parent | 4474073ee836d463af29329c86d49354559a41c5 (diff) | |
parent | b1fceadbd42b3047a9c06a8af6239c737d67344e (diff) | |
download | art-2fb1639a4bd836f6426cc0d4b8d21c59d2648527.zip art-2fb1639a4bd836f6426cc0d4b8d21c59d2648527.tar.gz art-2fb1639a4bd836f6426cc0d4b8d21c59d2648527.tar.bz2 |
Merge "ART: Change image_classes and compiled_classes to unordered set"
-rw-r--r-- | compiler/common_compiler_test.cc | 2 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.cc | 39 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.h | 19 | ||||
-rw-r--r-- | compiler/image_test.cc | 2 | ||||
-rw-r--r-- | compiler/image_writer.cc | 2 | ||||
-rw-r--r-- | dex2oat/dex2oat.cc | 24 |
6 files changed, 50 insertions, 38 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc index 96d90bb..8ffc86e 100644 --- a/compiler/common_compiler_test.cc +++ b/compiler/common_compiler_test.cc @@ -165,7 +165,7 @@ void CommonCompilerTest::SetUp() { method_inliner_map_.get(), compiler_kind, instruction_set, instruction_set_features_.get(), - true, new std::set<std::string>, nullptr, + true, new std::unordered_set<std::string>, nullptr, 2, true, true, "", timer_.get(), -1, "")); } // We typically don't generate an image in unit tests, disable this optimization by default. diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 538d969..1832647 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -76,6 +76,10 @@ static constexpr bool kTimeCompileMethod = !kIsDebugBuild; // Whether to produce 64-bit ELF files for 64-bit targets. Leave this off for now. static constexpr bool kProduce64BitELFFiles = false; +// Whether classes-to-compile is only applied to the boot image, or, when given, too all +// compilations. +static constexpr bool kRestrictCompilationFiltersToImage = true; + static double Percentage(size_t x, size_t y) { return 100.0 * (static_cast<double>(x)) / (static_cast<double>(x + y)); } @@ -343,9 +347,9 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, Compiler::Kind compiler_kind, InstructionSet instruction_set, const InstructionSetFeatures* instruction_set_features, - bool image, std::set<std::string>* image_classes, - std::set<std::string>* compiled_classes, size_t thread_count, - bool dump_stats, bool dump_passes, + bool image, std::unordered_set<std::string>* image_classes, + std::unordered_set<std::string>* compiled_classes, + size_t thread_count, bool dump_stats, bool dump_passes, const std::string& dump_cfg_file_name, CumulativeLogger* timer, int swap_fd, const std::string& profile_file) : swap_space_(swap_fd == -1 ? nullptr : new SwapSpace(swap_fd, 10 * MB)), @@ -656,14 +660,14 @@ bool CompilerDriver::IsImageClass(const char* descriptor) const { } bool CompilerDriver::IsClassToCompile(const char* descriptor) const { - if (!IsImage()) { + if (kRestrictCompilationFiltersToImage && !IsImage()) { + return true; + } + + if (classes_to_compile_ == nullptr) { return true; - } else { - if (classes_to_compile_ == nullptr) { - return true; - } - return classes_to_compile_->find(descriptor) != classes_to_compile_->end(); } + return classes_to_compile_->find(descriptor) != classes_to_compile_->end(); } static void ResolveExceptionsForMethod(MutableHandle<mirror::ArtMethod> method_handle, @@ -723,7 +727,8 @@ static bool ResolveCatchBlockExceptionsClassVisitor(mirror::Class* c, void* arg) static bool RecordImageClassesVisitor(mirror::Class* klass, void* arg) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - std::set<std::string>* image_classes = reinterpret_cast<std::set<std::string>*>(arg); + std::unordered_set<std::string>* image_classes = + reinterpret_cast<std::unordered_set<std::string>*>(arg); std::string temp; image_classes->insert(klass->GetDescriptor(&temp)); return true; @@ -795,7 +800,8 @@ void CompilerDriver::LoadImageClasses(TimingLogger* timings) CHECK_NE(image_classes_->size(), 0U); } -static void MaybeAddToImageClasses(Handle<mirror::Class> c, std::set<std::string>* image_classes) +static void MaybeAddToImageClasses(Handle<mirror::Class> c, + std::unordered_set<std::string>* image_classes) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { Thread* self = Thread::Current(); StackHandleScope<1> hs(self); @@ -804,7 +810,8 @@ static void MaybeAddToImageClasses(Handle<mirror::Class> c, std::set<std::string std::string temp; while (!klass->IsObjectClass()) { const char* descriptor = klass->GetDescriptor(&temp); - std::pair<std::set<std::string>::iterator, bool> result = image_classes->insert(descriptor); + std::pair<std::unordered_set<std::string>::iterator, bool> result = + image_classes->insert(descriptor); if (!result.second) { // Previously inserted. break; } @@ -826,8 +833,8 @@ static void MaybeAddToImageClasses(Handle<mirror::Class> c, std::set<std::string // Note: we can use object pointers because we suspend all threads. class ClinitImageUpdate { public: - static ClinitImageUpdate* Create(std::set<std::string>* image_class_descriptors, Thread* self, - ClassLinker* linker, std::string* error_msg) { + static ClinitImageUpdate* Create(std::unordered_set<std::string>* image_class_descriptors, + Thread* self, ClassLinker* linker, std::string* error_msg) { std::unique_ptr<ClinitImageUpdate> res(new ClinitImageUpdate(image_class_descriptors, self, linker)); if (res->art_method_class_ == nullptr) { @@ -867,7 +874,7 @@ class ClinitImageUpdate { } private: - ClinitImageUpdate(std::set<std::string>* image_class_descriptors, Thread* self, + ClinitImageUpdate(std::unordered_set<std::string>* image_class_descriptors, Thread* self, ClassLinker* linker) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : image_class_descriptors_(image_class_descriptors), self_(self) { @@ -933,7 +940,7 @@ class ClinitImageUpdate { } mutable std::unordered_set<mirror::Object*> marked_objects_; - std::set<std::string>* const image_class_descriptors_; + std::unordered_set<std::string>* const image_class_descriptors_; std::vector<mirror::Class*> image_classes_; const mirror::Class* art_method_class_; const mirror::Class* dex_cache_class_; diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h index bd9d7c1..bd4ed06 100644 --- a/compiler/driver/compiler_driver.h +++ b/compiler/driver/compiler_driver.h @@ -19,6 +19,7 @@ #include <set> #include <string> +#include <unordered_set> #include <vector> #include "arch/instruction_set.h" @@ -101,8 +102,8 @@ class CompilerDriver { Compiler::Kind compiler_kind, InstructionSet instruction_set, const InstructionSetFeatures* instruction_set_features, - bool image, std::set<std::string>* image_classes, - std::set<std::string>* compiled_classes, + bool image, std::unordered_set<std::string>* image_classes, + std::unordered_set<std::string>* compiled_classes, size_t thread_count, bool dump_stats, bool dump_passes, const std::string& dump_cfg_file_name, CumulativeLogger* timer, int swap_fd, @@ -154,7 +155,7 @@ class CompilerDriver { return image_; } - const std::set<std::string>* GetImageClasses() const { + const std::unordered_set<std::string>* GetImageClasses() const { return image_classes_.get(); } @@ -420,7 +421,7 @@ class CompilerDriver { // Checks if class specified by type_idx is one of the image_classes_ bool IsImageClass(const char* descriptor) const; - // Checks if the provided class should be compiled, i.e., is in classes_to_compile_. + // Checks whether the provided class should be compiled, i.e., is in classes_to_compile_. bool IsClassToCompile(const char* descriptor) const; void RecordClassStatus(ClassReference ref, mirror::Class::Status status) @@ -585,12 +586,12 @@ class CompilerDriver { // If image_ is true, specifies the classes that will be included in // the image. Note if image_classes_ is nullptr, all classes are // included in the image. - std::unique_ptr<std::set<std::string>> image_classes_; + std::unique_ptr<std::unordered_set<std::string>> image_classes_; - // If image_ is true, specifies the classes that will be compiled in - // the image. Note if classes_to_compile_ is nullptr, all classes are - // included in the image. - std::unique_ptr<std::set<std::string>> classes_to_compile_; + // Specifies the classes that will be compiled. Note that if classes_to_compile_ is nullptr, + // all classes are eligible for compilation (duplication filters etc. will still apply). + // This option may be restricted to the boot image, depending on a flag in the implementation. + std::unique_ptr<std::unordered_set<std::string>> classes_to_compile_; bool had_hard_verifier_failure_; diff --git a/compiler/image_test.cc b/compiler/image_test.cc index cfd525c..8016831 100644 --- a/compiler/image_test.cc +++ b/compiler/image_test.cc @@ -124,7 +124,7 @@ TEST_F(ImageTest, WriteRead) { } ASSERT_TRUE(compiler_driver_->GetImageClasses() != NULL); - std::set<std::string> image_classes(*compiler_driver_->GetImageClasses()); + std::unordered_set<std::string> image_classes(*compiler_driver_->GetImageClasses()); // Need to delete the compiler since it has worker threads which are attached to runtime. compiler_driver_.reset(); diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc index 670c897..a99ef34 100644 --- a/compiler/image_writer.cc +++ b/compiler/image_writer.cc @@ -776,7 +776,7 @@ void ImageWriter::CheckNonImageClassesRemovedCallback(Object* obj, void* arg) { } void ImageWriter::DumpImageClasses() { - const std::set<std::string>* image_classes = compiler_driver_.GetImageClasses(); + auto image_classes = compiler_driver_.GetImageClasses(); CHECK(image_classes != NULL); for (const std::string& image_class : *image_classes) { LOG(INFO) << " " << image_class; diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 7e32b43..70b4213 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -23,6 +23,7 @@ #include <iostream> #include <sstream> #include <string> +#include <unordered_set> #include <vector> #if defined(__linux__) && defined(__arm__) @@ -1102,7 +1103,7 @@ class Dex2Oat FINAL { return false; } } else if (image_) { - image_classes_.reset(new std::set<std::string>); + image_classes_.reset(new std::unordered_set<std::string>); } // If --compiled-classes was specified, calculate the full list of classes to compile in the // image. @@ -1615,20 +1616,22 @@ class Dex2Oat FINAL { } // Reads the class names (java.lang.Object) and returns a set of descriptors (Ljava/lang/Object;) - static std::set<std::string>* ReadImageClassesFromFile(const char* image_classes_filename) { + static std::unordered_set<std::string>* ReadImageClassesFromFile( + const char* image_classes_filename) { std::unique_ptr<std::ifstream> image_classes_file(new std::ifstream(image_classes_filename, std::ifstream::in)); if (image_classes_file.get() == nullptr) { LOG(ERROR) << "Failed to open image classes file " << image_classes_filename; return nullptr; } - std::unique_ptr<std::set<std::string>> result(ReadImageClasses(*image_classes_file)); + std::unique_ptr<std::unordered_set<std::string>> result(ReadImageClasses(*image_classes_file)); image_classes_file->close(); return result.release(); } - static std::set<std::string>* ReadImageClasses(std::istream& image_classes_stream) { - std::unique_ptr<std::set<std::string>> image_classes(new std::set<std::string>); + static std::unordered_set<std::string>* ReadImageClasses(std::istream& image_classes_stream) { + std::unique_ptr<std::unordered_set<std::string>> image_classes( + new std::unordered_set<std::string>); while (image_classes_stream.good()) { std::string dot; std::getline(image_classes_stream, dot); @@ -1642,9 +1645,10 @@ class Dex2Oat FINAL { } // Reads the class names (java.lang.Object) and returns a set of descriptors (Ljava/lang/Object;) - static std::set<std::string>* ReadImageClassesFromZip(const char* zip_filename, - const char* image_classes_filename, - std::string* error_msg) { + static std::unordered_set<std::string>* ReadImageClassesFromZip( + const char* zip_filename, + const char* image_classes_filename, + std::string* error_msg) { std::unique_ptr<ZipArchive> zip_archive(ZipArchive::Open(zip_filename, error_msg)); if (zip_archive.get() == nullptr) { return nullptr; @@ -1720,8 +1724,8 @@ class Dex2Oat FINAL { const char* image_classes_filename_; const char* compiled_classes_zip_filename_; const char* compiled_classes_filename_; - std::unique_ptr<std::set<std::string>> image_classes_; - std::unique_ptr<std::set<std::string>> compiled_classes_; + std::unique_ptr<std::unordered_set<std::string>> image_classes_; + std::unique_ptr<std::unordered_set<std::string>> compiled_classes_; bool image_; std::unique_ptr<ImageWriter> image_writer_; bool is_host_; |