Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 20 | #include <atomic> |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 21 | #include <iomanip> |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 22 | #include <string> |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 23 | #include <type_traits> |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 24 | |
| 25 | #include "atomic.h" |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame^] | 26 | #include "globals.h" |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | enum MethodCompilationStat { |
| 31 | kAttemptCompilation = 0, |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 32 | kCHAInline, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 33 | kCompiled, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 34 | kInlinedInvoke, |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 35 | kReplacedInvokeWithSimplePattern, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 36 | kInstructionSimplifications, |
Alexandre Rames | 44b9cf9 | 2015-08-19 15:39:06 +0100 | [diff] [blame] | 37 | kInstructionSimplificationsArch, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 38 | kUnresolvedMethod, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 39 | kUnresolvedField, |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 40 | kUnresolvedFieldNotAFastAccess, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 41 | kRemovedCheckedCast, |
| 42 | kRemovedDeadInstruction, |
| 43 | kRemovedNullCheck, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 44 | kNotCompiledSkipped, |
| 45 | kNotCompiledInvalidBytecode, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 46 | kNotCompiledThrowCatchLoop, |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 47 | kNotCompiledAmbiguousArrayOp, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 48 | kNotCompiledHugeMethod, |
| 49 | kNotCompiledLargeMethodNoBranches, |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 50 | kNotCompiledMalformedOpcode, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 51 | kNotCompiledNoCodegen, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 52 | kNotCompiledPathological, |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 53 | kNotCompiledSpaceFilter, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 54 | kNotCompiledUnhandledInstruction, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 55 | kNotCompiledUnsupportedIsa, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 56 | kNotCompiledVerificationError, |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 57 | kNotCompiledVerifyAtRuntime, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 58 | kInlinedMonomorphicCall, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 59 | kInlinedPolymorphicCall, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 60 | kMonomorphicCall, |
| 61 | kPolymorphicCall, |
| 62 | kMegamorphicCall, |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 63 | kBooleanSimplified, |
| 64 | kIntrinsicRecognized, |
| 65 | kLoopInvariantMoved, |
| 66 | kSelectGenerated, |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 67 | kRemovedInstanceOf, |
| 68 | kInlinedInvokeVirtualOrInterface, |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 69 | kImplicitNullCheckGenerated, |
| 70 | kExplicitNullCheckGenerated, |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 71 | kSimplifyIf, |
Nicolas Geoffray | b813ca1 | 2017-02-16 22:08:29 +0000 | [diff] [blame] | 72 | kInstructionSunk, |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 73 | kNotInlinedUnresolvedEntrypoint, |
| 74 | kNotInlinedDexCache, |
| 75 | kNotInlinedStackMaps, |
| 76 | kNotInlinedEnvironmentBudget, |
| 77 | kNotInlinedInstructionBudget, |
| 78 | kNotInlinedLoopWithoutExit, |
| 79 | kNotInlinedIrreducibleLoop, |
| 80 | kNotInlinedAlwaysThrows, |
| 81 | kNotInlinedInfiniteLoop, |
| 82 | kNotInlinedTryCatch, |
| 83 | kNotInlinedRegisterAllocator, |
| 84 | kNotInlinedCannotBuild, |
| 85 | kNotInlinedNotVerified, |
| 86 | kNotInlinedCodeItem, |
| 87 | kNotInlinedWont, |
| 88 | kNotInlinedRecursiveBudget, |
| 89 | kNotInlinedProxy, |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame^] | 90 | kConstructorFenceGeneratedNew, |
| 91 | kConstructorFenceGeneratedFinal, |
| 92 | kConstructorFenceRemovedLSE, |
| 93 | kConstructorFenceRemovedPFRA, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 94 | kLastStat |
| 95 | }; |
| 96 | |
| 97 | class OptimizingCompilerStats { |
| 98 | public: |
Vladimir Marko | ff754d1 | 2017-02-24 15:01:41 +0000 | [diff] [blame] | 99 | OptimizingCompilerStats() { |
| 100 | // The std::atomic<> default constructor leaves values uninitialized, so initialize them now. |
| 101 | Reset(); |
| 102 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 103 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 104 | void RecordStat(MethodCompilationStat stat, uint32_t count = 1) { |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 105 | compile_stats_[stat] += count; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void Log() const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 109 | if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) { |
| 110 | // Log only in debug builds or if the compiler is verbose. |
| 111 | return; |
| 112 | } |
| 113 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 114 | if (compile_stats_[kAttemptCompilation] == 0) { |
| 115 | LOG(INFO) << "Did not compile any method."; |
| 116 | } else { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 117 | float compiled_percent = |
| 118 | compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation]; |
| 119 | LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation] |
| 120 | << " methods: " << std::fixed << std::setprecision(2) |
| 121 | << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled."; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 122 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 123 | for (size_t i = 0; i < kLastStat; i++) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 124 | if (compile_stats_[i] != 0) { |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 125 | LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": " |
| 126 | << compile_stats_[i]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 132 | void AddTo(OptimizingCompilerStats* other_stats) { |
| 133 | for (size_t i = 0; i != kLastStat; ++i) { |
| 134 | uint32_t count = compile_stats_[i]; |
| 135 | if (count != 0) { |
| 136 | other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | void Reset() { |
| 142 | for (size_t i = 0; i != kLastStat; ++i) { |
| 143 | compile_stats_[i] = 0u; |
| 144 | } |
| 145 | } |
| 146 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 147 | private: |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 148 | std::string PrintMethodCompilationStat(MethodCompilationStat stat) const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 149 | std::string name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 150 | switch (stat) { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 151 | case kAttemptCompilation : name = "AttemptCompilation"; break; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 152 | case kCHAInline : name = "CHAInline"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 153 | case kCompiled : name = "Compiled"; break; |
| 154 | case kInlinedInvoke : name = "InlinedInvoke"; break; |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 155 | case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 156 | case kInstructionSimplifications: name = "InstructionSimplifications"; break; |
| 157 | case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break; |
| 158 | case kUnresolvedMethod : name = "UnresolvedMethod"; break; |
| 159 | case kUnresolvedField : name = "UnresolvedField"; break; |
| 160 | case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break; |
| 161 | case kRemovedCheckedCast: name = "RemovedCheckedCast"; break; |
| 162 | case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break; |
| 163 | case kRemovedNullCheck: name = "RemovedNullCheck"; break; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 164 | case kNotCompiledSkipped: name = "NotCompiledSkipped"; break; |
| 165 | case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 166 | case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break; |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 167 | case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 168 | case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break; |
| 169 | case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break; |
| 170 | case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break; |
| 171 | case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break; |
| 172 | case kNotCompiledPathological : name = "NotCompiledPathological"; break; |
| 173 | case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break; |
| 174 | case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break; |
| 175 | case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break; |
| 176 | case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break; |
| 177 | case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 178 | case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 179 | case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 180 | case kMonomorphicCall: name = "MonomorphicCall"; break; |
| 181 | case kPolymorphicCall: name = "PolymorphicCall"; break; |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 182 | case kMegamorphicCall: name = "MegamorphicCall"; break; |
| 183 | case kBooleanSimplified : name = "BooleanSimplified"; break; |
| 184 | case kIntrinsicRecognized : name = "IntrinsicRecognized"; break; |
| 185 | case kLoopInvariantMoved : name = "LoopInvariantMoved"; break; |
| 186 | case kSelectGenerated : name = "SelectGenerated"; break; |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 187 | case kRemovedInstanceOf: name = "RemovedInstanceOf"; break; |
| 188 | case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break; |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 189 | case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break; |
| 190 | case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break; |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 191 | case kSimplifyIf: name = "SimplifyIf"; break; |
Nicolas Geoffray | b813ca1 | 2017-02-16 22:08:29 +0000 | [diff] [blame] | 192 | case kInstructionSunk: name = "InstructionSunk"; break; |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 193 | case kNotInlinedUnresolvedEntrypoint: name = "NotInlinedUnresolvedEntrypoint"; break; |
| 194 | case kNotInlinedDexCache: name = "NotInlinedDexCache"; break; |
| 195 | case kNotInlinedStackMaps: name = "NotInlinedStackMaps"; break; |
| 196 | case kNotInlinedEnvironmentBudget: name = "NotInlinedEnvironmentBudget"; break; |
| 197 | case kNotInlinedInstructionBudget: name = "NotInlinedInstructionBudget"; break; |
| 198 | case kNotInlinedLoopWithoutExit: name = "NotInlinedLoopWithoutExit"; break; |
| 199 | case kNotInlinedIrreducibleLoop: name = "NotInlinedIrreducibleLoop"; break; |
| 200 | case kNotInlinedAlwaysThrows: name = "NotInlinedAlwaysThrows"; break; |
| 201 | case kNotInlinedInfiniteLoop: name = "NotInlinedInfiniteLoop"; break; |
| 202 | case kNotInlinedTryCatch: name = "NotInlinedTryCatch"; break; |
| 203 | case kNotInlinedRegisterAllocator: name = "NotInlinedRegisterAllocator"; break; |
| 204 | case kNotInlinedCannotBuild: name = "NotInlinedCannotBuild"; break; |
| 205 | case kNotInlinedNotVerified: name = "NotInlinedNotVerified"; break; |
| 206 | case kNotInlinedCodeItem: name = "NotInlinedCodeItem"; break; |
| 207 | case kNotInlinedWont: name = "NotInlinedWont"; break; |
| 208 | case kNotInlinedRecursiveBudget: name = "NotInlinedRecursiveBudget"; break; |
| 209 | case kNotInlinedProxy: name = "NotInlinedProxy"; break; |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame^] | 210 | case kConstructorFenceGeneratedNew: name = "ConstructorFenceGeneratedNew"; break; |
| 211 | case kConstructorFenceGeneratedFinal: name = "ConstructorFenceGeneratedFinal"; break; |
| 212 | case kConstructorFenceRemovedLSE: name = "ConstructorFenceRemovedLSE"; break; |
| 213 | case kConstructorFenceRemovedPFRA: name = "ConstructorFenceRemovedPFRA"; break; |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 214 | |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 215 | case kLastStat: |
| 216 | LOG(FATAL) << "invalid stat " |
| 217 | << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat); |
| 218 | UNREACHABLE(); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 219 | } |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 220 | return "OptStat#" + name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 223 | std::atomic<uint32_t> compile_stats_[kLastStat]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 224 | |
| 225 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats); |
| 226 | }; |
| 227 | |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 228 | inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats, |
| 229 | MethodCompilationStat stat, |
| 230 | uint32_t count = 1) { |
| 231 | if (compiler_stats != nullptr) { |
| 232 | compiler_stats->RecordStat(stat, count); |
| 233 | } |
| 234 | } |
| 235 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 236 | } // namespace art |
| 237 | |
| 238 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |