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

heap: More compilation fixes for the Oilpan library

Miscellaneous changes:
- IWYU fixes for the library;
- Move some needed traits to global includes;
- Add stub for invoking a testing GC;

Bug: 1056170
Change-Id: Ia4871852a4f73595d0c9466140d7fb7cd7bd6e61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624729
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842706}
parent 16a30826
...@@ -103,7 +103,7 @@ blink_platform_sources("heap") { ...@@ -103,7 +103,7 @@ blink_platform_sources("heap") {
"v8_wrapper/garbage_collected.h", "v8_wrapper/garbage_collected.h",
"v8_wrapper/gc_task_runner.h", "v8_wrapper/gc_task_runner.h",
"v8_wrapper/heap.h", "v8_wrapper/heap.h",
"v8_wrapper/heap_allocator.h", "v8_wrapper/heap_allocator_impl.h",
"v8_wrapper/heap_stats_collector.h", "v8_wrapper/heap_stats_collector.h",
"v8_wrapper/heap_traits.h", "v8_wrapper/heap_traits.h",
"v8_wrapper/member.h", "v8_wrapper/member.h",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_MAP_H_ #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_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_HASH_MAP_H_
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.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/heap/heap_allocator_impl.h"
#include "third_party/blink/renderer/platform/heap/visitor.h" #include "third_party/blink/renderer/platform/heap/visitor.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LIST_HASH_SET_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_LIST_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/member.h"
#include "third_party/blink/renderer/platform/wtf/list_hash_set.h" #include "third_party/blink/renderer/platform/wtf/list_hash_set.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h" #include "third_party/blink/renderer/platform/wtf/type_traits.h"
......
...@@ -69,10 +69,6 @@ class HeapVector final : public GarbageCollected<HeapVector<T, inlineCapacity>>, ...@@ -69,10 +69,6 @@ class HeapVector final : public GarbageCollected<HeapVector<T, inlineCapacity>>,
} }
}; };
template <typename T, wtf_size_t inlineCapacity>
struct GCInfoTrait<HeapVector<T, inlineCapacity>>
: public GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator>> {};
} // namespace blink } // namespace blink
namespace WTF { namespace WTF {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "third_party/blink/renderer/platform/wtf/buildflags.h" #include "third_party/blink/renderer/platform/wtf/buildflags.h"
#if BUILDFLAG(USE_V8_OILPAN) #if BUILDFLAG(USE_V8_OILPAN)
// TODO(1056170): Add wrapper version. #include "third_party/blink/renderer/platform/heap/v8_wrapper/heap_allocator_impl.h"
#else // !USE_V8_OILPAN #else // !USE_V8_OILPAN
#include "third_party/blink/renderer/platform/heap/impl/heap_allocator_impl.h" #include "third_party/blink/renderer/platform/heap/impl/heap_allocator_impl.h"
#endif // !USE_V8_OILPAN #endif // !USE_V8_OILPAN
......
...@@ -488,53 +488,6 @@ struct TraceTrait<WeakMember<T>> : public MemberTraceTraits<WeakMember<T>> {}; ...@@ -488,53 +488,6 @@ struct TraceTrait<WeakMember<T>> : public MemberTraceTraits<WeakMember<T>> {};
namespace WTF { namespace WTF {
// PtrHash is the default hash for hash tables with Member<>-derived elements.
template <typename T>
struct MemberHash : PtrHash<T> {
STATIC_ONLY(MemberHash);
template <typename U>
static unsigned GetHash(const U& key) {
return PtrHash<T>::GetHash(key);
}
template <typename U, typename V>
static bool Equal(const U& a, const V& b) {
return a == b;
}
};
template <typename T>
struct DefaultHash<blink::Member<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::WeakMember<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::UntracedMember<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct IsTraceable<blink::Member<T>> {
STATIC_ONLY(IsTraceable);
static const bool value = true;
};
template <typename T>
struct IsWeak<blink::WeakMember<T>> : std::true_type {};
template <typename T>
struct IsTraceable<blink::WeakMember<T>> {
STATIC_ONLY(IsTraceable);
static const bool value = true;
};
template <typename T, typename Traits, typename Allocator> template <typename T, typename Traits, typename Allocator>
class MemberConstructTraits { class MemberConstructTraits {
STATIC_ONLY(MemberConstructTraits); STATIC_ONLY(MemberConstructTraits);
......
...@@ -808,17 +808,6 @@ Persistent<T> WrapPersistentInternal(T* value) { ...@@ -808,17 +808,6 @@ Persistent<T> WrapPersistentInternal(T* value) {
#define WrapPersistent(value) WrapPersistentInternal(value) #define WrapPersistent(value) WrapPersistentInternal(value)
#endif // BUILDFLAG(RAW_HEAP_SNAPSHOTS) #endif // BUILDFLAG(RAW_HEAP_SNAPSHOTS)
template <typename T,
typename = std::enable_if_t<WTF::IsGarbageCollectedType<T>::value>>
Persistent<T> WrapPersistentIfNeeded(T* value) {
return Persistent<T>(value);
}
template <typename T>
T& WrapPersistentIfNeeded(T& value) {
return value;
}
template <typename T> template <typename T>
WeakPersistent<T> WrapWeakPersistent(T* value) { WeakPersistent<T> WrapWeakPersistent(T* value) {
return WeakPersistent<T>(value); return WeakPersistent<T>(value);
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#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_functions.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h" #include "third_party/blink/renderer/platform/wtf/hash_traits.h"
#include "third_party/blink/renderer/platform/wtf/type_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"
...@@ -25,6 +27,53 @@ inline void swap(Member<T>& a, Member<T>& b) { ...@@ -25,6 +27,53 @@ inline void swap(Member<T>& a, Member<T>& b) {
namespace WTF { namespace WTF {
// PtrHash is the default hash for hash tables with Member<>-derived elements.
template <typename T>
struct MemberHash : PtrHash<T> {
STATIC_ONLY(MemberHash);
template <typename U>
static unsigned GetHash(const U& key) {
return PtrHash<T>::GetHash(key);
}
template <typename U, typename V>
static bool Equal(const U& a, const V& b) {
return a == b;
}
};
template <typename T>
struct DefaultHash<blink::Member<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::WeakMember<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct DefaultHash<blink::UntracedMember<T>> {
STATIC_ONLY(DefaultHash);
using Hash = MemberHash<T>;
};
template <typename T>
struct IsTraceable<blink::Member<T>> {
STATIC_ONLY(IsTraceable);
static const bool value = true;
};
template <typename T>
struct IsWeak<blink::WeakMember<T>> : std::true_type {};
template <typename T>
struct IsTraceable<blink::WeakMember<T>> {
STATIC_ONLY(IsTraceable);
static const bool value = true;
};
template <typename T> template <typename T>
struct HashTraits<blink::Member<T>> : SimpleClassHashTraits<blink::Member<T>> { struct HashTraits<blink::Member<T>> : SimpleClassHashTraits<blink::Member<T>> {
STATIC_ONLY(HashTraits); STATIC_ONLY(HashTraits);
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_PERSISTENT_H_
#include "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/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
#if BUILDFLAG(USE_V8_OILPAN) #if BUILDFLAG(USE_V8_OILPAN)
#include "third_party/blink/renderer/platform/heap/v8_wrapper/persistent.h" #include "third_party/blink/renderer/platform/heap/v8_wrapper/persistent.h"
...@@ -13,25 +16,45 @@ ...@@ -13,25 +16,45 @@
#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 blink {
template <typename T,
typename = std::enable_if_t<WTF::IsGarbageCollectedType<T>::value>>
Persistent<T> WrapPersistentIfNeeded(T* value) {
return Persistent<T>(value);
}
template <typename T>
T& WrapPersistentIfNeeded(T& value) {
return value;
}
} // namespace blink
namespace WTF { namespace WTF {
template < template <typename T>
typename T, struct PersistentVectorTraitsBase : VectorTraitsBase<T> {
blink::WeaknessPersistentConfiguration weaknessConfiguration, STATIC_ONLY(PersistentVectorTraitsBase);
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 kCanInitializeWithMemset = true;
static const bool kCanClearUnusedSlotsWithMemset = false;
static const bool kCanMoveWithMemcpy = true;
}; };
template <typename T>
struct VectorTraits<blink::Persistent<T>>
: PersistentVectorTraitsBase<blink::Persistent<T>> {};
template <typename T>
struct VectorTraits<blink::WeakPersistent<T>>
: PersistentVectorTraitsBase<blink::WeakPersistent<T>> {};
template <typename T>
struct VectorTraits<blink::CrossThreadPersistent<T>>
: PersistentVectorTraitsBase<blink::CrossThreadPersistent<T>> {};
template <typename T>
struct VectorTraits<blink::CrossThreadWeakPersistent<T>>
: PersistentVectorTraitsBase<blink::CrossThreadWeakPersistent<T>> {};
template <typename T, typename H> template <typename T, typename H>
struct HandleHashTraits : SimpleClassHashTraits<H> { struct HandleHashTraits : SimpleClassHashTraits<H> {
STATIC_ONLY(HandleHashTraits); STATIC_ONLY(HandleHashTraits);
......
...@@ -5,6 +5,22 @@ ...@@ -5,6 +5,22 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_
// TODO(chromium:1056170): Implement wrapper. #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
class PLATFORM_EXPORT BlinkGC final {
STATIC_ONLY(BlinkGC);
public:
// When garbage collecting we need to know whether or not there can be
// pointers to Oilpan-managed objects on the stack for each thread. When
// threads reach a safe point they record whether or not they have pointers on
// the stack.
enum StackState { kNoHeapPointersOnStack, kHeapPointersOnStack };
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_BLINK_GC_H_
// Copyright 2020 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_IMPL_H_
// TODO(chromium:1056170): Implement wrapper. #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_H_ namespace blink {
class PLATFORM_EXPORT HeapAllocator {
STATIC_ONLY(HeapAllocator);
public:
static constexpr bool kIsGarbageCollected = true;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_HEAP_ALLOCATOR_IMPL_H_
...@@ -56,17 +56,6 @@ CrossThreadWeakPersistent<T> WrapCrossThreadWeakPersistent( ...@@ -56,17 +56,6 @@ CrossThreadWeakPersistent<T> WrapCrossThreadWeakPersistent(
return CrossThreadWeakPersistent<T>(value, loc); return CrossThreadWeakPersistent<T>(value, loc);
} }
template <typename T,
typename = std::enable_if_t<WTF::IsGarbageCollectedType<T>::value>>
Persistent<T> WrapPersistentIfNeeded(T* value) {
return Persistent<T>(value);
}
template <typename T>
T& WrapPersistentIfNeeded(T& value) {
return value;
}
#if BUILDFLAG(RAW_HEAP_SNAPSHOTS) #if BUILDFLAG(RAW_HEAP_SNAPSHOTS)
#define PERSISTENT_FROM_HERE PersistentLocation::Current() #define PERSISTENT_FROM_HERE PersistentLocation::Current()
#else #else
...@@ -75,21 +64,4 @@ T& WrapPersistentIfNeeded(T& value) { ...@@ -75,21 +64,4 @@ T& WrapPersistentIfNeeded(T& value) {
} // namespace blink } // namespace blink
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_V8_WRAPPER_PERSISTENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "third_party/blink/renderer/platform/heap/blink_gc.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/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
...@@ -76,6 +77,15 @@ class ThreadState final { ...@@ -76,6 +77,15 @@ class ThreadState final {
return nullptr; return nullptr;
} }
// Forced garbage collection for testing:
//
// Collects garbage as long as live memory decreases (capped at 5).
void CollectAllGarbageForTesting(
BlinkGC::StackState stack_state =
BlinkGC::StackState::kNoHeapPointersOnStack) {
// TODO(1056170): Implement.
}
private: private:
// Main-thread ThreadState avoids TLS completely by using a regular global. // Main-thread ThreadState avoids TLS completely by using a regular global.
// The object is manually managed and should not rely on global ctor/dtor. // The object is manually managed and should not rely on global ctor/dtor.
......
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