blob: 8e148aa7460187d5efbe67396543105fa3b563be [file] [log] [blame]
Andreas Gampe93104952017-12-13 17:13:15 -08001/*
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"
Andreas Gampe7fbc4a52018-11-28 08:26:47 -080023#include "base/locks.h"
Andreas Gampe93104952017-12-13 17:13:15 -080024#include "monitor.h"
25#include "stack.h"
26#include "thread.h"
27#include "thread_state.h"
28
29namespace art {
30
31namespace mirror {
32class Object;
33}
34
35class Context;
36
37class MonitorObjectsStackVisitor : public StackVisitor {
38 public:
39 MonitorObjectsStackVisitor(Thread* thread_in,
40 Context* context,
41 bool check_suspended = true,
42 bool dump_locks_in = true)
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
Vladimir Markof52d92f2019-03-29 12:33:02 +000057 bool VisitFrame() final REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe93104952017-12-13 17:13:15 -080058
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
Vladimir Markof52d92f2019-03-29 12:33:02 +000065 virtual void VisitWaitingObject(ObjPtr<mirror::Object> obj, ThreadState state)
Andreas Gampe93104952017-12-13 17:13:15 -080066 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Vladimir Markof52d92f2019-03-29 12:33:02 +000067 virtual void VisitSleepingObject(ObjPtr<mirror::Object> obj)
Andreas Gampe93104952017-12-13 17:13:15 -080068 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Vladimir Markof52d92f2019-03-29 12:33:02 +000069 virtual void VisitBlockedOnObject(ObjPtr<mirror::Object> obj,
70 ThreadState state,
71 uint32_t owner_tid)
Andreas Gampe93104952017-12-13 17:13:15 -080072 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Vladimir Markof52d92f2019-03-29 12:33:02 +000073 virtual void VisitLockedObject(ObjPtr<mirror::Object> obj)
Andreas Gampe93104952017-12-13 17:13:15 -080074 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
75
76 size_t frame_count;
77
78 private:
Vladimir Markof52d92f2019-03-29 12:33:02 +000079 static void VisitLockedObject(ObjPtr<mirror::Object> o, void* context)
80 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe93104952017-12-13 17:13:15 -080081
82 const bool dump_locks;
83};
84
85} // namespace art
86
87#endif // ART_RUNTIME_MONITOR_OBJECTS_STACK_VISITOR_H_