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 | |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 25 | #include "base/atomic.h" |
| 26 | #include "base/globals.h" |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 27 | #include "base/logging.h" // For VLOG_IS_ON. |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 31 | enum class MethodCompilationStat { |
| 32 | kAttemptBytecodeCompilation = 0, |
| 33 | kAttemptIntrinsicCompilation, |
| 34 | kCompiledNativeStub, |
| 35 | kCompiledIntrinsic, |
| 36 | kCompiledBytecode, |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 37 | kCHAInline, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 38 | kInlinedInvoke, |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 39 | kReplacedInvokeWithSimplePattern, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 40 | kInstructionSimplifications, |
Alexandre Rames | 44b9cf9 | 2015-08-19 15:39:06 +0100 | [diff] [blame] | 41 | kInstructionSimplificationsArch, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 42 | kUnresolvedMethod, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 43 | kUnresolvedField, |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 44 | kUnresolvedFieldNotAFastAccess, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 45 | kRemovedCheckedCast, |
| 46 | kRemovedDeadInstruction, |
| 47 | kRemovedNullCheck, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 48 | kNotCompiledSkipped, |
| 49 | kNotCompiledInvalidBytecode, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 50 | kNotCompiledThrowCatchLoop, |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 51 | kNotCompiledAmbiguousArrayOp, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 52 | kNotCompiledHugeMethod, |
| 53 | kNotCompiledLargeMethodNoBranches, |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 54 | kNotCompiledMalformedOpcode, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 55 | kNotCompiledNoCodegen, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 56 | kNotCompiledPathological, |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 57 | kNotCompiledSpaceFilter, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 58 | kNotCompiledUnhandledInstruction, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 59 | kNotCompiledUnsupportedIsa, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 60 | kNotCompiledVerificationError, |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 61 | kNotCompiledVerifyAtRuntime, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 62 | kInlinedMonomorphicCall, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 63 | kInlinedPolymorphicCall, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 64 | kMonomorphicCall, |
| 65 | kPolymorphicCall, |
| 66 | kMegamorphicCall, |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 67 | kBooleanSimplified, |
| 68 | kIntrinsicRecognized, |
| 69 | kLoopInvariantMoved, |
Aart Bik | 21b8592 | 2017-09-06 13:29:16 -0700 | [diff] [blame] | 70 | kLoopVectorized, |
| 71 | kLoopVectorizedIdiom, |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 72 | kSelectGenerated, |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 73 | kRemovedInstanceOf, |
| 74 | kInlinedInvokeVirtualOrInterface, |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 75 | kImplicitNullCheckGenerated, |
| 76 | kExplicitNullCheckGenerated, |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 77 | kSimplifyIf, |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 78 | kSimplifyThrowingInvoke, |
Nicolas Geoffray | b813ca1 | 2017-02-16 22:08:29 +0000 | [diff] [blame] | 79 | kInstructionSunk, |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 80 | kNotInlinedUnresolvedEntrypoint, |
| 81 | kNotInlinedDexCache, |
| 82 | kNotInlinedStackMaps, |
| 83 | kNotInlinedEnvironmentBudget, |
| 84 | kNotInlinedInstructionBudget, |
| 85 | kNotInlinedLoopWithoutExit, |
| 86 | kNotInlinedIrreducibleLoop, |
| 87 | kNotInlinedAlwaysThrows, |
| 88 | kNotInlinedInfiniteLoop, |
| 89 | kNotInlinedTryCatch, |
| 90 | kNotInlinedRegisterAllocator, |
| 91 | kNotInlinedCannotBuild, |
| 92 | kNotInlinedNotVerified, |
| 93 | kNotInlinedCodeItem, |
| 94 | kNotInlinedWont, |
| 95 | kNotInlinedRecursiveBudget, |
| 96 | kNotInlinedProxy, |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 97 | kConstructorFenceGeneratedNew, |
| 98 | kConstructorFenceGeneratedFinal, |
| 99 | kConstructorFenceRemovedLSE, |
| 100 | kConstructorFenceRemovedPFRA, |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 101 | kConstructorFenceRemovedCFRE, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 102 | kBitstringTypeCheck, |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 103 | kJitOutOfMemoryForCommit, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 104 | kLastStat |
| 105 | }; |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 106 | std::ostream& operator<<(std::ostream& os, const MethodCompilationStat& rhs); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 107 | |
| 108 | class OptimizingCompilerStats { |
| 109 | public: |
Vladimir Marko | ff754d1 | 2017-02-24 15:01:41 +0000 | [diff] [blame] | 110 | OptimizingCompilerStats() { |
| 111 | // The std::atomic<> default constructor leaves values uninitialized, so initialize them now. |
| 112 | Reset(); |
| 113 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 114 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 115 | void RecordStat(MethodCompilationStat stat, uint32_t count = 1) { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 116 | size_t stat_index = static_cast<size_t>(stat); |
| 117 | DCHECK_LT(stat_index, arraysize(compile_stats_)); |
| 118 | compile_stats_[stat_index] += count; |
| 119 | } |
| 120 | |
| 121 | uint32_t GetStat(MethodCompilationStat stat) const { |
| 122 | size_t stat_index = static_cast<size_t>(stat); |
| 123 | DCHECK_LT(stat_index, arraysize(compile_stats_)); |
| 124 | return compile_stats_[stat_index]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void Log() const { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 128 | uint32_t compiled_intrinsics = GetStat(MethodCompilationStat::kCompiledIntrinsic); |
| 129 | uint32_t compiled_native_stubs = GetStat(MethodCompilationStat::kCompiledNativeStub); |
| 130 | uint32_t bytecode_attempts = |
| 131 | GetStat(MethodCompilationStat::kAttemptBytecodeCompilation); |
| 132 | if (compiled_intrinsics == 0u && compiled_native_stubs == 0u && bytecode_attempts == 0u) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 133 | LOG(INFO) << "Did not compile any method."; |
| 134 | } else { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 135 | uint32_t compiled_bytecode_methods = |
| 136 | GetStat(MethodCompilationStat::kCompiledBytecode); |
| 137 | // Successful intrinsic compilation preempts other compilation attempts but failed intrinsic |
| 138 | // compilation shall still count towards bytecode or native stub compilation attempts. |
| 139 | uint32_t num_compilation_attempts = |
| 140 | compiled_intrinsics + compiled_native_stubs + bytecode_attempts; |
| 141 | uint32_t num_successful_compilations = |
| 142 | compiled_intrinsics + compiled_native_stubs + compiled_bytecode_methods; |
| 143 | float compiled_percent = num_successful_compilations * 100.0f / num_compilation_attempts; |
| 144 | LOG(INFO) << "Attempted compilation of " |
| 145 | << num_compilation_attempts << " methods: " << std::fixed << std::setprecision(2) |
| 146 | << compiled_percent << "% (" << num_successful_compilations << ") compiled."; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 147 | |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 148 | for (size_t i = 0; i < arraysize(compile_stats_); ++i) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 149 | if (compile_stats_[i] != 0) { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 150 | LOG(INFO) << "OptStat#" << static_cast<MethodCompilationStat>(i) << ": " |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 151 | << compile_stats_[i]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 157 | void AddTo(OptimizingCompilerStats* other_stats) { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 158 | for (size_t i = 0; i != arraysize(compile_stats_); ++i) { |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 159 | uint32_t count = compile_stats_[i]; |
| 160 | if (count != 0) { |
| 161 | other_stats->RecordStat(static_cast<MethodCompilationStat>(i), count); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | void Reset() { |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 167 | for (std::atomic<uint32_t>& stat : compile_stats_) { |
| 168 | stat = 0u; |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 172 | private: |
Vladimir Marko | cd09e1f | 2017-11-24 15:02:40 +0000 | [diff] [blame] | 173 | std::atomic<uint32_t> compile_stats_[static_cast<size_t>(MethodCompilationStat::kLastStat)]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 174 | |
| 175 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats); |
| 176 | }; |
| 177 | |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 178 | inline void MaybeRecordStat(OptimizingCompilerStats* compiler_stats, |
| 179 | MethodCompilationStat stat, |
| 180 | uint32_t count = 1) { |
| 181 | if (compiler_stats != nullptr) { |
| 182 | compiler_stats->RecordStat(stat, count); |
| 183 | } |
| 184 | } |
| 185 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 186 | } // namespace art |
| 187 | |
| 188 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |