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_HEAP_VERIFIER_H_
6#define RUNTIME_VM_HEAP_VERIFIER_H_
7
8#include "vm/flags.h"
9#include "vm/globals.h"
10#include "vm/handle_visitor.h"
11#include "vm/handles.h"
12#include "vm/thread.h"
13#include "vm/visitor.h"
14
15namespace dart {
16
17// Forward declarations.
18class IsolateGroup;
19class ObjectSet;
20
21enum MarkExpectation { kForbidMarked, kAllowMarked, kRequireMarked };
22
23class VerifyObjectVisitor : public ObjectVisitor {
24 public:
25 VerifyObjectVisitor(IsolateGroup* isolate_group,
26 ObjectSet* allocated_set,
27 MarkExpectation mark_expectation)
28 : isolate_group_(isolate_group),
29 allocated_set_(allocated_set),
30 mark_expectation_(mark_expectation) {}
31
32 virtual void VisitObject(ObjectPtr obj);
33
34 private:
35 IsolateGroup* isolate_group_;
36 ObjectSet* allocated_set_;
37 MarkExpectation mark_expectation_;
38
39 DISALLOW_COPY_AND_ASSIGN(VerifyObjectVisitor);
40};
41
42// A sample object pointer visitor implementation which verifies that
43// the pointers visited are contained in the isolate heap.
44class VerifyPointersVisitor : public ObjectPointerVisitor {
45 public:
46 explicit VerifyPointersVisitor(IsolateGroup* isolate_group,
47 ObjectSet* allocated_set)
48 : ObjectPointerVisitor(isolate_group), allocated_set_(allocated_set) {}
49
50 virtual void VisitPointers(ObjectPtr* first, ObjectPtr* last);
51
52 static void VerifyPointers(MarkExpectation mark_expectation = kForbidMarked);
53
54 private:
55 ObjectSet* allocated_set_;
56
57 DISALLOW_COPY_AND_ASSIGN(VerifyPointersVisitor);
58};
59
60class VerifyWeakPointersVisitor : public HandleVisitor {
61 public:
62 explicit VerifyWeakPointersVisitor(VerifyPointersVisitor* visitor)
63 : HandleVisitor(Thread::Current()), visitor_(visitor) {}
64
65 virtual void VisitHandle(uword addr);
66
67 private:
68 ObjectPointerVisitor* visitor_;
69
70 ObjectSet* allocated_set;
71
72 DISALLOW_COPY_AND_ASSIGN(VerifyWeakPointersVisitor);
73};
74
75#if defined(DEBUG)
76class VerifyCanonicalVisitor : public ObjectVisitor {
77 public:
78 explicit VerifyCanonicalVisitor(Thread* thread);
79 virtual void VisitObject(ObjectPtr obj);
80
81 private:
82 Thread* thread_;
83 Instance& instanceHandle_;
84
85 DISALLOW_COPY_AND_ASSIGN(VerifyCanonicalVisitor);
86};
87#endif // defined(DEBUG)
88
89} // namespace dart
90
91#endif // RUNTIME_VM_HEAP_VERIFIER_H_
92