blob: ffd14335d7abe883604d2678f6dd987626196444 [file] [log] [blame]
Calin Juravle31f2c152015-10-23 17:56:15 +01001/*
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 Juravle4d77b6a2015-12-01 18:38:09 +000021#include <vector>
Calin Juravle31f2c152015-10-23 17:56:15 +010022
23#include "atomic.h"
24#include "dex_file.h"
Calin Juravle226501b2015-12-11 14:41:31 +000025#include "method_reference.h"
Calin Juravle31f2c152015-10-23 17:56:15 +010026#include "safe_map.h"
27
28namespace art {
29
30class ArtMethod;
31
Calin Juravle998c2162015-12-21 15:39:33 +020032// TODO: rename file.
Calin Juravle31f2c152015-10-23 17:56:15 +010033/**
Calin Juravle998c2162015-12-21 15:39:33 +020034 * Profile information in a format suitable to be queried by the compiler and
35 * performing profile guided compilation.
36 * It is a serialize-friendly format based on information collected by the
37 * interpreter (ProfileInfo).
Calin Juravle31f2c152015-10-23 17:56:15 +010038 * Currently it stores only the hot compiled methods.
39 */
Calin Juravle226501b2015-12-11 14:41:31 +000040class ProfileCompilationInfo {
41 public:
Calin Juravle877fd962016-01-05 14:29:29 +000042 // Saves profile information about the given methods in the given file.
43 // Note that the saving proceeds only if the file can be locked for exclusive access.
44 // If not (the locking is not blocking), the function does not save and returns false.
Calin Juravle998c2162015-12-21 15:39:33 +020045 static bool SaveProfilingInfo(const std::string& filename,
46 const std::vector<ArtMethod*>& methods);
Calin Juravle226501b2015-12-11 14:41:31 +000047
Calin Juravle877fd962016-01-05 14:29:29 +000048 // Loads profile information from the given file descriptor.
49 bool Load(uint32_t fd);
Calin Juravle998c2162015-12-21 15:39:33 +020050 // Loads the data from another ProfileCompilationInfo object.
51 bool Load(const ProfileCompilationInfo& info);
Calin Juravle877fd962016-01-05 14:29:29 +000052 // Saves the profile data to the given file descriptor.
53 bool Save(uint32_t fd);
Calin Juravle998c2162015-12-21 15:39:33 +020054 // Returns the number of methods that were profiled.
55 uint32_t GetNumberOfMethods() const;
Calin Juravle226501b2015-12-11 14:41:31 +000056
57 // Returns true if the method reference is present in the profiling info.
58 bool ContainsMethod(const MethodReference& method_ref) const;
59
Calin Juravle226501b2015-12-11 14:41:31 +000060 // Dumps all the loaded profile info into a string and returns it.
Calin Juravle998c2162015-12-21 15:39:33 +020061 // If dex_files is not null then the method indices will be resolved to their
62 // names.
Calin Juravle226501b2015-12-11 14:41:31 +000063 // This is intended for testing and debugging.
Calin Juravle998c2162015-12-21 15:39:33 +020064 std::string DumpInfo(const std::vector<const DexFile*>* dex_files,
65 bool print_full_dex_location = true) const;
Calin Juravle226501b2015-12-11 14:41:31 +000066
Calin Juravle877fd962016-01-05 14:29:29 +000067 // For testing purposes.
68 bool Equals(ProfileCompilationInfo& other);
69
Calin Juravle226501b2015-12-11 14:41:31 +000070 private:
Calin Juravle998c2162015-12-21 15:39:33 +020071 bool AddData(const std::string& dex_location, uint32_t checksum, uint16_t method_idx);
72 bool ProcessLine(const std::string& line);
Calin Juravle226501b2015-12-11 14:41:31 +000073
Calin Juravle998c2162015-12-21 15:39:33 +020074 struct DexFileData {
75 explicit DexFileData(uint32_t location_checksum) : checksum(location_checksum) {}
76 uint32_t checksum;
77 std::set<uint16_t> method_set;
Calin Juravle877fd962016-01-05 14:29:29 +000078
79 bool operator==(const DexFileData& other) const {
80 return checksum == other.checksum && method_set == other.method_set;
81 }
Calin Juravle998c2162015-12-21 15:39:33 +020082 };
Calin Juravle226501b2015-12-11 14:41:31 +000083
Calin Juravle998c2162015-12-21 15:39:33 +020084 using DexFileToProfileInfoMap = SafeMap<const std::string, DexFileData>;
85
Calin Juravle877fd962016-01-05 14:29:29 +000086 friend class ProfileCompilationInfoTest;
87 friend class CompilerDriverProfileTest;
88 friend class ProfileAssistantTest;
89
Calin Juravle226501b2015-12-11 14:41:31 +000090 DexFileToProfileInfoMap info_;
91};
92
Calin Juravle31f2c152015-10-23 17:56:15 +010093} // namespace art
94
95#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_