Commit f482da2b authored by Michael Lippautz's avatar Michael Lippautz Committed by Chromium LUCI CQ

heap: Refactor collections into their own files

Similar to WTF, refactor collections into their own files, allowing
for IWYU but also simplifying the library transition as these data
structures should work with the Blink and the library implementation.

Blink users include `heap_allocator.h` to get the data structures and
not HeapAllocator.

HeapAllocator is now provided through `heap_allocator_impl.h` which is
pulled in by the corresponding data structures.

We cannot work with forward declarations of HeapAllocator, as WTF
doesn't work solely on the type but on Allocator::kIsGarbageCollected.

Bug: 1056170
Change-Id: I1e6f0a481b2e332b0299a6487c41b6b1112f355b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616561
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarOmer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841688}
parent 2ed7f715
...@@ -54,10 +54,15 @@ blink_platform_sources("heap") { ...@@ -54,10 +54,15 @@ blink_platform_sources("heap") {
sources = [ sources = [
"blink_gc_memory_dump_provider.h", "blink_gc_memory_dump_provider.h",
"collection_support/heap_deque.h",
"collection_support/heap_hash_counted_set.h",
"collection_support/heap_hash_map.h",
"collection_support/heap_hash_set.h",
"collection_support/heap_hash_table_backing.h", "collection_support/heap_hash_table_backing.h",
"collection_support/heap_linked_hash_set.h", "collection_support/heap_linked_hash_set.h",
"collection_support/heap_linked_stack.h", "collection_support/heap_linked_stack.h",
"collection_support/heap_list_hash_set.h", "collection_support/heap_list_hash_set.h",
"collection_support/heap_vector.h",
"collection_support/heap_vector_backing.h", "collection_support/heap_vector_backing.h",
"disallow_new_wrapper.h", "disallow_new_wrapper.h",
"garbage_collected.h", "garbage_collected.h",
...@@ -65,6 +70,7 @@ blink_platform_sources("heap") { ...@@ -65,6 +70,7 @@ blink_platform_sources("heap") {
"handle.h", "handle.h",
"heap.h", "heap.h",
"heap_allocator.h", "heap_allocator.h",
"heap_allocator_impl.h",
"heap_stats_collector.h", "heap_stats_collector.h",
"heap_traits.h", "heap_traits.h",
"member.h", "member.h",
...@@ -128,8 +134,8 @@ blink_platform_sources("heap") { ...@@ -128,8 +134,8 @@ blink_platform_sources("heap") {
"impl/gc_task_runner.h", "impl/gc_task_runner.h",
"impl/heap.cc", "impl/heap.cc",
"impl/heap.h", "impl/heap.h",
"impl/heap_allocator.cc", "impl/heap_allocator_impl.cc",
"impl/heap_allocator.h", "impl/heap_allocator_impl.h",
"impl/heap_compact.cc", "impl/heap_compact.cc",
"impl/heap_compact.h", "impl/heap_compact.h",
"impl/heap_page.cc", "impl/heap_page.cc",
......
// Copyright 2021 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_DEQUE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_DEQUE_H_
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
namespace blink {
template <typename T>
class HeapDeque final : public Deque<T, 0, HeapAllocator> {
IS_GARBAGE_COLLECTED_CONTAINER_TYPE();
DISALLOW_NEW();
static void CheckType() {
static_assert(WTF::IsMemberType<T>::value,
"HeapDeque supports only Member.");
static_assert(std::is_trivially_destructible<HeapDeque>::value,
"HeapDeque must be trivially destructible.");
static_assert(WTF::IsTraceable<T>::value,
"For vectors without traceable elements, use Deque<> instead "
"of HeapDeque<>");
}
public:
template <typename>
static void* AllocateObject(size_t size) {
return ThreadHeap::Allocate<HeapDeque<T>>(size);
}
HeapDeque() { CheckType(); }
explicit HeapDeque(wtf_size_t size) : Deque<T, 0, HeapAllocator>(size) {
CheckType();
}
HeapDeque(wtf_size_t size, const T& val)
: Deque<T, 0, HeapAllocator>(size, val) {
CheckType();
}
HeapDeque& operator=(const HeapDeque& other) {
HeapDeque<T> copy(other);
Deque<T, 0, HeapAllocator>::Swap(copy);
return *this;
}
HeapDeque(const HeapDeque<T>& other) : Deque<T, 0, HeapAllocator>(other) {}
};
template <typename T>
struct GCInfoTrait<HeapDeque<T>>
: public GCInfoTrait<Deque<T, 0, HeapAllocator>> {};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_DEQUE_H_
// Copyright 2021 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_COUNTED_SET_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_COUNTED_SET_H_
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/hash_counted_set.h"
namespace blink {
template <typename Value,
typename HashFunctions = typename DefaultHash<Value>::Hash,
typename Traits = HashTraits<Value>>
class HeapHashCountedSet final
: public HashCountedSet<Value, HashFunctions, Traits, HeapAllocator> {
IS_GARBAGE_COLLECTED_CONTAINER_TYPE();
DISALLOW_NEW();
static void CheckType() {
static_assert(WTF::IsMemberOrWeakMemberType<Value>::value,
"HeapHashCountedSet supports only Member and WeakMember.");
static_assert(std::is_trivially_destructible<HeapHashCountedSet>::value,
"HeapHashCountedSet must be trivially destructible.");
static_assert(WTF::IsTraceable<Value>::value,
"For counted sets without traceable elements, use "
"HashCountedSet<> instead of HeapHashCountedSet<>.");
}
public:
template <typename>
static void* AllocateObject(size_t size) {
return ThreadHeap::Allocate<
HeapHashCountedSet<Value, HashFunctions, Traits>>(size);
}
HeapHashCountedSet() { CheckType(); }
};
template <typename T, typename U, typename V>
struct GCInfoTrait<HeapHashCountedSet<T, U, V>>
: public GCInfoTrait<HashCountedSet<T, U, V, HeapAllocator>> {};
} // namespace blink
namespace WTF {
template <typename Value,
typename HashFunctions,
typename Traits,
typename VectorType>
inline void CopyToVector(
const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set,
VectorType& vector) {
CopyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits,
blink::HeapAllocator>&>(set),
vector);
}
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_COUNTED_SET_H_
// Copyright 2021 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_MAP_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_MAP_H_
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace blink {
template <typename KeyArg,
typename MappedArg,
typename HashArg = typename DefaultHash<KeyArg>::Hash,
typename KeyTraitsArg = HashTraits<KeyArg>,
typename MappedTraitsArg = HashTraits<MappedArg>>
class HeapHashMap final : public HashMap<KeyArg,
MappedArg,
HashArg,
KeyTraitsArg,
MappedTraitsArg,
HeapAllocator> {
IS_GARBAGE_COLLECTED_CONTAINER_TYPE();
DISALLOW_NEW();
static void CheckType() {
static_assert(std::is_trivially_destructible<HeapHashMap>::value,
"HeapHashMap must be trivially destructible.");
static_assert(
WTF::IsTraceable<KeyArg>::value || WTF::IsTraceable<MappedArg>::value,
"For hash maps without traceable elements, use HashMap<> "
"instead of HeapHashMap<>.");
static_assert(WTF::IsMemberOrWeakMemberType<KeyArg>::value ||
!WTF::IsTraceable<KeyArg>::value,
"HeapHashMap supports only Member, WeakMember and "
"non-traceable types as keys.");
static_assert(WTF::IsMemberOrWeakMemberType<MappedArg>::value ||
!WTF::IsTraceable<MappedArg>::value ||
WTF::IsSubclassOfTemplate<MappedArg,
TraceWrapperV8Reference>::value,
"HeapHashMap supports only Member, WeakMember, "
"TraceWrapperV8Reference and "
"non-traceable types as values.");
}
public:
template <typename>
static void* AllocateObject(size_t size) {
return ThreadHeap::Allocate<
HeapHashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>>(
size);
}
HeapHashMap() { CheckType(); }
};
template <typename T, typename U, typename V, typename W, typename X>
struct GCInfoTrait<HeapHashMap<T, U, V, W, X>>
: public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator>> {};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_MAP_H_
// Copyright 2021 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_SET_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_SET_H_
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
namespace blink {
template <typename ValueArg,
typename HashArg = typename DefaultHash<ValueArg>::Hash,
typename TraitsArg = HashTraits<ValueArg>>
class HeapHashSet
: public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator> {
IS_GARBAGE_COLLECTED_CONTAINER_TYPE();
DISALLOW_NEW();
static void CheckType() {
static_assert(WTF::IsMemberOrWeakMemberType<ValueArg>::value,
"HeapHashSet supports only Member and WeakMember.");
static_assert(std::is_trivially_destructible<HeapHashSet>::value,
"HeapHashSet must be trivially destructible.");
static_assert(WTF::IsTraceable<ValueArg>::value,
"For hash sets without traceable elements, use HashSet<> "
"instead of HeapHashSet<>.");
}
public:
template <typename>
static void* AllocateObject(size_t size) {
return ThreadHeap::Allocate<HeapHashSet<ValueArg, HashArg, TraitsArg>>(
size);
}
HeapHashSet() { CheckType(); }
};
template <typename T, typename U, typename V>
struct GCInfoTrait<HeapHashSet<T, U, V>>
: public GCInfoTrait<HashSet<T, U, V, HeapAllocator>> {};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_SET_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LINKED_HASH_SET_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LINKED_HASH_SET_H_
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/linked_hash_set.h" #include "third_party/blink/renderer/platform/wtf/linked_hash_set.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h" #include "third_party/blink/renderer/platform/wtf/type_traits.h"
......
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LINKED_STACK_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LINKED_STACK_H_
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h" #include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/heap/visitor.h" #include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
namespace blink { namespace blink {
...@@ -76,7 +77,7 @@ class HeapLinkedStack final : public GarbageCollected<HeapLinkedStack<T>> { ...@@ -76,7 +77,7 @@ class HeapLinkedStack final : public GarbageCollected<HeapLinkedStack<T>> {
}; };
static void CheckType() { static void CheckType() {
static_assert(internal::IsMember<T>, static_assert(WTF::IsMemberType<T>::value,
"HeapLinkedStack supports only Member."); "HeapLinkedStack supports only Member.");
} }
......
// Copyright 2021 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_VECTOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_VECTOR_H_
#include "third_party/blink/renderer/platform/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
template <typename T, wtf_size_t inlineCapacity = 0>
class HeapVector final : public Vector<T, inlineCapacity, HeapAllocator> {
IS_GARBAGE_COLLECTED_CONTAINER_TYPE();
DISALLOW_NEW();
static void CheckType() {
static_assert(
std::is_trivially_destructible<HeapVector>::value || inlineCapacity,
"HeapVector must be trivially destructible.");
static_assert(WTF::IsTraceable<T>::value,
"For vectors without traceable elements, use Vector<> "
"instead of HeapVector<>.");
static_assert(!WTF::IsWeak<T>::value,
"Weak types are not allowed in HeapVector.");
static_assert(WTF::IsTraceableInCollectionTrait<VectorTraits<T>>::value,
"Type must be traceable in collection");
}
public:
template <typename>
static void* AllocateObject(size_t size) {
// On-heap HeapVectors generally should not have inline capacity, but it is
// hard to avoid when using a type alias. Hence we only disallow the
// VectorTraits<T>::kNeedsDestruction case for now.
static_assert(inlineCapacity == 0 || !VectorTraits<T>::kNeedsDestruction,
"on-heap HeapVector<> should not have an inline capacity");
return ThreadHeap::Allocate<HeapVector<T, inlineCapacity>>(size);
}
HeapVector() { CheckType(); }
explicit HeapVector(wtf_size_t size)
: Vector<T, inlineCapacity, HeapAllocator>(size) {
CheckType();
}
HeapVector(wtf_size_t size, const T& val)
: Vector<T, inlineCapacity, HeapAllocator>(size, val) {
CheckType();
}
template <wtf_size_t otherCapacity>
HeapVector(const HeapVector<T, otherCapacity>& other) // NOLINT
: Vector<T, inlineCapacity, HeapAllocator>(other) {
CheckType();
}
HeapVector(const HeapVector& other)
: Vector<T, inlineCapacity, HeapAllocator>(other) {
CheckType();
}
HeapVector& operator=(const HeapVector& other) {
Vector<T, inlineCapacity, HeapAllocator>::operator=(other);
return *this;
}
HeapVector(HeapVector&& other) noexcept
: Vector<T, inlineCapacity, HeapAllocator>(std::move(other)) {
CheckType();
}
HeapVector& operator=(HeapVector&& other) noexcept {
Vector<T, inlineCapacity, HeapAllocator>::operator=(std::move(other));
return *this;
}
HeapVector(std::initializer_list<T> elements)
: Vector<T, inlineCapacity, HeapAllocator>(elements) {
CheckType();
}
};
template <typename T, wtf_size_t inlineCapacity>
struct GCInfoTrait<HeapVector<T, inlineCapacity>>
: public GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator>> {};
} // namespace blink
namespace WTF {
template <typename T>
struct VectorTraits<blink::Member<T>> : VectorTraitsBase<blink::Member<T>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = false;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = true;
static const bool kCanCopyWithMemcpy = true;
static const bool kCanMoveWithMemcpy = true;
static constexpr bool kCanTraceConcurrently = true;
};
// These traits are used in VectorBackedLinkedList to support WeakMember in
// HeapLinkedHashSet though HeapVector<WeakMember> usage is still banned.
// (See the discussion in https://crrev.com/c/2246014)
template <typename T>
struct VectorTraits<blink::WeakMember<T>>
: VectorTraitsBase<blink::WeakMember<T>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = false;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = true;
static const bool kCanCopyWithMemcpy = true;
static const bool kCanMoveWithMemcpy = true;
static constexpr bool kCanTraceConcurrently = true;
};
template <typename T>
struct VectorTraits<blink::UntracedMember<T>>
: VectorTraitsBase<blink::UntracedMember<T>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = false;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = true;
static const bool kCanMoveWithMemcpy = true;
};
template <typename T>
struct VectorTraits<blink::HeapVector<T, 0>>
: VectorTraitsBase<blink::HeapVector<T, 0>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = false;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = true;
static const bool kCanMoveWithMemcpy = true;
};
template <typename T>
struct VectorTraits<blink::HeapDeque<T>>
: VectorTraitsBase<blink::HeapDeque<T>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = false;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = true;
static const bool kCanMoveWithMemcpy = true;
};
template <typename T, wtf_size_t inlineCapacity>
struct VectorTraits<blink::HeapVector<T, inlineCapacity>>
: VectorTraitsBase<blink::HeapVector<T, inlineCapacity>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = VectorTraits<T>::kNeedsDestruction;
static const bool kCanInitializeWithMemset =
VectorTraits<T>::kCanInitializeWithMemset;
static const bool kCanClearUnusedSlotsWithMemset =
VectorTraits<T>::kCanClearUnusedSlotsWithMemset;
static const bool kCanMoveWithMemcpy = VectorTraits<T>::kCanMoveWithMemcpy;
};
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_VECTOR_H_
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/impl/finalizer_traits.h" #include "third_party/blink/renderer/platform/heap/impl/finalizer_traits.h"
#include "third_party/blink/renderer/platform/heap/impl/gc_info.h" #include "third_party/blink/renderer/platform/heap/impl/gc_info.h"
#include "third_party/blink/renderer/platform/heap/impl/threading_traits.h" #include "third_party/blink/renderer/platform/heap/impl/threading_traits.h"
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_
// Legacy: Users including `heap_allocator.h` actually expect it to pull in the
// containers.
#include "third_party/blink/renderer/platform/heap/collection_support/heap_deque.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_counted_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_linked_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_list_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/wtf/buildflags.h" #include "third_party/blink/renderer/platform/wtf/buildflags.h"
#if BUILDFLAG(USE_V8_OILPAN)
#include "third_party/blink/renderer/platform/heap/v8_wrapper/heap_allocator.h"
#else // !USE_V8_OILPAN
#include "third_party/blink/renderer/platform/heap/impl/heap_allocator.h"
#endif // !USE_V8_OILPAN
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_
// Copyright 2020 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_IMPL_H_
#include "third_party/blink/renderer/platform/wtf/buildflags.h"
#if BUILDFLAG(USE_V8_OILPAN)
// TODO(1056170): Add wrapper version.
#else // !USE_V8_OILPAN
#include "third_party/blink/renderer/platform/heap/impl/heap_allocator_impl.h"
#endif // !USE_V8_OILPAN
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_IMPL_H_
// Copyright 2015 The Chromium Authors. All rights reserved. // Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/renderer/platform/heap/heap_allocator.h" #include "third_party/blink/renderer/platform/heap/impl/heap_allocator_impl.h"
namespace blink { namespace blink {
......
// Copyright 2015 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_ALLOCATOR_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_ALLOCATOR_IMPL_H_
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_table_backing.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector_backing.h"
#include "third_party/blink/renderer/platform/heap/impl/heap.h"
#include "third_party/blink/renderer/platform/heap/impl/marking_visitor.h"
#include "third_party/blink/renderer/platform/heap/impl/trace_traits.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
namespace blink {
// This is a static-only class used as a trait on collections to make them heap
// allocated.
class PLATFORM_EXPORT HeapAllocator {
STATIC_ONLY(HeapAllocator);
public:
using LivenessBroker = blink::LivenessBroker;
using Visitor = blink::Visitor;
static constexpr bool kIsGarbageCollected = true;
// See wtf/size_t.h for details.
static constexpr size_t kMaxHeapObjectSizeLog2 = 27;
static constexpr size_t kMaxHeapObjectSize = 1 << kMaxHeapObjectSizeLog2;
template <typename T>
static size_t MaxElementCountInBackingStore() {
return kMaxHeapObjectSize / sizeof(T);
}
template <typename T>
static size_t QuantizedSize(size_t count) {
CHECK_LE(count, MaxElementCountInBackingStore<T>());
// Oilpan's internal size is independent of MaxElementCountInBackingStore()
// and the required size to match capacity needs.
return count * sizeof(T);
}
template <typename T>
static T* AllocateVectorBacking(size_t size) {
return reinterpret_cast<T*>(
MakeGarbageCollected<HeapVectorBacking<T>>(size / sizeof(T)));
}
static void FreeVectorBacking(void*);
static bool ExpandVectorBacking(void*, size_t);
static bool ShrinkVectorBacking(void* address,
size_t quantized_current_size,
size_t quantized_shrunk_size);
template <typename T, typename HashTable>
static T* AllocateHashTableBacking(size_t size) {
return reinterpret_cast<T*>(
MakeGarbageCollected<HeapHashTableBacking<HashTable>>(
size / sizeof(typename HashTable::ValueType)));
}
template <typename T, typename HashTable>
static T* AllocateZeroedHashTableBacking(size_t size) {
return AllocateHashTableBacking<T, HashTable>(size);
}
static void FreeHashTableBacking(void* address);
static bool ExpandHashTableBacking(void*, size_t);
static bool IsAllocationAllowed() {
return ThreadState::Current()->IsAllocationAllowed();
}
static bool IsIncrementalMarking() {
return ThreadState::IsAnyIncrementalMarking() &&
ThreadState::Current()->IsIncrementalMarking();
}
static void EnterGCForbiddenScope() {
ThreadState::Current()->EnterGCForbiddenScope();
}
static void LeaveGCForbiddenScope() {
ThreadState::Current()->LeaveGCForbiddenScope();
}
template <typename T, typename Traits>
static void Trace(Visitor* visitor, const T& t) {
TraceCollectionIfEnabled<WTF::WeakHandlingTrait<T>::value, T,
Traits>::Trace(visitor, &t);
}
template <typename T>
static void TraceVectorBacking(Visitor* visitor,
const T* backing,
const T* const* backing_slot) {
visitor->TraceMovablePointer(backing_slot);
visitor->Trace(reinterpret_cast<const HeapVectorBacking<T>*>(backing));
}
template <typename T, typename HashTable>
static void TraceHashTableBackingStrongly(Visitor* visitor,
const T* backing,
const T* const* backing_slot) {
visitor->TraceMovablePointer(backing_slot);
visitor->Trace(
reinterpret_cast<const HeapHashTableBacking<HashTable>*>(backing));
}
template <typename T, typename HashTable>
static void TraceHashTableBackingWeakly(Visitor* visitor,
const T* backing,
const T* const* backing_slot,
WeakCallback callback,
const void* parameter) {
visitor->TraceMovablePointer(backing_slot);
visitor->TraceWeakContainer(
reinterpret_cast<const HeapHashTableBacking<HashTable>*>(backing),
reinterpret_cast<const HeapHashTableBacking<HashTable>* const*>(
backing_slot),
TraceTrait<HeapHashTableBacking<HashTable>>::GetTraceDescriptor(
backing),
TraceTrait<HeapHashTableBacking<HashTable>>::GetWeakTraceDescriptor(
backing),
callback, parameter);
}
template <typename T>
static void BackingWriteBarrier(T** slot) {
MarkingVisitor::WriteBarrier(reinterpret_cast<void**>(slot));
}
static void TraceBackingStoreIfMarked(const void* object) {
MarkingVisitor::RetraceObject(object);
}
template <typename T, typename Traits>
static void NotifyNewObject(T* object) {
MarkingVisitor::WriteBarrier(
[]() { return ThreadState::Current(); }, object, sizeof(T), 1,
TraceCollectionIfEnabled<WTF::kNoWeakHandling, T, Traits>::Trace);
}
template <typename T, typename Traits>
static void NotifyNewObjects(T* array, size_t len) {
MarkingVisitor::WriteBarrier(
[]() { return ThreadState::Current(); }, array, sizeof(T), len,
TraceCollectionIfEnabled<WTF::kNoWeakHandling, T, Traits>::Trace);
}
private:
static void BackingFree(void*);
static bool BackingExpand(void*, size_t);
static bool BackingShrink(void*,
size_t quantized_current_size,
size_t quantized_shrunk_size);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_ALLOCATOR_IMPL_H_
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/platform/heap/impl/heap_page.h" #include "third_party/blink/renderer/platform/heap/impl/heap_page.h"
#include "third_party/blink/renderer/platform/heap/impl/marking_visitor.h" #include "third_party/blink/renderer/platform/heap/impl/marking_visitor.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/construct_traits.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h" #include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h" #include "third_party/blink/renderer/platform/wtf/hash_traits.h"
......
...@@ -886,86 +886,4 @@ inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { ...@@ -886,86 +886,4 @@ inline bool operator!=(const Persistent<T>& a, const Member<U>& b) {
} // namespace blink } // namespace blink
namespace WTF {
template <
typename T,
blink::WeaknessPersistentConfiguration weaknessConfiguration,
blink::CrossThreadnessPersistentConfiguration crossThreadnessConfiguration>
struct VectorTraits<blink::PersistentBase<T,
weaknessConfiguration,
crossThreadnessConfiguration>>
: VectorTraitsBase<blink::PersistentBase<T,
weaknessConfiguration,
crossThreadnessConfiguration>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = true;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = false;
static const bool kCanMoveWithMemcpy = true;
};
template <typename T>
struct HashTraits<blink::Persistent<T>>
: HandleHashTraits<T, blink::Persistent<T>> {};
template <typename T>
struct HashTraits<blink::CrossThreadPersistent<T>>
: HandleHashTraits<T, blink::CrossThreadPersistent<T>> {};
template <typename T>
struct DefaultHash<blink::Persistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::WeakPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::CrossThreadPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::CrossThreadWeakPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct CrossThreadCopier<blink::CrossThreadPersistent<T>>
: public CrossThreadCopierPassThrough<blink::CrossThreadPersistent<T>> {
STATIC_ONLY(CrossThreadCopier);
};
template <typename T>
struct CrossThreadCopier<blink::CrossThreadWeakPersistent<T>>
: public CrossThreadCopierPassThrough<blink::CrossThreadWeakPersistent<T>> {
STATIC_ONLY(CrossThreadCopier);
};
} // namespace WTF
namespace base {
template <typename T>
struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
template <typename T>
struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
template <typename T>
struct BindUnwrapTraits<blink::CrossThreadWeakPersistent<T>> {
static blink::CrossThreadPersistent<T> Unwrap(
const blink::CrossThreadWeakPersistent<T>& wrapped) {
return blink::CrossThreadPersistent<T>(wrapped);
}
};
} // namespace base
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_PERSISTENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_PERSISTENT_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_MEMBER_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_MEMBER_H_
#include "third_party/blink/renderer/platform/wtf/buildflags.h" #include "third_party/blink/renderer/platform/wtf/buildflags.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h"
#if BUILDFLAG(USE_V8_OILPAN) #if BUILDFLAG(USE_V8_OILPAN)
#include "third_party/blink/renderer/platform/heap/v8_wrapper/member.h" #include "third_party/blink/renderer/platform/heap/v8_wrapper/member.h"
...@@ -13,4 +14,108 @@ ...@@ -13,4 +14,108 @@
#include "third_party/blink/renderer/platform/heap/impl/member.h" #include "third_party/blink/renderer/platform/heap/impl/member.h"
#endif // !USE_V8_OILPAN #endif // !USE_V8_OILPAN
namespace WTF {
template <typename T>
struct HashTraits<blink::Member<T>> : SimpleClassHashTraits<blink::Member<T>> {
STATIC_ONLY(HashTraits);
// FIXME: Implement proper const'ness for iterator types. Requires support
// in the marking Visitor.
using PeekInType = T*;
using IteratorGetType = blink::Member<T>*;
using IteratorConstGetType = const blink::Member<T>*;
using IteratorReferenceType = blink::Member<T>&;
using IteratorConstReferenceType = const blink::Member<T>&;
static IteratorReferenceType GetToReferenceConversion(IteratorGetType x) {
return *x;
}
static IteratorConstReferenceType GetToReferenceConstConversion(
IteratorConstGetType x) {
return *x;
}
using PeekOutType = T*;
template <typename U>
static void Store(const U& value, blink::Member<T>& storage) {
storage = value;
}
static PeekOutType Peek(const blink::Member<T>& value) { return value; }
static void ConstructDeletedValue(blink::Member<T>& slot, bool) {
slot = WTF::kHashTableDeletedValue;
}
static constexpr bool kCanTraceConcurrently = true;
};
template <typename T>
struct HashTraits<blink::WeakMember<T>>
: SimpleClassHashTraits<blink::WeakMember<T>> {
STATIC_ONLY(HashTraits);
static const bool kNeedsDestruction = false;
// FIXME: Implement proper const'ness for iterator types. Requires support
// in the marking Visitor.
using PeekInType = T*;
using IteratorGetType = blink::WeakMember<T>*;
using IteratorConstGetType = const blink::WeakMember<T>*;
using IteratorReferenceType = blink::WeakMember<T>&;
using IteratorConstReferenceType = const blink::WeakMember<T>&;
static IteratorReferenceType GetToReferenceConversion(IteratorGetType x) {
return *x;
}
static IteratorConstReferenceType GetToReferenceConstConversion(
IteratorConstGetType x) {
return *x;
}
using PeekOutType = T*;
template <typename U>
static void Store(const U& value, blink::WeakMember<T>& storage) {
storage = value;
}
static PeekOutType Peek(const blink::WeakMember<T>& value) { return value; }
static void ConstructDeletedValue(blink::WeakMember<T>& slot, bool) {
slot = WTF::kHashTableDeletedValue;
}
static constexpr bool kCanTraceConcurrently = true;
};
template <typename T>
struct HashTraits<blink::UntracedMember<T>>
: SimpleClassHashTraits<blink::UntracedMember<T>> {
STATIC_ONLY(HashTraits);
static const bool kNeedsDestruction = false;
// FIXME: Implement proper const'ness for iterator types.
using PeekInType = T*;
using IteratorGetType = blink::UntracedMember<T>*;
using IteratorConstGetType = const blink::UntracedMember<T>*;
using IteratorReferenceType = blink::UntracedMember<T>&;
using IteratorConstReferenceType = const blink::UntracedMember<T>&;
static IteratorReferenceType GetToReferenceConversion(IteratorGetType x) {
return *x;
}
static IteratorConstReferenceType GetToReferenceConstConversion(
IteratorConstGetType x) {
return *x;
}
using PeekOutType = T*;
template <typename U>
static void Store(const U& value, blink::UntracedMember<T>& storage) {
storage = value;
}
static PeekOutType Peek(const blink::UntracedMember<T>& value) {
return value;
}
};
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_MEMBER_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_MEMBER_H_
...@@ -13,4 +13,115 @@ ...@@ -13,4 +13,115 @@
#include "third_party/blink/renderer/platform/heap/impl/persistent.h" #include "third_party/blink/renderer/platform/heap/impl/persistent.h"
#endif // !USE_V8_OILPAN #endif // !USE_V8_OILPAN
namespace WTF {
template <
typename T,
blink::WeaknessPersistentConfiguration weaknessConfiguration,
blink::CrossThreadnessPersistentConfiguration crossThreadnessConfiguration>
struct VectorTraits<blink::PersistentBase<T,
weaknessConfiguration,
crossThreadnessConfiguration>>
: VectorTraitsBase<blink::PersistentBase<T,
weaknessConfiguration,
crossThreadnessConfiguration>> {
STATIC_ONLY(VectorTraits);
static const bool kNeedsDestruction = true;
static const bool kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = false;
static const bool kCanMoveWithMemcpy = true;
};
template <typename T, typename H>
struct HandleHashTraits : SimpleClassHashTraits<H> {
STATIC_ONLY(HandleHashTraits);
// TODO: Implement proper const'ness for iterator types. Requires support
// in the marking Visitor.
using PeekInType = T*;
using IteratorGetType = H*;
using IteratorConstGetType = const H*;
using IteratorReferenceType = H&;
using IteratorConstReferenceType = const H&;
static IteratorReferenceType GetToReferenceConversion(IteratorGetType x) {
return *x;
}
static IteratorConstReferenceType GetToReferenceConstConversion(
IteratorConstGetType x) {
return *x;
}
using PeekOutType = T*;
template <typename U>
static void Store(const U& value, H& storage) {
storage = value;
}
static PeekOutType Peek(const H& value) { return value; }
};
template <typename T>
struct HashTraits<blink::Persistent<T>>
: HandleHashTraits<T, blink::Persistent<T>> {};
template <typename T>
struct HashTraits<blink::CrossThreadPersistent<T>>
: HandleHashTraits<T, blink::CrossThreadPersistent<T>> {};
template <typename T>
struct DefaultHash<blink::Persistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::WeakPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::CrossThreadPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::CrossThreadWeakPersistent<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct CrossThreadCopier<blink::CrossThreadPersistent<T>>
: public CrossThreadCopierPassThrough<blink::CrossThreadPersistent<T>> {
STATIC_ONLY(CrossThreadCopier);
};
template <typename T>
struct CrossThreadCopier<blink::CrossThreadWeakPersistent<T>>
: public CrossThreadCopierPassThrough<blink::CrossThreadWeakPersistent<T>> {
STATIC_ONLY(CrossThreadCopier);
};
} // namespace WTF
namespace base {
template <typename T>
struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
template <typename T>
struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
template <typename T>
struct BindUnwrapTraits<blink::CrossThreadWeakPersistent<T>> {
static blink::CrossThreadPersistent<T> Unwrap(
const blink::CrossThreadWeakPersistent<T>& wrapped) {
return blink::CrossThreadPersistent<T>(wrapped);
}
};
} // namespace base
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_
...@@ -134,6 +134,9 @@ struct IsMemberOrWeakMemberType ...@@ -134,6 +134,9 @@ struct IsMemberOrWeakMemberType
cppgc::IsMemberTypeV<T> || cppgc::IsMemberTypeV<T> ||
cppgc::IsWeakMemberTypeV<T>> {}; cppgc::IsWeakMemberTypeV<T>> {};
template <typename T>
struct IsMemberType : std::integral_constant<bool, cppgc::IsMemberTypeV<T>> {};
#else // !USE_V8_OILPAN #else // !USE_V8_OILPAN
namespace internal { namespace internal {
...@@ -226,6 +229,12 @@ struct IsMemberOrWeakMemberType ...@@ -226,6 +229,12 @@ struct IsMemberOrWeakMemberType
WTF::IsSubclassOfTemplate<T, blink::Member>::value || WTF::IsSubclassOfTemplate<T, blink::Member>::value ||
WTF::IsSubclassOfTemplate<T, blink::WeakMember>::value> {}; WTF::IsSubclassOfTemplate<T, blink::WeakMember>::value> {};
template <typename T>
struct IsMemberType : std::integral_constant<
bool,
WTF::IsSubclassOfTemplate<T, blink::Member>::value> {
};
#endif // !USE_V8_OILPAN #endif // !USE_V8_OILPAN
// Convenience template wrapping the IsTraceableInCollection template in // Convenience template wrapping the IsTraceableInCollection template in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment