Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |
| 18 | #define ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |
| 19 | |
| 20 | #include <set> |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 21 | #include <vector> |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 22 | |
| 23 | #include "atomic.h" |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 24 | #include "dex_cache_resolved_classes.h" |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 25 | #include "dex_file.h" |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 26 | #include "method_reference.h" |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 27 | #include "safe_map.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | class ArtMethod; |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 32 | class DexCacheProfileData; |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 33 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 34 | // TODO: rename file. |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 35 | /** |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 36 | * Profile information in a format suitable to be queried by the compiler and |
| 37 | * performing profile guided compilation. |
| 38 | * It is a serialize-friendly format based on information collected by the |
| 39 | * interpreter (ProfileInfo). |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 40 | * Currently it stores only the hot compiled methods. |
| 41 | */ |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 42 | class ProfileCompilationInfo { |
| 43 | public: |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 44 | // Saves profile information about the given methods in the given file. |
| 45 | // Note that the saving proceeds only if the file can be locked for exclusive access. |
| 46 | // If not (the locking is not blocking), the function does not save and returns false. |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 47 | static bool SaveProfilingInfo(const std::string& filename, |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 48 | const std::vector<ArtMethod*>& methods, |
Calin Juravle | b8e6999 | 2016-03-09 15:37:48 +0000 | [diff] [blame] | 49 | const std::set<DexCacheResolvedClasses>& resolved_classes, |
| 50 | uint64_t* bytes_written = nullptr); |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 51 | |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 52 | // Add the given methods and classes to the current profile object. |
| 53 | bool AddMethodsAndClasses(const std::vector<ArtMethod*>& methods, |
| 54 | const std::set<DexCacheResolvedClasses>& resolved_classes); |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 55 | // Loads profile information from the given file descriptor. |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 56 | bool Load(int fd); |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 57 | // Merge the data from another ProfileCompilationInfo into the current object. |
| 58 | bool MergeWith(const ProfileCompilationInfo& info); |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 59 | // Saves the profile data to the given file descriptor. |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 60 | bool Save(int fd); |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 61 | // Loads and merges profile information from the given file into the current |
| 62 | // object and tries to save it back to disk. |
| 63 | bool MergeAndSave(const std::string& filename, uint64_t* bytes_written); |
| 64 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 65 | // Returns the number of methods that were profiled. |
| 66 | uint32_t GetNumberOfMethods() const; |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 67 | // Returns the number of resolved classes that were profiled. |
| 68 | uint32_t GetNumberOfResolvedClasses() const; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 69 | |
| 70 | // Returns true if the method reference is present in the profiling info. |
| 71 | bool ContainsMethod(const MethodReference& method_ref) const; |
| 72 | |
Mathieu Chartier | a807780 | 2016-03-16 19:08:31 -0700 | [diff] [blame] | 73 | // Returns true if the class is present in the profiling info. |
| 74 | bool ContainsClass(const DexFile& dex_file, uint16_t class_def_idx) const; |
| 75 | |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 76 | // Dumps all the loaded profile info into a string and returns it. |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 77 | // If dex_files is not null then the method indices will be resolved to their |
| 78 | // names. |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 79 | // This is intended for testing and debugging. |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 80 | std::string DumpInfo(const std::vector<const DexFile*>* dex_files, |
| 81 | bool print_full_dex_location = true) const; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 82 | |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 83 | bool Equals(const ProfileCompilationInfo& other); |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 84 | |
Calin Juravle | 31708b7 | 2016-02-05 19:44:05 +0000 | [diff] [blame] | 85 | static std::string GetProfileDexFileKey(const std::string& dex_location); |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 86 | |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 87 | // Returns the class descriptors for all of the classes in the profiles' class sets. |
| 88 | // Note the dex location is actually the profile key, the caller needs to call back in to the |
| 89 | // profile info stuff to generate a map back to the dex location. |
| 90 | std::set<DexCacheResolvedClasses> GetResolvedClasses() const; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 91 | |
Calin Juravle | 6726546 | 2016-03-18 16:23:40 +0000 | [diff] [blame^] | 92 | // Clears the resolved classes from the current object. |
| 93 | void ClearResolvedClasses(); |
| 94 | |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 95 | private: |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 96 | struct DexFileData { |
| 97 | explicit DexFileData(uint32_t location_checksum) : checksum(location_checksum) {} |
| 98 | uint32_t checksum; |
| 99 | std::set<uint16_t> method_set; |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 100 | std::set<uint16_t> class_set; |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 101 | |
| 102 | bool operator==(const DexFileData& other) const { |
| 103 | return checksum == other.checksum && method_set == other.method_set; |
| 104 | } |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 105 | }; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 106 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 107 | using DexFileToProfileInfoMap = SafeMap<const std::string, DexFileData>; |
| 108 | |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 109 | DexFileData* GetOrAddDexFileData(const std::string& dex_location, uint32_t checksum); |
| 110 | bool AddMethodIndex(const std::string& dex_location, uint32_t checksum, uint16_t method_idx); |
| 111 | bool AddClassIndex(const std::string& dex_location, uint32_t checksum, uint16_t class_idx); |
| 112 | bool AddResolvedClasses(const DexCacheResolvedClasses& classes) |
| 113 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 114 | bool ProcessLine(const std::string& line); |
| 115 | |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 116 | friend class ProfileCompilationInfoTest; |
| 117 | friend class CompilerDriverProfileTest; |
| 118 | friend class ProfileAssistantTest; |
| 119 | |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 120 | DexFileToProfileInfoMap info_; |
| 121 | }; |
| 122 | |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 123 | } // namespace art |
| 124 | |
| 125 | #endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |