OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/verifier.h" | 5 #include "vm/verifier.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
10 #include "vm/freelist.h" | 10 #include "vm/freelist.h" |
11 #include "vm/heap.h" | 11 #include "vm/heap.h" |
12 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
13 #include "vm/object.h" | 13 #include "vm/object.h" |
14 #include "vm/object_set.h" | 14 #include "vm/object_set.h" |
15 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
16 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
20 void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) { | 20 void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) { |
21 if (raw_obj->IsHeapObject()) { | 21 if (raw_obj->IsHeapObject()) { |
22 uword raw_addr = RawObject::ToAddr(raw_obj); | 22 uword raw_addr = RawObject::ToAddr(raw_obj); |
23 if (raw_obj->IsFreeListElement() || raw_obj->IsForwardingCorpse()) { | 23 if (raw_obj->IsFreeListElement() || raw_obj->IsForwardingCorpse()) { |
24 if (raw_obj->IsMarked()) { | 24 if (raw_obj->IsMarked()) { |
25 FATAL1("Marked free list element encountered %#" Px "\n", raw_addr); | 25 FATAL1("Marked free list element encountered %#" Px "\n", raw_addr); |
26 } | 26 } |
27 } else { | 27 } else { |
28 switch (mark_expectation_) { | 28 switch (mark_expectation_) { |
29 case kForbidMarked: | 29 case kForbidMarked: |
30 if (raw_obj->IsMarked()) { | 30 if (raw_obj->IsMarked()) { |
31 FATAL1("Marked object encountered %#" Px "\n", raw_addr); | 31 FATAL1("Marked object encountered %#" Px "\n", raw_addr); |
32 } | 32 } |
33 break; | 33 break; |
34 case kAllowMarked: | 34 case kAllowMarked: |
35 break; | 35 break; |
36 case kRequireMarked: | 36 case kRequireMarked: |
37 if (!raw_obj->IsMarked()) { | 37 if (!raw_obj->IsMarked()) { |
38 FATAL1("Unmarked object encountered %#" Px "\n", raw_addr); | 38 FATAL1("Unmarked object encountered %#" Px "\n", raw_addr); |
39 } | 39 } |
40 break; | 40 break; |
41 } | 41 } |
42 } | 42 } |
43 } | 43 } |
44 allocated_set_->Add(raw_obj); | 44 allocated_set_->Add(raw_obj); |
45 raw_obj->Validate(isolate_); | 45 raw_obj->Validate(isolate_); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { | 49 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { |
50 for (RawObject** current = first; current <= last; current++) { | 50 for (RawObject** current = first; current <= last; current++) { |
(...skipping 14 matching lines...) Expand all Loading... |
65 RawObject* raw_obj = handle->raw(); | 65 RawObject* raw_obj = handle->raw(); |
66 visitor_->VisitPointer(&raw_obj); | 66 visitor_->VisitPointer(&raw_obj); |
67 } | 67 } |
68 | 68 |
69 | 69 |
70 void VerifyPointersVisitor::VerifyPointers(MarkExpectation mark_expectation) { | 70 void VerifyPointersVisitor::VerifyPointers(MarkExpectation mark_expectation) { |
71 NoSafepointScope no_safepoint; | 71 NoSafepointScope no_safepoint; |
72 Thread* thread = Thread::Current(); | 72 Thread* thread = Thread::Current(); |
73 Isolate* isolate = thread->isolate(); | 73 Isolate* isolate = thread->isolate(); |
74 StackZone stack_zone(thread); | 74 StackZone stack_zone(thread); |
75 ObjectSet* allocated_set = | 75 ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet( |
76 isolate->heap()->CreateAllocatedObjectSet(stack_zone.GetZone(), | 76 stack_zone.GetZone(), mark_expectation); |
77 mark_expectation); | |
78 VerifyPointersVisitor visitor(isolate, allocated_set); | 77 VerifyPointersVisitor visitor(isolate, allocated_set); |
79 // Visit all strongly reachable objects. | 78 // Visit all strongly reachable objects. |
80 isolate->IterateObjectPointers(&visitor, | 79 isolate->IterateObjectPointers(&visitor, StackFrameIterator::kValidateFrames); |
81 StackFrameIterator::kValidateFrames); | |
82 VerifyWeakPointersVisitor weak_visitor(&visitor); | 80 VerifyWeakPointersVisitor weak_visitor(&visitor); |
83 // Visit weak handles and prologue weak handles. | 81 // Visit weak handles and prologue weak handles. |
84 isolate->VisitWeakPersistentHandles(&weak_visitor); | 82 isolate->VisitWeakPersistentHandles(&weak_visitor); |
85 } | 83 } |
86 | 84 |
87 | 85 |
88 #if defined(DEBUG) | 86 #if defined(DEBUG) |
89 VerifyCanonicalVisitor::VerifyCanonicalVisitor(Thread* thread) | 87 VerifyCanonicalVisitor::VerifyCanonicalVisitor(Thread* thread) |
90 : thread_(thread), | 88 : thread_(thread), instanceHandle_(Instance::Handle(thread->zone())) {} |
91 instanceHandle_(Instance::Handle(thread->zone())) { | |
92 } | |
93 | 89 |
94 | 90 |
95 void VerifyCanonicalVisitor::VisitObject(RawObject* obj) { | 91 void VerifyCanonicalVisitor::VisitObject(RawObject* obj) { |
96 if (obj->GetClassId() >= kInstanceCid) { | 92 if (obj->GetClassId() >= kInstanceCid) { |
97 if (obj->IsCanonical()) { | 93 if (obj->IsCanonical()) { |
98 instanceHandle_ ^= obj; | 94 instanceHandle_ ^= obj; |
99 ASSERT(instanceHandle_.CheckIsCanonical(thread_)); | 95 ASSERT(instanceHandle_.CheckIsCanonical(thread_)); |
100 } | 96 } |
101 } | 97 } |
102 } | 98 } |
103 #endif // defined(DEBUG) | 99 #endif // defined(DEBUG) |
104 | 100 |
105 } // namespace dart | 101 } // namespace dart |
OLD | NEW |