| 1 | // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
|---|---|
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_VISITOR_H_ |
| 6 | #define RUNTIME_VM_VISITOR_H_ |
| 7 | |
| 8 | #include "vm/allocation.h" |
| 9 | #include "vm/class_table.h" |
| 10 | #include "vm/globals.h" |
| 11 | #include "vm/growable_array.h" |
| 12 | |
| 13 | namespace dart { |
| 14 | |
| 15 | // Forward declarations. |
| 16 | class Isolate; |
| 17 | class IsolateGroup; |
| 18 | |
| 19 | // An object pointer visitor interface. |
| 20 | class ObjectPointerVisitor { |
| 21 | public: |
| 22 | explicit ObjectPointerVisitor(IsolateGroup* isolate_group); |
| 23 | virtual ~ObjectPointerVisitor() {} |
| 24 | |
| 25 | IsolateGroup* isolate_group() const { return isolate_group_; } |
| 26 | |
| 27 | // Visit pointers inside the given typed data [view]. |
| 28 | // |
| 29 | // Range of pointers to visit 'first' <= pointer <= 'last'. |
| 30 | virtual void VisitTypedDataViewPointers(TypedDataViewPtr view, |
| 31 | ObjectPtr* first, |
| 32 | ObjectPtr* last) { |
| 33 | VisitPointers(first, last); |
| 34 | } |
| 35 | |
| 36 | // Range of pointers to visit 'first' <= pointer <= 'last'. |
| 37 | virtual void VisitPointers(ObjectPtr* first, ObjectPtr* last) = 0; |
| 38 | |
| 39 | // len argument is the number of pointers to visit starting from 'p'. |
| 40 | void VisitPointers(ObjectPtr* p, intptr_t len) { |
| 41 | VisitPointers(p, (p + len - 1)); |
| 42 | } |
| 43 | |
| 44 | void VisitPointer(ObjectPtr* p) { VisitPointers(p, p); } |
| 45 | |
| 46 | const char* gc_root_type() const { return gc_root_type_; } |
| 47 | void set_gc_root_type(const char* gc_root_type) { |
| 48 | gc_root_type_ = gc_root_type; |
| 49 | } |
| 50 | |
| 51 | void clear_gc_root_type() { gc_root_type_ = "unknown"; } |
| 52 | |
| 53 | virtual bool visit_weak_persistent_handles() const { return false; } |
| 54 | |
| 55 | const SharedClassTable* shared_class_table() const { |
| 56 | return shared_class_table_; |
| 57 | } |
| 58 | |
| 59 | private: |
| 60 | IsolateGroup* isolate_group_; |
| 61 | const char* gc_root_type_; |
| 62 | SharedClassTable* shared_class_table_; |
| 63 | |
| 64 | DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectPointerVisitor); |
| 65 | }; |
| 66 | |
| 67 | // An object visitor interface. |
| 68 | class ObjectVisitor { |
| 69 | public: |
| 70 | ObjectVisitor() {} |
| 71 | |
| 72 | virtual ~ObjectVisitor() {} |
| 73 | |
| 74 | // Invoked for each object. |
| 75 | virtual void VisitObject(ObjectPtr obj) = 0; |
| 76 | |
| 77 | private: |
| 78 | DISALLOW_COPY_AND_ASSIGN(ObjectVisitor); |
| 79 | }; |
| 80 | |
| 81 | // An object finder visitor interface. |
| 82 | class FindObjectVisitor { |
| 83 | public: |
| 84 | FindObjectVisitor() {} |
| 85 | virtual ~FindObjectVisitor() {} |
| 86 | |
| 87 | // Allow to specify a address filter. |
| 88 | virtual uword filter_addr() const { return 0; } |
| 89 | bool VisitRange(uword begin_addr, uword end_addr) const { |
| 90 | uword addr = filter_addr(); |
| 91 | return (addr == 0) || ((begin_addr <= addr) && (addr < end_addr)); |
| 92 | } |
| 93 | |
| 94 | // Check if object matches find condition. |
| 95 | virtual bool FindObject(ObjectPtr obj) const = 0; |
| 96 | |
| 97 | private: |
| 98 | DISALLOW_COPY_AND_ASSIGN(FindObjectVisitor); |
| 99 | }; |
| 100 | |
| 101 | } // namespace dart |
| 102 | |
| 103 | #endif // RUNTIME_VM_VISITOR_H_ |
| 104 |