diff options
author | 2015-12-02 22:44:52 +0000 | |
---|---|---|
committer | 2015-12-02 23:00:53 +0000 | |
commit | 9fdb129b90c9a985f606f9d95627b4852171dc11 (patch) | |
tree | c7b1e1da1450f61a504cdf6e21cda62541e93ee7 | |
parent | 57989d6f7292155f4d91ce423cede17d04dd9343 (diff) |
Revert "Enable profiled guided compilation in dex2oat"
Test has flakes:
+art F 30865 30865 art/runtime/java_vm_ext.cc:466] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0x80
+art F 30865 30865 art/runtime/java_vm_ext.cc:466] string: '��gy�'
+art F 30865 30865 art/runtime/java_vm_ext.cc:466] input: '<0x80> 0xd8 0x67 0x79 0x8e 0x7f'
+art F 30865 30865 art/runtime/java_vm_ext.cc:466] in call to NewStringUTF
+art F 30865 30865 art/runtime/java_vm_ext.cc:466] from java.lang.String Main.getProfileInfoDump(java.lang.String, java.lang.Class, java.lang.Class)
This reverts commit 27e17fd81cc30e16e86c9c15498cae7f920c9dfe.
Change-Id: Id224b5970c3620c4c71fc0d39ed4a2e4755e5f29
-rw-r--r-- | compiler/dex/mir_analysis.cc | 4 | ||||
-rw-r--r-- | compiler/dex/mir_graph.h | 5 | ||||
-rw-r--r-- | compiler/dex/quick/quick_compiler.cc | 8 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.cc | 77 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.h | 19 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 2 | ||||
-rw-r--r-- | runtime/jit/offline_profiling_info.cc | 228 | ||||
-rw-r--r-- | runtime/jit/offline_profiling_info.h | 40 | ||||
-rw-r--r-- | runtime/runtime.cc | 2 | ||||
-rw-r--r-- | test/554-jit-profile-file/expected.txt | 7 | ||||
-rw-r--r-- | test/554-jit-profile-file/info.txt | 1 | ||||
-rw-r--r-- | test/554-jit-profile-file/offline_profile.cc | 63 | ||||
-rw-r--r-- | test/554-jit-profile-file/run | 22 | ||||
-rw-r--r-- | test/554-jit-profile-file/src-multidex/OtherDex.java | 31 | ||||
-rw-r--r-- | test/554-jit-profile-file/src/Main.java | 136 | ||||
-rw-r--r-- | test/Android.libarttest.mk | 3 |
16 files changed, 85 insertions, 563 deletions
diff --git a/compiler/dex/mir_analysis.cc b/compiler/dex/mir_analysis.cc index 18ce563fc2..39f8ee8f7e 100644 --- a/compiler/dex/mir_analysis.cc +++ b/compiler/dex/mir_analysis.cc @@ -1430,4 +1430,8 @@ void MIRGraph::DoCacheMethodLoweringInfo() { method_lowering_infos_.data(), count); } +bool MIRGraph::SkipCompilationByName(const std::string& methodname) { + return cu_->compiler_driver->SkipCompilation(methodname); +} + } // namespace art diff --git a/compiler/dex/mir_graph.h b/compiler/dex/mir_graph.h index 3191fe9d57..2da8a98f00 100644 --- a/compiler/dex/mir_graph.h +++ b/compiler/dex/mir_graph.h @@ -564,6 +564,11 @@ class MIRGraph { bool SkipCompilation(std::string* skip_message); /* + * Should we skip the compilation of this method based on its name? + */ + bool SkipCompilationByName(const std::string& methodname); + + /* * Parse dex method and add MIR at current insert point. Returns id (which is * actually the index of the method in the m_units_ array). */ diff --git a/compiler/dex/quick/quick_compiler.cc b/compiler/dex/quick/quick_compiler.cc index 3260a7a050..05dde9f649 100644 --- a/compiler/dex/quick/quick_compiler.cc +++ b/compiler/dex/quick/quick_compiler.cc @@ -780,6 +780,14 @@ CompiledMethod* QuickCompiler::Compile(const DexFile::CodeItem* code_item, PassDriverMEOpts pass_driver(GetPreOptPassManager(), GetPostOptPassManager(), &cu); pass_driver.Launch(); + /* For non-leaf methods check if we should skip compilation when the profiler is enabled. */ + if (cu.compiler_driver->ProfilePresent() + && !cu.mir_graph->MethodIsLeaf() + && cu.mir_graph->SkipCompilationByName(PrettyMethod(method_idx, dex_file))) { + cu.EndTiming(); + return nullptr; + } + if (cu.enable_debug & (1 << kDebugDumpCheckStats)) { cu.mir_graph->DumpCheckStats(); } diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 6d317d8512..9d3af1681a 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -80,9 +80,6 @@ static constexpr bool kTimeCompileMethod = !kIsDebugBuild; // given, too all compilations. static constexpr bool kRestrictCompilationFiltersToImage = true; -// Print additional info during profile guided compilation. -static constexpr bool kDebugProfileGuidedCompilation = false; - static double Percentage(size_t x, size_t y) { return 100.0 * (static_cast<double>(x)) / (static_cast<double>(x + y)); } @@ -347,7 +344,8 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, const std::string& dump_cfg_file_name, bool dump_cfg_append, CumulativeLogger* timer, int swap_fd, const std::string& profile_file) - : compiler_options_(compiler_options), + : profile_present_(false), + compiler_options_(compiler_options), verification_results_(verification_results), method_inliner_map_(method_inliner_map), compiler_(Compiler::Create(this, compiler_kind)), @@ -385,8 +383,12 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, // Read the profile file if one is provided. if (!profile_file.empty()) { - profile_compilation_info_.reset(new ProfileCompilationInfo(profile_file)); - LOG(INFO) << "Using profile data from file " << profile_file; + profile_present_ = profile_file_.LoadFile(profile_file); + if (profile_present_) { + LOG(INFO) << "Using profile data form file " << profile_file; + } else { + LOG(INFO) << "Failed to load profile file " << profile_file; + } } } @@ -567,9 +569,7 @@ static void CompileMethod(Thread* self, (verified_method->GetEncounteredVerificationFailures() & (verifier::VERIFY_ERROR_FORCE_INTERPRETER | verifier::VERIFY_ERROR_LOCKING)) == 0 && // Is eligable for compilation by methods-to-compile filter. - driver->IsMethodToCompile(method_ref) && - driver->ShouldCompileBasedOnProfile(method_ref); - + driver->IsMethodToCompile(method_ref); if (compile) { // NOTE: if compiler declines to compile this method, it will return null. compiled_method = driver->GetCompiler()->Compile(code_item, access_flags, invoke_type, @@ -766,22 +766,6 @@ bool CompilerDriver::IsMethodToCompile(const MethodReference& method_ref) const return methods_to_compile_->find(tmp.c_str()) != methods_to_compile_->end(); } -bool CompilerDriver::ShouldCompileBasedOnProfile(const MethodReference& method_ref) const { - if (profile_compilation_info_ == nullptr) { - // If we miss profile information it means that we don't do a profile guided compilation. - // Return true, and let the other filters decide if the method should be compiled. - return true; - } - bool result = profile_compilation_info_->ContainsMethod(method_ref); - - if (kDebugProfileGuidedCompilation) { - LOG(INFO) << "[ProfileGuidedCompilation] " - << (result ? "Compiled" : "Skipped") << " method:" - << PrettyMethod(method_ref.dex_method_index, *method_ref.dex_file, true); - } - return result; -} - class ResolveCatchBlockExceptionsClassVisitor : public ClassVisitor { public: ResolveCatchBlockExceptionsClassVisitor( @@ -2289,16 +2273,6 @@ void CompilerDriver::InitializeClasses(jobject class_loader, void CompilerDriver::Compile(jobject class_loader, const std::vector<const DexFile*>& dex_files, ThreadPool* thread_pool, TimingLogger* timings) { - if (profile_compilation_info_ != nullptr) { - if (!profile_compilation_info_->Load(dex_files)) { - LOG(WARNING) << "Failed to load offline profile info from " - << profile_compilation_info_->GetFilename() - << ". No methods will be compiled"; - } else if (kDebugProfileGuidedCompilation) { - LOG(INFO) << "[ProfileGuidedCompilation] " - << profile_compilation_info_->DumpInfo(); - } - } for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; CHECK(dex_file != nullptr); @@ -2536,6 +2510,39 @@ bool CompilerDriver::RequiresConstructorBarrier(Thread* self, const DexFile* dex return freezing_constructor_classes_.count(ClassReference(dex_file, class_def_index)) != 0; } +bool CompilerDriver::SkipCompilation(const std::string& method_name) { + if (!profile_present_) { + return false; + } + // First find the method in the profile file. + ProfileFile::ProfileData data; + if (!profile_file_.GetProfileData(&data, method_name)) { + // Not in profile, no information can be determined. + if (kIsDebugBuild) { + VLOG(compiler) << "not compiling " << method_name << " because it's not in the profile"; + } + return true; + } + + // Methods that comprise top_k_threshold % of the total samples will be compiled. + // Compare against the start of the topK percentage bucket just in case the threshold + // falls inside a bucket. + bool compile = data.GetTopKUsedPercentage() - data.GetUsedPercent() + <= compiler_options_->GetTopKProfileThreshold(); + if (kIsDebugBuild) { + if (compile) { + LOG(INFO) << "compiling method " << method_name << " because its usage is part of top " + << data.GetTopKUsedPercentage() << "% with a percent of " << data.GetUsedPercent() << "%" + << " (topKThreshold=" << compiler_options_->GetTopKProfileThreshold() << ")"; + } else { + VLOG(compiler) << "not compiling method " << method_name + << " because it's not part of leading " << compiler_options_->GetTopKProfileThreshold() + << "% samples)"; + } + } + return !compile; +} + std::string CompilerDriver::GetMemoryUsageString(bool extended) const { std::ostringstream oss; Runtime* const runtime = Runtime::Current(); diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h index a351f6d5df..1347b37fa0 100644 --- a/compiler/driver/compiler_driver.h +++ b/compiler/driver/compiler_driver.h @@ -31,11 +31,11 @@ #include "compiler.h" #include "dex_file.h" #include "driver/compiled_method_storage.h" -#include "jit/offline_profiling_info.h" #include "invoke_type.h" #include "method_reference.h" #include "mirror/class.h" // For mirror::Class::Status. #include "os.h" +#include "profiler.h" #include "runtime.h" #include "safe_map.h" #include "thread_pool.h" @@ -147,6 +147,10 @@ class CompilerDriver { return compiler_.get(); } + bool ProfilePresent() const { + return profile_present_; + } + // Are we compiling and creating an image file? bool IsBootImage() const { return boot_image_; @@ -441,10 +445,6 @@ class CompilerDriver { // Checks whether the provided method should be compiled, i.e., is in method_to_compile_. bool IsMethodToCompile(const MethodReference& method_ref) const; - // Checks whether profile guided compilation is enabled and if the method should be compiled - // according to the profile file. - bool ShouldCompileBasedOnProfile(const MethodReference& method_ref) const; - void RecordClassStatus(ClassReference ref, mirror::Class::Status status) REQUIRES(!compiled_classes_lock_); @@ -454,6 +454,9 @@ class CompilerDriver { uint16_t class_def_idx, const DexFile& dex_file) const; + // Should the compiler run on this method given profile information? + bool SkipCompilation(const std::string& method_name); + // Get memory usage during compilation. std::string GetMemoryUsageString(bool extended) const; @@ -592,6 +595,9 @@ class CompilerDriver { ThreadPool* thread_pool, TimingLogger* timings) REQUIRES(!Locks::mutator_lock_); + ProfileFile profile_file_; + bool profile_present_; + const CompilerOptions* const compiler_options_; VerificationResults* const verification_results_; DexFileToMethodInlinerMap* const method_inliner_map_; @@ -641,9 +647,6 @@ class CompilerDriver { // This option may be restricted to the boot image, depending on a flag in the implementation. std::unique_ptr<std::unordered_set<std::string>> methods_to_compile_; - // Info for profile guided compilation. - std::unique_ptr<ProfileCompilationInfo> profile_compilation_info_; - bool had_hard_verifier_failure_; size_t thread_count_; diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 1b3086233c..27a0e2d1af 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -175,7 +175,7 @@ void Jit::SaveProfilingInfo(const std::string& filename) { uint64_t last_update_ns = code_cache_->GetLastUpdateTimeNs(); if (offline_profile_info_->NeedsSaving(last_update_ns)) { - VLOG(profiler) << "Initiate save profiling information to: " << filename; + VLOG(profiler) << "Iniate save profiling information to: " << filename; std::set<ArtMethod*> methods; { ScopedObjectAccess soa(Thread::Current()); diff --git a/runtime/jit/offline_profiling_info.cc b/runtime/jit/offline_profiling_info.cc index 583085f087..4450653a90 100644 --- a/runtime/jit/offline_profiling_info.cc +++ b/runtime/jit/offline_profiling_info.cc @@ -68,6 +68,7 @@ void OfflineProfilingInfo::SaveProfilingInfo(const std::string& filename, } } + void OfflineProfilingInfo::AddMethodInfo(ArtMethod* method, DexFileToMethodsMap* info) { DCHECK(method != nullptr); const DexFile* dex_file = method->GetDexFile(); @@ -79,25 +80,11 @@ void OfflineProfilingInfo::AddMethodInfo(ArtMethod* method, DexFileToMethodsMap* info_it->second.insert(method->GetDexMethodIndex()); } -enum OpenMode { - READ, - READ_WRITE -}; - -static int OpenFile(const std::string& filename, OpenMode open_mode) { - int fd = -1; - switch (open_mode) { - case READ: - fd = open(filename.c_str(), O_RDONLY); - break; - case READ_WRITE: - // TODO(calin) allow the shared uid of the app to access the file. - fd = open(filename.c_str(), - O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, - S_IRUSR | S_IWUSR); - break; - } - +static int OpenOrCreateFile(const std::string& filename) { + // TODO(calin) allow the shared uid of the app to access the file. + int fd = open(filename.c_str(), + O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, + S_IRUSR | S_IWUSR); if (fd < 0) { PLOG(WARNING) << "Failed to open profile file " << filename; return -1; @@ -109,6 +96,7 @@ static int OpenFile(const std::string& filename, OpenMode open_mode) { PLOG(WARNING) << "Failed to lock profile file " << filename; return -1; } + return fd; } @@ -141,8 +129,8 @@ static void WriteToFile(int fd, const std::ostringstream& os) { } while (length > 0); } -static constexpr const char kFieldSeparator = ','; -static constexpr const char kLineSeparator = '\n'; +static constexpr char kFieldSeparator = ','; +static constexpr char kLineSeparator = '\n'; /** * Serialization format: @@ -154,7 +142,7 @@ static constexpr const char kLineSeparator = '\n'; **/ bool OfflineProfilingInfo::Serialize(const std::string& filename, const DexFileToMethodsMap& info) const { - int fd = OpenFile(filename, READ_WRITE); + int fd = OpenOrCreateFile(filename); if (fd == -1) { return false; } @@ -180,200 +168,4 @@ bool OfflineProfilingInfo::Serialize(const std::string& filename, return CloseDescriptorForFile(fd, filename); } - -// TODO(calin): This a duplicate of Utils::Split fixing the case where the first character -// is the separator. Merge the fix into Utils::Split once verified that it doesn't break its users. -static void SplitString(const std::string& s, char separator, std::vector<std::string>* result) { - const char* p = s.data(); - const char* end = p + s.size(); - // Check if the first character is the separator. - if (p != end && *p ==separator) { - result->push_back(""); - ++p; - } - // Process the rest of the characters. - while (p != end) { - if (*p == separator) { - ++p; - } else { - const char* start = p; - while (++p != end && *p != separator) { - // Skip to the next occurrence of the separator. - } - result->push_back(std::string(start, p - start)); - } - } -} - -bool ProfileCompilationInfo::ProcessLine(const std::string& line, - const std::vector<const DexFile*>& dex_files) { - std::vector<std::string> parts; - SplitString(line, kFieldSeparator, &parts); - if (parts.size() < 3) { - LOG(WARNING) << "Invalid line: " << line; - return false; - } - - const std::string& multidex_suffix = parts[0]; - uint32_t checksum; - if (!ParseInt(parts[1].c_str(), &checksum)) { - return false; - } - - const DexFile* current_dex_file = nullptr; - for (auto dex_file : dex_files) { - if (DexFile::GetMultiDexSuffix(dex_file->GetLocation()) == multidex_suffix) { - if (checksum != dex_file->GetLocationChecksum()) { - LOG(WARNING) << "Checksum mismatch for " - << dex_file->GetLocation() << " when parsing " << filename_; - return false; - } - current_dex_file = dex_file; - break; - } - } - if (current_dex_file == nullptr) { - return true; - } - - for (size_t i = 2; i < parts.size(); i++) { - uint32_t method_idx; - if (!ParseInt(parts[i].c_str(), &method_idx)) { - LOG(WARNING) << "Cannot parse method_idx " << parts[i]; - return false; - } - uint16_t class_idx = current_dex_file->GetMethodId(method_idx).class_idx_; - auto info_it = info_.find(current_dex_file); - if (info_it == info_.end()) { - info_it = info_.Put(current_dex_file, ClassToMethodsMap()); - } - ClassToMethodsMap& class_map = info_it->second; - auto class_it = class_map.find(class_idx); - if (class_it == class_map.end()) { - class_it = class_map.Put(class_idx, std::set<uint32_t>()); - } - class_it->second.insert(method_idx); - } - return true; -} - -// Parses the buffer (of length n) starting from start_from and identify new lines -// based on kLineSeparator marker. -// Returns the first position after kLineSeparator in the buffer (starting from start_from), -// or -1 if the marker doesn't appear. -// The processed characters are appended to the given line. -static int GetLineFromBuffer(char* buffer, int n, int start_from, std::string& line) { - if (start_from >= n) { - return -1; - } - int new_line_pos = -1; - for (int i = start_from; i < n; i++) { - if (buffer[i] == kLineSeparator) { - new_line_pos = i; - break; - } - } - int append_limit = new_line_pos == -1 ? n : new_line_pos; - line.append(buffer + start_from, append_limit - start_from); - // Jump over kLineSeparator and return the position of the next character. - return new_line_pos == -1 ? new_line_pos : new_line_pos + 1; -} - -bool ProfileCompilationInfo::Load(const std::vector<const DexFile*>& dex_files) { - if (dex_files.empty()) { - return true; - } - if (kIsDebugBuild) { - // In debug builds verify that the multidex suffixes are unique. - std::set<std::string> suffixes; - for (auto dex_file : dex_files) { - std::string multidex_suffix = DexFile::GetMultiDexSuffix(dex_file->GetLocation()); - DCHECK(suffixes.find(multidex_suffix) == suffixes.end()) - << "DexFiles appear to belong to different apks." - << " There are multiple dex files with the same multidex suffix: " - << multidex_suffix; - suffixes.insert(multidex_suffix); - } - } - info_.clear(); - - int fd = OpenFile(filename_, READ); - if (fd == -1) { - return false; - } - - std::string current_line; - const int kBufferSize = 1024; - char buffer[kBufferSize]; - bool success = true; - - while (success) { - int n = read(fd, buffer, kBufferSize); - if (n < 0) { - PLOG(WARNING) << "Error when reading profile file " << filename_; - success = false; - break; - } else if (n == 0) { - break; - } - // Detect the new lines from the buffer. If we manage to complete a line, - // process it. Otherwise append to the current line. - int current_start_pos = 0; - while (current_start_pos < n) { - current_start_pos = GetLineFromBuffer(buffer, n, current_start_pos, current_line); - if (current_start_pos == -1) { - break; - } - if (!ProcessLine(current_line, dex_files)) { - success = false; - break; - } - // Reset the current line (we just processed it). - current_line.clear(); - } - } - if (!success) { - info_.clear(); - } - return CloseDescriptorForFile(fd, filename_) && success; -} - -bool ProfileCompilationInfo::ContainsMethod(const MethodReference& method_ref) const { - auto info_it = info_.find(method_ref.dex_file); - if (info_it != info_.end()) { - uint16_t class_idx = method_ref.dex_file->GetMethodId(method_ref.dex_method_index).class_idx_; - const ClassToMethodsMap& class_map = info_it->second; - auto class_it = class_map.find(class_idx); - if (class_it != class_map.end()) { - const std::set<uint32_t>& methods = class_it->second; - return methods.find(method_ref.dex_method_index) != methods.end(); - } - return false; - } - return false; -} - -std::string ProfileCompilationInfo::DumpInfo(bool print_full_dex_location) const { - std::ostringstream os; - os << "ProfileInfo:" << (info_.empty() ? "empty" : ""); - const std::string kFirstDexFileKeySubstitute = ":classes.dex"; - for (auto info_it : info_) { - os << "\n"; - const DexFile* dex_file = info_it.first; - if (print_full_dex_location) { - os << dex_file->GetLocation(); - } else { - // Replace the (empty) multidex suffix of the first key with a substitute for easier reading. - std::string multidex_suffix = DexFile::GetMultiDexSuffix(dex_file->GetLocation()); - os << (multidex_suffix.empty() ? kFirstDexFileKeySubstitute : multidex_suffix); - } - for (auto class_it : info_it.second) { - for (auto method_it : class_it.second) { - os << "\n " << PrettyMethod(method_it, *dex_file, true); - } - } - } - return os.str(); -} - } // namespace art diff --git a/runtime/jit/offline_profiling_info.h b/runtime/jit/offline_profiling_info.h index 90bda60ac7..e3117eb5ee 100644 --- a/runtime/jit/offline_profiling_info.h +++ b/runtime/jit/offline_profiling_info.h @@ -21,7 +21,6 @@ #include "atomic.h" #include "dex_file.h" -#include "method_reference.h" #include "safe_map.h" namespace art { @@ -51,47 +50,10 @@ class OfflineProfilingInfo { bool Serialize(const std::string& filename, const DexFileToMethodsMap& info) const; // TODO(calin): Verify if Atomic is really needed (are we sure to be called from a - // single thread?) + // singe thread?) Atomic<uint64_t> last_update_time_ns_; }; -/** - * Profile information in a format suitable to be queried by the compiler and performing - * profile guided compilation. - */ -class ProfileCompilationInfo { - public: - // Constructs a ProfileCompilationInfo backed by the provided file. - explicit ProfileCompilationInfo(const std::string& filename) : filename_(filename) {} - - // Loads profile information corresponding to the provided dex files. - // The dex files' multidex suffixes must be unique. - // This resets the state of the profiling information - // (i.e. all previously loaded info are cleared). - bool Load(const std::vector<const DexFile*>& dex_files); - - // Returns true if the method reference is present in the profiling info. - bool ContainsMethod(const MethodReference& method_ref) const; - - const std::string& GetFilename() const { return filename_; } - - // Dumps all the loaded profile info into a string and returns it. - // This is intended for testing and debugging. - std::string DumpInfo(bool print_full_dex_location = true) const; - - private: - bool ProcessLine(const std::string& line, - const std::vector<const DexFile*>& dex_files); - - using ClassToMethodsMap = SafeMap<uint32_t, std::set<uint32_t>>; - // Map identifying the location of the profiled methods. - // dex_file -> class_index -> [dex_method_index]+ - using DexFileToProfileInfoMap = SafeMap<const DexFile*, ClassToMethodsMap>; - - const std::string filename_; - DexFileToProfileInfoMap info_; -}; - } // namespace art #endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 3e7b26d0ff..fe8eb0d78d 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -219,6 +219,8 @@ Runtime::~Runtime() { UnloadNativeBridge(); } + MaybeSaveJitProfilingInfo(); + if (dump_gc_performance_on_shutdown_) { // This can't be called from the Heap destructor below because it // could call RosAlloc::InspectAll() which needs the thread_list diff --git a/test/554-jit-profile-file/expected.txt b/test/554-jit-profile-file/expected.txt deleted file mode 100644 index cde211e1c0..0000000000 --- a/test/554-jit-profile-file/expected.txt +++ /dev/null @@ -1,7 +0,0 @@ -JNI_OnLoad called -ProfileInfo: -:classes.dex - java.lang.String Main.hotMethod() - void Main.main(java.lang.String[]) -:classes2.dex - java.lang.String OtherDex.hotMethod() diff --git a/test/554-jit-profile-file/info.txt b/test/554-jit-profile-file/info.txt deleted file mode 100644 index b1bfe81eb8..0000000000 --- a/test/554-jit-profile-file/info.txt +++ /dev/null @@ -1 +0,0 @@ -Check that saving and restoring profile files works correctly in a JIT environment. diff --git a/test/554-jit-profile-file/offline_profile.cc b/test/554-jit-profile-file/offline_profile.cc deleted file mode 100644 index c63073d6be..0000000000 --- a/test/554-jit-profile-file/offline_profile.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dex_file.h" - -#include "jit/offline_profiling_info.h" -#include "jni.h" -#include "mirror/class-inl.h" -#include "oat_file_assistant.h" -#include "oat_file_manager.h" -#include "scoped_thread_state_change.h" -#include "thread.h" - -namespace art { -namespace { - -extern "C" JNIEXPORT jstring JNICALL Java_Main_getProfileInfoDump( - JNIEnv* env, jclass, jstring filename, jclass cls_from_primary, jclass cls_from_secondary) { - // Note: - // Ideally we would get the dex list from the primary oat file. - // e.g. - // oat_file = Runtime::Current()->GetOatFileManager().GetPrimaryOatFile(); - // dex_files = OatFileAssistant::LoadDexFiles(*oat_file, dex_location.c_str()); - // However the ownership of the pointers is complicated since the primary file - // already exists and the test crashed sporadically because some data changes under - // our feet. - // To simplify things get the dex files from the classes passed as arguments. - const DexFile* dex_primary; - const DexFile* dex_secondary; - { - ScopedObjectAccess soa(Thread::Current()); - dex_primary = soa.Decode<mirror::Class*>(cls_from_primary)->GetDexCache()->GetDexFile(); - dex_secondary = soa.Decode<mirror::Class*>(cls_from_secondary)->GetDexCache()->GetDexFile(); - } - - std::vector<const DexFile*> dex_files; - dex_files.push_back(dex_primary); - dex_files.push_back(dex_secondary); - - const char* filename_chars = env->GetStringUTFChars(filename, nullptr); - ProfileCompilationInfo info(filename_chars); - const char* result = info.Load(dex_files) - ? info.DumpInfo(/*print_full_dex_location*/false).c_str() - : nullptr; - env->ReleaseStringUTFChars(filename, filename_chars); - return env->NewStringUTF(result); -} - -} // namespace -} // namespace art diff --git a/test/554-jit-profile-file/run b/test/554-jit-profile-file/run deleted file mode 100644 index 08dcb38abb..0000000000 --- a/test/554-jit-profile-file/run +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -exec ${RUN} \ - -Xcompiler-option --compiler-filter=interpret-only \ - --runtime-option -Xjitsaveprofilinginfo \ - --runtime-option -Xusejit:true \ - --runtime-option -Xjitthreshold:100 \ - "${@}" diff --git a/test/554-jit-profile-file/src-multidex/OtherDex.java b/test/554-jit-profile-file/src-multidex/OtherDex.java deleted file mode 100644 index 51644db5aa..0000000000 --- a/test/554-jit-profile-file/src-multidex/OtherDex.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.HashMap; - -public class OtherDex { - public void coldMethod() { - hotMethod(); - } - - public String hotMethod() { - HashMap<String, String> map = new HashMap<String, String>(); - for (int i = 0; i < 10; i++) { - map.put("" + i, "" + i + 1); - } - return map.get("1"); - } -} diff --git a/test/554-jit-profile-file/src/Main.java b/test/554-jit-profile-file/src/Main.java deleted file mode 100644 index ba613ae569..0000000000 --- a/test/554-jit-profile-file/src/Main.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.HashMap; - -public class Main { - - public void coldMethod() { - hotMethod(); - } - - public String hotMethod() { - HashMap<String, String> map = new HashMap<String, String>(); - for (int i = 0; i < 10; i++) { - map.put("" + i, "" + i + 1); - } - return map.get("1"); - } - - private static final String PKG_NAME = "test.package"; - private static final String PROFILE_FILE = PKG_NAME + ".prof"; - private static final String TEMP_FILE_NAME_PREFIX = "dummy"; - private static final String TEMP_FILE_NAME_SUFFIX = ".file"; - private static final int JIT_INVOCATION_COUNT = 101; - - /* needs to match Runtime:: kProfileBackground */ - private static final int PROFILE_BACKGROUND = 1; - - public static void main(String[] args) throws Exception { - System.loadLibrary(args[0]); - - File file = null; - File profileDir = null; - File profileFile = null; - try { - // We don't know where we have rights to create the code_cache. So create - // a dummy temporary file and get its parent directory. That will serve as - // the app directory. - file = createTempFile(); - String appDir = file.getParent(); - profileDir = new File(appDir, "code_cache"); - profileDir.mkdir(); - - // Registering the app info will set the profile file name. - VMRuntime.registerAppInfo(PKG_NAME, appDir); - - // Make sure the hot methods are jitted. - Main m = new Main(); - OtherDex o = new OtherDex(); - for (int i = 0; i < JIT_INVOCATION_COUNT; i++) { - m.hotMethod(); - o.hotMethod(); - } - - // Updating the process state to BACKGROUND will trigger profile saving. - VMRuntime.updateProcessState(PROFILE_BACKGROUND); - - // Check that the profile file exists. - profileFile = new File(profileDir, PROFILE_FILE); - if (!profileFile.exists()) { - throw new RuntimeException("No profile file found"); - } - // Dump the profile file. - // We know what methods are hot and we compare with the golden `expected` output. - System.out.println(getProfileInfoDump(profileFile.getPath(), m.getClass(), o.getClass())); - } finally { - if (file != null) { - file.delete(); - } - if (profileFile != null) { - profileFile.delete(); - } - if (profileDir != null) { - profileDir.delete(); - } - } - } - - private static class VMRuntime { - private static final Method registerAppInfoMethod; - private static final Method updateProcessStateMethod; - private static final Method getRuntimeMethod; - static { - try { - Class c = Class.forName("dalvik.system.VMRuntime"); - registerAppInfoMethod = c.getDeclaredMethod("registerAppInfo", - String.class, String.class, String.class); - updateProcessStateMethod = c.getDeclaredMethod("updateProcessState", Integer.TYPE); - getRuntimeMethod = c.getDeclaredMethod("getRuntime"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static void registerAppInfo(String pkgName, String appDir) throws Exception { - registerAppInfoMethod.invoke(null, pkgName, appDir, null); - } - public static void updateProcessState(int state) throws Exception { - Object runtime = getRuntimeMethod.invoke(null); - updateProcessStateMethod.invoke(runtime, state); - } - } - - static native String getProfileInfoDump( - String filename, Class<?> clsFromPrimary, Class<?> clsFromSecondary); - - private static File createTempFile() throws Exception { - try { - return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); - } catch (IOException e) { - System.setProperty("java.io.tmpdir", "/data/local/tmp"); - try { - return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); - } catch (IOException e2) { - System.setProperty("java.io.tmpdir", "/sdcard"); - return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); - } - } - } -} diff --git a/test/Android.libarttest.mk b/test/Android.libarttest.mk index f8abe71bea..f74a516486 100644 --- a/test/Android.libarttest.mk +++ b/test/Android.libarttest.mk @@ -38,8 +38,7 @@ LIBARTTEST_COMMON_SRC_FILES := \ 461-get-reference-vreg/get_reference_vreg_jni.cc \ 466-get-live-vreg/get_live_vreg_jni.cc \ 497-inlining-and-class-loader/clear_dex_cache.cc \ - 543-env-long-ref/env_long_ref.cc \ - 551-jit-profile-file/offline_profile.cc + 543-env-long-ref/env_long_ref.cc ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttest.so ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttestd.so |