| 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 DEFINE_FLAG(bool, verify_on_transition, false, "Verify on dart <==> VM."); | 20 DEFINE_FLAG(bool, verify_on_transition, false, "Verify on dart <==> VM."); |
| 21 | 21 |
| 22 | 22 |
| 23 void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) { | 23 void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) { |
| 24 if (raw_obj->IsHeapObject()) { |
| 25 switch (mark_expectation_) { |
| 26 case kForbidMarked: |
| 27 if (raw_obj->IsMarked()) { |
| 28 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 29 FATAL1("Marked object encountered %#" Px "\n", raw_addr); |
| 30 } |
| 31 break; |
| 32 case kAllowMarked: |
| 33 break; |
| 34 case kRequireMarked: |
| 35 if (!raw_obj->IsMarked()) { |
| 36 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 37 FATAL1("Unmarked object encountered %#" Px "\n", raw_addr); |
| 38 } |
| 39 break; |
| 40 } |
| 41 } |
| 24 allocated_set_->Add(raw_obj); | 42 allocated_set_->Add(raw_obj); |
| 25 raw_obj->Validate(isolate()); | 43 raw_obj->Validate(isolate()); |
| 26 } | 44 } |
| 27 | 45 |
| 28 | 46 |
| 29 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { | 47 void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) { |
| 30 for (RawObject** current = first; current <= last; current++) { | 48 for (RawObject** current = first; current <= last; current++) { |
| 31 RawObject* raw_obj = *current; | 49 RawObject* raw_obj = *current; |
| 32 if (raw_obj->IsHeapObject()) { | 50 if (raw_obj->IsHeapObject()) { |
| 33 if (!allocated_set_->Contains(raw_obj)) { | 51 if (!allocated_set_->Contains(raw_obj)) { |
| 34 uword raw_addr = RawObject::ToAddr(raw_obj); | 52 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 35 FATAL1("Invalid object pointer encountered %#" Px "\n", raw_addr); | 53 FATAL1("Invalid object pointer encountered %#" Px "\n", raw_addr); |
| 36 } | 54 } |
| 37 } | 55 } |
| 38 } | 56 } |
| 39 } | 57 } |
| 40 | 58 |
| 41 | 59 |
| 42 void VerifyWeakPointersVisitor::VisitHandle(uword addr) { | 60 void VerifyWeakPointersVisitor::VisitHandle(uword addr) { |
| 43 FinalizablePersistentHandle* handle = | 61 FinalizablePersistentHandle* handle = |
| 44 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 62 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
| 45 RawObject* raw_obj = handle->raw(); | 63 RawObject* raw_obj = handle->raw(); |
| 46 visitor_->VisitPointer(&raw_obj); | 64 visitor_->VisitPointer(&raw_obj); |
| 47 } | 65 } |
| 48 | 66 |
| 49 | 67 |
| 50 void VerifyPointersVisitor::VerifyPointers() { | 68 void VerifyPointersVisitor::VerifyPointers(MarkExpectation mark_expectation) { |
| 51 NoGCScope no_gc; | 69 NoGCScope no_gc; |
| 52 Isolate* isolate = Isolate::Current(); | 70 Isolate* isolate = Isolate::Current(); |
| 53 ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet(); | 71 ObjectSet* allocated_set = |
| 72 isolate->heap()->CreateAllocatedObjectSet(mark_expectation); |
| 54 VerifyPointersVisitor visitor(isolate, allocated_set); | 73 VerifyPointersVisitor visitor(isolate, allocated_set); |
| 55 // Visit all strongly reachable objects. | 74 // Visit all strongly reachable objects. |
| 56 isolate->VisitObjectPointers(&visitor, | 75 isolate->VisitObjectPointers(&visitor, |
| 57 false, // skip prologue weak handles | 76 false, // skip prologue weak handles |
| 58 StackFrameIterator::kValidateFrames); | 77 StackFrameIterator::kValidateFrames); |
| 59 VerifyWeakPointersVisitor weak_visitor(&visitor); | 78 VerifyWeakPointersVisitor weak_visitor(&visitor); |
| 60 // Visit weak handles and prologue weak handles. | 79 // Visit weak handles and prologue weak handles. |
| 61 isolate->VisitWeakPersistentHandles(&weak_visitor, | 80 isolate->VisitWeakPersistentHandles(&weak_visitor, |
| 62 true); // visit prologue weak handles | 81 true); // visit prologue weak handles |
| 63 delete allocated_set; | 82 delete allocated_set; |
| 64 } | 83 } |
| 65 | 84 |
| 66 } // namespace dart | 85 } // namespace dart |
| OLD | NEW |