Lines Matching +full:state +full:- +full:of +full:- +full:the +full:- +full:art

1 /* Copyright (C) 2016 The Android Open Source Project
4 * This file implements interfaces from the file jvmti.h. This implementation
5 * is licensed under the same terms as the file jvmti.h. The
6 * copyright and license information for the file jvmti.h follows.
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Oracle designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Oracle in the LICENSE file that accompanied this code.
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
40 #include "android-base/thread_annotations.h"
42 #include "art_field-inl.h"
44 #include "art_method-inl.h"
49 #include "events-inl.h"
54 #include "handle_scope-inl.h"
58 #include "jni/jni_env_ext-inl.h"
60 #include "jvalue-inl.h"
64 #include "mirror/object-inl.h"
65 #include "monitor-inl.h"
68 #include "reflective_handle_scope-inl.h"
70 #include "scoped_thread_state_change-inl.h"
73 #include "thread-inl.h"
83 if (art::kIsDebugBuild) { in CopyExtensionsFrom()
133 EventMask& EventMasks::GetEventMask(art::Thread* thread) { in GetEventMask()
141 unique_thread.second == static_cast<uint32_t>(thread->GetTid())) { in GetEventMask()
146 // TODO: Remove old UniqueThread with the same pointer, if exists. in GetEventMask()
148 thread_event_masks.emplace_back(UniqueThread(thread, thread->GetTid()), EventMask()); in GetEventMask()
152 EventMask* EventMasks::GetEventMaskOrNull(art::Thread* thread) { in GetEventMaskOrNull()
160 unique_thread.second == static_cast<uint32_t>(thread->GetTid())) { in GetEventMaskOrNull()
169 void EventMasks::EnableEvent(ArtJvmTiEnv* env, art::Thread* thread, ArtJvmtiEvent event) { in EnableEvent()
170 DCHECK_EQ(&env->event_masks, this); in EnableEvent()
171 env->event_info_mutex_.AssertExclusiveHeld(art::Thread::Current()); in EnableEvent()
179 void EventMasks::DisableEvent(ArtJvmTiEnv* env, art::Thread* thread, ArtJvmtiEvent event) { in DisableEvent()
180 DCHECK_EQ(&env->event_masks, this); in DisableEvent()
181 env->event_info_mutex_.AssertExclusiveHeld(art::Thread::Current()); in DisableEvent()
185 // Regenerate union for the event. in DisableEvent()
199 // If we are giving this env the retransform classes cap we need to switch all events of in HandleChangedCapabilities()
227 art::WriterMutexLock mu(art::Thread::Current(), envs_lock_); in RegisterArtJvmTiEnv()
232 art::WriterMutexLock mu(art::Thread::Current(), envs_lock_); in RemoveArtJvmTiEnv()
233 // Since we might be currently iterating over the envs list we cannot actually erase elements. in RemoveArtJvmTiEnv()
265 static Type AddLocalRef(art::JNIEnvExt* e, art::ObjPtr<art::mirror::Object> obj) in AddLocalRef()
266 REQUIRES_SHARED(art::Locks::mutator_lock_) { in AddLocalRef()
267 return (obj == nullptr) ? nullptr : e->AddLocalReference<Type>(obj); in AddLocalRef()
272 art::Thread* self, in RunEventCallback()
273 art::JNIEnvExt* jnienv, in RunEventCallback()
275 REQUIRES_SHARED(art::Locks::mutator_lock_) { in RunEventCallback()
276 ScopedLocalRef<jthread> thread_jni(jnienv, AddLocalRef<jthread>(jnienv, self->GetPeer())); in RunEventCallback()
277 handler->DispatchEvent<kEvent>(self, in RunEventCallback()
283 static void SetupDdmTracking(art::DdmCallback* listener, bool enable) { in SetupDdmTracking()
284 art::ScopedObjectAccess soa(art::Thread::Current()); in SetupDdmTracking()
286 art::Runtime::Current()->GetRuntimeCallbacks()->AddDdmCallback(listener); in SetupDdmTracking()
288 art::Runtime::Current()->GetRuntimeCallbacks()->RemoveDdmCallback(listener); in SetupDdmTracking()
292 class JvmtiDdmChunkListener : public art::DdmCallback {
296 void DdmPublishChunk(uint32_t type, const art::ArrayRef<const uint8_t>& data) in DdmPublishChunk()
297 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in DdmPublishChunk()
298 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kDdmPublishChunk)) { in DdmPublishChunk()
299 art::Thread* self = art::Thread::Current(); in DdmPublishChunk()
300 handler_->DispatchEvent<ArtJvmtiEvent::kDdmPublishChunk>( in DdmPublishChunk()
318 void ObjectAllocated(art::Thread* self, art::ObjPtr<art::mirror::Object>* obj, size_t byte_count) in ObjectAllocated()
319 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in ObjectAllocated()
320 DCHECK_EQ(self, art::Thread::Current()); in ObjectAllocated()
322 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kVmObjectAlloc)) { in ObjectAllocated()
323 art::StackHandleScope<1> hs(self); in ObjectAllocated()
332 art::JNIEnvExt* jni_env = self->GetJniEnv(); in ObjectAllocated()
334 jni_env, jni_env->AddLocalReference<jobject>(*obj)); in ObjectAllocated()
336 jni_env, jni_env->AddLocalReference<jclass>(obj->Ptr()->GetClass())); in ObjectAllocated()
352 // We must not hold the mutator lock here, but if we're in FastJNI, for example, we might. For in SetupObjectAllocationTracking()
354 art::ScopedObjectAccess soa(art::Thread::Current()); in SetupObjectAllocationTracking()
356 AllocationManager::Get()->EnableAllocationCallback(soa.Self()); in SetupObjectAllocationTracking()
358 AllocationManager::Get()->DisableAllocationCallback(soa.Self()); in SetupObjectAllocationTracking()
362 class JvmtiMonitorListener : public art::MonitorCallback {
366 void MonitorContendedLocking(art::Monitor* m) in MonitorContendedLocking()
367 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in MonitorContendedLocking()
368 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorContendedEnter)) { in MonitorContendedLocking()
369 art::Thread* self = art::Thread::Current(); in MonitorContendedLocking()
370 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MonitorContendedLocking()
371 ScopedLocalRef<jobject> mon(jnienv, AddLocalRef<jobject>(jnienv, m->GetObject())); in MonitorContendedLocking()
380 void MonitorContendedLocked(art::Monitor* m) in MonitorContendedLocked()
381 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in MonitorContendedLocked()
382 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorContendedEntered)) { in MonitorContendedLocked()
383 art::Thread* self = art::Thread::Current(); in MonitorContendedLocked()
384 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MonitorContendedLocked()
385 ScopedLocalRef<jobject> mon(jnienv, AddLocalRef<jobject>(jnienv, m->GetObject())); in MonitorContendedLocked()
394 void ObjectWaitStart(art::Handle<art::mirror::Object> obj, int64_t timeout) in ObjectWaitStart()
395 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in ObjectWaitStart()
396 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorWait)) { in ObjectWaitStart()
397 art::Thread* self = art::Thread::Current(); in ObjectWaitStart()
398 art::JNIEnvExt* jnienv = self->GetJniEnv(); in ObjectWaitStart()
410 // Our interpretation of the spec is that the JVMTI_EVENT_MONITOR_WAITED will be sent immediately
411 // after a thread has woken up from a sleep caused by a call to Object#wait. If the thread will
412 // never go to sleep (due to not having the lock, having bad arguments, or having an exception
415 // This does not fully match the RI semantics. Specifically, we will not send the
416 // JVMTI_EVENT_MONITOR_WAITED event in one situation where the RI would, there was an exception in
417 // the JVMTI_EVENT_MONITOR_WAIT event but otherwise the call was fine. In that case the RI would
421 void MonitorWaitFinished(art::Monitor* m, bool timeout) in MonitorWaitFinished()
422 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in MonitorWaitFinished()
423 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorWaited)) { in MonitorWaitFinished()
424 art::Thread* self = art::Thread::Current(); in MonitorWaitFinished()
425 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MonitorWaitFinished()
426 ScopedLocalRef<jobject> mon(jnienv, AddLocalRef<jobject>(jnienv, m->GetObject())); in MonitorWaitFinished()
440 class JvmtiParkListener : public art::ParkCallback {
445 override REQUIRES_SHARED(art::Locks::mutator_lock_) { in ThreadParkStart()
446 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorWait)) { in ThreadParkStart()
447 art::Thread* self = art::Thread::Current(); in ThreadParkStart()
448 art::JNIEnvExt* jnienv = self->GetJniEnv(); in ThreadParkStart()
449 art::ObjPtr<art::mirror::Object> blocker_obj = in ThreadParkStart()
450 art::WellKnownClasses::java_lang_Thread_parkBlocker->GetObj(self->GetPeer()); in ThreadParkStart()
452 blocker_obj = self->GetPeer(); in ThreadParkStart()
461 // If we were instructed to park for a nonzero number of nanoseconds, but not enough in ThreadParkStart()
472 timeout_ms = timeout - now; in ThreadParkStart()
475 // the past or the current time will return immediately, so emulate in ThreadParkStart()
476 // the shortest possible wait event. in ThreadParkStart()
491 // Our interpretation of the spec is that the JVMTI_EVENT_MONITOR_WAITED will be sent immediately
492 // after a thread has woken up from a sleep caused by a call to Object#wait. If the thread will
493 // never go to sleep (due to not having the lock, having bad arguments, or having an exception
496 // This does not fully match the RI semantics. Specifically, we will not send the
497 // JVMTI_EVENT_MONITOR_WAITED event in one situation where the RI would, there was an exception in
498 // the JVMTI_EVENT_MONITOR_WAIT event but otherwise the call was fine. In that case the RI would
502 void ThreadParkFinished(bool timeout) override REQUIRES_SHARED(art::Locks::mutator_lock_) { in ThreadParkFinished()
503 if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMonitorWaited)) { in ThreadParkFinished()
504 art::Thread* self = art::Thread::Current(); in ThreadParkFinished()
505 art::JNIEnvExt* jnienv = self->GetJniEnv(); in ThreadParkFinished()
506 art::ObjPtr<art::mirror::Object> blocker_obj = in ThreadParkFinished()
507 art::WellKnownClasses::java_lang_Thread_parkBlocker->GetObj(self->GetPeer()); in ThreadParkFinished()
509 blocker_obj = self->GetPeer(); in ThreadParkFinished()
525 static void SetupMonitorListener(art::MonitorCallback* monitor_listener, art::ParkCallback* park_li… in SetupMonitorListener()
526 // We must not hold the mutator lock here, but if we're in FastJNI, for example, we might. For in SetupMonitorListener()
528 art::ScopedObjectAccess soa(art::Thread::Current()); in SetupMonitorListener()
530 art::Runtime::Current()->GetRuntimeCallbacks()->AddMonitorCallback(monitor_listener); in SetupMonitorListener()
531 art::Runtime::Current()->GetRuntimeCallbacks()->AddParkCallback(park_listener); in SetupMonitorListener()
533 art::Runtime::Current()->GetRuntimeCallbacks()->RemoveMonitorCallback(monitor_listener); in SetupMonitorListener()
534 art::Runtime::Current()->GetRuntimeCallbacks()->RemoveParkCallback(park_listener); in SetupMonitorListener()
539 class JvmtiGcPauseListener : public art::gc::GcPauseListener {
547 handler_->DispatchEvent<ArtJvmtiEvent::kGarbageCollectionStart>(art::Thread::Current()); in StartPause()
551 handler_->DispatchEvent<ArtJvmtiEvent::kGarbageCollectionFinish>(art::Thread::Current()); in EndPause()
573 bool old_state = listener->IsEnabled(); in SetupGcPauseTracking()
576 listener->SetStartEnabled(enable); in SetupGcPauseTracking()
578 listener->SetFinishEnabled(enable); in SetupGcPauseTracking()
581 bool new_state = listener->IsEnabled(); in SetupGcPauseTracking()
585 art::Runtime::Current()->GetHeap()->SetGcPauseListener(listener); in SetupGcPauseTracking()
587 art::Runtime::Current()->GetHeap()->RemoveGcPauseListener(); in SetupGcPauseTracking()
592 class JvmtiMethodTraceListener final : public art::instrumentation::InstrumentationListener {
597 art::LockLevel::kGenericBottomLock) {} in JvmtiMethodTraceListener()
599 void AddDelayedNonStandardExitEvent(const art::ShadowFrame* frame, bool is_object, jvalue val) in AddDelayedNonStandardExitEvent()
600 REQUIRES_SHARED(art::Locks::mutator_lock_) in AddDelayedNonStandardExitEvent()
601 REQUIRES(art::Locks::user_code_suspension_lock_, art::Locks::thread_list_lock_) { in AddDelayedNonStandardExitEvent()
602 art::Thread* self = art::Thread::Current(); in AddDelayedNonStandardExitEvent()
604 jobject new_val = is_object ? self->GetJniEnv()->NewGlobalRef(val.l) : nullptr; in AddDelayedNonStandardExitEvent()
606 art::MutexLock mu(self, non_standard_exits_lock_); in AddDelayedNonStandardExitEvent()
616 to_cleanup = non_standard_exits_.find(frame)->second.return_val_obj_; in AddDelayedNonStandardExitEvent()
620 self->GetJniEnv()->DeleteGlobalRef(to_cleanup); in AddDelayedNonStandardExitEvent()
623 // Call-back for when a method is entered.
624 void MethodEntered(art::Thread* self, art::ArtMethod* method) in MethodEntered()
625 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in MethodEntered()
626 if (!method->IsRuntimeMethod() && in MethodEntered()
627 event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMethodEntry)) { in MethodEntered()
628 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MethodEntered()
632 art::jni::EncodeArtMethod(method)); in MethodEntered()
638 void MethodExited(art::Thread* self, in MethodExited()
639 art::ArtMethod* method, in MethodExited()
640 art::instrumentation::OptionalFrame frame, in MethodExited()
641 art::MutableHandle<art::mirror::Object>& return_value) in MethodExited()
642 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in MethodExited()
643 if (method->IsRuntimeMethod()) { in MethodExited()
646 if (frame.has_value() && UNLIKELY(event_handler_->IsEventEnabledAnywhere( in MethodExited()
648 DCHECK(!frame->get().GetSkipMethodExitEvents()); in MethodExited()
652 art::MutexLock mu(self, non_standard_exits_lock_); in MethodExited()
653 const art::ShadowFrame* sframe = &frame.value().get(); in MethodExited()
656 ret_val = it->second.return_val_obj_; in MethodExited()
662 return_value.Assign(self->DecodeJObject(ret_val)); in MethodExited()
663 ScopedLocalRef<jthread> thr(self->GetJniEnv(), in MethodExited()
664 self->GetJniEnv()->NewLocalRef(self->GetPeer())); in MethodExited()
665 art::ScopedThreadSuspension sts(self, art::ThreadState::kNative); in MethodExited()
666 self->GetJniEnv()->DeleteGlobalRef(ret_val); in MethodExited()
667 event_handler_->SetInternalEvent( in MethodExited()
671 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMethodExit)) { in MethodExited()
673 method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize)->GetReturnTypePrimitive(), in MethodExited()
674 art::Primitive::kPrimNot) << method->PrettyMethod(); in MethodExited()
675 DCHECK(!self->IsExceptionPending()); in MethodExited()
677 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MethodExited()
684 art::jni::EncodeArtMethod(method), in MethodExited()
690 // Call-back for when a method is exited.
691 void MethodExited(art::Thread* self, in MethodExited()
692 art::ArtMethod* method, in MethodExited()
693 art::instrumentation::OptionalFrame frame, in MethodExited()
694 art::JValue& return_value) REQUIRES_SHARED(art::Locks::mutator_lock_) override { in MethodExited()
696 UNLIKELY(event_handler_->IsEventEnabledAnywhere( in MethodExited()
698 DCHECK(!frame->get().GetSkipMethodExitEvents()); in MethodExited()
701 art::MutexLock mu(self, non_standard_exits_lock_); in MethodExited()
702 const art::ShadowFrame* sframe = &frame.value().get(); in MethodExited()
705 return_value.SetJ(it->second.return_val_.j); in MethodExited()
711 ScopedLocalRef<jthread> thr(self->GetJniEnv(), in MethodExited()
712 self->GetJniEnv()->NewLocalRef(self->GetPeer())); in MethodExited()
713 art::ScopedThreadSuspension sts(self, art::ThreadState::kNative); in MethodExited()
714 event_handler_->SetInternalEvent( in MethodExited()
718 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMethodExit)) { in MethodExited()
720 method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize)->GetReturnTypePrimitive(), in MethodExited()
721 art::Primitive::kPrimNot) << method->PrettyMethod(); in MethodExited()
722 DCHECK(!self->IsExceptionPending()) << self->GetException()->Dump(); in MethodExited()
724 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MethodExited()
725 // 64bit integer is the largest value in the union so we should be fine simply copying it into in MethodExited()
726 // the union. in MethodExited()
732 art::jni::EncodeArtMethod(method), in MethodExited()
738 // Call-back for when a method is popped due to an exception throw. A method will either cause a
739 // MethodExited call-back or a MethodUnwind call-back when its activation is removed.
740 void MethodUnwind(art::Thread* self, art::ArtMethod* method, [[maybe_unused]] uint32_t dex_pc) in MethodUnwind()
741 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in MethodUnwind()
742 if (!method->IsRuntimeMethod() && in MethodUnwind()
743 event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kMethodExit)) { in MethodUnwind()
746 val.j = static_cast<jlong>(-1); in MethodUnwind()
747 art::JNIEnvExt* jnienv = self->GetJniEnv(); in MethodUnwind()
748 art::StackHandleScope<1> hs(self); in MethodUnwind()
749 art::Handle<art::mirror::Throwable> old_exception(hs.NewHandle(self->GetException())); in MethodUnwind()
751 self->ClearException(); in MethodUnwind()
756 art::jni::EncodeArtMethod(method), in MethodUnwind()
759 // Match RI behavior of just throwing away original exception if a new one is thrown. in MethodUnwind()
760 if (LIKELY(!self->IsExceptionPending())) { in MethodUnwind()
761 self->SetException(old_exception.Get()); in MethodUnwind()
766 // Call-back for when the dex pc moves in a method.
767 void DexPcMoved(art::Thread* self, in DexPcMoved()
768 [[maybe_unused]] art::Handle<art::mirror::Object> this_object, in DexPcMoved()
769 art::ArtMethod* method, in DexPcMoved()
770 uint32_t new_dex_pc) REQUIRES_SHARED(art::Locks::mutator_lock_) override { in DexPcMoved()
771 DCHECK(!method->IsRuntimeMethod()); in DexPcMoved()
772 // Default methods might be copied to multiple classes. We need to get the canonical version of in DexPcMoved()
777 method = method->GetCanonicalMethod(); in DexPcMoved()
778 art::JNIEnvExt* jnienv = self->GetJniEnv(); in DexPcMoved()
779 jmethodID jmethod = art::jni::EncodeArtMethod(method); in DexPcMoved()
781 // Step event is reported first according to the spec. in DexPcMoved()
782 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kSingleStep)) { in DexPcMoved()
785 // Next we do the Breakpoint events. The Dispatch code will filter the individual in DexPcMoved()
786 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kBreakpoint)) { in DexPcMoved()
791 // Call-back for when we read from a field.
792 void FieldRead(art::Thread* self, in FieldRead()
793 art::Handle<art::mirror::Object> this_object, in FieldRead()
794 art::ArtMethod* method_p, in FieldRead()
796 art::ArtField* field_p) in FieldRead()
797 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in FieldRead()
798 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kFieldAccess)) { in FieldRead()
799 art::StackReflectiveHandleScope<1, 1> rhs(self); in FieldRead()
800 art::ReflectiveHandle<art::ArtField> field(rhs.NewHandle(field_p)); in FieldRead()
801 art::ReflectiveHandle<art::ArtMethod> method(rhs.NewHandle(method_p)); in FieldRead()
802 art::JNIEnvExt* jnienv = self->GetJniEnv(); in FieldRead()
803 // DCHECK(!self->IsExceptionPending()); in FieldRead()
807 field->GetDeclaringClass().Ptr())); in FieldRead()
811 art::jni::EncodeArtMethod(method), in FieldRead()
815 art::jni::EncodeArtField(field)); in FieldRead()
819 void FieldWritten(art::Thread* self, in FieldWritten()
820 art::Handle<art::mirror::Object> this_object, in FieldWritten()
821 art::ArtMethod* method_p, in FieldWritten()
823 art::ArtField* field_p, in FieldWritten()
824 art::Handle<art::mirror::Object> new_val) in FieldWritten()
825 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in FieldWritten()
826 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kFieldModification)) { in FieldWritten()
827 art::JNIEnvExt* jnienv = self->GetJniEnv(); in FieldWritten()
828 art::StackReflectiveHandleScope<1, 1> rhs(self); in FieldWritten()
829 art::ReflectiveHandle<art::ArtField> field(rhs.NewHandle(field_p)); in FieldWritten()
830 art::ReflectiveHandle<art::ArtMethod> method(rhs.NewHandle(method_p)); in FieldWritten()
831 // DCHECK(!self->IsExceptionPending()); in FieldWritten()
835 field->GetDeclaringClass().Ptr())); in FieldWritten()
843 art::jni::EncodeArtMethod(method), in FieldWritten()
846 field->IsStatic() ? nullptr : this_ref.get(), in FieldWritten()
847 art::jni::EncodeArtField(field), in FieldWritten()
853 // Call-back for when we write into a field.
854 void FieldWritten(art::Thread* self, in FieldWritten()
855 art::Handle<art::mirror::Object> this_object, in FieldWritten()
856 art::ArtMethod* method_p, in FieldWritten()
858 art::ArtField* field_p, in FieldWritten()
859 const art::JValue& field_value) in FieldWritten()
860 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in FieldWritten()
861 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kFieldModification)) { in FieldWritten()
862 art::JNIEnvExt* jnienv = self->GetJniEnv(); in FieldWritten()
863 art::StackReflectiveHandleScope<1, 1> rhs(self); in FieldWritten()
864 art::ReflectiveHandle<art::ArtField> field(rhs.NewHandle(field_p)); in FieldWritten()
865 art::ReflectiveHandle<art::ArtMethod> method(rhs.NewHandle(method_p)); in FieldWritten()
866 DCHECK(!self->IsExceptionPending()); in FieldWritten()
870 field->GetDeclaringClass().Ptr())); in FieldWritten()
871 char type_char = art::Primitive::Descriptor(field->GetTypeAsPrimitiveType())[0]; in FieldWritten()
873 // 64bit integer is the largest value in the union so we should be fine simply copying it into in FieldWritten()
874 // the union. in FieldWritten()
880 art::jni::EncodeArtMethod(method), in FieldWritten()
883 field->IsStatic() ? nullptr : this_ref.get(), // nb static field modification get given in FieldWritten()
884 // the class as this_object for some in FieldWritten()
886 art::jni::EncodeArtField(field), in FieldWritten()
892 void WatchedFramePop(art::Thread* self, const art::ShadowFrame& frame) in WatchedFramePop()
893 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in WatchedFramePop()
894 art::JNIEnvExt* jnienv = self->GetJniEnv(); in WatchedFramePop()
895 // Remove the force-interpreter added by the WatchFrame. in WatchedFramePop()
897 art::MutexLock mu(self, *art::Locks::thread_list_lock_); in WatchedFramePop()
898 CHECK_GT(self->ForceInterpreterCount(), 0u); in WatchedFramePop()
899 self->DecrementForceInterpreterCount(); in WatchedFramePop()
901 jboolean is_exception_pending = self->IsExceptionPending(); in WatchedFramePop()
906 art::jni::EncodeArtMethod(frame.GetMethod()), in WatchedFramePop()
911 static void FindCatchMethodsFromThrow(art::Thread* self, in FindCatchMethodsFromThrow()
912 art::Handle<art::mirror::Throwable> exception, in FindCatchMethodsFromThrow()
913 /*out*/ art::ArtMethod** out_method, in FindCatchMethodsFromThrow()
915 REQUIRES_SHARED(art::Locks::mutator_lock_) { in FindCatchMethodsFromThrow()
916 // Finds the location where this exception will most likely be caught. We ignore intervening in FindCatchMethodsFromThrow()
917 // native frames (which could catch the exception) and return the closest java frame with a in FindCatchMethodsFromThrow()
919 class CatchLocationFinder final : public art::StackVisitor { in FindCatchMethodsFromThrow()
921 CatchLocationFinder(art::Thread* target, in FindCatchMethodsFromThrow()
922 art::Handle<art::mirror::Class> exception_class, in FindCatchMethodsFromThrow()
923 art::Context* context, in FindCatchMethodsFromThrow()
924 /*out*/ art::ArtMethod** out_catch_method, in FindCatchMethodsFromThrow()
926 REQUIRES_SHARED(art::Locks::mutator_lock_) in FindCatchMethodsFromThrow()
927 : StackVisitor(target, context, art::StackVisitor::StackWalkKind::kIncludeInlinedFrames), in FindCatchMethodsFromThrow()
932 bool VisitFrame() override REQUIRES_SHARED(art::Locks::mutator_lock_) { in FindCatchMethodsFromThrow()
933 art::ArtMethod* method = GetMethod(); in FindCatchMethodsFromThrow()
935 if (method->IsRuntimeMethod()) { in FindCatchMethodsFromThrow()
939 if (!method->IsNative()) { in FindCatchMethodsFromThrow()
941 if (cur_dex_pc == art::dex::kDexNoIndex) { in FindCatchMethodsFromThrow()
946 uint32_t found_dex_pc = method->FindCatchBlock( in FindCatchMethodsFromThrow()
948 if (found_dex_pc != art::dex::kDexNoIndex) { in FindCatchMethodsFromThrow()
949 // We found the catch. Store the result and return. in FindCatchMethodsFromThrow()
959 art::Handle<art::mirror::Class> exception_class_; in FindCatchMethodsFromThrow()
960 art::ArtMethod** catch_method_ptr_; in FindCatchMethodsFromThrow()
966 art::StackHandleScope<1> hs(self); in FindCatchMethodsFromThrow()
969 std::unique_ptr<art::Context> context(art::Context::Create()); in FindCatchMethodsFromThrow()
972 hs.NewHandle(exception->GetClass()), in FindCatchMethodsFromThrow()
979 // Call-back when an exception is thrown.
980 void ExceptionThrown(art::Thread* self, art::Handle<art::mirror::Throwable> exception_object) in ExceptionThrown()
981 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in ExceptionThrown()
982 DCHECK(self->IsExceptionThrownByCurrentMethod(exception_object.Get())); in ExceptionThrown()
983 // The instrumentation events get rid of this for us. in ExceptionThrown()
984 DCHECK(!self->IsExceptionPending()); in ExceptionThrown()
985 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kException)) { in ExceptionThrown()
986 art::JNIEnvExt* jnienv = self->GetJniEnv(); in ExceptionThrown()
987 art::ArtMethod* catch_method; in ExceptionThrown()
991 art::ArtMethod* method = self->GetCurrentMethod(&dex_pc, in ExceptionThrown()
993 /* abort_on_error= */ art::kIsDebugBuild); in ExceptionThrown()
1000 art::jni::EncodeArtMethod(method), in ExceptionThrown()
1003 art::jni::EncodeArtMethod(catch_method), in ExceptionThrown()
1009 // Call-back when an exception is handled.
1010 void ExceptionHandled(art::Thread* self, art::Handle<art::mirror::Throwable> exception_object) in ExceptionHandled()
1011 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in ExceptionHandled()
1012 // Since the exception has already been handled there shouldn't be one pending. in ExceptionHandled()
1013 DCHECK(!self->IsExceptionPending()); in ExceptionHandled()
1014 if (event_handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kExceptionCatch)) { in ExceptionHandled()
1015 art::JNIEnvExt* jnienv = self->GetJniEnv(); in ExceptionHandled()
1017 art::ArtMethod* method = self->GetCurrentMethod(&dex_pc, in ExceptionHandled()
1019 /* abort_on_error= */ art::kIsDebugBuild); in ExceptionHandled()
1026 art::jni::EncodeArtMethod(method), in ExceptionHandled()
1033 // Call-back for when we execute a branch.
1034 void Branch([[maybe_unused]] art::Thread* self, in Branch()
1035 [[maybe_unused]] art::ArtMethod* method, in Branch()
1038 REQUIRES_SHARED(art::Locks::mutator_lock_) override { in Branch()
1044 // if non-null is a GlobalReference to the returned value.
1046 // The return-value to be passed to the MethodExit event.
1052 mutable art::Mutex non_standard_exits_lock_
1053 ACQUIRED_BEFORE(art::Locks::instrument_entrypoints_lock_);
1055 std::unordered_map<const art::ShadowFrame*, NonStandardExitEventInfo> non_standard_exits_
1062 return art::instrumentation::Instrumentation::kMethodEntered; in GetInstrumentationEventsFor()
1065 // return art::instrumentation::Instrumentation::kMethodExited; in GetInstrumentationEventsFor()
1074 return art::instrumentation::Instrumentation::kMethodExited | in GetInstrumentationEventsFor()
1075 art::instrumentation::Instrumentation::kMethodUnwind; in GetInstrumentationEventsFor()
1077 // The event needs to be kept around/is already enabled by the other jvmti event that uses in GetInstrumentationEventsFor()
1078 // the same instrumentation event. in GetInstrumentationEventsFor()
1083 return art::instrumentation::Instrumentation::kFieldWritten; in GetInstrumentationEventsFor()
1085 return art::instrumentation::Instrumentation::kFieldRead; in GetInstrumentationEventsFor()
1088 // Need to skip adding the listeners if the event is breakpoint/single-step since those events in GetInstrumentationEventsFor()
1089 // share the same art-instrumentation underlying event. We need to give them their own deopt in GetInstrumentationEventsFor()
1090 // request though so the test waits until here. in GetInstrumentationEventsFor()
1095 return art::instrumentation::Instrumentation::kDexPcMoved; in GetInstrumentationEventsFor()
1097 // The event needs to be kept around/is already enabled by the other jvmti event that uses in GetInstrumentationEventsFor()
1098 // the same instrumentation event. in GetInstrumentationEventsFor()
1103 return art::instrumentation::Instrumentation::kWatchedFramePop; in GetInstrumentationEventsFor()
1105 return art::instrumentation::Instrumentation::kExceptionThrown; in GetInstrumentationEventsFor()
1107 return art::instrumentation::Instrumentation::kExceptionHandled; in GetInstrumentationEventsFor()
1174 art::ScopedObjectAccess soa(art::Thread::Current()); in HandleEventDeopt()
1178 deopt_manager->AddDeoptimizationRequester(); in HandleEventDeopt()
1181 deopt_manager->AddDeoptimizeAllMethods(); in HandleEventDeopt()
1184 err = deopt_manager->AddDeoptimizeThreadMethods(soa, thread); in HandleEventDeopt()
1190 deopt_manager->RemoveDeoptimizationRequester(); in HandleEventDeopt()
1196 deopt_manager->RemoveDeoptimizeAllMethods(); in HandleEventDeopt()
1199 err = deopt_manager->RemoveDeoptimizeThreadMethods(soa, thread); in HandleEventDeopt()
1204 deopt_manager->RemoveDeoptimizationRequester(); in HandleEventDeopt()
1216 // Add the actual listeners. in SetupTraceListener()
1221 art::ScopedThreadStateChange stsc(art::Thread::Current(), art::ThreadState::kNative); in SetupTraceListener()
1222 art::instrumentation::Instrumentation* instr = art::Runtime::Current()->GetInstrumentation(); in SetupTraceListener()
1223 art::ScopedSuspendAll ssa("jvmti method tracing installation"); in SetupTraceListener()
1225 instr->AddListener(listener, new_events); in SetupTraceListener()
1227 instr->RemoveListener(listener, new_events); in SetupTraceListener()
1233 // the switch interpreter) when we try to get or set a local variable.
1235 class UpdateEntryPointsClassVisitor : public art::ClassVisitor { in HandleLocalAccessCapabilityAdded()
1237 explicit UpdateEntryPointsClassVisitor(art::Runtime* runtime) in HandleLocalAccessCapabilityAdded()
1240 bool operator()(art::ObjPtr<art::mirror::Class> klass) in HandleLocalAccessCapabilityAdded()
1241 override REQUIRES(art::Locks::mutator_lock_) { in HandleLocalAccessCapabilityAdded()
1242 if (!klass->IsLoaded()) { in HandleLocalAccessCapabilityAdded()
1244 // their methods. Furthemore since the jvmti-plugin must have been loaded by this point in HandleLocalAccessCapabilityAdded()
1248 for (auto& m : klass->GetMethods(art::kRuntimePointerSize)) { in HandleLocalAccessCapabilityAdded()
1252 } else if (!runtime_->GetClassLinker()->IsQuickToInterpreterBridge(code) && in HandleLocalAccessCapabilityAdded()
1253 !runtime_->IsAsyncDeoptimizeable(&m, reinterpret_cast<uintptr_t>(code))) { in HandleLocalAccessCapabilityAdded()
1254 runtime_->GetInstrumentation()->InitializeMethodsCode(&m, /*aot_code=*/ nullptr); in HandleLocalAccessCapabilityAdded()
1261 art::Runtime* runtime_; in HandleLocalAccessCapabilityAdded()
1263 art::ScopedObjectAccess soa(art::Thread::Current()); in HandleLocalAccessCapabilityAdded()
1264 UpdateEntryPointsClassVisitor visitor(art::Runtime::Current()); in HandleLocalAccessCapabilityAdded()
1265 art::Runtime::Current()->GetClassLinker()->VisitClasses(&visitor); in HandleLocalAccessCapabilityAdded()
1290 // remove the listener if we have no outstanding frames. in SetupFramePopTraceListener()
1292 art::ReaderMutexLock mu(art::Thread::Current(), envs_lock_); in SetupFramePopTraceListener()
1294 art::ReaderMutexLock event_mu(art::Thread::Current(), env->event_info_mutex_); in SetupFramePopTraceListener()
1295 if (!env->notify_frames.empty()) { in SetupFramePopTraceListener()
1306 // Handle special work for the given event type, if necessary.
1320 // pop-events since we would either need to deal with dangling pointers or have missed events. in HandleEventType()
1323 // The frame-pop event was held on by pending events so we don't need to do anything. in HandleEventType()
1353 // Checks to see if the env has the capabilities associated with the given event.
1356 jvmtiCapabilities caps = env->capabilities; in HasAssociatedCapability()
1421 art::Thread* self = art::Thread::Current(); in SetInternalEvent()
1422 art::Thread* target = nullptr; in SetInternalEvent()
1424 // The overall state across all threads and jvmtiEnvs. This is used to control the state of the in SetInternalEvent()
1428 // The state for just the current 'thread' (including null) across all jvmtiEnvs. This is used to in SetInternalEvent()
1429 // control the deoptimization state since we do refcounting for that and need to perform different in SetInternalEvent()
1430 // actions depending on if the event is limited to a single thread or global. in SetInternalEvent()
1434 // From now on we know we cannot get suspended by user-code. in SetInternalEvent()
1435 // NB This does a SuspendCheck (during thread state change) so we need to in SetInternalEvent()
1436 // make sure we don't have the 'suspend_lock' locked here. in SetInternalEvent()
1437 art::ScopedObjectAccess soa(self); in SetInternalEvent()
1438 art::WriterMutexLock el_mu(self, envs_lock_); in SetInternalEvent()
1439 art::MutexLock tll_mu(self, *art::Locks::thread_list_lock_); in SetInternalEvent()
1443 } else if (target->IsStillStarting() || target->GetState() == art::ThreadState::kStarting) { in SetInternalEvent()
1444 target->Dump(LOG_STREAM(WARNING) << "Is not alive: "); in SetInternalEvent()
1448 // Make sure we have a valid jthread to pass to deopt-manager. in SetInternalEvent()
1450 soa.Env(), thread != nullptr ? nullptr : soa.AddLocalReference<jthread>(target->GetPeer())); in SetInternalEvent()
1457 DCHECK_GE(GetInternalEventRefcount(event) + (mode == JVMTI_ENABLE ? 1 : -1), 0) in SetInternalEvent()
1459 DCHECK_GE(GetInternalEventThreadRefcount(event, target) + (mode == JVMTI_ENABLE ? 1 : -1), 0) in SetInternalEvent()
1476 // Handle any special work required for the event type. We still have the in SetInternalEvent()
1515 art::Thread* self = art::Thread::Current(); in SetEvent()
1516 art::Thread* target = nullptr; in SetEvent()
1518 // The overall state across all threads and jvmtiEnvs. This is used to control the state of the in SetEvent()
1522 // The state for just the current 'thread' (including null) across all jvmtiEnvs. This is used to in SetEvent()
1523 // control the deoptimization state since we do refcounting for that and need to perform different in SetEvent()
1524 // actions depending on if the event is limited to a single thread or global. in SetEvent()
1528 // From now on we know we cannot get suspended by user-code. in SetEvent()
1529 // NB This does a SuspendCheck (during thread state change) so we need to in SetEvent()
1530 // make sure we don't have the 'suspend_lock' locked here. in SetEvent()
1531 art::ScopedObjectAccess soa(self); in SetEvent()
1532 art::WriterMutexLock el_mu(self, envs_lock_); in SetEvent()
1533 art::MutexLock tll_mu(self, *art::Locks::thread_list_lock_); in SetEvent()
1538 } else if (target->IsStillStarting() || in SetEvent()
1539 target->GetState() == art::ThreadState::kStarting) { in SetEvent()
1540 target->Dump(LOG_STREAM(WARNING) << "Is not alive: "); in SetEvent()
1546 art::WriterMutexLock ei_mu(self, env->event_info_mutex_); in SetEvent()
1550 env->event_masks.EnableEvent(env, target, event); in SetEvent()
1558 env->event_masks.DisableEvent(env, target, event); in SetEvent()
1565 // Handle any special work required for the event type. We still have the in SetEvent()
1576 bool EventHandler::GetThreadEventState(ArtJvmtiEvent event, art::Thread* thread) { in GetThreadEventState()
1581 auto& masks = stored_env->event_masks; in GetThreadEventState()
1586 if (mask != nullptr && mask->Test(event)) { in GetThreadEventState()
1596 DeoptManager::Get()->AddDeoptimizationRequester(); in HandleBreakpointEventsChanged()
1598 DeoptManager::Get()->RemoveDeoptimizationRequester(); in HandleBreakpointEventsChanged()
1602 void EventHandler::AddDelayedNonStandardExitEvent(const art::ShadowFrame *frame, in AddDelayedNonStandardExitEvent()
1605 method_trace_listener_->AddDelayedNonStandardExitEvent(frame, is_object, val); in AddDelayedNonStandardExitEvent()
1610 return static_cast<size_t>(event) - static_cast<size_t>(ArtJvmtiEvent::kMinInternalEventTypeVal); in GetInternalEventIndex()
1613 int32_t EventHandler::DecrInternalEventThreadRefcount(ArtJvmtiEvent event, art::Thread* target) { in DecrInternalEventThreadRefcount()
1614 return --GetInternalEventThreadRefcount(event, target); in DecrInternalEventThreadRefcount()
1617 int32_t EventHandler::IncrInternalEventThreadRefcount(ArtJvmtiEvent event, art::Thread* target) { in IncrInternalEventThreadRefcount()
1621 int32_t& EventHandler::GetInternalEventThreadRefcount(ArtJvmtiEvent event, art::Thread* target) { in GetInternalEventThreadRefcount()
1623 UniqueThread target_ut{target, target->GetTid()}; in GetInternalEventThreadRefcount()
1631 return --internal_event_refcount_[GetInternalEventIndex(event)]; in DecrInternalEventRefcount()
1643 // Need to remove the method_trace_listener_ if it's there. in Shutdown()
1644 art::Thread* self = art::Thread::Current(); in Shutdown()
1645 art::gc::ScopedGCCriticalSection gcs(self, in Shutdown()
1646 art::gc::kGcCauseInstrumentation, in Shutdown()
1647 art::gc::kCollectorTypeInstrumentation); in Shutdown()
1648 art::ScopedSuspendAll ssa("jvmti method tracing uninstallation"); in Shutdown()
1650 art::Runtime::Current()->GetInstrumentation()->RemoveListener(method_trace_listener_.get(), ~0); in Shutdown()
1651 AllocationManager::Get()->RemoveAllocListener(); in Shutdown()
1655 : envs_lock_("JVMTI Environment List Lock", art::LockLevel::kPostMutatorTopLockLevel), in EventHandler()
1659 AllocationManager::Get()->SetAllocListener(alloc_listener_.get());