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 Class; |
| 35 | class Object; |
| 36 | class Throwable; |
| 37 | } // namespace mirror |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 38 | class ArtField; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 39 | class ArtMethod; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 40 | union JValue; |
| 41 | class Thread; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 42 | |
| 43 | namespace jit { |
| 44 | |
| 45 | // Keeps track of which methods are hot. |
| 46 | class JitInstrumentationCache { |
| 47 | public: |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 48 | JitInstrumentationCache(size_t hot_method_threshold, size_t warm_method_threshold); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 49 | void AddSamples(Thread* self, ArtMethod* method, size_t samples) |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 50 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 51 | void CreateThreadPool(); |
| 52 | void DeleteThreadPool(); |
| 53 | |
| 54 | private: |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 55 | size_t hot_method_threshold_; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 56 | size_t warm_method_threshold_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 57 | std::unique_ptr<ThreadPool> thread_pool_; |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 58 | |
| 59 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationCache); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | class JitInstrumentationListener : public instrumentation::InstrumentationListener { |
| 63 | public: |
| 64 | explicit JitInstrumentationListener(JitInstrumentationCache* cache); |
| 65 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 66 | void MethodEntered(Thread* thread, mirror::Object* /*this_object*/, |
| 67 | ArtMethod* method, uint32_t /*dex_pc*/) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 68 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 69 | instrumentation_cache_->AddSamples(thread, method, 1); |
| 70 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 71 | void MethodExited(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 72 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 73 | const JValue& /*return_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 74 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 75 | void MethodUnwind(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 76 | ArtMethod* /*method*/, uint32_t /*dex_pc*/) OVERRIDE { } |
| 77 | void FieldRead(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 78 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 79 | ArtField* /*field*/) OVERRIDE { } |
| 80 | void FieldWritten(Thread* /*thread*/, mirror::Object* /*this_object*/, |
| 81 | ArtMethod* /*method*/, uint32_t /*dex_pc*/, |
| 82 | ArtField* /*field*/, const JValue& /*field_value*/) |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 83 | OVERRIDE { } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 84 | void ExceptionCaught(Thread* /*thread*/, |
| 85 | mirror::Throwable* /*exception_object*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 86 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 87 | void DexPcMoved(Thread* /*self*/, mirror::Object* /*this_object*/, |
| 88 | ArtMethod* /*method*/, uint32_t /*new_dex_pc*/) OVERRIDE { } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 89 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 90 | void BackwardBranch(Thread* thread, ArtMethod* method, int32_t dex_pc_offset) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 91 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 92 | CHECK_LE(dex_pc_offset, 0); |
| 93 | instrumentation_cache_->AddSamples(thread, method, 1); |
| 94 | } |
| 95 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame^] | 96 | void InvokeVirtualOrInterface(Thread* thread, |
| 97 | mirror::Object* this_object, |
| 98 | ArtMethod* caller, |
| 99 | uint32_t dex_pc, |
| 100 | ArtMethod* callee) |
| 101 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
| 102 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 103 | private: |
| 104 | JitInstrumentationCache* const instrumentation_cache_; |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 105 | |
| 106 | DISALLOW_IMPLICIT_CONSTRUCTORS(JitInstrumentationListener); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | } // namespace jit |
| 110 | } // namespace art |
| 111 | |
| 112 | #endif // ART_RUNTIME_JIT_JIT_INSTRUMENTATION_H_ |