blob: a1d0a5a845a1cd460cf0d91d402418c4c5b5d56b [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
Andreas Gampe85f1c572018-11-21 13:52:48 -080025#include <android-base/logging.h>
26
David Sehrc431b9d2018-03-02 12:01:51 -080027#include "base/atomic.h"
28#include "base/globals.h"
Vladimír Marko434d9682022-11-04 14:04:17 +000029#include "base/macros.h"
Calin Juravle48c2b032014-12-09 18:11:36 +000030
Vladimír Marko434d9682022-11-04 14:04:17 +000031namespace art HIDDEN {
Calin Juravle48c2b032014-12-09 18:11:36 +000032
Vladimir Markocd09e1f2017-11-24 15:02:40 +000033enum class MethodCompilationStat {
34 kAttemptBytecodeCompilation = 0,
35 kAttemptIntrinsicCompilation,
36 kCompiledNativeStub,
37 kCompiledIntrinsic,
38 kCompiledBytecode,
Mingyao Yang063fc772016-08-02 11:02:54 -070039 kCHAInline,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000040 kInlinedInvoke,
Santiago Aboy Solanes15580482021-10-12 13:11:29 +010041 kInlinedLastInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000042 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010043 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010044 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010045 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010046 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010047 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000048 kRemovedCheckedCast,
49 kRemovedDeadInstruction,
Santiago Aboy Solanesb2d364d2022-11-10 10:26:31 +000050 kRemovedTry,
Calin Juravlead543382015-11-19 17:26:29 +000051 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000052 kNotCompiledSkipped,
53 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000054 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000055 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000056 kNotCompiledHugeMethod,
57 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010058 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000059 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010060 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000061 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000062 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010063 kNotCompiledUnsupportedIsa,
Santiago Aboy Solanes07c7d432022-10-12 17:35:58 +010064 kNotCompiledInliningIrreducibleLoop,
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +010065 kNotCompiledIrreducibleLoopAndStringInit,
Nicolas Geoffray7cfc8f52019-08-07 10:41:09 +010066 kNotCompiledPhiEquivalentInOsr,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010067 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000068 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010069 kMonomorphicCall,
70 kPolymorphicCall,
71 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010072 kBooleanSimplified,
73 kIntrinsicRecognized,
74 kLoopInvariantMoved,
Aart Bik21b85922017-09-06 13:29:16 -070075 kLoopVectorized,
76 kLoopVectorizedIdiom,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010077 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000078 kRemovedInstanceOf,
Santiago Aboy Solanes8c3b58a2022-08-15 13:21:59 +000079 kPropagatedIfValue,
Calin Juravle69158982016-03-16 11:53:41 +000080 kInlinedInvokeVirtualOrInterface,
Santiago Aboy Solanes15580482021-10-12 13:11:29 +010081 kInlinedLastInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000082 kImplicitNullCheckGenerated,
83 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010084 kSimplifyIf,
Santiago Aboy Solanes10d68702023-01-24 18:05:10 +000085 kSimplifyIfAddedPhi,
Aart Bika8b8e9b2018-01-09 11:01:02 -080086 kSimplifyThrowingInvoke,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000087 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000088 kNotInlinedUnresolvedEntrypoint,
Santiago Aboy Solanese43aa3f2021-11-01 09:02:09 +000089 kNotInlinedBss,
Santiago Aboy Solanesfa73acc2021-11-12 14:23:27 +000090 kNotInlinedDexCacheInaccessibleToCaller,
91 kNotInlinedDexCacheClinitCheck,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000092 kNotInlinedStackMaps,
93 kNotInlinedEnvironmentBudget,
94 kNotInlinedInstructionBudget,
95 kNotInlinedLoopWithoutExit,
Santiago Aboy Solanes802ac602022-12-15 18:45:33 +000096 kNotInlinedIrreducibleLoopCallee,
97 kNotInlinedIrreducibleLoopCaller,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000098 kNotInlinedAlwaysThrows,
99 kNotInlinedInfiniteLoop,
Santiago Aboy Solanesfa73acc2021-11-12 14:23:27 +0000100 kNotInlinedTryCatchCallee,
Santiago Aboy Solanes8efb1a62022-06-24 11:16:35 +0100101 kNotInlinedTryCatchDisabled,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000102 kNotInlinedRegisterAllocator,
103 kNotInlinedCannotBuild,
Santiago Aboy Solanes2979d532022-09-29 18:03:13 +0100104 kNotInlinedNeverInlineAnnotation,
Santiago Aboy Solanesfa73acc2021-11-12 14:23:27 +0000105 kNotInlinedNotCompilable,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000106 kNotInlinedNotVerified,
107 kNotInlinedCodeItem,
Santiago Aboy Solanesa669df32022-10-31 11:27:24 +0000108 kNotInlinedEndsWithThrow,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000109 kNotInlinedWont,
110 kNotInlinedRecursiveBudget,
Santiago Aboy Solanes4f5b7cb2022-02-10 10:25:15 +0000111 kNotInlinedPolymorphicRecursiveBudget,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +0000112 kNotInlinedProxy,
Mathieu Chartier8284e9a2020-05-15 17:14:33 -0700113 kNotInlinedUnresolved,
114 kNotInlinedPolymorphic,
115 kNotInlinedCustom,
Santiago Aboy Solanes3633fe42023-01-12 16:10:05 +0000116 kNotVarAnalyzedPathological,
Mathieu Chartier8284e9a2020-05-15 17:14:33 -0700117 kTryInline,
Igor Murashkin6ef45672017-08-08 13:59:55 -0700118 kConstructorFenceGeneratedNew,
119 kConstructorFenceGeneratedFinal,
120 kConstructorFenceRemovedLSE,
121 kConstructorFenceRemovedPFRA,
Igor Murashkindd018df2017-08-09 10:38:31 -0700122 kConstructorFenceRemovedCFRE,
Santiago Aboy Solanesd4229602023-01-03 16:20:50 +0000123 kPossibleWriteBarrier,
124 kRemovedWriteBarrier,
Vladimir Marko175e7862018-03-27 09:03:13 +0000125 kBitstringTypeCheck,
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000126 kJitOutOfMemoryForCommit,
Alex Light86fe9b82020-11-16 16:54:01 +0000127 kFullLSEAllocationRemoved,
128 kFullLSEPossible,
129 kNonPartialLoadRemoved,
130 kPartialLSEPossible,
131 kPartialStoreRemoved,
Alex Light3a73ffb2021-01-25 14:11:05 +0000132 kPartialAllocationMoved,
133 kPredicatedLoadAdded,
134 kPredicatedStoreAdded,
Nicolas Geoffraye1e0e0f2021-04-29 08:57:13 +0000135 kDevirtualized,
Calin Juravle48c2b032014-12-09 18:11:36 +0000136 kLastStat
137};
Vladimir Marko9974e3c2020-06-10 16:27:06 +0100138std::ostream& operator<<(std::ostream& os, MethodCompilationStat rhs);
Calin Juravle48c2b032014-12-09 18:11:36 +0000139
140class OptimizingCompilerStats {
141 public:
Vladimir Markoff754d12017-02-24 15:01:41 +0000142 OptimizingCompilerStats() {
143 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
144 Reset();
145 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000146
Vladimir Marko438709f2017-02-23 18:56:13 +0000147 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000148 size_t stat_index = static_cast<size_t>(stat);
149 DCHECK_LT(stat_index, arraysize(compile_stats_));
150 compile_stats_[stat_index] += count;
151 }
152
153 uint32_t GetStat(MethodCompilationStat stat) const {
154 size_t stat_index = static_cast<size_t>(stat);
155 DCHECK_LT(stat_index, arraysize(compile_stats_));
156 return compile_stats_[stat_index];
Calin Juravle48c2b032014-12-09 18:11:36 +0000157 }
158
159 void Log() const {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000160 uint32_t compiled_intrinsics = GetStat(MethodCompilationStat::kCompiledIntrinsic);
161 uint32_t compiled_native_stubs = GetStat(MethodCompilationStat::kCompiledNativeStub);
162 uint32_t bytecode_attempts =
163 GetStat(MethodCompilationStat::kAttemptBytecodeCompilation);
164 if (compiled_intrinsics == 0u && compiled_native_stubs == 0u && bytecode_attempts == 0u) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000165 LOG(INFO) << "Did not compile any method.";
166 } else {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000167 uint32_t compiled_bytecode_methods =
168 GetStat(MethodCompilationStat::kCompiledBytecode);
169 // Successful intrinsic compilation preempts other compilation attempts but failed intrinsic
170 // compilation shall still count towards bytecode or native stub compilation attempts.
171 uint32_t num_compilation_attempts =
172 compiled_intrinsics + compiled_native_stubs + bytecode_attempts;
173 uint32_t num_successful_compilations =
174 compiled_intrinsics + compiled_native_stubs + compiled_bytecode_methods;
175 float compiled_percent = num_successful_compilations * 100.0f / num_compilation_attempts;
176 LOG(INFO) << "Attempted compilation of "
177 << num_compilation_attempts << " methods: " << std::fixed << std::setprecision(2)
178 << compiled_percent << "% (" << num_successful_compilations << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100179
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000180 for (size_t i = 0; i < arraysize(compile_stats_); ++i) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000181 if (compile_stats_[i] != 0) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000182 LOG(INFO) << "OptStat#" << static_cast<MethodCompilationStat>(i) << ": "
Andreas Gampeda9badb2015-06-05 20:22:12 -0700183 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000184 }
185 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000186 }
187 }
188
Vladimir Marko438709f2017-02-23 18:56:13 +0000189 void AddTo(OptimizingCompilerStats* other_stats) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000190 for (size_t i = 0; i != arraysize(compile_stats_); ++i) {
Vladimir Marko438709f2017-02-23 18:56:13 +0000191 uint32_t count = compile_stats_[i];
192 if (count != 0) {
193 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
194 }
195 }
196 }
197
198 void Reset() {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000199 for (std::atomic<uint32_t>& stat : compile_stats_) {
200 stat = 0u;
Vladimir Marko438709f2017-02-23 18:56:13 +0000201 }
202 }
203
Calin Juravle48c2b032014-12-09 18:11:36 +0000204 private:
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000205 std::atomic<uint32_t> compile_stats_[static_cast<size_t>(MethodCompilationStat::kLastStat)];
Calin Juravle48c2b032014-12-09 18:11:36 +0000206
207 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
208};
209
Igor Murashkin1e065a52017-08-09 13:20:34 -0700210inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats,
211 MethodCompilationStat stat,
212 uint32_t count = 1) {
213 if (compiler_stats != nullptr) {
214 compiler_stats->RecordStat(stat, count);
215 }
216}
217
Calin Juravle48c2b032014-12-09 18:11:36 +0000218} // namespace art
219
220#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_