Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
verifier.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/heap/verifier.h"
6
7#include "platform/assert.h"
8#include "vm/dart.h"
9#include "vm/dart_api_state.h"
10#include "vm/heap/heap.h"
11#include "vm/isolate.h"
12#include "vm/object.h"
13#include "vm/object_set.h"
14#include "vm/raw_object.h"
15#include "vm/stack_frame.h"
16
17namespace dart {
18
20 ASSERT(obj->IsHeapObject());
21 uword addr = UntaggedObject::ToAddr(obj);
22 if (obj->IsFreeListElement() || obj->IsForwardingCorpse()) {
23 if (obj->IsOldObject() && obj->untag()->IsMarked()) {
24 FATAL("Marked free list element encountered %#" Px "\n", addr);
25 }
26 } else {
27 switch (mark_expectation_) {
28 case kForbidMarked:
29 if (obj->IsOldObject() && obj->untag()->IsMarked()) {
30 FATAL("Marked object encountered %#" Px "\n", addr);
31 }
32 break;
33 case kAllowMarked:
34 break;
35 case kRequireMarked:
36 if (obj->IsOldObject() && !obj->untag()->IsMarked()) {
37 FATAL("Unmarked object encountered %#" Px "\n", addr);
38 }
39 break;
40 }
41 allocated_set_->Add(obj);
42 }
43 obj->Validate(isolate_group_);
44}
45
47 for (ObjectPtr* ptr = from; ptr <= to; ptr++) {
48 ObjectPtr obj = *ptr;
49 if (obj->IsHeapObject()) {
50 if (!allocated_set_->Contains(obj)) {
51 FATAL("%s: Invalid pointer: *0x%" Px " = 0x%" Px "\n", msg_,
52 reinterpret_cast<uword>(ptr), static_cast<uword>(obj));
53 }
54 }
55 }
56}
57
58#if defined(DART_COMPRESSED_POINTERS)
62 for (CompressedObjectPtr* ptr = from; ptr <= to; ptr++) {
63 ObjectPtr obj = ptr->Decompress(heap_base);
64 if (obj->IsHeapObject()) {
65 if (!allocated_set_->Contains(obj)) {
66 FATAL("%s: Invalid pointer: *0x%" Px " = 0x%" Px "\n", msg_,
67 reinterpret_cast<uword>(ptr), static_cast<uword>(obj));
68 }
69 }
70 }
71}
72#endif
73
76 reinterpret_cast<FinalizablePersistentHandle*>(addr);
77 ObjectPtr raw_obj = handle->ptr();
78 visitor_->VisitPointer(&raw_obj);
79}
80
82 MarkExpectation mark_expectation) {
83 Thread* thread = Thread::Current();
84 auto isolate_group = thread->isolate_group();
85 HeapIterationScope iteration(thread);
86 StackZone stack_zone(thread);
88 stack_zone.GetZone(), mark_expectation);
89
90 VerifyPointersVisitor visitor(isolate_group, allocated_set, msg);
91 // Visit all strongly reachable objects.
93 VerifyWeakPointersVisitor weak_visitor(&visitor);
94
95 // Visit weak handles and prologue weak handles.
97}
98
99} // namespace dart
void IterateObjectPointers(ObjectPointerVisitor *visitor, ValidationPolicy validate_frames)
Definition heap.cc:357
ObjectSet * CreateAllocatedObjectSet(Zone *zone, MarkExpectation mark_expectation)
Definition heap.cc:732
Heap * heap() const
Definition isolate.h:295
void VisitWeakPersistentHandles(HandleVisitor *visitor)
Definition isolate.cc:2952
IsolateGroup * isolate_group() const
Definition visitor.h:25
void VisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition visitor.h:43
void VisitPointer(ObjectPtr *p)
Definition visitor.h:55
void Validate(IsolateGroup *isolate_group) const
Definition raw_object.cc:30
bool IsFreeListElement() const
ObjectPtr Decompress(uword heap_base) const
UntaggedObject * untag() const
bool IsForwardingCorpse() const
void Add(ObjectPtr raw_obj)
Definition object_set.h:75
bool Contains(ObjectPtr raw_obj) const
Definition object_set.h:66
Zone * GetZone()
Definition zone.h:213
static Thread * Current()
Definition thread.h:361
IsolateGroup * isolate_group() const
Definition thread.h:540
static bool IsMarked(uword tags)
Definition raw_object.h:298
static uword ToAddr(const UntaggedObject *raw_obj)
Definition raw_object.h:501
void VisitObject(ObjectPtr obj) override
Definition verifier.cc:19
void VisitPointers(ObjectPtr *first, ObjectPtr *last) override
Definition verifier.cc:46
static void VerifyPointers(const char *msg, MarkExpectation mark_expectation=kForbidMarked)
Definition verifier.cc:81
void VisitHandle(uword addr) override
Definition verifier.cc:74
#define ASSERT(E)
#define FATAL(error)
uintptr_t uword
Definition globals.h:501
MarkExpectation
Definition verifier.h:21
@ kAllowMarked
Definition verifier.h:21
@ kRequireMarked
Definition verifier.h:21
@ kForbidMarked
Definition verifier.h:21
#define Px
Definition globals.h:410