Commit 2954bf5c authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap: Move HeapHashTableBacking support into its own file

Same as with HeapVectorBacking, move the GC support for
HeapHashTableBacking into its own file instead of distributing it over
the GC internals.

Bug: 1056170
Change-Id: Ie4d26fd4135258c5cf4f4a133e7084d8105e02fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074617
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744742}
parent 1bb2aa7a
......@@ -46,6 +46,7 @@ blink_platform_sources("heap") {
"blink_gc_memory_dump_provider.h",
"cancelable_task_scheduler.cc",
"cancelable_task_scheduler.h",
"collection_support/heap_hash_table_backing.h",
"collection_support/heap_vector_backing.h",
"disallow_new_wrapper.h",
"finalizer_traits.h",
......
......@@ -91,8 +91,6 @@ struct FinalizerTrait {
};
class HeapAllocator;
template <typename Table>
class HeapHashTableBacking;
template <typename T, typename U, typename V>
struct FinalizerTrait<LinkedHashSet<T, U, V, HeapAllocator>> {
......@@ -137,17 +135,6 @@ struct FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator>> {
}
};
template <typename Table>
struct FinalizerTrait<HeapHashTableBacking<Table>> {
STATIC_ONLY(FinalizerTrait);
static const bool kNonTrivialFinalizer =
!std::is_trivially_destructible<typename Table::ValueType>::value;
static void Finalize(void* obj) {
internal::FinalizerTraitImpl<HeapHashTableBacking<Table>,
kNonTrivialFinalizer>::Finalize(obj);
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_FINALIZER_TRAITS_H_
......@@ -8,6 +8,7 @@
#include <type_traits>
#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/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_buildflags.h"
......@@ -46,16 +47,6 @@ template <typename T>
struct IsAllowedInContainer<T, typename T::IsDisallowedInContainerMarker>
: std::false_type {};
template <typename Table>
class HeapHashTableBacking {
DISALLOW_NEW();
IS_GARBAGE_COLLECTED_TYPE();
public:
static void Finalize(void* pointer);
void FinalizeGarbageCollectedObject() { Finalize(this); }
};
// This is a static-only class used as a trait on collections to make them heap
// allocated. However see also HeapListHashSetAllocator.
class PLATFORM_EXPORT HeapAllocator {
......@@ -90,16 +81,9 @@ class PLATFORM_EXPORT HeapAllocator {
template <typename T, typename HashTable>
static T* AllocateHashTableBacking(size_t size) {
uint32_t gc_info_index =
GCInfoTrait<HeapHashTableBacking<HashTable>>::Index();
ThreadState* state =
ThreadStateFor<ThreadingTrait<T>::kAffinity>::GetState();
const char* type_name =
WTF_HEAP_PROFILER_TYPE_NAME(HeapHashTableBacking<HashTable>);
return reinterpret_cast<T*>(
MarkAsConstructed(state->Heap().AllocateOnArenaIndex(
state, size, BlinkGC::kHashTableArenaIndex, gc_info_index,
type_name)));
MakeGarbageCollected<HeapHashTableBacking<HashTable>>(
size / sizeof(typename HashTable::ValueType)));
}
template <typename T, typename HashTable>
static T* AllocateZeroedHashTableBacking(size_t size) {
......@@ -396,23 +380,6 @@ class HeapListHashSetAllocator : public HeapAllocator {
}
};
template <typename Table>
void HeapHashTableBacking<Table>::Finalize(void* pointer) {
using Value = typename Table::ValueType;
static_assert(
!std::is_trivially_destructible<Value>::value,
"Finalization of trivially destructible classes should not happen.");
HeapObjectHeader* header = HeapObjectHeader::FromPayload(pointer);
// Use the payload size as recorded by the heap to determine how many
// elements to finalize.
size_t length = header->PayloadSize() / sizeof(Value);
Value* table = reinterpret_cast<Value*>(pointer);
for (unsigned i = 0; i < length; ++i) {
if (!Table::IsEmptyOrDeletedBucket(table[i]))
table[i].~Value();
}
}
namespace internal {
template <typename T>
......
......@@ -56,8 +56,6 @@ struct DefaultThreadingTrait<T, true> {
};
class HeapAllocator;
template <typename Table>
class HeapHashTableBacking;
template <typename T>
class Member;
template <typename T>
......@@ -128,18 +126,6 @@ struct ThreadingTrait<HashCountedSet<T, U, V, HeapAllocator>> {
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename Table>
struct ThreadingTrait<HeapHashTableBacking<Table>> {
STATIC_ONLY(ThreadingTrait);
using Key = typename Table::KeyType;
using Value = typename Table::ValueType;
static const ThreadAffinity kAffinity =
(ThreadingTrait<Key>::Affinity == kMainThreadOnly) &&
(ThreadingTrait<Value>::Affinity == kMainThreadOnly)
? kMainThreadOnly
: kAnyThread;
};
template <typename T, typename U, typename V, typename W, typename X>
class HeapHashMap;
template <typename T, typename U, typename V>
......
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