blob: 32a94ab5e4b7c431f07aacedeeea106cc3dd1bf4 [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"
Andreas Gampe57943812017-12-06 21:39:13 -080026#include "base/logging.h" // For VLOG_IS_ON.
Igor Murashkin6ef45672017-08-08 13:59:55 -070027#include "globals.h"
Calin Juravle48c2b032014-12-09 18:11:36 +000028
29namespace art {
30
Vladimir Markocd09e1f2017-11-24 15:02:40 +000031enum class MethodCompilationStat {
32 kAttemptBytecodeCompilation = 0,
33 kAttemptIntrinsicCompilation,
34 kCompiledNativeStub,
35 kCompiledIntrinsic,
36 kCompiledBytecode,
Mingyao Yang063fc772016-08-02 11:02:54 -070037 kCHAInline,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000038 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000039 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010040 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010041 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010042 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010043 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010044 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000045 kRemovedCheckedCast,
46 kRemovedDeadInstruction,
47 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000048 kNotCompiledSkipped,
49 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000050 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000051 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000052 kNotCompiledHugeMethod,
53 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010054 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000055 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010056 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000057 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000058 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010059 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000060 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010061 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010062 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000063 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010064 kMonomorphicCall,
65 kPolymorphicCall,
66 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010067 kBooleanSimplified,
68 kIntrinsicRecognized,
69 kLoopInvariantMoved,
Aart Bik21b85922017-09-06 13:29:16 -070070 kLoopVectorized,
71 kLoopVectorizedIdiom,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010072 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000073 kRemovedInstanceOf,
74 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000075 kImplicitNullCheckGenerated,
76 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010077 kSimplifyIf,
Nicolas Geoffrayb813ca12017-02-16 22:08:29 +000078 kInstructionSunk,
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +000079 kNotInlinedUnresolvedEntrypoint,
80 kNotInlinedDexCache,
81 kNotInlinedStackMaps,
82 kNotInlinedEnvironmentBudget,
83 kNotInlinedInstructionBudget,
84 kNotInlinedLoopWithoutExit,
85 kNotInlinedIrreducibleLoop,
86 kNotInlinedAlwaysThrows,
87 kNotInlinedInfiniteLoop,
88 kNotInlinedTryCatch,
89 kNotInlinedRegisterAllocator,
90 kNotInlinedCannotBuild,
91 kNotInlinedNotVerified,
92 kNotInlinedCodeItem,
93 kNotInlinedWont,
94 kNotInlinedRecursiveBudget,
95 kNotInlinedProxy,
Igor Murashkin6ef45672017-08-08 13:59:55 -070096 kConstructorFenceGeneratedNew,
97 kConstructorFenceGeneratedFinal,
98 kConstructorFenceRemovedLSE,
99 kConstructorFenceRemovedPFRA,
Igor Murashkindd018df2017-08-09 10:38:31 -0700100 kConstructorFenceRemovedCFRE,
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000101 kJitOutOfMemoryForCommit,
Calin Juravle48c2b032014-12-09 18:11:36 +0000102 kLastStat
103};
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000104std::ostream& operator<<(std::ostream& os, const MethodCompilationStat& rhs);
Calin Juravle48c2b032014-12-09 18:11:36 +0000105
106class OptimizingCompilerStats {
107 public:
Vladimir Markoff754d12017-02-24 15:01:41 +0000108 OptimizingCompilerStats() {
109 // The std::atomic<> default constructor leaves values uninitialized, so initialize them now.
110 Reset();
111 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000112
Vladimir Marko438709f2017-02-23 18:56:13 +0000113 void RecordStat(MethodCompilationStat stat, uint32_t count = 1) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000114 size_t stat_index = static_cast<size_t>(stat);
115 DCHECK_LT(stat_index, arraysize(compile_stats_));
116 compile_stats_[stat_index] += count;
117 }
118
119 uint32_t GetStat(MethodCompilationStat stat) const {
120 size_t stat_index = static_cast<size_t>(stat);
121 DCHECK_LT(stat_index, arraysize(compile_stats_));
122 return compile_stats_[stat_index];
Calin Juravle48c2b032014-12-09 18:11:36 +0000123 }
124
125 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +0000126 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
127 // Log only in debug builds or if the compiler is verbose.
128 return;
129 }
130
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000131 uint32_t compiled_intrinsics = GetStat(MethodCompilationStat::kCompiledIntrinsic);
132 uint32_t compiled_native_stubs = GetStat(MethodCompilationStat::kCompiledNativeStub);
133 uint32_t bytecode_attempts =
134 GetStat(MethodCompilationStat::kAttemptBytecodeCompilation);
135 if (compiled_intrinsics == 0u && compiled_native_stubs == 0u && bytecode_attempts == 0u) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000136 LOG(INFO) << "Did not compile any method.";
137 } else {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000138 uint32_t compiled_bytecode_methods =
139 GetStat(MethodCompilationStat::kCompiledBytecode);
140 // Successful intrinsic compilation preempts other compilation attempts but failed intrinsic
141 // compilation shall still count towards bytecode or native stub compilation attempts.
142 uint32_t num_compilation_attempts =
143 compiled_intrinsics + compiled_native_stubs + bytecode_attempts;
144 uint32_t num_successful_compilations =
145 compiled_intrinsics + compiled_native_stubs + compiled_bytecode_methods;
146 float compiled_percent = num_successful_compilations * 100.0f / num_compilation_attempts;
147 LOG(INFO) << "Attempted compilation of "
148 << num_compilation_attempts << " methods: " << std::fixed << std::setprecision(2)
149 << compiled_percent << "% (" << num_successful_compilations << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100150
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000151 for (size_t i = 0; i < arraysize(compile_stats_); ++i) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000152 if (compile_stats_[i] != 0) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000153 LOG(INFO) << "OptStat#" << static_cast<MethodCompilationStat>(i) << ": "
Andreas Gampeda9badb2015-06-05 20:22:12 -0700154 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000155 }
156 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000157 }
158 }
159
Vladimir Marko438709f2017-02-23 18:56:13 +0000160 void AddTo(OptimizingCompilerStats* other_stats) {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000161 for (size_t i = 0; i != arraysize(compile_stats_); ++i) {
Vladimir Marko438709f2017-02-23 18:56:13 +0000162 uint32_t count = compile_stats_[i];
163 if (count != 0) {
164 other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count);
165 }
166 }
167 }
168
169 void Reset() {
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000170 for (std::atomic<uint32_t>& stat : compile_stats_) {
171 stat = 0u;
Vladimir Marko438709f2017-02-23 18:56:13 +0000172 }
173 }
174
Calin Juravle48c2b032014-12-09 18:11:36 +0000175 private:
Vladimir Markocd09e1f2017-11-24 15:02:40 +0000176 std::atomic<uint32_t> compile_stats_[static_cast<size_t>(MethodCompilationStat::kLastStat)];
Calin Juravle48c2b032014-12-09 18:11:36 +0000177
178 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
179};
180
Igor Murashkin1e065a52017-08-09 13:20:34 -0700181inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats,
182 MethodCompilationStat stat,
183 uint32_t count = 1) {
184 if (compiler_stats != nullptr) {
185 compiler_stats->RecordStat(stat, count);
186 }
187}
188
Calin Juravle48c2b032014-12-09 18:11:36 +0000189} // namespace art
190
191#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_