From: Calin Juravle Date: Tue, 19 Apr 2016 15:33:46 +0000 (+0100) Subject: ProfileSaver: query profiling_infos instead of the code_map X-Git-Tag: android-x86-7.1-r1~45^2~152^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e2d066d0337b7c81d47e4806e6025b70d83fcd56;p=android-x86%2Fart.git ProfileSaver: query profiling_infos instead of the code_map This is the first step in being able to record profiles without jit being active. Bug: 27916886 Change-Id: I2fcbd03560e109e6866ad6d82c79b902a889e620 --- diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc index 1f3e08b39..b7b3ee743 100644 --- a/runtime/jit/jit_code_cache.cc +++ b/runtime/jit/jit_code_cache.cc @@ -890,13 +890,15 @@ void* JitCodeCache::MoreCore(const void* mspace, intptr_t increment) NO_THREAD_S } } -void JitCodeCache::GetCompiledArtMethods(const std::set& dex_base_locations, - std::vector& methods) { +void JitCodeCache::GetProfiledMethods(const std::set& dex_base_locations, + std::vector& methods) { ScopedTrace trace(__FUNCTION__); MutexLock mu(Thread::Current(), lock_); - for (auto it : method_code_map_) { - if (ContainsElement(dex_base_locations, it.second->GetDexFile()->GetBaseLocation())) { - methods.push_back(it.second); + for (const ProfilingInfo* info : profiling_infos_) { + ArtMethod* method = info->GetMethod(); + const DexFile* dex_file = method->GetDexFile(); + if (ContainsElement(dex_base_locations, dex_file->GetBaseLocation())) { + methods.emplace_back(dex_file, method->GetDexMethodIndex()); } } } diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h index f31cc51d5..4df676251 100644 --- a/runtime/jit/jit_code_cache.h +++ b/runtime/jit/jit_code_cache.h @@ -26,6 +26,7 @@ #include "gc/accounting/bitmap.h" #include "gc_root.h" #include "jni.h" +#include "method_reference.h" #include "oat_file.h" #include "object_callbacks.h" #include "safe_map.h" @@ -165,9 +166,9 @@ class JitCodeCache { void* MoreCore(const void* mspace, intptr_t increment); - // Adds to `methods` all the compiled ArtMethods which are part of any of the given dex locations. - void GetCompiledArtMethods(const std::set& dex_base_locations, - std::vector& methods) + // Adds to `methods` all profiled methods which are part of any of the given dex locations. + void GetProfiledMethods(const std::set& dex_base_locations, + std::vector& methods) REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); diff --git a/runtime/jit/offline_profiling_info.cc b/runtime/jit/offline_profiling_info.cc index 024c73a2c..a79bcf05a 100644 --- a/runtime/jit/offline_profiling_info.cc +++ b/runtime/jit/offline_profiling_info.cc @@ -56,14 +56,12 @@ std::string ProfileCompilationInfo::GetProfileDexFileKey(const std::string& dex_ } bool ProfileCompilationInfo::AddMethodsAndClasses( - const std::vector& methods, + const std::vector& methods, const std::set& resolved_classes) { - ScopedObjectAccess soa(Thread::Current()); - for (ArtMethod* method : methods) { - const DexFile* dex_file = method->GetDexFile(); - if (!AddMethodIndex(GetProfileDexFileKey(dex_file->GetLocation()), - dex_file->GetLocationChecksum(), - method->GetDexMethodIndex())) { + for (const MethodReference& method : methods) { + if (!AddMethodIndex(GetProfileDexFileKey(method.dex_file->GetLocation()), + method.dex_file->GetLocationChecksum(), + method.dex_method_index)) { return false; } } diff --git a/runtime/jit/offline_profiling_info.h b/runtime/jit/offline_profiling_info.h index c4055b386..5a07da79a 100644 --- a/runtime/jit/offline_profiling_info.h +++ b/runtime/jit/offline_profiling_info.h @@ -28,9 +28,6 @@ namespace art { -class ArtMethod; -class DexCacheProfileData; - // TODO: rename file. /** * Profile information in a format suitable to be queried by the compiler and @@ -45,7 +42,7 @@ class ProfileCompilationInfo { static const uint8_t kProfileVersion[]; // Add the given methods and classes to the current profile object. - bool AddMethodsAndClasses(const std::vector& methods, + bool AddMethodsAndClasses(const std::vector& methods, const std::set& resolved_classes); // Loads profile information from the given file descriptor. bool Load(int fd); @@ -114,8 +111,7 @@ class ProfileCompilationInfo { DexFileData* GetOrAddDexFileData(const std::string& dex_location, uint32_t checksum); bool AddMethodIndex(const std::string& dex_location, uint32_t checksum, uint16_t method_idx); bool AddClassIndex(const std::string& dex_location, uint32_t checksum, uint16_t class_idx); - bool AddResolvedClasses(const DexCacheResolvedClasses& classes) - SHARED_REQUIRES(Locks::mutator_lock_); + bool AddResolvedClasses(const DexCacheResolvedClasses& classes); // Parsing functionality. diff --git a/runtime/jit/profile_compilation_info_test.cc b/runtime/jit/profile_compilation_info_test.cc index ad9af7017..c8f4d94c7 100644 --- a/runtime/jit/profile_compilation_info_test.cc +++ b/runtime/jit/profile_compilation_info_test.cc @@ -21,6 +21,7 @@ #include "class_linker-inl.h" #include "common_runtime_test.h" #include "dex_file.h" +#include "method_reference.h" #include "mirror/class-inl.h" #include "mirror/class_loader.h" #include "handle_scope-inl.h" @@ -72,7 +73,12 @@ class ProfileCompilationInfoTest : public CommonRuntimeTest { const std::vector& methods, const std::set& resolved_classes) { ProfileCompilationInfo info; - if (!info.AddMethodsAndClasses(methods, resolved_classes)) { + std::vector method_refs; + ScopedObjectAccess soa(Thread::Current()); + for (ArtMethod* method : methods) { + method_refs.emplace_back(method->GetDexFile(), method->GetDexMethodIndex()); + } + if (!info.AddMethodsAndClasses(method_refs, resolved_classes)) { return false; } return info.MergeAndSave(filename, nullptr, false); diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc index 949215af8..7a9d2506d 100644 --- a/runtime/jit/profile_saver.cc +++ b/runtime/jit/profile_saver.cc @@ -162,7 +162,7 @@ void ProfileSaver::FetchAndCacheResolvedClasses() { } } ProfileCompilationInfo* info = GetCachedProfiledInfo(filename); - info->AddMethodsAndClasses(std::vector(), resolved_classes_for_location); + info->AddMethodsAndClasses(std::vector(), resolved_classes_for_location); total_number_of_profile_entries_cached += resolved_classes_for_location.size(); } max_number_of_profile_entries_cached_ = std::max( @@ -187,10 +187,10 @@ bool ProfileSaver::ProcessProfilingInfo() { } const std::string& filename = it.first; const std::set& locations = it.second; - std::vector methods; + std::vector methods; { ScopedObjectAccess soa(Thread::Current()); - jit_code_cache_->GetCompiledArtMethods(locations, methods); + jit_code_cache_->GetProfiledMethods(locations, methods); total_number_of_code_cache_queries_++; }