Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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_RUNTIME_JIT_PROFILING_INFO_H_ |
| 18 | #define ART_RUNTIME_JIT_PROFILING_INFO_H_ |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "base/macros.h" |
| 23 | #include "gc_root.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 24 | #include "offsets.h" |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | class ArtMethod; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 29 | class ProfilingInfo; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 30 | |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 31 | namespace jit { |
| 32 | class JitCodeCache; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 33 | } // namespace jit |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 35 | namespace mirror { |
| 36 | class Class; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 37 | } // namespace mirror |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 38 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 39 | // Structure to store the classes seen at runtime for a specific instruction. |
| 40 | // Once the classes_ array is full, we consider the INVOKE to be megamorphic. |
| 41 | class InlineCache { |
| 42 | public: |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 43 | // This is hard coded in the assembly stub art_quick_update_inline_cache. |
Calin Juravle | 940eb0c | 2017-01-30 19:30:44 -0800 | [diff] [blame] | 44 | static constexpr uint8_t kIndividualCacheSize = 5; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 45 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 46 | static constexpr MemberOffset ClassesOffset() { |
| 47 | return MemberOffset(OFFSETOF_MEMBER(InlineCache, classes_)); |
| 48 | } |
| 49 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 50 | private: |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 51 | uint32_t dex_pc_; |
| 52 | GcRoot<mirror::Class> classes_[kIndividualCacheSize]; |
| 53 | |
Nicolas Geoffray | e51ca8b | 2016-11-22 14:49:31 +0000 | [diff] [blame] | 54 | friend class jit::JitCodeCache; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 55 | friend class ProfilingInfo; |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(InlineCache); |
| 58 | }; |
| 59 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 60 | /** |
| 61 | * Profiling info for a method, created and filled by the interpreter once the |
| 62 | * method is warm, and used by the compiler to drive optimizations. |
| 63 | */ |
| 64 | class ProfilingInfo { |
| 65 | public: |
Nicolas Geoffray | 60ef399 | 2020-08-07 07:49:57 +0000 | [diff] [blame^] | 66 | // Create a ProfilingInfo for 'method'. |
| 67 | static ProfilingInfo* Create(Thread* self, ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 68 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 69 | |
| 70 | // Add information from an executed INVOKE instruction to the profile. |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 71 | void AddInvokeInfo(uint32_t dex_pc, mirror::Class* cls) |
| 72 | // Method should not be interruptible, as it manipulates the ProfilingInfo |
| 73 | // which can be concurrently collected. |
| 74 | REQUIRES(Roles::uninterruptible_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 75 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 76 | |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 77 | ArtMethod* GetMethod() const { |
| 78 | return method_; |
| 79 | } |
| 80 | |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 81 | // Mutator lock only required for debugging output. |
| 82 | InlineCache* GetInlineCache(uint32_t dex_pc) |
| 83 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 84 | |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 85 | // Increments the number of times this method is currently being inlined. |
| 86 | // Returns whether it was successful, that is it could increment without |
| 87 | // overflowing. |
| 88 | bool IncrementInlineUse() { |
| 89 | if (current_inline_uses_ == std::numeric_limits<uint16_t>::max()) { |
| 90 | return false; |
| 91 | } |
Nicolas Geoffray | b6e20ae | 2016-03-07 14:29:04 +0000 | [diff] [blame] | 92 | current_inline_uses_++; |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 93 | return true; |
Nicolas Geoffray | b6e20ae | 2016-03-07 14:29:04 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void DecrementInlineUse() { |
| 97 | DCHECK_GT(current_inline_uses_, 0); |
| 98 | current_inline_uses_--; |
| 99 | } |
| 100 | |
| 101 | bool IsInUseByCompiler() const { |
Nicolas Geoffray | f8cc26e | 2020-06-10 15:37:37 +0100 | [diff] [blame] | 102 | return current_inline_uses_ > 0; |
Nicolas Geoffray | 511e41b | 2016-03-02 17:09:35 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 105 | static constexpr MemberOffset BaselineHotnessCountOffset() { |
| 106 | return MemberOffset(OFFSETOF_MEMBER(ProfilingInfo, baseline_hotness_count_)); |
| 107 | } |
| 108 | |
Nicolas Geoffray | b0a9747 | 2019-12-05 15:17:46 +0000 | [diff] [blame] | 109 | void SetBaselineHotnessCount(uint16_t count) { |
| 110 | baseline_hotness_count_ = count; |
| 111 | } |
| 112 | |
| 113 | uint16_t GetBaselineHotnessCount() const { |
| 114 | return baseline_hotness_count_; |
| 115 | } |
| 116 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 117 | private: |
Mathieu Chartier | 6597577 | 2016-08-05 10:46:36 -0700 | [diff] [blame] | 118 | ProfilingInfo(ArtMethod* method, const std::vector<uint32_t>& entries); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 119 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 120 | // Hotness count for methods compiled with the JIT baseline compiler. Once |
| 121 | // a threshold is hit (currentily the maximum value of uint16_t), we will |
| 122 | // JIT compile optimized the method. |
| 123 | uint16_t baseline_hotness_count_; |
| 124 | |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 125 | // Method this profiling info is for. |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 126 | // Not 'const' as JVMTI introduces obsolete methods that we implement by creating new ArtMethods. |
| 127 | // See JitCodeCache::MoveObsoleteMethod. |
| 128 | ArtMethod* method_; |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 129 | |
Andreas Gampe | e40f65f | 2018-05-07 17:02:22 -0700 | [diff] [blame] | 130 | // Number of instructions we are profiling in the ArtMethod. |
| 131 | const uint32_t number_of_inline_caches_; |
| 132 | |
| 133 | // When the compiler inlines the method associated to this ProfilingInfo, |
| 134 | // it updates this counter so that the GC does not try to clear the inline caches. |
| 135 | uint16_t current_inline_uses_; |
| 136 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 137 | // Dynamically allocated array of size `number_of_inline_caches_`. |
| 138 | InlineCache cache_[0]; |
| 139 | |
Nicolas Geoffray | 26705e2 | 2015-10-28 12:50:11 +0000 | [diff] [blame] | 140 | friend class jit::JitCodeCache; |
| 141 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 142 | DISALLOW_COPY_AND_ASSIGN(ProfilingInfo); |
| 143 | }; |
| 144 | |
| 145 | } // namespace art |
| 146 | |
| 147 | #endif // ART_RUNTIME_JIT_PROFILING_INFO_H_ |