blob: d6da73cc1cd66457cc64228d515c8799e7da2719 [file] [log] [blame]
Calin Juravle48c2b032014-12-09 18:11:36 +00001/*
2 * Copyright (C) 2014 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_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_
18#define ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_
19
Vladimir Marko438709f2017-02-23 18:56:13 +000020#include <atomic>
Calin Juravlead543382015-11-19 17:26:29 +000021#include <iomanip>
Calin Juravle48c2b032014-12-09 18:11:36 +000022#include <string>
Andreas Gampeda9badb2015-06-05 20:22:12 -070023#include <type_traits>
Calin Juravle48c2b032014-12-09 18:11:36 +000024
25#include "atomic.h"
Igor Murashkin6ef45672017-08-08 13:59:55 -070026#include "globals.h"
Calin Juravle48c2b032014-12-09 18:11:36 +000027
28namespace art {
29
30enum MethodCompilationStat {
31 kAttemptCompilation = 0,
Mingyao Yang063fc772016-08-02 11:02:54 -070032 kCHAInline,
Calin Juravlead543382015-11-19 17:26:29 +000033 kCompiled,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000034 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000035 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010036 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010037 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010038 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010039 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010040 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000041 kRemovedCheckedCast,
42 kRemovedDeadInstruction,
43 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000044 kNotCompiledSkipped,
45 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000046 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000047 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000048 kNotCompiledHugeMethod,
49 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010050 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000051 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010052 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000053 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000054 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010055 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000056 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010057 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010058 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000059 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010060 kMonomorphicCall,
61 kPolymorphicCall,
62 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010063 kBooleanSimplified,
64 kIntrinsicRecognized,
65 kLoopInvariantMoved,
66 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000067 kRemovedInstanceOf,
68 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000069 kImplicitNullCheckGenerated,
70 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010071 kSimplifyIf,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000072 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000073 kNotInlinedUnresolvedEntrypoint,
74 kNotInlinedDexCache,
75 kNotInlinedStackMaps,
76 kNotInlinedEnvironmentBudget,
77 kNotInlinedInstructionBudget,
78 kNotInlinedLoopWithoutExit,
79 kNotInlinedIrreducibleLoop,
80 kNotInlinedAlwaysThrows,
81 kNotInlinedInfiniteLoop,
82 kNotInlinedTryCatch,
83 kNotInlinedRegisterAllocator,
84 kNotInlinedCannotBuild,
85 kNotInlinedNotVerified,
86 kNotInlinedCodeItem,
87 kNotInlinedWont,
88 kNotInlinedRecursiveBudget,
89 kNotInlinedProxy,
Igor Murashkin6ef45672017-08-08 13:59:55 -070090 kConstructorFenceGeneratedNew,
91 kConstructorFenceGeneratedFinal,
92 kConstructorFenceRemovedLSE,
93 kConstructorFenceRemovedPFRA,
Calin Juravle48c2b032014-12-09 18:11:36 +000094 kLastStat
95};
96
97class OptimizingCompilerStats {
98 public:
Vladimir Markoff754d12017-02-24 15:01:41 +000099 OptimizingCompilerStats() {
100 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
101 Reset();
102 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000103
Vladimir Marko438709f2017-02-23 18:56:13 +0000104 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
David Brazdil2d7352b2015-04-20 14:52:42 +0100105 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +0000106 }
107
108 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +0000109 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
110 // Log only in debug builds or if the compiler is verbose.
111 return;
112 }
113
Calin Juravle48c2b032014-12-09 18:11:36 +0000114 if (compile_stats_[kAttemptCompilation] == 0) {
115 LOG(INFO) << "Did not compile any method.";
116 } else {
Calin Juravlead543382015-11-19 17:26:29 +0000117 float compiled_percent =
118 compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation];
119 LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation]
120 << " methods: " << std::fixed << std::setprecision(2)
121 << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100122
Vladimir Marko438709f2017-02-23 18:56:13 +0000123 for (size_t i = 0; i < kLastStat; i++) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000124 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -0700125 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
126 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000127 }
128 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000129 }
130 }
131
Vladimir Marko438709f2017-02-23 18:56:13 +0000132 void AddTo(OptimizingCompilerStats* other_stats) {
133 for (size_t i = 0; i != kLastStat; ++i) {
134 uint32_t count = compile_stats_[i];
135 if (count != 0) {
136 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
137 }
138 }
139 }
140
141 void Reset() {
142 for (size_t i = 0; i != kLastStat; ++i) {
143 compile_stats_[i] = 0u;
144 }
145 }
146
Calin Juravle48c2b032014-12-09 18:11:36 +0000147 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -0700148 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +0000149 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000150 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +0000151 case kAttemptCompilation : name = "AttemptCompilation"; break;
Mingyao Yang063fc772016-08-02 11:02:54 -0700152 case kCHAInline : name = "CHAInline"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000153 case kCompiled : name = "Compiled"; break;
154 case kInlinedInvoke : name = "InlinedInvoke"; break;
Vladimir Markobe10e8e2016-01-22 12:09:44 +0000155 case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000156 case kInstructionSimplifications: name = "InstructionSimplifications"; break;
157 case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break;
158 case kUnresolvedMethod : name = "UnresolvedMethod"; break;
159 case kUnresolvedField : name = "UnresolvedField"; break;
160 case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break;
161 case kRemovedCheckedCast: name = "RemovedCheckedCast"; break;
162 case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
163 case kRemovedNullCheck: name = "RemovedNullCheck"; break;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000164 case kNotCompiledSkipped: name = "NotCompiledSkipped"; break;
165 case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000166 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000167 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000168 case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
169 case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break;
170 case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break;
171 case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break;
172 case kNotCompiledPathological : name = "NotCompiledPathological"; break;
173 case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break;
174 case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break;
175 case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break;
176 case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break;
177 case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100178 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000179 case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100180 case kMonomorphicCall: name = "MonomorphicCall"; break;
181 case kPolymorphicCall: name = "PolymorphicCall"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100182 case kMegamorphicCall: name = "MegamorphicCall"; break;
183 case kBooleanSimplified : name = "BooleanSimplified"; break;
184 case kIntrinsicRecognized : name = "IntrinsicRecognized"; break;
185 case kLoopInvariantMoved : name = "LoopInvariantMoved"; break;
186 case kSelectGenerated : name = "SelectGenerated"; break;
Calin Juravle69158982016-03-16 11:53:41 +0000187 case kRemovedInstanceOf: name = "RemovedInstanceOf"; break;
188 case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break;
Calin Juravle2ae48182016-03-16 14:05:09 +0000189 case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break;
190 case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break;
Nicolas Geoffraydac9b192016-07-15 10:46:17 +0100191 case kSimplifyIf: name = "SimplifyIf"; break;
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +0000192 case kInstructionSunk: name = "InstructionSunk"; break;
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000193 case kNotInlinedUnresolvedEntrypoint: name = "NotInlinedUnresolvedEntrypoint"; break;
194 case kNotInlinedDexCache: name = "NotInlinedDexCache"; break;
195 case kNotInlinedStackMaps: name = "NotInlinedStackMaps"; break;
196 case kNotInlinedEnvironmentBudget: name = "NotInlinedEnvironmentBudget"; break;
197 case kNotInlinedInstructionBudget: name = "NotInlinedInstructionBudget"; break;
198 case kNotInlinedLoopWithoutExit: name = "NotInlinedLoopWithoutExit"; break;
199 case kNotInlinedIrreducibleLoop: name = "NotInlinedIrreducibleLoop"; break;
200 case kNotInlinedAlwaysThrows: name = "NotInlinedAlwaysThrows"; break;
201 case kNotInlinedInfiniteLoop: name = "NotInlinedInfiniteLoop"; break;
202 case kNotInlinedTryCatch: name = "NotInlinedTryCatch"; break;
203 case kNotInlinedRegisterAllocator: name = "NotInlinedRegisterAllocator"; break;
204 case kNotInlinedCannotBuild: name = "NotInlinedCannotBuild"; break;
205 case kNotInlinedNotVerified: name = "NotInlinedNotVerified"; break;
206 case kNotInlinedCodeItem: name = "NotInlinedCodeItem"; break;
207 case kNotInlinedWont: name = "NotInlinedWont"; break;
208 case kNotInlinedRecursiveBudget: name = "NotInlinedRecursiveBudget"; break;
209 case kNotInlinedProxy: name = "NotInlinedProxy"; break;
Igor Murashkin6ef45672017-08-08 13:59:55 -0700210 case kConstructorFenceGeneratedNew: name = "ConstructorFenceGeneratedNew"; break;
211 case kConstructorFenceGeneratedFinal: name = "ConstructorFenceGeneratedFinal"; break;
212 case kConstructorFenceRemovedLSE: name = "ConstructorFenceRemovedLSE"; break;
213 case kConstructorFenceRemovedPFRA: name = "ConstructorFenceRemovedPFRA"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700214
Calin Juravlead543382015-11-19 17:26:29 +0000215 case kLastStat:
216 LOG(FATAL) << "invalid stat "
217 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
218 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000219 }
Calin Juravlead543382015-11-19 17:26:29 +0000220 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000221 }
222
Vladimir Marko438709f2017-02-23 18:56:13 +0000223 std::atomic<uint32_t> compile_stats_[kLastStat];
Calin Juravle48c2b032014-12-09 18:11:36 +0000224
225 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
226};
227
Igor Murashkin1e065a52017-08-09 13:20:34 -0700228inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats,
229 MethodCompilationStat stat,
230 uint32_t count = 1) {
231 if (compiler_stats != nullptr) {
232 compiler_stats->RecordStat(stat, count);
233 }
234}
235
Calin Juravle48c2b032014-12-09 18:11:36 +0000236} // namespace art
237
238#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_