• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "CheckGCRootsVisitor.h"
6 
CheckGCRootsVisitor()7 CheckGCRootsVisitor::CheckGCRootsVisitor() {
8 }
9 
gc_roots()10 CheckGCRootsVisitor::Errors& CheckGCRootsVisitor::gc_roots() {
11   return gc_roots_;
12 }
13 
ContainsGCRoots(RecordInfo * info)14 bool CheckGCRootsVisitor::ContainsGCRoots(RecordInfo* info) {
15   for (RecordInfo::Fields::iterator it = info->GetFields().begin();
16        it != info->GetFields().end();
17        ++it) {
18     current_.push_back(&it->second);
19     it->second.edge()->Accept(this);
20     current_.pop_back();
21   }
22   return !gc_roots_.empty();
23 }
24 
VisitValue(Value * edge)25 void CheckGCRootsVisitor::VisitValue(Value* edge) {
26   // TODO: what should we do to check unions?
27   if (edge->value()->record()->isUnion())
28     return;
29 
30   // Prevent infinite regress for cyclic part objects.
31   if (visiting_set_.find(edge->value()) != visiting_set_.end())
32     return;
33 
34   visiting_set_.insert(edge->value());
35   // If the value is a part object, then continue checking for roots.
36   for (Context::iterator it = context().begin();
37        it != context().end();
38        ++it) {
39     if (!(*it)->IsCollection())
40       return;
41   }
42   ContainsGCRoots(edge->value());
43   visiting_set_.erase(edge->value());
44 }
45 
VisitPersistent(Persistent * edge)46 void CheckGCRootsVisitor::VisitPersistent(Persistent* edge) {
47   gc_roots_.push_back(current_);
48 }
49 
AtCollection(Collection * edge)50 void CheckGCRootsVisitor::AtCollection(Collection* edge) {
51   if (edge->is_root())
52     gc_roots_.push_back(current_);
53 }
54