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