0928c651e5
The previous algorithm would visit each pointer in the heap and verify it without regard for whether the pointer had already been visited. The new algorithm computes the set of allocated objects and verifies each object in the set. In a second pass, each pointer is visited and tested for membership in the set. BUG=2606 Review URL: https://chromiumcodereview.appspot.com//10696029 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9532 260f80e4-7a28-3924-810f-c04153c831b5
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/verifier.h"
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/dart.h"
|
|
#include "vm/dart_api_state.h"
|
|
#include "vm/freelist.h"
|
|
#include "vm/heap.h"
|
|
#include "vm/isolate.h"
|
|
#include "vm/object.h"
|
|
#include "vm/object_set.h"
|
|
#include "vm/raw_object.h"
|
|
#include "vm/stack_frame.h"
|
|
|
|
namespace dart {
|
|
|
|
DEFINE_FLAG(bool, verify_on_transition, false, "Verify on dart <==> VM.");
|
|
|
|
|
|
void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) {
|
|
allocated_set_->Add(raw_obj);
|
|
raw_obj->Validate(isolate());
|
|
}
|
|
|
|
|
|
void VerifyPointersVisitor::VisitPointers(RawObject** first, RawObject** last) {
|
|
for (RawObject** current = first; current <= last; current++) {
|
|
RawObject* raw_obj = *current;
|
|
if (raw_obj->IsHeapObject()) {
|
|
if (!allocated_set_->Contains(raw_obj)) {
|
|
uword raw_addr = RawObject::ToAddr(raw_obj);
|
|
FATAL1("Invalid object pointer encountered %#lx\n", raw_addr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void VerifyWeakPointersVisitor::VisitHandle(uword addr) {
|
|
FinalizablePersistentHandle* handle =
|
|
reinterpret_cast<FinalizablePersistentHandle*>(addr);
|
|
RawObject* raw_obj = handle->raw();
|
|
visitor_->VisitPointer(&raw_obj);
|
|
}
|
|
|
|
|
|
void VerifyPointersVisitor::VerifyPointers() {
|
|
NoGCScope no_gc;
|
|
Isolate* isolate = Isolate::Current();
|
|
ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet();
|
|
VerifyPointersVisitor visitor(isolate, allocated_set);
|
|
// Visit all strongly reachable objects.
|
|
isolate->VisitObjectPointers(&visitor,
|
|
false, // skip prologue weak handles
|
|
StackFrameIterator::kValidateFrames);
|
|
VerifyWeakPointersVisitor weak_visitor(&visitor);
|
|
// Visit weak handles and prologue weak handles.
|
|
isolate->VisitWeakPersistentHandles(&weak_visitor,
|
|
true); // visit prologue weak handles
|
|
delete allocated_set;
|
|
}
|
|
|
|
} // namespace dart
|