1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_MONITOR_OBJECTS_STACK_VISITOR_H_ 18 #define ART_RUNTIME_MONITOR_OBJECTS_STACK_VISITOR_H_ 19 20 #include <android-base/logging.h> 21 22 #include "art_method.h" 23 #include "base/locks.h" 24 #include "monitor.h" 25 #include "stack.h" 26 #include "thread.h" 27 #include "thread_state.h" 28 29 namespace art { 30 31 namespace mirror { 32 class Object; 33 } 34 35 class Context; 36 37 class MonitorObjectsStackVisitor : public StackVisitor { 38 public: 39 MonitorObjectsStackVisitor(Thread* thread_in, 40 Context* context, 41 bool check_suspended = true, 42 bool dump_locks_in = true) REQUIRES_SHARED(Locks::mutator_lock_)43 REQUIRES_SHARED(Locks::mutator_lock_) 44 : StackVisitor(thread_in, 45 context, 46 StackVisitor::StackWalkKind::kIncludeInlinedFrames, 47 check_suspended), 48 frame_count(0u), 49 dump_locks(dump_locks_in) {} 50 51 enum class VisitMethodResult { 52 kContinueMethod, 53 kSkipMethod, 54 kEndStackWalk, 55 }; 56 57 bool VisitFrame() final REQUIRES_SHARED(Locks::mutator_lock_); 58 59 protected: 60 virtual VisitMethodResult StartMethod(ArtMethod* m, size_t frame_nr) 61 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 62 virtual VisitMethodResult EndMethod(ArtMethod* m) 63 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 64 65 virtual void VisitWaitingObject(ObjPtr<mirror::Object> obj, ThreadState state) 66 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 67 virtual void VisitSleepingObject(ObjPtr<mirror::Object> obj) 68 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 69 virtual void VisitBlockedOnObject(ObjPtr<mirror::Object> obj, 70 ThreadState state, 71 uint32_t owner_tid) 72 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 73 virtual void VisitLockedObject(ObjPtr<mirror::Object> obj) 74 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 75 76 size_t frame_count; 77 78 private: 79 static void VisitLockedObject(ObjPtr<mirror::Object> o, void* context) 80 REQUIRES_SHARED(Locks::mutator_lock_); 81 82 const bool dump_locks; 83 }; 84 85 } // namespace art 86 87 #endif // ART_RUNTIME_MONITOR_OBJECTS_STACK_VISITOR_H_ 88