blob: 90bda60ac76f30a2c912fb7cfed4d0059624ea49 [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>
21
22#include "atomic.h"
23#include "dex_file.h"
Calin Juravle27e17fd2015-11-25 15:59:14 +000024#include "method_reference.h"
Calin Juravle31f2c152015-10-23 17:56:15 +010025#include "safe_map.h"
26
27namespace art {
28
29class ArtMethod;
30
31/**
32 * Profiling information in a format that can be serialized to disk.
33 * It is a serialize-friendly format based on information collected
34 * by the interpreter (ProfileInfo).
35 * Currently it stores only the hot compiled methods.
36 */
37class OfflineProfilingInfo {
38 public:
39 bool NeedsSaving(uint64_t last_update_time_ns) const;
40 void SaveProfilingInfo(const std::string& filename,
41 uint64_t last_update_time_ns,
42 const std::set<ArtMethod*>& methods);
43
44 private:
45 // Map identifying the location of the profiled methods.
46 // dex_file_ -> [dex_method_index]+
47 using DexFileToMethodsMap = SafeMap<const DexFile*, std::set<uint32_t>>;
48
49 void AddMethodInfo(ArtMethod* method, DexFileToMethodsMap* info)
50 SHARED_REQUIRES(Locks::mutator_lock_);
51 bool Serialize(const std::string& filename, const DexFileToMethodsMap& info) const;
52
53 // TODO(calin): Verify if Atomic is really needed (are we sure to be called from a
Calin Juravle27e17fd2015-11-25 15:59:14 +000054 // single thread?)
Calin Juravle31f2c152015-10-23 17:56:15 +010055 Atomic<uint64_t> last_update_time_ns_;
56};
57
Calin Juravle27e17fd2015-11-25 15:59:14 +000058/**
59 * Profile information in a format suitable to be queried by the compiler and performing
60 * profile guided compilation.
61 */
62class ProfileCompilationInfo {
63 public:
64 // Constructs a ProfileCompilationInfo backed by the provided file.
65 explicit ProfileCompilationInfo(const std::string& filename) : filename_(filename) {}
66
67 // Loads profile information corresponding to the provided dex files.
68 // The dex files' multidex suffixes must be unique.
69 // This resets the state of the profiling information
70 // (i.e. all previously loaded info are cleared).
71 bool Load(const std::vector<const DexFile*>& dex_files);
72
73 // Returns true if the method reference is present in the profiling info.
74 bool ContainsMethod(const MethodReference& method_ref) const;
75
76 const std::string& GetFilename() const { return filename_; }
77
78 // Dumps all the loaded profile info into a string and returns it.
79 // This is intended for testing and debugging.
80 std::string DumpInfo(bool print_full_dex_location = true) const;
81
82 private:
83 bool ProcessLine(const std::string& line,
84 const std::vector<const DexFile*>& dex_files);
85
86 using ClassToMethodsMap = SafeMap<uint32_t, std::set<uint32_t>>;
87 // Map identifying the location of the profiled methods.
88 // dex_file -> class_index -> [dex_method_index]+
89 using DexFileToProfileInfoMap = SafeMap<const DexFile*, ClassToMethodsMap>;
90
91 const std::string filename_;
92 DexFileToProfileInfoMap info_;
93};
94
Calin Juravle31f2c152015-10-23 17:56:15 +010095} // namespace art
96
97#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_