Flutter Engine
The Flutter Engine
visitor.h
Go to the documentation of this file.
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
13namespace dart {
14
15// Forward declarations.
16class Isolate;
17class IsolateGroup;
18
19// An object pointer visitor interface.
21 public:
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,
32 CompressedObjectPtr* last) {
33 VisitCompressedPointers(view->heap_base(), first, last);
34 }
35
36 // Range of pointers to visit 'first' <= pointer <= 'last'.
37 virtual void VisitPointers(ObjectPtr* first, ObjectPtr* last) = 0;
38#if defined(DART_COMPRESSED_POINTERS)
39 virtual void VisitCompressedPointers(uword heap_base,
41 CompressedObjectPtr* last) = 0;
42#else
45 CompressedObjectPtr* last) {
46 VisitPointers(first, last);
47 }
48#endif
49
50 // len argument is the number of pointers to visit starting from 'p'.
51 void VisitPointers(ObjectPtr* p, intptr_t len) {
52 VisitPointers(p, (p + len - 1));
53 }
54
56
57 const char* gc_root_type() const { return gc_root_type_; }
58 void set_gc_root_type(const char* gc_root_type) {
59 gc_root_type_ = gc_root_type;
60 }
61
62 void clear_gc_root_type() { gc_root_type_ = "unknown"; }
63
64 virtual bool visit_weak_persistent_handles() const { return false; }
65
66 // When visiting objects to build retaining paths, trace field values
67 // through fields.
68 // Otherwise trace field values through isolate's field_table.
69 virtual bool trace_values_through_fields() const { return false; }
70
71 const ClassTable* class_table() const { return class_table_; }
72
73 // Returns true if pointers of the given SuspendState object can be visited.
74 // Compactor overrides this method in order to postpone visiting SuspendState
75 // objects with evacuated frames, as visiting them may touch other Dart
76 // objects (array of InstructionsTables) which have inconsistent state
77 // until compaction is finished.
78 virtual bool CanVisitSuspendStatePointers(SuspendStatePtr suspend_state) {
79 return true;
80 }
81
82 private:
83 IsolateGroup* isolate_group_;
84 const char* gc_root_type_;
85 ClassTable* class_table_;
86
87 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectPointerVisitor);
88};
89
91 public:
94 virtual bool PredicateVisitPointers(ObjectPtr* first, ObjectPtr* last) = 0;
95#if defined(DART_COMPRESSED_POINTERS)
96 virtual bool PredicateVisitCompressedPointers(uword heap_base,
98 CompressedObjectPtr* last) = 0;
99#else
101 CompressedObjectPtr* first,
102 CompressedObjectPtr* last) {
103 return PredicateVisitPointers(first, last);
104 }
105#endif
106};
107
108// An object visitor interface.
110 public:
112
113 virtual ~ObjectVisitor() {}
114
115 // Invoked for each object.
116 virtual void VisitObject(ObjectPtr obj) = 0;
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(ObjectVisitor);
120};
121
122} // namespace dart
123
124#endif // RUNTIME_VM_VISITOR_H_
virtual ~ObjectPointerVisitor()
Definition: visitor.h:23
void VisitPointers(ObjectPtr *p, intptr_t len)
Definition: visitor.h:51
virtual void VisitTypedDataViewPointers(TypedDataViewPtr view, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition: visitor.h:30
void set_gc_root_type(const char *gc_root_type)
Definition: visitor.h:58
virtual void VisitPointers(ObjectPtr *first, ObjectPtr *last)=0
const ClassTable * class_table() const
Definition: visitor.h:71
IsolateGroup * isolate_group() const
Definition: visitor.h:25
virtual bool CanVisitSuspendStatePointers(SuspendStatePtr suspend_state)
Definition: visitor.h:78
void VisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition: visitor.h:43
ObjectPointerVisitor(IsolateGroup *isolate_group)
Definition: visitor.cc:11
virtual bool visit_weak_persistent_handles() const
Definition: visitor.h:64
void VisitPointer(ObjectPtr *p)
Definition: visitor.h:55
const char * gc_root_type() const
Definition: visitor.h:57
virtual bool trace_values_through_fields() const
Definition: visitor.h:69
virtual ~ObjectVisitor()
Definition: visitor.h:113
virtual void VisitObject(ObjectPtr obj)=0
virtual bool PredicateVisitPointers(ObjectPtr *first, ObjectPtr *last)=0
bool PredicateVisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition: visitor.h:100
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501