blob: 07f9635abaddb8f3189cd72277abf2e7803cc629 [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,
Aart Bik21b85922017-09-06 13:29:16 -070066 kLoopVectorized,
67 kLoopVectorizedIdiom,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010068 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000069 kRemovedInstanceOf,
70 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000071 kImplicitNullCheckGenerated,
72 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010073 kSimplifyIf,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000074 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000075 kNotInlinedUnresolvedEntrypoint,
76 kNotInlinedDexCache,
77 kNotInlinedStackMaps,
78 kNotInlinedEnvironmentBudget,
79 kNotInlinedInstructionBudget,
80 kNotInlinedLoopWithoutExit,
81 kNotInlinedIrreducibleLoop,
82 kNotInlinedAlwaysThrows,
83 kNotInlinedInfiniteLoop,
84 kNotInlinedTryCatch,
85 kNotInlinedRegisterAllocator,
86 kNotInlinedCannotBuild,
87 kNotInlinedNotVerified,
88 kNotInlinedCodeItem,
89 kNotInlinedWont,
90 kNotInlinedRecursiveBudget,
91 kNotInlinedProxy,
Igor Murashkin6ef45672017-08-08 13:59:55 -070092 kConstructorFenceGeneratedNew,
93 kConstructorFenceGeneratedFinal,
94 kConstructorFenceRemovedLSE,
95 kConstructorFenceRemovedPFRA,
Igor Murashkindd018df2017-08-09 10:38:31 -070096 kConstructorFenceRemovedCFRE,
Calin Juravle48c2b032014-12-09 18:11:36 +000097 kLastStat
98};
99
100class OptimizingCompilerStats {
101 public:
Vladimir Markoff754d12017-02-24 15:01:41 +0000102 OptimizingCompilerStats() {
103 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
104 Reset();
105 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000106
Vladimir Marko438709f2017-02-23 18:56:13 +0000107 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
David Brazdil2d7352b2015-04-20 14:52:42 +0100108 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +0000109 }
110
111 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +0000112 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
113 // Log only in debug builds or if the compiler is verbose.
114 return;
115 }
116
Calin Juravle48c2b032014-12-09 18:11:36 +0000117 if (compile_stats_[kAttemptCompilation] == 0) {
118 LOG(INFO) << "Did not compile any method.";
119 } else {
Calin Juravlead543382015-11-19 17:26:29 +0000120 float compiled_percent =
121 compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation];
122 LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation]
123 << " methods: " << std::fixed << std::setprecision(2)
124 << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100125
Vladimir Marko438709f2017-02-23 18:56:13 +0000126 for (size_t i = 0; i < kLastStat; i++) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000127 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -0700128 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
129 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000130 }
131 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000132 }
133 }
134
Vladimir Marko438709f2017-02-23 18:56:13 +0000135 void AddTo(OptimizingCompilerStats* other_stats) {
136 for (size_t i = 0; i != kLastStat; ++i) {
137 uint32_t count = compile_stats_[i];
138 if (count != 0) {
139 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
140 }
141 }
142 }
143
144 void Reset() {
145 for (size_t i = 0; i != kLastStat; ++i) {
146 compile_stats_[i] = 0u;
147 }
148 }
149
Calin Juravle48c2b032014-12-09 18:11:36 +0000150 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -0700151 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +0000152 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000153 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +0000154 case kAttemptCompilation : name = "AttemptCompilation"; break;
Mingyao Yang063fc772016-08-02 11:02:54 -0700155 case kCHAInline : name = "CHAInline"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000156 case kCompiled : name = "Compiled"; break;
157 case kInlinedInvoke : name = "InlinedInvoke"; break;
Vladimir Markobe10e8e2016-01-22 12:09:44 +0000158 case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000159 case kInstructionSimplifications: name = "InstructionSimplifications"; break;
160 case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break;
161 case kUnresolvedMethod : name = "UnresolvedMethod"; break;
162 case kUnresolvedField : name = "UnresolvedField"; break;
163 case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break;
164 case kRemovedCheckedCast: name = "RemovedCheckedCast"; break;
165 case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
166 case kRemovedNullCheck: name = "RemovedNullCheck"; break;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000167 case kNotCompiledSkipped: name = "NotCompiledSkipped"; break;
168 case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000169 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000170 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000171 case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
172 case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break;
173 case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break;
174 case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break;
175 case kNotCompiledPathological : name = "NotCompiledPathological"; break;
176 case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break;
177 case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break;
178 case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break;
179 case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break;
180 case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100181 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000182 case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100183 case kMonomorphicCall: name = "MonomorphicCall"; break;
184 case kPolymorphicCall: name = "PolymorphicCall"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100185 case kMegamorphicCall: name = "MegamorphicCall"; break;
186 case kBooleanSimplified : name = "BooleanSimplified"; break;
187 case kIntrinsicRecognized : name = "IntrinsicRecognized"; break;
188 case kLoopInvariantMoved : name = "LoopInvariantMoved"; break;
Aart Bik21b85922017-09-06 13:29:16 -0700189 case kLoopVectorized : name = "LoopVectorized"; break;
190 case kLoopVectorizedIdiom : name = "LoopVectorizedIdiom"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100191 case kSelectGenerated : name = "SelectGenerated"; break;
Calin Juravle69158982016-03-16 11:53:41 +0000192 case kRemovedInstanceOf: name = "RemovedInstanceOf"; break;
193 case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break;
Calin Juravle2ae48182016-03-16 14:05:09 +0000194 case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break;
195 case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break;
Nicolas Geoffraydac9b192016-07-15 10:46:17 +0100196 case kSimplifyIf: name = "SimplifyIf"; break;
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +0000197 case kInstructionSunk: name = "InstructionSunk"; break;
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000198 case kNotInlinedUnresolvedEntrypoint: name = "NotInlinedUnresolvedEntrypoint"; break;
199 case kNotInlinedDexCache: name = "NotInlinedDexCache"; break;
200 case kNotInlinedStackMaps: name = "NotInlinedStackMaps"; break;
201 case kNotInlinedEnvironmentBudget: name = "NotInlinedEnvironmentBudget"; break;
202 case kNotInlinedInstructionBudget: name = "NotInlinedInstructionBudget"; break;
203 case kNotInlinedLoopWithoutExit: name = "NotInlinedLoopWithoutExit"; break;
204 case kNotInlinedIrreducibleLoop: name = "NotInlinedIrreducibleLoop"; break;
205 case kNotInlinedAlwaysThrows: name = "NotInlinedAlwaysThrows"; break;
206 case kNotInlinedInfiniteLoop: name = "NotInlinedInfiniteLoop"; break;
207 case kNotInlinedTryCatch: name = "NotInlinedTryCatch"; break;
208 case kNotInlinedRegisterAllocator: name = "NotInlinedRegisterAllocator"; break;
209 case kNotInlinedCannotBuild: name = "NotInlinedCannotBuild"; break;
210 case kNotInlinedNotVerified: name = "NotInlinedNotVerified"; break;
211 case kNotInlinedCodeItem: name = "NotInlinedCodeItem"; break;
212 case kNotInlinedWont: name = "NotInlinedWont"; break;
213 case kNotInlinedRecursiveBudget: name = "NotInlinedRecursiveBudget"; break;
214 case kNotInlinedProxy: name = "NotInlinedProxy"; break;
Igor Murashkin6ef45672017-08-08 13:59:55 -0700215 case kConstructorFenceGeneratedNew: name = "ConstructorFenceGeneratedNew"; break;
216 case kConstructorFenceGeneratedFinal: name = "ConstructorFenceGeneratedFinal"; break;
217 case kConstructorFenceRemovedLSE: name = "ConstructorFenceRemovedLSE"; break;
218 case kConstructorFenceRemovedPFRA: name = "ConstructorFenceRemovedPFRA"; break;
Igor Murashkindd018df2017-08-09 10:38:31 -0700219 case kConstructorFenceRemovedCFRE: name = "ConstructorFenceRemovedCFRE"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700220
Calin Juravlead543382015-11-19 17:26:29 +0000221 case kLastStat:
222 LOG(FATAL) << "invalid stat "
223 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
224 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000225 }
Calin Juravlead543382015-11-19 17:26:29 +0000226 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000227 }
228
Vladimir Marko438709f2017-02-23 18:56:13 +0000229 std::atomic<uint32_t> compile_stats_[kLastStat];
Calin Juravle48c2b032014-12-09 18:11:36 +0000230
231 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
232};
233
Igor Murashkin1e065a52017-08-09 13:20:34 -0700234inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats,
235 MethodCompilationStat stat,
236 uint32_t count = 1) {
237 if (compiler_stats != nullptr) {
238 compiler_stats->RecordStat(stat, count);
239 }
240}
241
Calin Juravle48c2b032014-12-09 18:11:36 +0000242} // namespace art
243
244#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_