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 { |
| 43 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 44 | class JitInstrumentationCache; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 45 | |
| 46 | class JitInstrumentationListener : public instrumentation::InstrumentationListener { |
| 47 | public: |
| 48 | explicit JitInstrumentationListener(JitInstrumentationCache* cache); |
| 49 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 50 | void MethodEntered(Thread* thread, mirror::Object* /*this_object*/, |
| 51 | ArtMethod* method, uint32_t /*dex_pc*/) |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 52 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
| 53 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 54 | void MethodExited(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 55 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 56 | const JValue& /*return_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 57 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 58 | void MethodUnwind(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 59 | ArtMethod* /*method*/, uint32_t /*dex_pc*/) OVERRIDE { } |
| 60 | void FieldRead(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 61 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 62 | ArtField* /*field*/) OVERRIDE { } |
| 63 | void FieldWritten(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 64 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 65 | ArtField* /*field*/, const JValue& /*field_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 66 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 67 | void ExceptionCaught(Thread* /*thread*/, |
| 68 | mirror::Throwable* /*exception_object*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 69 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 70 | void DexPcMoved(Thread* /*self*/, mirror::Object* /*this_object*/, |
| 71 | ArtMethod* /*method*/, uint32_t /*new_dex_pc*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 72 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 73 | 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] | 74 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 75 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 76 | void InvokeVirtualOrInterface(Thread* thread, |
| 77 | mirror::Object* this_object, |
| 78 | ArtMethod* caller, |
| 79 | uint32_t dex_pc, |
| 80 | ArtMethod* callee) |
Mathieu Chartier | 3fdb3fe | 2016-01-14 10:24:28 -0800 | [diff] [blame] | 81 | OVERRIDE |
| 82 | REQUIRES(Roles::uninterruptible_) |
| 83 | SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 84 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 85 | static constexpr uint32_t kJitEvents = |
| 86 | instrumentation::Instrumentation::kMethodEntered | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 87 | instrumentation::Instrumentation::kBranch | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 88 | instrumentation::Instrumentation::kInvokeVirtualOrInterface; |
| 89 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 90 | private: |
| 91 | JitInstrumentationCache* const instrumentation_cache_; |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 92 | |
| 93 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationListener); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
Nicolas Geoffray | 629e935 | 2015-11-04 17:22:16 +0000 | [diff] [blame] | 96 | // Keeps track of which methods are hot. |
| 97 | class JitInstrumentationCache { |
| 98 | public: |
| 99 | JitInstrumentationCache(size_t hot_method_threshold, size_t warm_method_threshold); |
| 100 | void AddSamples(Thread* self, ArtMethod* method, size_t samples) |
| 101 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 102 | void CreateThreadPool(); |
| 103 | void DeleteThreadPool(Thread* self); |
| 104 | // Wait until there is no more pending compilation tasks. |
| 105 | void WaitForCompilationToFinish(Thread* self); |
| 106 | |
| 107 | private: |
| 108 | size_t hot_method_threshold_; |
| 109 | size_t warm_method_threshold_; |
| 110 | JitInstrumentationListener listener_; |
| 111 | std::unique_ptr<ThreadPool> thread_pool_; |
| 112 | |
| 113 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationCache); |
| 114 | }; |
| 115 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 116 | } // namespace jit |
| 117 | } // namespace art |
| 118 | |
| 119 | #endif // ART_RUNTIME_JIT_JIT_INSTRUMENTATION_H_ |