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 "base/macros.h" 25 #include "monitor.h" 26 #include "stack.h" 27 #include "thread.h" 28 #include "thread_state.h" 29 30 namespace art HIDDEN { 31 32 namespace mirror { 33 class Object; 34 } 35 36 class Context; 37 38 class MonitorObjectsStackVisitor : public StackVisitor { 39 public: 40 MonitorObjectsStackVisitor(Thread* thread_in, 41 Context* context, 42 bool check_suspended = true, 43 bool dump_locks_in = true) REQUIRES_SHARED(Locks::mutator_lock_)44 REQUIRES_SHARED(Locks::mutator_lock_) 45 : StackVisitor(thread_in, 46 context, 47 StackVisitor::StackWalkKind::kIncludeInlinedFrames, 48 check_suspended), 49 frame_count(0u), 50 dump_locks(dump_locks_in) {} 51 52 enum class VisitMethodResult { 53 kContinueMethod, 54 kSkipMethod, 55 kEndStackWalk, 56 }; 57 58 bool VisitFrame() final REQUIRES_SHARED(Locks::mutator_lock_); 59 60 protected: 61 virtual VisitMethodResult StartMethod(ArtMethod* m, size_t frame_nr) 62 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 63 virtual VisitMethodResult EndMethod(ArtMethod* m) 64 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 65 66 virtual void VisitWaitingObject(ObjPtr<mirror::Object> obj, ThreadState state) 67 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 68 virtual void VisitSleepingObject(ObjPtr<mirror::Object> obj) 69 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 70 virtual void VisitBlockedOnObject(ObjPtr<mirror::Object> obj, 71 ThreadState state, 72 uint32_t owner_tid) 73 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 74 virtual void VisitLockedObject(ObjPtr<mirror::Object> obj) 75 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 76 77 size_t frame_count; 78 79 private: 80 static void VisitLockedObject(ObjPtr<mirror::Object> o, void* context) 81 REQUIRES_SHARED(Locks::mutator_lock_); 82 83 const bool dump_locks; 84 }; 85 86 } // namespace art 87 88 #endif // ART_RUNTIME_MONITOR_OBJECTS_STACK_VISITOR_H_ 89