Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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_RUNTIME_JIT_JIT_INSTRUMENTATION_H_ |
| 18 | #define ART_RUNTIME_JIT_JIT_INSTRUMENTATION_H_ |
| 19 | |
| 20 | #include <unordered_map> |
| 21 | |
| 22 | #include "instrumentation.h" |
| 23 | |
| 24 | #include "atomic.h" |
| 25 | #include "base/macros.h" |
| 26 | #include "base/mutex.h" |
| 27 | #include "gc_root.h" |
| 28 | #include "jni.h" |
| 29 | #include "object_callbacks.h" |
| 30 | #include "thread_pool.h" |
| 31 | |
| 32 | namespace art { |
| 33 | namespace mirror { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 34 | class Object; |
| 35 | class Throwable; |
| 36 | } // namespace mirror |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 37 | class ArtField; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | class ArtMethod; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 39 | union JValue; |
| 40 | class Thread; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 41 | |
| 42 | namespace jit { |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame^] | 43 | static constexpr int16_t kJitCheckForOSR = -1; |
| 44 | static constexpr int16_t kJitHotnessDisabled = -2; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 45 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 46 | class JitInstrumentationCache; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 47 | |
| 48 | class JitInstrumentationListener : public instrumentation::InstrumentationListener { |
| 49 | public: |
| 50 | explicit JitInstrumentationListener(JitInstrumentationCache* cache); |
| 51 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 52 | void MethodEntered(Thread* thread, mirror::Object* /*this_object*/, |
| 53 | ArtMethod* method, uint32_t /*dex_pc*/) |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 54 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
| 55 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 56 | void MethodExited(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 57 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 58 | const JValue& /*return_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 59 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 60 | void MethodUnwind(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 61 | ArtMethod* /*method*/, uint32_t /*dex_pc*/) OVERRIDE { } |
| 62 | void FieldRead(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 63 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 64 | ArtField* /*field*/) OVERRIDE { } |
| 65 | void FieldWritten(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 66 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 67 | ArtField* /*field*/, const JValue& /*field_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 68 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 69 | void ExceptionCaught(Thread* /*thread*/, |
| 70 | mirror::Throwable* /*exception_object*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 71 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 72 | void DexPcMoved(Thread* /*self*/, mirror::Object* /*this_object*/, |
| 73 | ArtMethod* /*method*/, uint32_t /*new_dex_pc*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 74 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 75 | void Branch(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t dex_pc_offset) |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 76 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 77 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 78 | void InvokeVirtualOrInterface(Thread* thread, |
| 79 | mirror::Object* this_object, |
| 80 | ArtMethod* caller, |
| 81 | uint32_t dex_pc, |
| 82 | ArtMethod* callee) |
Mathieu Chartier | 3fdb3fe | 2016-01-14 10:24:28 -0800 | [diff] [blame] | 83 | OVERRIDE |
| 84 | REQUIRES(Roles::uninterruptible_) |
| 85 | SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 87 | static constexpr uint32_t kJitEvents = |
| 88 | instrumentation::Instrumentation::kMethodEntered | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 89 | instrumentation::Instrumentation::kInvokeVirtualOrInterface; |
| 90 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 91 | private: |
| 92 | JitInstrumentationCache* const instrumentation_cache_; |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 93 | |
| 94 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationListener); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 97 | // Keeps track of which methods are hot. |
| 98 | class JitInstrumentationCache { |
| 99 | public: |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame^] | 100 | JitInstrumentationCache(uint16_t hot_method_threshold, |
| 101 | uint16_t warm_method_threshold, |
| 102 | uint16_t osr_method_threshold); |
| 103 | void AddSamples(Thread* self, ArtMethod* method, uint16_t samples) |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 104 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 105 | void CreateThreadPool(); |
| 106 | void DeleteThreadPool(Thread* self); |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 107 | |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame^] | 108 | size_t OSRMethodThreshold() const { |
| 109 | return osr_method_threshold_; |
| 110 | } |
| 111 | |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 112 | size_t HotMethodThreshold() const { |
| 113 | return hot_method_threshold_; |
| 114 | } |
| 115 | |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame^] | 116 | size_t WarmMethodThreshold() const { |
| 117 | return warm_method_threshold_; |
| 118 | } |
| 119 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 120 | // Wait until there is no more pending compilation tasks. |
| 121 | void WaitForCompilationToFinish(Thread* self); |
| 122 | |
| 123 | private: |
Bill Buzbee | 1d011d9 | 2016-04-04 16:59:29 +0000 | [diff] [blame^] | 124 | uint16_t hot_method_threshold_; |
| 125 | uint16_t warm_method_threshold_; |
| 126 | uint16_t osr_method_threshold_; |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 127 | JitInstrumentationListener listener_; |
| 128 | std::unique_ptr<ThreadPool> thread_pool_; |
| 129 | |
| 130 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationCache); |
| 131 | }; |
| 132 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 133 | } // namespace jit |
| 134 | } // namespace art |
| 135 | |
| 136 | #endif // ART_RUNTIME_JIT_JIT_INSTRUMENTATION_H_ |