diff options
author | zerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 17:24:14 +0000 |
---|---|---|
committer | zerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 17:24:14 +0000 |
commit | 05939d2f9570c85efa713d5c5407147bec1ab0d0 (patch) | |
tree | c1ba695659ffa5221122c44c103caa8c691d8540 | |
parent | effacd2aae0aa9d85937a3880d4aad84c6e4363e (diff) | |
download | chromium_src-05939d2f9570c85efa713d5c5407147bec1ab0d0.zip chromium_src-05939d2f9570c85efa713d5c5407147bec1ab0d0.tar.gz chromium_src-05939d2f9570c85efa713d5c5407147bec1ab0d0.tar.bz2 |
Blink GC plugin: fix construction of collection edges containing primitive types.
R=ager@chromium.org
BUG=
Review URL: https://codereview.chromium.org/262883004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267836 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 276 insertions, 18 deletions
diff --git a/tools/clang/blink_gc_plugin/Config.h b/tools/clang/blink_gc_plugin/Config.h index ba440be..917d070 100644 --- a/tools/clang/blink_gc_plugin/Config.h +++ b/tools/clang/blink_gc_plugin/Config.h @@ -56,26 +56,35 @@ class Config { static bool IsWTFCollection(const std::string& name) { return name == "Vector" || + name == "Deque" || name == "HashSet" || - name == "HashMap" || - name == "HashCountedSet" || name == "ListHashSet" || - name == "Deque"; - } - - static bool IsPersistentGCCollection(const std::string& name) { - return name == "PersistentHeapVector" || - name == "PersistentHeapHashMap" || - name == "PersistentHeapHashSet"; + name == "LinkedHashSet" || + name == "HashCountedSet" || + name == "HashMap"; } static bool IsGCCollection(const std::string& name) { return name == "HeapVector" || - name == "HeapHashMap" || + name == "HeapDeque" || name == "HeapHashSet" || + name == "HeapListHashSet" || + name == "HeapLinkedHashSet" || + name == "HeapHashCountedSet" || + name == "HeapHashMap" || IsPersistentGCCollection(name); } + static bool IsPersistentGCCollection(const std::string& name) { + return name == "PersistentHeapVector" || + name == "PersistentHeapDeque" || + name == "PersistentHeapHashSet" || + name == "PersistentHeapListHashSet" || + name == "PersistentHeapLinkedHashSet" || + name == "PersistentHeapHashCountedSet" || + name == "PersistentHeapHashMap"; + } + static bool IsHashMap(const std::string& name) { return name == "HashMap" || name == "HeapHashMap" || diff --git a/tools/clang/blink_gc_plugin/RecordInfo.cpp b/tools/clang/blink_gc_plugin/RecordInfo.cpp index bbe4e58..1d26fa7 100644 --- a/tools/clang/blink_gc_plugin/RecordInfo.cpp +++ b/tools/clang/blink_gc_plugin/RecordInfo.cpp @@ -504,11 +504,9 @@ Edge* RecordInfo::CreateEdge(const Type* type) { for (TemplateArgs::iterator it = args.begin(); it != args.end(); ++it) { if (Edge* member = CreateEdge(*it)) { edge->members().push_back(member); - } else { - // We failed to create an edge so abort the entire edge construction. - delete edge; // Will delete the already allocated members. - return 0; } + // TODO: Handle the case where we fail to create an edge (eg, if the + // argument is a primitive type or just not fully known yet). } return edge; } diff --git a/tools/clang/blink_gc_plugin/tests/heap/stubs.h b/tools/clang/blink_gc_plugin/tests/heap/stubs.h index 41bf6ba..ca2b259 100644 --- a/tools/clang/blink_gc_plugin/tests/heap/stubs.h +++ b/tools/clang/blink_gc_plugin/tests/heap/stubs.h @@ -53,9 +53,10 @@ class VectorDestructorBase<inlineCapacity, true, false> {}; template<> class VectorDestructorBase<0, true, true> {}; -template<typename T, - size_t inlineCapacity = 0, - typename Allocator = DefaultAllocator> +template< + typename T, + size_t inlineCapacity = 0, + typename Allocator = DefaultAllocator> class Vector : public VectorDestructorBase<inlineCapacity, Allocator::isGarbageCollected, VectorTraits<T>::needsDestruction> { @@ -64,6 +65,49 @@ public: T& operator[](size_t); }; +template< + typename T, + size_t inlineCapacity = 0, + typename Allocator = DefaultAllocator> +class Deque {}; + +template< + typename ValueArg, + typename HashArg = void, + typename TraitsArg = void, + typename Allocator = DefaultAllocator> +class HashSet {}; + +template< + typename ValueArg, + typename HashArg = void, + typename TraitsArg = void, + typename Allocator = DefaultAllocator> +class ListHashSet {}; + +template< + typename ValueArg, + typename HashArg = void, + typename TraitsArg = void, + typename Allocator = DefaultAllocator> +class LinkedHashSet {}; + +template< + typename ValueArg, + typename HashArg = void, + typename TraitsArg = void, + typename Allocator = DefaultAllocator> +class HashCountedSet {}; + +template< + typename KeyArg, + typename MappedArg, + typename HashArg = void, + typename KeyTraitsArg = void, + typename MappedTraitsArg = void, + typename Allocator = DefaultAllocator> +class HashMap {}; + } namespace WebCore { @@ -107,6 +151,13 @@ public: bool operator!() const { return false; } }; +template<typename T> class WeakMember { +public: + operator T*() const { return 0; } + T* operator->() { return 0; } + bool operator!() const { return false; } +}; + template<typename T> class Persistent { public: operator T*() const { return 0; } @@ -122,12 +173,36 @@ public: template<typename T, size_t inlineCapacity = 0> class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { }; +template<typename T, size_t inlineCapacity = 0> +class HeapDeque : public Vector<T, inlineCapacity, HeapAllocator> { }; + +template<typename T> +class HeapHashSet : public HashSet<T, void, void, HeapAllocator> { }; + +template<typename T> +class HeapListHashSet : public ListHashSet<T, void, void, HeapAllocator> { }; + +template<typename T> +class HeapLinkedHashSet : public LinkedHashSet<T, void, void, HeapAllocator> { +}; + +template<typename T> +class HeapHashCountedSet : public HashCountedSet<T, void, void, HeapAllocator> { +}; + +template<typename K, typename V> +class HeapHashMap : public HashMap<K, V, void, void, void, HeapAllocator> { }; + template<typename T> class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; class Visitor { public: - template<typename T> void trace(const T&); + template<typename T> + void trace(const T&); + + template<typename T, void (T::*method)(Visitor*)> + void registerWeakMembers(const T* obj); }; class GarbageCollectedMixin { diff --git a/tools/clang/blink_gc_plugin/tests/trace_collections.cpp b/tools/clang/blink_gc_plugin/tests/trace_collections.cpp new file mode 100644 index 0000000..2dd028e --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/trace_collections.cpp @@ -0,0 +1,13 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "trace_collections.h" + +namespace WebCore { + +void HeapObject::trace(Visitor* visitor) +{ +} + +} diff --git a/tools/clang/blink_gc_plugin/tests/trace_collections.h b/tools/clang/blink_gc_plugin/tests/trace_collections.h new file mode 100644 index 0000000..0694bec --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/trace_collections.h @@ -0,0 +1,44 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef TRACE_COLLECTIONS_H_ +#define TRACE_COLLECTIONS_H_ + +#include "heap/stubs.h" + +namespace WebCore { + +class HeapObject : public GarbageCollected<HeapObject> { +public: + void trace(Visitor*); +private: + HeapVector<Member<HeapObject> > m_heapVector; + Vector<Member<HeapObject>, 0, HeapAllocator> m_wtfVector; + + HeapDeque<Member<HeapObject> > m_heapDeque; + Deque<Member<HeapObject>, 0, HeapAllocator> m_wtfDeque; + + HeapHashSet<Member<HeapObject> > m_heapSet; + HashSet<Member<HeapObject>, void, HeapAllocator> m_wtfSet; + + HeapListHashSet<Member<HeapObject> > m_heapListSet; + ListHashSet<Member<HeapObject>, void, HeapAllocator> m_wtfListSet; + + HeapLinkedHashSet<Member<HeapObject> > m_heapLinkedSet; + LinkedHashSet<Member<HeapObject>, void, HeapAllocator> m_wtfLinkedSet; + + HeapHashCountedSet<Member<HeapObject> > m_heapCountedSet; + HashCountedSet<Member<HeapObject>, void, HeapAllocator> m_wtfCountedSet; + + HeapHashMap<int, Member<HeapObject> > m_heapMapKey; + HeapHashMap<Member<HeapObject>, int > m_heapMapVal; + HashMap<int, Member<HeapObject>, void, void, void, HeapAllocator> + m_wtfMapKey; + HashMap<Member<HeapObject>, int, void, void, void, HeapAllocator> + m_wtfMapVal; +}; + +} + +#endif diff --git a/tools/clang/blink_gc_plugin/tests/trace_collections.txt b/tools/clang/blink_gc_plugin/tests/trace_collections.txt new file mode 100644 index 0000000..7c20ad4 --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/trace_collections.txt @@ -0,0 +1,52 @@ +trace_collections.cpp:9:1: warning: [blink-gc] Class 'HeapObject' has untraced fields that require tracing. +void HeapObject::trace(Visitor* visitor) +^ +./trace_collections.h:16:5: note: [blink-gc] Untraced field 'm_heapVector' declared here: + HeapVector<Member<HeapObject> > m_heapVector; + ^ +./trace_collections.h:17:5: note: [blink-gc] Untraced field 'm_wtfVector' declared here: + Vector<Member<HeapObject>, 0, HeapAllocator> m_wtfVector; + ^ +./trace_collections.h:19:5: note: [blink-gc] Untraced field 'm_heapDeque' declared here: + HeapDeque<Member<HeapObject> > m_heapDeque; + ^ +./trace_collections.h:20:5: note: [blink-gc] Untraced field 'm_wtfDeque' declared here: + Deque<Member<HeapObject>, 0, HeapAllocator> m_wtfDeque; + ^ +./trace_collections.h:22:5: note: [blink-gc] Untraced field 'm_heapSet' declared here: + HeapHashSet<Member<HeapObject> > m_heapSet; + ^ +./trace_collections.h:23:5: note: [blink-gc] Untraced field 'm_wtfSet' declared here: + HashSet<Member<HeapObject>, void, HeapAllocator> m_wtfSet; + ^ +./trace_collections.h:25:5: note: [blink-gc] Untraced field 'm_heapListSet' declared here: + HeapListHashSet<Member<HeapObject> > m_heapListSet; + ^ +./trace_collections.h:26:5: note: [blink-gc] Untraced field 'm_wtfListSet' declared here: + ListHashSet<Member<HeapObject>, void, HeapAllocator> m_wtfListSet; + ^ +./trace_collections.h:28:5: note: [blink-gc] Untraced field 'm_heapLinkedSet' declared here: + HeapLinkedHashSet<Member<HeapObject> > m_heapLinkedSet; + ^ +./trace_collections.h:29:5: note: [blink-gc] Untraced field 'm_wtfLinkedSet' declared here: + LinkedHashSet<Member<HeapObject>, void, HeapAllocator> m_wtfLinkedSet; + ^ +./trace_collections.h:31:5: note: [blink-gc] Untraced field 'm_heapCountedSet' declared here: + HeapHashCountedSet<Member<HeapObject> > m_heapCountedSet; + ^ +./trace_collections.h:32:5: note: [blink-gc] Untraced field 'm_wtfCountedSet' declared here: + HashCountedSet<Member<HeapObject>, void, HeapAllocator> m_wtfCountedSet; + ^ +./trace_collections.h:34:5: note: [blink-gc] Untraced field 'm_heapMapKey' declared here: + HeapHashMap<int, Member<HeapObject> > m_heapMapKey; + ^ +./trace_collections.h:35:5: note: [blink-gc] Untraced field 'm_heapMapVal' declared here: + HeapHashMap<Member<HeapObject>, int > m_heapMapVal; + ^ +./trace_collections.h:36:5: note: [blink-gc] Untraced field 'm_wtfMapKey' declared here: + HashMap<int, Member<HeapObject>, void, void, void, HeapAllocator> + ^ +./trace_collections.h:38:5: note: [blink-gc] Untraced field 'm_wtfMapVal' declared here: + HashMap<Member<HeapObject>, int, void, void, void, HeapAllocator> + ^ +1 warning generated. diff --git a/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.cpp b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.cpp new file mode 100644 index 0000000..478cc65 --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.cpp @@ -0,0 +1,28 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "weak_fields_require_tracing.h" + +namespace WebCore { + +void HeapObject::trace(Visitor* visitor) +{ + // Missing visitor->trace(m_obj1); + // Missing visitor->trace(m_obj2); + // visitor->trace(m_obj3) in callback. + // Missing visitor->trace(m_set1); + visitor->trace(m_set2); + visitor->registerWeakMembers<HeapObject, + &HeapObject::clearWeakMembers>(this); +} + +void HeapObject::clearWeakMembers(Visitor* visitor) +{ + visitor->trace(m_obj1); // Does not count. + // Missing visitor->trace(m_obj2); + visitor->trace(m_obj3); // OK. + visitor->trace(m_set1); // Does not count. +} + +} diff --git a/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.h b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.h new file mode 100644 index 0000000..67264d5 --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.h @@ -0,0 +1,26 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEAK_FIELDS_REQUIRE_TRACING_H_ +#define WEAK_FIELDS_REQUIRE_TRACING_H_ + +#include "heap/stubs.h" + +namespace WebCore { + +class HeapObject : public GarbageCollected<HeapObject> { +public: + void trace(Visitor*); + void clearWeakMembers(Visitor*); +private: + Member<HeapObject> m_obj1; + WeakMember<HeapObject> m_obj2; + WeakMember<HeapObject> m_obj3; + HeapHashSet<WeakMember<HeapObject> > m_set1; + HeapHashSet<WeakMember<HeapObject> > m_set2; +}; + +} + +#endif diff --git a/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.txt b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.txt new file mode 100644 index 0000000..02f56a3 --- /dev/null +++ b/tools/clang/blink_gc_plugin/tests/weak_fields_require_tracing.txt @@ -0,0 +1,13 @@ +weak_fields_require_tracing.cpp:9:1: warning: [blink-gc] Class 'HeapObject' has untraced fields that require tracing. +void HeapObject::trace(Visitor* visitor) +^ +./weak_fields_require_tracing.h:17:5: note: [blink-gc] Untraced field 'm_obj1' declared here: + Member<HeapObject> m_obj1; + ^ +./weak_fields_require_tracing.h:18:5: note: [blink-gc] Untraced field 'm_obj2' declared here: + WeakMember<HeapObject> m_obj2; + ^ +./weak_fields_require_tracing.h:20:5: note: [blink-gc] Untraced field 'm_set1' declared here: + HeapHashSet<WeakMember<HeapObject> > m_set1; + ^ +1 warning generated. |