Files
sdk/runtime/vm/heap/verifier.cc
T
Régis Crelier a39833d957 Reland "Reland "[VM runtime] Dual mapping of executable pages.""
This is a reland of 6da340bf76

Original change's description:
> Reland "[VM runtime] Dual mapping of executable pages."
> 
> This is a reland of 44186dfdcd
> 
> Original change's description:
> > [VM runtime] Dual mapping of executable pages.
> > 
> > Change-Id: Iaad78d324e25462ce951f4df26974a6a368c50b7
> > Reviewed-on: https://dart-review.googlesource.com/c/93377
> > Commit-Queue: Régis Crelier <regis@google.com>
> > Reviewed-by: Ryan Macnak <rmacnak@google.com>
> 
> Change-Id: I7a0caa078950637d9fe831732577fd2467061099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95263
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

Change-Id: I3a01f0e67d733c5db41618f691431e72c1e1cb2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96422
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2019-03-12 20:45:45 +00:00

107 lines
3.5 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/heap/verifier.h"
#include "platform/assert.h"
#include "vm/dart.h"
#include "vm/dart_api_state.h"
#include "vm/heap/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 {
void VerifyObjectVisitor::VisitObject(RawObject* raw_obj) {
if (raw_obj->IsHeapObject()) {
uword raw_addr = RawObject::ToAddr(raw_obj);
if (raw_obj->IsFreeListElement() || raw_obj->IsForwardingCorpse()) {
if (raw_obj->IsOldObject() && raw_obj->IsMarked()) {
FATAL1("Marked free list element encountered %#" Px "\n", raw_addr);
}
} else {
switch (mark_expectation_) {
case kForbidMarked:
if (raw_obj->IsOldObject() && raw_obj->IsMarked()) {
FATAL1("Marked object encountered %#" Px "\n", raw_addr);
}
break;
case kAllowMarked:
break;
case kRequireMarked:
if (raw_obj->IsOldObject() && !raw_obj->IsMarked()) {
FATAL1("Unmarked object encountered %#" Px "\n", raw_addr);
}
break;
}
}
}
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)) {
if (raw_obj->IsInstructions() &&
allocated_set_->Contains(HeapPage::ToWritable(raw_obj))) {
continue;
}
uword raw_addr = RawObject::ToAddr(raw_obj);
FATAL1("Invalid object pointer encountered %#" Px "\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(MarkExpectation mark_expectation) {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
HeapIterationScope iteration(thread);
StackZone stack_zone(thread);
ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet(
stack_zone.GetZone(), mark_expectation);
VerifyPointersVisitor visitor(isolate, allocated_set);
// Visit all strongly reachable objects.
iteration.IterateObjectPointers(&visitor, ValidationPolicy::kValidateFrames);
VerifyWeakPointersVisitor weak_visitor(&visitor);
// Visit weak handles and prologue weak handles.
isolate->VisitWeakPersistentHandles(&weak_visitor);
}
#if defined(DEBUG)
VerifyCanonicalVisitor::VerifyCanonicalVisitor(Thread* thread)
: thread_(thread), instanceHandle_(Instance::Handle(thread->zone())) {}
void VerifyCanonicalVisitor::VisitObject(RawObject* obj) {
if ((obj->GetClassId() >= kInstanceCid) &&
(obj->GetClassId() != kTypeArgumentsCid)) {
if (obj->IsCanonical()) {
instanceHandle_ ^= obj;
const bool is_canonical = instanceHandle_.CheckIsCanonical(thread_);
if (!is_canonical) {
OS::PrintErr("Instance `%s` is not canonical!\n",
instanceHandle_.ToCString());
}
ASSERT(is_canonical);
}
}
}
#endif // defined(DEBUG)
} // namespace dart