blob: edc591c2eb763f1baafa230be359817a418f1056 [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.
Calin Juravle2e2db782016-02-23 12:00:03 +000049 bool Load(int 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.
Calin Juravle2e2db782016-02-23 12:00:03 +000053 bool Save(int 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.
Calin Juravle2e2db782016-02-23 12:00:03 +000068 bool Equals(const ProfileCompilationInfo& other);
Calin Juravle31708b72016-02-05 19:44:05 +000069 static std::string GetProfileDexFileKey(const std::string& dex_location);
Calin Juravle877fd962016-01-05 14:29:29 +000070
Calin Juravle226501b2015-12-11 14:41:31 +000071 private:
Calin Juravle998c2162015-12-21 15:39:33 +020072 bool AddData(const std::string& dex_location, uint32_t checksum, uint16_t method_idx);
73 bool ProcessLine(const std::string& line);
Calin Juravle226501b2015-12-11 14:41:31 +000074
Calin Juravle998c2162015-12-21 15:39:33 +020075 struct DexFileData {
76 explicit DexFileData(uint32_t location_checksum) : checksum(location_checksum) {}
77 uint32_t checksum;
78 std::set<uint16_t> method_set;
Calin Juravle877fd962016-01-05 14:29:29 +000079
80 bool operator==(const DexFileData& other) const {
81 return checksum == other.checksum && method_set == other.method_set;
82 }
Calin Juravle998c2162015-12-21 15:39:33 +020083 };
Calin Juravle226501b2015-12-11 14:41:31 +000084
Calin Juravle998c2162015-12-21 15:39:33 +020085 using DexFileToProfileInfoMap = SafeMap<const std::string, DexFileData>;
86
Calin Juravle877fd962016-01-05 14:29:29 +000087 friend class ProfileCompilationInfoTest;
88 friend class CompilerDriverProfileTest;
89 friend class ProfileAssistantTest;
90
Calin Juravle226501b2015-12-11 14:41:31 +000091 DexFileToProfileInfoMap info_;
92};
93
Calin Juravle31f2c152015-10-23 17:56:15 +010094} // namespace art
95
96#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_