blob: a211c5472a7900cd6eab439b6e7d71ff8a1586ca [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"
26
27namespace art {
28
29enum MethodCompilationStat {
30 kAttemptCompilation = 0,
Mingyao Yang063fc772016-08-02 11:02:54 -070031 kCHAInline,
Calin Juravlead543382015-11-19 17:26:29 +000032 kCompiled,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000033 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000034 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010035 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010036 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010037 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010038 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010039 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000040 kRemovedCheckedCast,
41 kRemovedDeadInstruction,
42 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000043 kNotCompiledSkipped,
44 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000045 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000046 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000047 kNotCompiledHugeMethod,
48 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010049 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000050 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010051 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000052 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000053 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010054 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000055 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010056 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010057 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000058 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010059 kMonomorphicCall,
60 kPolymorphicCall,
61 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010062 kBooleanSimplified,
63 kIntrinsicRecognized,
64 kLoopInvariantMoved,
65 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000066 kRemovedInstanceOf,
67 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000068 kImplicitNullCheckGenerated,
69 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010070 kSimplifyIf,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000071 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000072 kNotInlinedUnresolvedEntrypoint,
73 kNotInlinedDexCache,
74 kNotInlinedStackMaps,
75 kNotInlinedEnvironmentBudget,
76 kNotInlinedInstructionBudget,
77 kNotInlinedLoopWithoutExit,
78 kNotInlinedIrreducibleLoop,
79 kNotInlinedAlwaysThrows,
80 kNotInlinedInfiniteLoop,
81 kNotInlinedTryCatch,
82 kNotInlinedRegisterAllocator,
83 kNotInlinedCannotBuild,
84 kNotInlinedNotVerified,
85 kNotInlinedCodeItem,
86 kNotInlinedWont,
87 kNotInlinedRecursiveBudget,
88 kNotInlinedProxy,
Calin Juravle48c2b032014-12-09 18:11:36 +000089 kLastStat
90};
91
92class OptimizingCompilerStats {
93 public:
Vladimir Markoff754d12017-02-24 15:01:41 +000094 OptimizingCompilerStats() {
95 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
96 Reset();
97 }
Calin Juravle48c2b032014-12-09 18:11:36 +000098
Vladimir Marko438709f2017-02-23 18:56:13 +000099 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
David Brazdil2d7352b2015-04-20 14:52:42 +0100100 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +0000101 }
102
103 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +0000104 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
105 // Log only in debug builds or if the compiler is verbose.
106 return;
107 }
108
Calin Juravle48c2b032014-12-09 18:11:36 +0000109 if (compile_stats_[kAttemptCompilation] == 0) {
110 LOG(INFO) << "Did not compile any method.";
111 } else {
Calin Juravlead543382015-11-19 17:26:29 +0000112 float compiled_percent =
113 compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation];
114 LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation]
115 << " methods: " << std::fixed << std::setprecision(2)
116 << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100117
Vladimir Marko438709f2017-02-23 18:56:13 +0000118 for (size_t i = 0; i < kLastStat; i++) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000119 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -0700120 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
121 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000122 }
123 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000124 }
125 }
126
Vladimir Marko438709f2017-02-23 18:56:13 +0000127 void AddTo(OptimizingCompilerStats* other_stats) {
128 for (size_t i = 0; i != kLastStat; ++i) {
129 uint32_t count = compile_stats_[i];
130 if (count != 0) {
131 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
132 }
133 }
134 }
135
136 void Reset() {
137 for (size_t i = 0; i != kLastStat; ++i) {
138 compile_stats_[i] = 0u;
139 }
140 }
141
Calin Juravle48c2b032014-12-09 18:11:36 +0000142 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -0700143 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +0000144 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000145 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +0000146 case kAttemptCompilation : name = "AttemptCompilation"; break;
Mingyao Yang063fc772016-08-02 11:02:54 -0700147 case kCHAInline : name = "CHAInline"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000148 case kCompiled : name = "Compiled"; break;
149 case kInlinedInvoke : name = "InlinedInvoke"; break;
Vladimir Markobe10e8e2016-01-22 12:09:44 +0000150 case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000151 case kInstructionSimplifications: name = "InstructionSimplifications"; break;
152 case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break;
153 case kUnresolvedMethod : name = "UnresolvedMethod"; break;
154 case kUnresolvedField : name = "UnresolvedField"; break;
155 case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break;
156 case kRemovedCheckedCast: name = "RemovedCheckedCast"; break;
157 case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
158 case kRemovedNullCheck: name = "RemovedNullCheck"; break;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000159 case kNotCompiledSkipped: name = "NotCompiledSkipped"; break;
160 case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000161 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000162 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000163 case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
164 case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break;
165 case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break;
166 case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break;
167 case kNotCompiledPathological : name = "NotCompiledPathological"; break;
168 case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break;
169 case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break;
170 case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break;
171 case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break;
172 case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100173 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000174 case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100175 case kMonomorphicCall: name = "MonomorphicCall"; break;
176 case kPolymorphicCall: name = "PolymorphicCall"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100177 case kMegamorphicCall: name = "MegamorphicCall"; break;
178 case kBooleanSimplified : name = "BooleanSimplified"; break;
179 case kIntrinsicRecognized : name = "IntrinsicRecognized"; break;
180 case kLoopInvariantMoved : name = "LoopInvariantMoved"; break;
181 case kSelectGenerated : name = "SelectGenerated"; break;
Calin Juravle69158982016-03-16 11:53:41 +0000182 case kRemovedInstanceOf: name = "RemovedInstanceOf"; break;
183 case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break;
Calin Juravle2ae48182016-03-16 14:05:09 +0000184 case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break;
185 case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break;
Nicolas Geoffraydac9b192016-07-15 10:46:17 +0100186 case kSimplifyIf: name = "SimplifyIf"; break;
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +0000187 case kInstructionSunk: name = "InstructionSunk"; break;
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000188 case kNotInlinedUnresolvedEntrypoint: name = "NotInlinedUnresolvedEntrypoint"; break;
189 case kNotInlinedDexCache: name = "NotInlinedDexCache"; break;
190 case kNotInlinedStackMaps: name = "NotInlinedStackMaps"; break;
191 case kNotInlinedEnvironmentBudget: name = "NotInlinedEnvironmentBudget"; break;
192 case kNotInlinedInstructionBudget: name = "NotInlinedInstructionBudget"; break;
193 case kNotInlinedLoopWithoutExit: name = "NotInlinedLoopWithoutExit"; break;
194 case kNotInlinedIrreducibleLoop: name = "NotInlinedIrreducibleLoop"; break;
195 case kNotInlinedAlwaysThrows: name = "NotInlinedAlwaysThrows"; break;
196 case kNotInlinedInfiniteLoop: name = "NotInlinedInfiniteLoop"; break;
197 case kNotInlinedTryCatch: name = "NotInlinedTryCatch"; break;
198 case kNotInlinedRegisterAllocator: name = "NotInlinedRegisterAllocator"; break;
199 case kNotInlinedCannotBuild: name = "NotInlinedCannotBuild"; break;
200 case kNotInlinedNotVerified: name = "NotInlinedNotVerified"; break;
201 case kNotInlinedCodeItem: name = "NotInlinedCodeItem"; break;
202 case kNotInlinedWont: name = "NotInlinedWont"; break;
203 case kNotInlinedRecursiveBudget: name = "NotInlinedRecursiveBudget"; break;
204 case kNotInlinedProxy: name = "NotInlinedProxy"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700205
Calin Juravlead543382015-11-19 17:26:29 +0000206 case kLastStat:
207 LOG(FATAL) << "invalid stat "
208 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
209 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000210 }
Calin Juravlead543382015-11-19 17:26:29 +0000211 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000212 }
213
Vladimir Marko438709f2017-02-23 18:56:13 +0000214 std::atomic<uint32_t> compile_stats_[kLastStat];
Calin Juravle48c2b032014-12-09 18:11:36 +0000215
216 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
217};
218
219} // namespace art
220
221#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_