blob: a2f71cfdf3e52a030107db004c2ad2a9d2f99607 [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"
Calin Juravle48c2b032014-12-09 18:11:36 +000029
Vladimir Marko0a516052019-10-14 13:00:44 +000030namespace art {
Calin Juravle48c2b032014-12-09 18:11:36 +000031
Vladimir Markocd09e1f2017-11-24 15:02:40 +000032enum class MethodCompilationStat {
33 kAttemptBytecodeCompilation = 0,
34 kAttemptIntrinsicCompilation,
35 kCompiledNativeStub,
36 kCompiledIntrinsic,
37 kCompiledBytecode,
Mingyao Yang063fc772016-08-02 11:02:54 -070038 kCHAInline,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000039 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000040 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010041 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010042 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010043 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010044 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010045 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000046 kRemovedCheckedCast,
47 kRemovedDeadInstruction,
48 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000049 kNotCompiledSkipped,
50 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000051 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000052 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000053 kNotCompiledHugeMethod,
54 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010055 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000056 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010057 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000058 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000059 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010060 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000061 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010062 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +010063 kNotCompiledIrreducibleLoopAndStringInit,
Nicolas Geoffray7cfc8f52019-08-07 10:41:09 +010064 kNotCompiledPhiEquivalentInOsr,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010065 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000066 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010067 kMonomorphicCall,
68 kPolymorphicCall,
69 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010070 kBooleanSimplified,
71 kIntrinsicRecognized,
72 kLoopInvariantMoved,
Aart Bik21b85922017-09-06 13:29:16 -070073 kLoopVectorized,
74 kLoopVectorizedIdiom,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010075 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000076 kRemovedInstanceOf,
77 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000078 kImplicitNullCheckGenerated,
79 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010080 kSimplifyIf,
Aart Bika8b8e9b2018-01-09 11:01:02 -080081 kSimplifyThrowingInvoke,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000082 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000083 kNotInlinedUnresolvedEntrypoint,
84 kNotInlinedDexCache,
85 kNotInlinedStackMaps,
86 kNotInlinedEnvironmentBudget,
87 kNotInlinedInstructionBudget,
88 kNotInlinedLoopWithoutExit,
89 kNotInlinedIrreducibleLoop,
90 kNotInlinedAlwaysThrows,
91 kNotInlinedInfiniteLoop,
92 kNotInlinedTryCatch,
93 kNotInlinedRegisterAllocator,
94 kNotInlinedCannotBuild,
95 kNotInlinedNotVerified,
96 kNotInlinedCodeItem,
97 kNotInlinedWont,
98 kNotInlinedRecursiveBudget,
99 kNotInlinedProxy,
Mathieu Chartier8284e9a2020-05-15 17:14:33 -0700100 kNotInlinedUnresolved,
101 kNotInlinedPolymorphic,
102 kNotInlinedCustom,
103 kTryInline,
Igor Murashkin6ef45672017-08-08 13:59:55 -0700104 kConstructorFenceGeneratedNew,
105 kConstructorFenceGeneratedFinal,
106 kConstructorFenceRemovedLSE,
107 kConstructorFenceRemovedPFRA,
Igor Murashkindd018df2017-08-09 10:38:31 -0700108 kConstructorFenceRemovedCFRE,
Vladimir Marko175e7862018-03-27 09:03:13 +0000109 kBitstringTypeCheck,
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000110 kJitOutOfMemoryForCommit,
Alex Light86fe9b82020-11-16 16:54:01 +0000111 kFullLSEAllocationRemoved,
112 kFullLSEPossible,
113 kNonPartialLoadRemoved,
114 kPartialLSEPossible,
115 kPartialStoreRemoved,
Alex Light3a73ffb2021-01-25 14:11:05 +0000116 kPartialAllocationMoved,
117 kPredicatedLoadAdded,
118 kPredicatedStoreAdded,
Calin Juravle48c2b032014-12-09 18:11:36 +0000119 kLastStat
120};
Vladimir Marko9974e3c2020-06-10 16:27:06 +0100121std::ostream& operator<<(std::ostream& os, MethodCompilationStat rhs);
Calin Juravle48c2b032014-12-09 18:11:36 +0000122
123class OptimizingCompilerStats {
124 public:
Vladimir Markoff754d12017-02-24 15:01:41 +0000125 OptimizingCompilerStats() {
126 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
127 Reset();
128 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000129
Vladimir Marko438709f2017-02-23 18:56:13 +0000130 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000131 size_t stat_index = static_cast<size_t>(stat);
132 DCHECK_LT(stat_index, arraysize(compile_stats_));
133 compile_stats_[stat_index] += count;
134 }
135
136 uint32_t GetStat(MethodCompilationStat stat) const {
137 size_t stat_index = static_cast<size_t>(stat);
138 DCHECK_LT(stat_index, arraysize(compile_stats_));
139 return compile_stats_[stat_index];
Calin Juravle48c2b032014-12-09 18:11:36 +0000140 }
141
142 void Log() const {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000143 uint32_t compiled_intrinsics = GetStat(MethodCompilationStat::kCompiledIntrinsic);
144 uint32_t compiled_native_stubs = GetStat(MethodCompilationStat::kCompiledNativeStub);
145 uint32_t bytecode_attempts =
146 GetStat(MethodCompilationStat::kAttemptBytecodeCompilation);
147 if (compiled_intrinsics == 0u && compiled_native_stubs == 0u && bytecode_attempts == 0u) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000148 LOG(INFO) << "Did not compile any method.";
149 } else {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000150 uint32_t compiled_bytecode_methods =
151 GetStat(MethodCompilationStat::kCompiledBytecode);
152 // Successful intrinsic compilation preempts other compilation attempts but failed intrinsic
153 // compilation shall still count towards bytecode or native stub compilation attempts.
154 uint32_t num_compilation_attempts =
155 compiled_intrinsics + compiled_native_stubs + bytecode_attempts;
156 uint32_t num_successful_compilations =
157 compiled_intrinsics + compiled_native_stubs + compiled_bytecode_methods;
158 float compiled_percent = num_successful_compilations * 100.0f / num_compilation_attempts;
159 LOG(INFO) << "Attempted compilation of "
160 << num_compilation_attempts << " methods: " << std::fixed << std::setprecision(2)
161 << compiled_percent << "% (" << num_successful_compilations << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100162
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000163 for (size_t i = 0; i < arraysize(compile_stats_); ++i) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000164 if (compile_stats_[i] != 0) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000165 LOG(INFO) << "OptStat#" << static_cast<MethodCompilationStat>(i) << ": "
Andreas Gampeda9badb2015-06-05 20:22:12 -0700166 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000167 }
168 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000169 }
170 }
171
Vladimir Marko438709f2017-02-23 18:56:13 +0000172 void AddTo(OptimizingCompilerStats* other_stats) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000173 for (size_t i = 0; i != arraysize(compile_stats_); ++i) {
Vladimir Marko438709f2017-02-23 18:56:13 +0000174 uint32_t count = compile_stats_[i];
175 if (count != 0) {
176 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
177 }
178 }
179 }
180
181 void Reset() {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000182 for (std::atomic<uint32_t>& stat : compile_stats_) {
183 stat = 0u;
Vladimir Marko438709f2017-02-23 18:56:13 +0000184 }
185 }
186
Calin Juravle48c2b032014-12-09 18:11:36 +0000187 private:
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000188 std::atomic<uint32_t> compile_stats_[static_cast<size_t>(MethodCompilationStat::kLastStat)];
Calin Juravle48c2b032014-12-09 18:11:36 +0000189
190 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
191};
192
Igor Murashkin1e065a52017-08-09 13:20:34 -0700193inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats,
194 MethodCompilationStat stat,
195 uint32_t count = 1) {
196 if (compiler_stats != nullptr) {
197 compiler_stats->RecordStat(stat, count);
198 }
199}
200
Calin Juravle48c2b032014-12-09 18:11:36 +0000201} // namespace art
202
203#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_