| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 | |
| 49 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { | 48 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { |
| 50 for (RawObject** current = first; current <= last; current++) { | 49 for (RawObject** current = first; current <= last; current++) { |
| 51 RawObject* raw_obj = *current; | 50 RawObject* raw_obj = *current; |
| 52 if (raw_obj->IsHeapObject()) { | 51 if (raw_obj->IsHeapObject()) { |
| 53 if (!allocated_set_->Contains(raw_obj)) { | 52 if (!allocated_set_->Contains(raw_obj)) { |
| 54 uword raw_addr = RawObject::ToAddr(raw_obj); | 53 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 55 FATAL1("Invalid object pointer encountered %#" Px "\n", raw_addr); | 54 FATAL1("Invalid object pointer encountered %#" Px "\n", raw_addr); |
| 56 } | 55 } |
| 57 } | 56 } |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 | |
| 62 void VerifyWeakPointersVisitor::VisitHandle(uword addr) { | 60 void VerifyWeakPointersVisitor::VisitHandle(uword addr) { |
| 63 FinalizablePersistentHandle* handle = | 61 FinalizablePersistentHandle* handle = |
| 64 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 62 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
| 65 RawObject* raw_obj = handle->raw(); | 63 RawObject* raw_obj = handle->raw(); |
| 66 visitor_->VisitPointer(&raw_obj); | 64 visitor_->VisitPointer(&raw_obj); |
| 67 } | 65 } |
| 68 | 66 |
| 69 | |
| 70 void VerifyPointersVisitor::VerifyPointers(MarkExpectation mark_expectation) { | 67 void VerifyPointersVisitor::VerifyPointers(MarkExpectation mark_expectation) { |
| 71 NoSafepointScope no_safepoint; | 68 NoSafepointScope no_safepoint; |
| 72 Thread* thread = Thread::Current(); | 69 Thread* thread = Thread::Current(); |
| 73 Isolate* isolate = thread->isolate(); | 70 Isolate* isolate = thread->isolate(); |
| 74 StackZone stack_zone(thread); | 71 StackZone stack_zone(thread); |
| 75 ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet( | 72 ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet( |
| 76 stack_zone.GetZone(), mark_expectation); | 73 stack_zone.GetZone(), mark_expectation); |
| 77 VerifyPointersVisitor visitor(isolate, allocated_set); | 74 VerifyPointersVisitor visitor(isolate, allocated_set); |
| 78 // Visit all strongly reachable objects. | 75 // Visit all strongly reachable objects. |
| 79 isolate->IterateObjectPointers(&visitor, StackFrameIterator::kValidateFrames); | 76 isolate->IterateObjectPointers(&visitor, StackFrameIterator::kValidateFrames); |
| 80 VerifyWeakPointersVisitor weak_visitor(&visitor); | 77 VerifyWeakPointersVisitor weak_visitor(&visitor); |
| 81 // Visit weak handles and prologue weak handles. | 78 // Visit weak handles and prologue weak handles. |
| 82 isolate->VisitWeakPersistentHandles(&weak_visitor); | 79 isolate->VisitWeakPersistentHandles(&weak_visitor); |
| 83 } | 80 } |
| 84 | 81 |
| 85 | |
| 86 #if defined(DEBUG) | 82 #if defined(DEBUG) |
| 87 VerifyCanonicalVisitor::VerifyCanonicalVisitor(Thread* thread) | 83 VerifyCanonicalVisitor::VerifyCanonicalVisitor(Thread* thread) |
| 88 : thread_(thread), instanceHandle_(Instance::Handle(thread->zone())) {} | 84 : thread_(thread), instanceHandle_(Instance::Handle(thread->zone())) {} |
| 89 | 85 |
| 90 | |
| 91 void VerifyCanonicalVisitor::VisitObject(RawObject* obj) { | 86 void VerifyCanonicalVisitor::VisitObject(RawObject* obj) { |
| 92 if (obj->GetClassId() >= kInstanceCid) { | 87 if (obj->GetClassId() >= kInstanceCid) { |
| 93 if (obj->IsCanonical()) { | 88 if (obj->IsCanonical()) { |
| 94 instanceHandle_ ^= obj; | 89 instanceHandle_ ^= obj; |
| 95 const bool is_canonical = instanceHandle_.CheckIsCanonical(thread_); | 90 const bool is_canonical = instanceHandle_.CheckIsCanonical(thread_); |
| 96 if (!is_canonical) { | 91 if (!is_canonical) { |
| 97 OS::PrintErr("Instance `%s` is not canonical!\n", | 92 OS::PrintErr("Instance `%s` is not canonical!\n", |
| 98 instanceHandle_.ToCString()); | 93 instanceHandle_.ToCString()); |
| 99 } | 94 } |
| 100 ASSERT(is_canonical); | 95 ASSERT(is_canonical); |
| 101 } | 96 } |
| 102 } | 97 } |
| 103 } | 98 } |
| 104 #endif // defined(DEBUG) | 99 #endif // defined(DEBUG) |
| 105 | 100 |
| 106 } // namespace dart | 101 } // namespace dart |
| OLD | NEW |