1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "off-heap-collections-of-gced.h"
namespace blink {
class WithCollections : public GarbageCollected<WithCollections> {
public:
virtual void Trace(Visitor* v) const {
(void)set_;
(void)vector_;
(void)map_key_;
(void)map_value_;
(void)set_ptr_;
(void)vector_ref_;
(void)map_const_;
(void)vector_pair_;
(void)ignored_set_;
(void)array_;
(void)array_of_vectors_;
v->Trace(heap_hash_set_);
v->Trace(heap_deque_);
v->Trace(heap_vector_);
v->Trace(heap_linked_hash_set_);
v->Trace(heap_hash_counted_set_);
v->Trace(heap_hash_map_key_);
v->Trace(heap_hash_map_value_);
// The following calls are not needed and are added merely to silence false
// untraced field errors.
v->Trace(wtf_hash_set_);
v->Trace(wtf_deque_);
v->Trace(wtf_vector_);
v->Trace(wtf_hash_map_key_);
v->Trace(wtf_hash_map_value_);
}
private:
// Bad stl collections:
std::set<Base> set_;
std::vector<Derived> vector_;
std::map<Mixin, int> map_key_;
std::unordered_map<int, Base> map_value_;
std::unordered_set<Base*> set_ptr_;
std::vector<Derived&> vector_ref_;
std::map<const Mixin, int> map_const_;
std::vector<std::pair<Base, int>> vector_pair_;
std::array<Base, 4> array_;
std::array<HeapVector<Base>, 4> array_of_vectors_;
// Bad WTF collections:
WTF::HashSet<Base> wtf_hash_set_;
WTF::Deque<Derived> wtf_deque_;
WTF::Vector<Mixin> wtf_vector_;
WTF::LinkedHashSet<Base*> wtf_linked_hash_set_;
WTF::HashCountedSet<Derived&> wtf_hash_counted_set_;
WTF::HashMap<Mixin, bool> wtf_hash_map_key_;
WTF::HashMap<double, const Base> wtf_hash_map_value_;
// Good collections:
blink::HeapHashSet<Base> heap_hash_set_;
blink::HeapDeque<Derived> heap_deque_;
blink::HeapVector<Mixin> heap_vector_;
blink::HeapLinkedHashSet<Base> heap_linked_hash_set_;
blink::HeapHashCountedSet<Derived> heap_hash_counted_set_;
blink::HeapHashMap<Mixin, bool> heap_hash_map_key_;
blink::HeapHashMap<double, Base> heap_hash_map_value_;
GC_PLUGIN_IGNORE("For testing")
std::set<Base> ignored_set_;
};
class StackAllocated {
STACK_ALLOCATED();
public:
StackAllocated() {
(void)array_;
(void)array_of_vectors_;
}
private:
std::array<Base, 4> array_;
std::array<HeapVector<Base>, 4> array_of_vectors_;
};
void DisallowedUseOfCollections() {
// Bad stl collections:
std::set<Base> set;
(void)set;
std::vector<Derived> vector;
(void)vector;
std::map<Mixin, int> map_key;
(void)map_key;
std::unordered_map<int, Base> map_value;
(void)map_value;
std::unordered_set<Base*> set_ptr;
(void)set_ptr;
std::vector<Derived&> vector_ref;
(void)vector_ref;
std::map<const Mixin, int> map_const;
(void)map_const;
std::vector<std::pair<Base, int>> vector_pair;
(void)vector_pair;
// Bad WTF collections:
WTF::HashSet<Base> wtf_hash_set;
WTF::Deque<Derived> wtf_deque;
WTF::Vector<Mixin> wtf_vector;
WTF::LinkedHashSet<Base*> wtf_linked_hash_set;
WTF::HashCountedSet<Derived&> wtf_hash_counted_set;
WTF::HashMap<Mixin, bool> wtf_hash_map_key;
WTF::HashMap<double, const Base> wtf_hash_map_value;
// Good collections:
blink::HeapHashSet<Base> heap_hash_set;
blink::HeapDeque<Derived> heap_deque;
blink::HeapVector<Mixin> heap_vector;
blink::HeapLinkedHashSet<Base> heap_linked_hash_set;
blink::HeapHashCountedSet<Derived> heap_hash_counted_set;
blink::HeapHashMap<Mixin, bool> heap_hash_map_key;
blink::HeapHashMap<double, Base> heap_hash_map_value;
std::array<Base, 4> array;
(void)array;
std::array<HeapVector<Base>, 4> array_of_vectors;
(void)array_of_vectors;
GC_PLUGIN_IGNORE("For testing")
std::set<Base> ignored_set;
(void)ignored_set;
}
} // namespace blink
|