Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [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 | #include "instrumentation.h" |
| 18 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 19 | #include "base/enums.h" |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 20 | #include "common_runtime_test.h" |
| 21 | #include "common_throws.h" |
| 22 | #include "class_linker-inl.h" |
| 23 | #include "dex_file.h" |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 24 | #include "gc/scoped_gc_critical_section.h" |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 25 | #include "handle_scope-inl.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 26 | #include "jni_internal.h" |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 27 | #include "jvalue.h" |
| 28 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 29 | #include "scoped_thread_state_change-inl.h" |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 30 | #include "thread_list.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 31 | #include "thread-inl.h" |
| 32 | #include "well_known_classes.h" |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | namespace instrumentation { |
| 36 | |
| 37 | class TestInstrumentationListener FINAL : public instrumentation::InstrumentationListener { |
| 38 | public: |
| 39 | TestInstrumentationListener() |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 40 | : received_method_enter_event(false), |
| 41 | received_method_exit_event(false), |
| 42 | received_method_exit_object_event(false), |
| 43 | received_method_unwind_event(false), |
| 44 | received_dex_pc_moved_event(false), |
| 45 | received_field_read_event(false), |
| 46 | received_field_written_event(false), |
| 47 | received_field_written_object_event(false), |
| 48 | received_exception_caught_event(false), |
| 49 | received_branch_event(false), |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 50 | received_invoke_virtual_or_interface_event(false) {} |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 51 | |
| 52 | virtual ~TestInstrumentationListener() {} |
| 53 | |
| 54 | void MethodEntered(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 55 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 56 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 57 | uint32_t dex_pc ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 58 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 59 | received_method_enter_event = true; |
| 60 | } |
| 61 | |
| 62 | void MethodExited(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 63 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
| 64 | ArtMethod* method ATTRIBUTE_UNUSED, |
| 65 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 66 | Handle<mirror::Object> return_value ATTRIBUTE_UNUSED) |
| 67 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
| 68 | received_method_exit_object_event = true; |
| 69 | } |
| 70 | |
| 71 | void MethodExited(Thread* thread ATTRIBUTE_UNUSED, |
| 72 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 73 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 74 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 75 | const JValue& return_value ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 76 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 77 | received_method_exit_event = true; |
| 78 | } |
| 79 | |
| 80 | void MethodUnwind(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 81 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 82 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 83 | uint32_t dex_pc ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 84 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 85 | received_method_unwind_event = true; |
| 86 | } |
| 87 | |
| 88 | void DexPcMoved(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 89 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 90 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 91 | uint32_t new_dex_pc ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 92 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 93 | received_dex_pc_moved_event = true; |
| 94 | } |
| 95 | |
| 96 | void FieldRead(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 97 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 98 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 99 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 100 | ArtField* field ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 101 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 102 | received_field_read_event = true; |
| 103 | } |
| 104 | |
| 105 | void FieldWritten(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 106 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
| 107 | ArtMethod* method ATTRIBUTE_UNUSED, |
| 108 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 109 | ArtField* field ATTRIBUTE_UNUSED, |
| 110 | Handle<mirror::Object> field_value ATTRIBUTE_UNUSED) |
| 111 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
| 112 | received_field_written_object_event = true; |
| 113 | } |
| 114 | |
| 115 | void FieldWritten(Thread* thread ATTRIBUTE_UNUSED, |
| 116 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 117 | ArtMethod* method ATTRIBUTE_UNUSED, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 118 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 119 | ArtField* field ATTRIBUTE_UNUSED, |
| 120 | const JValue& field_value ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 121 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 122 | received_field_written_event = true; |
| 123 | } |
| 124 | |
| 125 | void ExceptionCaught(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 126 | Handle<mirror::Throwable> exception_object ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 127 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 128 | received_exception_caught_event = true; |
| 129 | } |
| 130 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 131 | void Branch(Thread* thread ATTRIBUTE_UNUSED, |
| 132 | ArtMethod* method ATTRIBUTE_UNUSED, |
| 133 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 134 | int32_t dex_pc_offset ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 135 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 136 | received_branch_event = true; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 139 | void InvokeVirtualOrInterface(Thread* thread ATTRIBUTE_UNUSED, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 140 | Handle<mirror::Object> this_object ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 141 | ArtMethod* caller ATTRIBUTE_UNUSED, |
| 142 | uint32_t dex_pc ATTRIBUTE_UNUSED, |
| 143 | ArtMethod* callee ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 144 | OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 145 | received_invoke_virtual_or_interface_event = true; |
| 146 | } |
| 147 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 148 | void Reset() { |
| 149 | received_method_enter_event = false; |
| 150 | received_method_exit_event = false; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 151 | received_method_exit_object_event = false; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 152 | received_method_unwind_event = false; |
| 153 | received_dex_pc_moved_event = false; |
| 154 | received_field_read_event = false; |
| 155 | received_field_written_event = false; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 156 | received_field_written_object_event = false; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 157 | received_exception_caught_event = false; |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 158 | received_branch_event = false; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 159 | received_invoke_virtual_or_interface_event = false; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | bool received_method_enter_event; |
| 163 | bool received_method_exit_event; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 164 | bool received_method_exit_object_event; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 165 | bool received_method_unwind_event; |
| 166 | bool received_dex_pc_moved_event; |
| 167 | bool received_field_read_event; |
| 168 | bool received_field_written_event; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 169 | bool received_field_written_object_event; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 170 | bool received_exception_caught_event; |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 171 | bool received_branch_event; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 172 | bool received_invoke_virtual_or_interface_event; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 173 | |
| 174 | private: |
| 175 | DISALLOW_COPY_AND_ASSIGN(TestInstrumentationListener); |
| 176 | }; |
| 177 | |
| 178 | class InstrumentationTest : public CommonRuntimeTest { |
| 179 | public: |
| 180 | // Unique keys used to test Instrumentation::ConfigureStubs. |
| 181 | static constexpr const char* kClientOneKey = "TestClient1"; |
| 182 | static constexpr const char* kClientTwoKey = "TestClient2"; |
| 183 | |
| 184 | void CheckConfigureStubs(const char* key, Instrumentation::InstrumentationLevel level) { |
| 185 | ScopedObjectAccess soa(Thread::Current()); |
| 186 | instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 187 | ScopedThreadSuspension sts(soa.Self(), kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 188 | gc::ScopedGCCriticalSection gcs(soa.Self(), |
| 189 | gc::kGcCauseInstrumentation, |
| 190 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 191 | ScopedSuspendAll ssa("Instrumentation::ConfigureStubs"); |
| 192 | instr->ConfigureStubs(key, level); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | Instrumentation::InstrumentationLevel GetCurrentInstrumentationLevel() { |
| 196 | return Runtime::Current()->GetInstrumentation()->GetCurrentInstrumentationLevel(); |
| 197 | } |
| 198 | |
| 199 | size_t GetInstrumentationUserCount() { |
| 200 | ScopedObjectAccess soa(Thread::Current()); |
| 201 | return Runtime::Current()->GetInstrumentation()->requested_instrumentation_levels_.size(); |
| 202 | } |
| 203 | |
| 204 | void TestEvent(uint32_t instrumentation_event) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 205 | TestEvent(instrumentation_event, nullptr, nullptr, false); |
| 206 | } |
| 207 | |
| 208 | void TestEvent(uint32_t instrumentation_event, |
| 209 | ArtMethod* event_method, |
| 210 | ArtField* event_field, |
| 211 | bool with_object) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 212 | ScopedObjectAccess soa(Thread::Current()); |
| 213 | instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); |
| 214 | TestInstrumentationListener listener; |
| 215 | { |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 216 | ScopedThreadSuspension sts(soa.Self(), kSuspended); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 217 | ScopedSuspendAll ssa("Add instrumentation listener"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 218 | instr->AddListener(&listener, instrumentation_event); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 221 | mirror::Object* const event_obj = nullptr; |
| 222 | const uint32_t event_dex_pc = 0; |
| 223 | |
| 224 | // Check the listener is registered and is notified of the event. |
| 225 | EXPECT_TRUE(HasEventListener(instr, instrumentation_event)); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 226 | EXPECT_FALSE(DidListenerReceiveEvent(listener, instrumentation_event, with_object)); |
| 227 | ReportEvent(instr, |
| 228 | instrumentation_event, |
| 229 | soa.Self(), |
| 230 | event_method, |
| 231 | event_obj, |
| 232 | event_field, |
| 233 | event_dex_pc); |
| 234 | EXPECT_TRUE(DidListenerReceiveEvent(listener, instrumentation_event, with_object)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 235 | |
| 236 | listener.Reset(); |
| 237 | { |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 238 | ScopedThreadSuspension sts(soa.Self(), kSuspended); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 239 | ScopedSuspendAll ssa("Remove instrumentation listener"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 240 | instr->RemoveListener(&listener, instrumentation_event); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Check the listener is not registered and is not notified of the event. |
| 244 | EXPECT_FALSE(HasEventListener(instr, instrumentation_event)); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 245 | EXPECT_FALSE(DidListenerReceiveEvent(listener, instrumentation_event, with_object)); |
| 246 | ReportEvent(instr, |
| 247 | instrumentation_event, |
| 248 | soa.Self(), |
| 249 | event_method, |
| 250 | event_obj, |
| 251 | event_field, |
| 252 | event_dex_pc); |
| 253 | EXPECT_FALSE(DidListenerReceiveEvent(listener, instrumentation_event, with_object)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 256 | void DeoptimizeMethod(Thread* self, ArtMethod* method, bool enable_deoptimization) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 257 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 258 | Runtime* runtime = Runtime::Current(); |
| 259 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 260 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 261 | gc::ScopedGCCriticalSection gcs(self, |
| 262 | gc::kGcCauseInstrumentation, |
| 263 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 264 | ScopedSuspendAll ssa("Single method deoptimization"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 265 | if (enable_deoptimization) { |
| 266 | instrumentation->EnableDeoptimization(); |
| 267 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 268 | instrumentation->Deoptimize(method); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 271 | void UndeoptimizeMethod(Thread* self, ArtMethod* method, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 272 | const char* key, bool disable_deoptimization) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 273 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 274 | Runtime* runtime = Runtime::Current(); |
| 275 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 276 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 277 | gc::ScopedGCCriticalSection gcs(self, |
| 278 | gc::kGcCauseInstrumentation, |
| 279 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 280 | ScopedSuspendAll ssa("Single method undeoptimization"); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 281 | instrumentation->Undeoptimize(method); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 282 | if (disable_deoptimization) { |
| 283 | instrumentation->DisableDeoptimization(key); |
| 284 | } |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void DeoptimizeEverything(Thread* self, const char* key, bool enable_deoptimization) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 288 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 289 | Runtime* runtime = Runtime::Current(); |
| 290 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 291 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 292 | gc::ScopedGCCriticalSection gcs(self, |
| 293 | gc::kGcCauseInstrumentation, |
| 294 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 295 | ScopedSuspendAll ssa("Full deoptimization"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 296 | if (enable_deoptimization) { |
| 297 | instrumentation->EnableDeoptimization(); |
| 298 | } |
| 299 | instrumentation->DeoptimizeEverything(key); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void UndeoptimizeEverything(Thread* self, const char* key, bool disable_deoptimization) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 303 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 304 | Runtime* runtime = Runtime::Current(); |
| 305 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 306 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 307 | gc::ScopedGCCriticalSection gcs(self, |
| 308 | gc::kGcCauseInstrumentation, |
| 309 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 310 | ScopedSuspendAll ssa("Full undeoptimization"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 311 | instrumentation->UndeoptimizeEverything(key); |
| 312 | if (disable_deoptimization) { |
| 313 | instrumentation->DisableDeoptimization(key); |
| 314 | } |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void EnableMethodTracing(Thread* self, const char* key, bool needs_interpreter) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 318 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 319 | Runtime* runtime = Runtime::Current(); |
| 320 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 321 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 322 | gc::ScopedGCCriticalSection gcs(self, |
| 323 | gc::kGcCauseInstrumentation, |
| 324 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 325 | ScopedSuspendAll ssa("EnableMethodTracing"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 326 | instrumentation->EnableMethodTracing(key, needs_interpreter); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void DisableMethodTracing(Thread* self, const char* key) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 330 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 331 | Runtime* runtime = Runtime::Current(); |
| 332 | instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 333 | ScopedThreadSuspension sts(self, kSuspended); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 334 | gc::ScopedGCCriticalSection gcs(self, |
| 335 | gc::kGcCauseInstrumentation, |
| 336 | gc::kCollectorTypeInstrumentation); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 337 | ScopedSuspendAll ssa("EnableMethodTracing"); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 338 | instrumentation->DisableMethodTracing(key); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | private: |
| 342 | static bool HasEventListener(const instrumentation::Instrumentation* instr, uint32_t event_type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 343 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 344 | switch (event_type) { |
| 345 | case instrumentation::Instrumentation::kMethodEntered: |
| 346 | return instr->HasMethodEntryListeners(); |
| 347 | case instrumentation::Instrumentation::kMethodExited: |
| 348 | return instr->HasMethodExitListeners(); |
| 349 | case instrumentation::Instrumentation::kMethodUnwind: |
| 350 | return instr->HasMethodUnwindListeners(); |
| 351 | case instrumentation::Instrumentation::kDexPcMoved: |
| 352 | return instr->HasDexPcListeners(); |
| 353 | case instrumentation::Instrumentation::kFieldRead: |
| 354 | return instr->HasFieldReadListeners(); |
| 355 | case instrumentation::Instrumentation::kFieldWritten: |
| 356 | return instr->HasFieldWriteListeners(); |
| 357 | case instrumentation::Instrumentation::kExceptionCaught: |
| 358 | return instr->HasExceptionCaughtListeners(); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 359 | case instrumentation::Instrumentation::kBranch: |
| 360 | return instr->HasBranchListeners(); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 361 | case instrumentation::Instrumentation::kInvokeVirtualOrInterface: |
| 362 | return instr->HasInvokeVirtualOrInterfaceListeners(); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 363 | default: |
| 364 | LOG(FATAL) << "Unknown instrumentation event " << event_type; |
| 365 | UNREACHABLE(); |
| 366 | } |
| 367 | } |
| 368 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 369 | static void ReportEvent(const instrumentation::Instrumentation* instr, |
| 370 | uint32_t event_type, |
| 371 | Thread* self, |
| 372 | ArtMethod* method, |
| 373 | mirror::Object* obj, |
| 374 | ArtField* field, |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 375 | uint32_t dex_pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 376 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 377 | switch (event_type) { |
| 378 | case instrumentation::Instrumentation::kMethodEntered: |
| 379 | instr->MethodEnterEvent(self, obj, method, dex_pc); |
| 380 | break; |
| 381 | case instrumentation::Instrumentation::kMethodExited: { |
| 382 | JValue value; |
| 383 | instr->MethodExitEvent(self, obj, method, dex_pc, value); |
| 384 | break; |
| 385 | } |
| 386 | case instrumentation::Instrumentation::kMethodUnwind: |
| 387 | instr->MethodUnwindEvent(self, obj, method, dex_pc); |
| 388 | break; |
| 389 | case instrumentation::Instrumentation::kDexPcMoved: |
| 390 | instr->DexPcMovedEvent(self, obj, method, dex_pc); |
| 391 | break; |
| 392 | case instrumentation::Instrumentation::kFieldRead: |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 393 | instr->FieldReadEvent(self, obj, method, dex_pc, field); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 394 | break; |
| 395 | case instrumentation::Instrumentation::kFieldWritten: { |
| 396 | JValue value; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 397 | instr->FieldWriteEvent(self, obj, method, dex_pc, field, value); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 398 | break; |
| 399 | } |
| 400 | case instrumentation::Instrumentation::kExceptionCaught: { |
| 401 | ThrowArithmeticExceptionDivideByZero(); |
| 402 | mirror::Throwable* event_exception = self->GetException(); |
| 403 | instr->ExceptionCaughtEvent(self, event_exception); |
| 404 | self->ClearException(); |
| 405 | break; |
| 406 | } |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 407 | case instrumentation::Instrumentation::kBranch: |
| 408 | instr->Branch(self, method, dex_pc, -1); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 409 | break; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 410 | case instrumentation::Instrumentation::kInvokeVirtualOrInterface: |
| 411 | instr->InvokeVirtualOrInterface(self, obj, method, dex_pc, method); |
| 412 | break; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 413 | default: |
| 414 | LOG(FATAL) << "Unknown instrumentation event " << event_type; |
| 415 | UNREACHABLE(); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | static bool DidListenerReceiveEvent(const TestInstrumentationListener& listener, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 420 | uint32_t event_type, |
| 421 | bool with_object) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 422 | switch (event_type) { |
| 423 | case instrumentation::Instrumentation::kMethodEntered: |
| 424 | return listener.received_method_enter_event; |
| 425 | case instrumentation::Instrumentation::kMethodExited: |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 426 | return (!with_object && listener.received_method_exit_event) || |
| 427 | (with_object && listener.received_method_exit_object_event); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 428 | case instrumentation::Instrumentation::kMethodUnwind: |
| 429 | return listener.received_method_unwind_event; |
| 430 | case instrumentation::Instrumentation::kDexPcMoved: |
| 431 | return listener.received_dex_pc_moved_event; |
| 432 | case instrumentation::Instrumentation::kFieldRead: |
| 433 | return listener.received_field_read_event; |
| 434 | case instrumentation::Instrumentation::kFieldWritten: |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 435 | return (!with_object && listener.received_field_written_event) || |
| 436 | (with_object && listener.received_field_written_object_event); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 437 | case instrumentation::Instrumentation::kExceptionCaught: |
| 438 | return listener.received_exception_caught_event; |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 439 | case instrumentation::Instrumentation::kBranch: |
| 440 | return listener.received_branch_event; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 441 | case instrumentation::Instrumentation::kInvokeVirtualOrInterface: |
| 442 | return listener.received_invoke_virtual_or_interface_event; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 443 | default: |
| 444 | LOG(FATAL) << "Unknown instrumentation event " << event_type; |
| 445 | UNREACHABLE(); |
| 446 | } |
| 447 | } |
| 448 | }; |
| 449 | |
| 450 | TEST_F(InstrumentationTest, NoInstrumentation) { |
| 451 | ScopedObjectAccess soa(Thread::Current()); |
| 452 | instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); |
| 453 | ASSERT_NE(instr, nullptr); |
| 454 | |
| 455 | EXPECT_FALSE(instr->AreExitStubsInstalled()); |
| 456 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 457 | EXPECT_FALSE(instr->IsActive()); |
| 458 | EXPECT_FALSE(instr->ShouldNotifyMethodEnterExitEvents()); |
| 459 | |
| 460 | // Test interpreter table is the default one. |
| 461 | EXPECT_EQ(instrumentation::kMainHandlerTable, instr->GetInterpreterHandlerTable()); |
| 462 | |
| 463 | // Check there is no registered listener. |
| 464 | EXPECT_FALSE(instr->HasDexPcListeners()); |
| 465 | EXPECT_FALSE(instr->HasExceptionCaughtListeners()); |
| 466 | EXPECT_FALSE(instr->HasFieldReadListeners()); |
| 467 | EXPECT_FALSE(instr->HasFieldWriteListeners()); |
| 468 | EXPECT_FALSE(instr->HasMethodEntryListeners()); |
| 469 | EXPECT_FALSE(instr->HasMethodExitListeners()); |
| 470 | EXPECT_FALSE(instr->IsActive()); |
| 471 | } |
| 472 | |
| 473 | // Test instrumentation listeners for each event. |
| 474 | TEST_F(InstrumentationTest, MethodEntryEvent) { |
| 475 | TestEvent(instrumentation::Instrumentation::kMethodEntered); |
| 476 | } |
| 477 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 478 | TEST_F(InstrumentationTest, MethodExitObjectEvent) { |
| 479 | ScopedObjectAccess soa(Thread::Current()); |
| 480 | jobject class_loader = LoadDex("Instrumentation"); |
| 481 | Runtime* const runtime = Runtime::Current(); |
| 482 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 483 | StackHandleScope<1> hs(soa.Self()); |
| 484 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
| 485 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 486 | ASSERT_TRUE(klass != nullptr); |
| 487 | ArtMethod* method = klass->FindDeclaredDirectMethod("returnReference", |
| 488 | "()Ljava/lang/Object;", |
| 489 | kRuntimePointerSize); |
| 490 | ASSERT_TRUE(method != nullptr); |
| 491 | TestEvent(instrumentation::Instrumentation::kMethodExited, |
| 492 | /*event_method*/ method, |
| 493 | /*event_field*/ nullptr, |
| 494 | /*with_object*/ true); |
| 495 | } |
| 496 | |
| 497 | TEST_F(InstrumentationTest, MethodExitPrimEvent) { |
| 498 | ScopedObjectAccess soa(Thread::Current()); |
| 499 | jobject class_loader = LoadDex("Instrumentation"); |
| 500 | Runtime* const runtime = Runtime::Current(); |
| 501 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 502 | StackHandleScope<1> hs(soa.Self()); |
| 503 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
| 504 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 505 | ASSERT_TRUE(klass != nullptr); |
| 506 | ArtMethod* method = klass->FindDeclaredDirectMethod("returnPrimitive", |
| 507 | "()I", |
| 508 | kRuntimePointerSize); |
| 509 | ASSERT_TRUE(method != nullptr); |
| 510 | TestEvent(instrumentation::Instrumentation::kMethodExited, |
| 511 | /*event_method*/ method, |
| 512 | /*event_field*/ nullptr, |
| 513 | /*with_object*/ false); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | TEST_F(InstrumentationTest, MethodUnwindEvent) { |
| 517 | TestEvent(instrumentation::Instrumentation::kMethodUnwind); |
| 518 | } |
| 519 | |
| 520 | TEST_F(InstrumentationTest, DexPcMovedEvent) { |
| 521 | TestEvent(instrumentation::Instrumentation::kDexPcMoved); |
| 522 | } |
| 523 | |
| 524 | TEST_F(InstrumentationTest, FieldReadEvent) { |
| 525 | TestEvent(instrumentation::Instrumentation::kFieldRead); |
| 526 | } |
| 527 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame^] | 528 | TEST_F(InstrumentationTest, FieldWriteObjectEvent) { |
| 529 | ScopedObjectAccess soa(Thread::Current()); |
| 530 | jobject class_loader = LoadDex("Instrumentation"); |
| 531 | Runtime* const runtime = Runtime::Current(); |
| 532 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 533 | StackHandleScope<1> hs(soa.Self()); |
| 534 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
| 535 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 536 | ASSERT_TRUE(klass != nullptr); |
| 537 | ArtField* field = klass->FindDeclaredStaticField("referenceField", "Ljava/lang/Object;"); |
| 538 | ASSERT_TRUE(field != nullptr); |
| 539 | |
| 540 | TestEvent(instrumentation::Instrumentation::kFieldWritten, |
| 541 | /*event_method*/ nullptr, |
| 542 | /*event_field*/ field, |
| 543 | /*with_object*/ true); |
| 544 | } |
| 545 | |
| 546 | TEST_F(InstrumentationTest, FieldWritePrimEvent) { |
| 547 | ScopedObjectAccess soa(Thread::Current()); |
| 548 | jobject class_loader = LoadDex("Instrumentation"); |
| 549 | Runtime* const runtime = Runtime::Current(); |
| 550 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 551 | StackHandleScope<1> hs(soa.Self()); |
| 552 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
| 553 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 554 | ASSERT_TRUE(klass != nullptr); |
| 555 | ArtField* field = klass->FindDeclaredStaticField("primitiveField", "I"); |
| 556 | ASSERT_TRUE(field != nullptr); |
| 557 | |
| 558 | TestEvent(instrumentation::Instrumentation::kFieldWritten, |
| 559 | /*event_method*/ nullptr, |
| 560 | /*event_field*/ field, |
| 561 | /*with_object*/ false); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | TEST_F(InstrumentationTest, ExceptionCaughtEvent) { |
| 565 | TestEvent(instrumentation::Instrumentation::kExceptionCaught); |
| 566 | } |
| 567 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 568 | TEST_F(InstrumentationTest, BranchEvent) { |
| 569 | TestEvent(instrumentation::Instrumentation::kBranch); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 572 | TEST_F(InstrumentationTest, InvokeVirtualOrInterfaceEvent) { |
| 573 | TestEvent(instrumentation::Instrumentation::kInvokeVirtualOrInterface); |
| 574 | } |
| 575 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 576 | TEST_F(InstrumentationTest, DeoptimizeDirectMethod) { |
| 577 | ScopedObjectAccess soa(Thread::Current()); |
| 578 | jobject class_loader = LoadDex("Instrumentation"); |
| 579 | Runtime* const runtime = Runtime::Current(); |
| 580 | instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); |
| 581 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 582 | StackHandleScope<1> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 583 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 584 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 585 | ASSERT_TRUE(klass != nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 586 | ArtMethod* method_to_deoptimize = klass->FindDeclaredDirectMethod("instanceMethod", "()V", |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 587 | kRuntimePointerSize); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 588 | ASSERT_TRUE(method_to_deoptimize != nullptr); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 589 | |
| 590 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 591 | EXPECT_FALSE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 592 | |
| 593 | DeoptimizeMethod(soa.Self(), method_to_deoptimize, true); |
| 594 | |
| 595 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 596 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 597 | EXPECT_TRUE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 598 | |
| 599 | constexpr const char* instrumentation_key = "DeoptimizeDirectMethod"; |
| 600 | UndeoptimizeMethod(soa.Self(), method_to_deoptimize, instrumentation_key, true); |
| 601 | |
| 602 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 603 | EXPECT_FALSE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | TEST_F(InstrumentationTest, FullDeoptimization) { |
| 607 | ScopedObjectAccess soa(Thread::Current()); |
| 608 | Runtime* const runtime = Runtime::Current(); |
| 609 | instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); |
| 610 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 611 | |
| 612 | constexpr const char* instrumentation_key = "FullDeoptimization"; |
| 613 | DeoptimizeEverything(soa.Self(), instrumentation_key, true); |
| 614 | |
| 615 | EXPECT_TRUE(instr->AreAllMethodsDeoptimized()); |
| 616 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
| 617 | |
| 618 | UndeoptimizeEverything(soa.Self(), instrumentation_key, true); |
| 619 | |
| 620 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 621 | } |
| 622 | |
| 623 | TEST_F(InstrumentationTest, MixedDeoptimization) { |
| 624 | ScopedObjectAccess soa(Thread::Current()); |
| 625 | jobject class_loader = LoadDex("Instrumentation"); |
| 626 | Runtime* const runtime = Runtime::Current(); |
| 627 | instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); |
| 628 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 629 | StackHandleScope<1> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 630 | Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 631 | mirror::Class* klass = class_linker->FindClass(soa.Self(), "LInstrumentation;", loader); |
| 632 | ASSERT_TRUE(klass != nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 633 | ArtMethod* method_to_deoptimize = klass->FindDeclaredDirectMethod("instanceMethod", "()V", |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 634 | kRuntimePointerSize); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 635 | ASSERT_TRUE(method_to_deoptimize != nullptr); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 636 | |
| 637 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 638 | EXPECT_FALSE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 639 | |
| 640 | DeoptimizeMethod(soa.Self(), method_to_deoptimize, true); |
| 641 | // Deoptimizing a method does not change instrumentation level. |
| 642 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, |
| 643 | GetCurrentInstrumentationLevel()); |
| 644 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 645 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 646 | EXPECT_TRUE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 647 | |
| 648 | constexpr const char* instrumentation_key = "MixedDeoptimization"; |
| 649 | DeoptimizeEverything(soa.Self(), instrumentation_key, false); |
| 650 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, |
| 651 | GetCurrentInstrumentationLevel()); |
| 652 | EXPECT_TRUE(instr->AreAllMethodsDeoptimized()); |
| 653 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 654 | EXPECT_TRUE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 655 | |
| 656 | UndeoptimizeEverything(soa.Self(), instrumentation_key, false); |
| 657 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, |
| 658 | GetCurrentInstrumentationLevel()); |
| 659 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 660 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 661 | EXPECT_TRUE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 662 | |
| 663 | UndeoptimizeMethod(soa.Self(), method_to_deoptimize, instrumentation_key, true); |
| 664 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, |
| 665 | GetCurrentInstrumentationLevel()); |
| 666 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 667 | EXPECT_FALSE(instr->IsDeoptimized(method_to_deoptimize)); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | TEST_F(InstrumentationTest, MethodTracing_Interpreter) { |
| 671 | ScopedObjectAccess soa(Thread::Current()); |
| 672 | Runtime* const runtime = Runtime::Current(); |
| 673 | instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); |
| 674 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 675 | |
| 676 | constexpr const char* instrumentation_key = "MethodTracing"; |
| 677 | EnableMethodTracing(soa.Self(), instrumentation_key, true); |
| 678 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, |
| 679 | GetCurrentInstrumentationLevel()); |
| 680 | EXPECT_TRUE(instr->AreAllMethodsDeoptimized()); |
| 681 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
| 682 | |
| 683 | DisableMethodTracing(soa.Self(), instrumentation_key); |
| 684 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, |
| 685 | GetCurrentInstrumentationLevel()); |
| 686 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 687 | } |
| 688 | |
| 689 | TEST_F(InstrumentationTest, MethodTracing_InstrumentationEntryExitStubs) { |
| 690 | ScopedObjectAccess soa(Thread::Current()); |
| 691 | Runtime* const runtime = Runtime::Current(); |
| 692 | instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); |
| 693 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 694 | |
| 695 | constexpr const char* instrumentation_key = "MethodTracing"; |
| 696 | EnableMethodTracing(soa.Self(), instrumentation_key, false); |
| 697 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 698 | GetCurrentInstrumentationLevel()); |
| 699 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 700 | EXPECT_TRUE(instr->AreExitStubsInstalled()); |
| 701 | |
| 702 | DisableMethodTracing(soa.Self(), instrumentation_key); |
| 703 | EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, |
| 704 | GetCurrentInstrumentationLevel()); |
| 705 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); |
| 706 | } |
| 707 | |
| 708 | // We use a macro to print the line number where the test is failing. |
| 709 | #define CHECK_INSTRUMENTATION(_level, _user_count) \ |
| 710 | do { \ |
| 711 | Instrumentation* const instr = Runtime::Current()->GetInstrumentation(); \ |
| 712 | bool interpreter = \ |
Chih-Hung Hsieh | 1a0de6a | 2016-08-26 15:06:11 -0700 | [diff] [blame] | 713 | ((_level) == Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); \ |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 714 | EXPECT_EQ(_level, GetCurrentInstrumentationLevel()); \ |
| 715 | EXPECT_EQ(_user_count, GetInstrumentationUserCount()); \ |
| 716 | if (instr->IsForcedInterpretOnly()) { \ |
| 717 | EXPECT_TRUE(instr->InterpretOnly()); \ |
| 718 | } else if (interpreter) { \ |
| 719 | EXPECT_TRUE(instr->InterpretOnly()); \ |
| 720 | } else { \ |
| 721 | EXPECT_FALSE(instr->InterpretOnly()); \ |
| 722 | } \ |
| 723 | if (interpreter) { \ |
| 724 | EXPECT_TRUE(instr->AreAllMethodsDeoptimized()); \ |
| 725 | } else { \ |
| 726 | EXPECT_FALSE(instr->AreAllMethodsDeoptimized()); \ |
| 727 | } \ |
| 728 | } while (false) |
| 729 | |
| 730 | TEST_F(InstrumentationTest, ConfigureStubs_Nothing) { |
| 731 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 732 | |
| 733 | // Check no-op. |
| 734 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 735 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 736 | } |
| 737 | |
| 738 | TEST_F(InstrumentationTest, ConfigureStubs_InstrumentationStubs) { |
| 739 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 740 | |
| 741 | // Check we can switch to instrumentation stubs |
| 742 | CheckConfigureStubs(kClientOneKey, |
| 743 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 744 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 745 | 1U); |
| 746 | |
| 747 | // Check we can disable instrumentation. |
| 748 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 749 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 750 | } |
| 751 | |
| 752 | TEST_F(InstrumentationTest, ConfigureStubs_Interpreter) { |
| 753 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 754 | |
| 755 | // Check we can switch to interpreter |
| 756 | CheckConfigureStubs(kClientOneKey, |
| 757 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 758 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 759 | |
| 760 | // Check we can disable instrumentation. |
| 761 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 762 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 763 | } |
| 764 | |
| 765 | TEST_F(InstrumentationTest, ConfigureStubs_InstrumentationStubsToInterpreter) { |
| 766 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 767 | |
| 768 | // Configure stubs with instrumentation stubs. |
| 769 | CheckConfigureStubs(kClientOneKey, |
| 770 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 771 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 772 | 1U); |
| 773 | |
| 774 | // Configure stubs with interpreter. |
| 775 | CheckConfigureStubs(kClientOneKey, |
| 776 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 777 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 778 | |
| 779 | // Check we can disable instrumentation. |
| 780 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 781 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 782 | } |
| 783 | |
| 784 | TEST_F(InstrumentationTest, ConfigureStubs_InterpreterToInstrumentationStubs) { |
| 785 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 786 | |
| 787 | // Configure stubs with interpreter. |
| 788 | CheckConfigureStubs(kClientOneKey, |
| 789 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 790 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 791 | |
| 792 | // Configure stubs with instrumentation stubs. |
| 793 | CheckConfigureStubs(kClientOneKey, |
| 794 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 795 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 796 | 1U); |
| 797 | |
| 798 | // Check we can disable instrumentation. |
| 799 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 800 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 801 | } |
| 802 | |
| 803 | TEST_F(InstrumentationTest, |
| 804 | ConfigureStubs_InstrumentationStubsToInterpreterToInstrumentationStubs) { |
| 805 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 806 | |
| 807 | // Configure stubs with instrumentation stubs. |
| 808 | CheckConfigureStubs(kClientOneKey, |
| 809 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 810 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 811 | 1U); |
| 812 | |
| 813 | // Configure stubs with interpreter. |
| 814 | CheckConfigureStubs(kClientOneKey, |
| 815 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 816 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 817 | |
| 818 | // Configure stubs with instrumentation stubs again. |
| 819 | CheckConfigureStubs(kClientOneKey, |
| 820 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 821 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 822 | 1U); |
| 823 | |
| 824 | // Check we can disable instrumentation. |
| 825 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 826 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 827 | } |
| 828 | |
| 829 | TEST_F(InstrumentationTest, MultiConfigureStubs_Nothing) { |
| 830 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 831 | |
| 832 | // Check kInstrumentNothing with two clients. |
| 833 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 834 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 835 | |
| 836 | CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 837 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 838 | } |
| 839 | |
| 840 | TEST_F(InstrumentationTest, MultiConfigureStubs_InstrumentationStubs) { |
| 841 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 842 | |
| 843 | // Configure stubs with instrumentation stubs for 1st client. |
| 844 | CheckConfigureStubs(kClientOneKey, |
| 845 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 846 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 847 | 1U); |
| 848 | |
| 849 | // Configure stubs with instrumentation stubs for 2nd client. |
| 850 | CheckConfigureStubs(kClientTwoKey, |
| 851 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 852 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 853 | 2U); |
| 854 | |
| 855 | // 1st client requests instrumentation deactivation but 2nd client still needs |
| 856 | // instrumentation stubs. |
| 857 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 858 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 859 | 1U); |
| 860 | |
| 861 | // 2nd client requests instrumentation deactivation |
| 862 | CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 863 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 864 | } |
| 865 | |
| 866 | TEST_F(InstrumentationTest, MultiConfigureStubs_Interpreter) { |
| 867 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 868 | |
| 869 | // Configure stubs with interpreter for 1st client. |
| 870 | CheckConfigureStubs(kClientOneKey, |
| 871 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 872 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 873 | |
| 874 | // Configure stubs with interpreter for 2nd client. |
| 875 | CheckConfigureStubs(kClientTwoKey, |
| 876 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 877 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); |
| 878 | |
| 879 | // 1st client requests instrumentation deactivation but 2nd client still needs interpreter. |
| 880 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 881 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 882 | |
| 883 | // 2nd client requests instrumentation deactivation |
| 884 | CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 885 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 886 | } |
| 887 | |
| 888 | TEST_F(InstrumentationTest, MultiConfigureStubs_InstrumentationStubsThenInterpreter) { |
| 889 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 890 | |
| 891 | // Configure stubs with instrumentation stubs for 1st client. |
| 892 | CheckConfigureStubs(kClientOneKey, |
| 893 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 894 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 895 | 1U); |
| 896 | |
| 897 | // Configure stubs with interpreter for 2nd client. |
| 898 | CheckConfigureStubs(kClientTwoKey, |
| 899 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 900 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); |
| 901 | |
| 902 | // 1st client requests instrumentation deactivation but 2nd client still needs interpreter. |
| 903 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 904 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 905 | |
| 906 | // 2nd client requests instrumentation deactivation |
| 907 | CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 908 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 909 | } |
| 910 | |
| 911 | TEST_F(InstrumentationTest, MultiConfigureStubs_InterpreterThenInstrumentationStubs) { |
| 912 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 913 | |
| 914 | // Configure stubs with interpreter for 1st client. |
| 915 | CheckConfigureStubs(kClientOneKey, |
| 916 | Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); |
| 917 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); |
| 918 | |
| 919 | // Configure stubs with instrumentation stubs for 2nd client. |
| 920 | CheckConfigureStubs(kClientTwoKey, |
| 921 | Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 922 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); |
| 923 | |
| 924 | // 1st client requests instrumentation deactivation but 2nd client still needs |
| 925 | // instrumentation stubs. |
| 926 | CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 927 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInstrumentationStubs, |
| 928 | 1U); |
| 929 | |
| 930 | // 2nd client requests instrumentation deactivation |
| 931 | CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); |
| 932 | CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); |
| 933 | } |
| 934 | |
| 935 | } // namespace instrumentation |
| 936 | } // namespace art |