Commit 68635148 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

BlinkMemoryMgt: Annotate Blink's platform/heap with the macros of Allocator

As a step to annotate the macros of Allocator for the Onion Soup, this CL annotates
some classes of //third_party/blink/renderer/platform/heap with the macros of
Allocator.

After some analyzes, it was concluded that for the case of GlobalPool, View,
PrefinalizerRegistration, BlinkGCObserver, ThingWithDestructor, and AtomicEntryFlag
classes, they make sense to use DISALLOW_NEW because they have been used as a member
variable with a reference type.

In ThreadHeap, HeapCompact::MovableObjectFixups, ThreadHeapStatsCollector,
KeyWithCopyingMoveConstructor, ThreadMarker, OffHeapInt, Visitor classes, they make
sense to use USING_FAST_MALLOC because they're used with new or smart pointers.

Lastly, the rest of classes this CL annotates make sense to use STACK_ALLOCATED or
STATIC_ONLY.

Bug: 919389
Change-Id: Ib3e5c90650f35370cbb2041b46042b8aa0db37c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1502254Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#637912}
parent ddb0edba
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_ADDRESS_CACHE_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_ADDRESS_CACHE_H_
#include "third_party/blink/renderer/platform/heap/blink_gc.h" #include "third_party/blink/renderer/platform/heap/blink_gc.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink { namespace blink {
...@@ -17,6 +18,8 @@ class PLATFORM_EXPORT AddressCache { ...@@ -17,6 +18,8 @@ class PLATFORM_EXPORT AddressCache {
public: public:
class PLATFORM_EXPORT EnabledScope { class PLATFORM_EXPORT EnabledScope {
STACK_ALLOCATED();
public: public:
explicit EnabledScope(AddressCache*); explicit EnabledScope(AddressCache*);
~EnabledScope(); ~EnabledScope();
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <atomic> #include <atomic>
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink { namespace blink {
// A flag which provides a fast check whether a scope may be entered on the // A flag which provides a fast check whether a scope may be entered on the
...@@ -27,6 +29,8 @@ namespace blink { ...@@ -27,6 +29,8 @@ namespace blink {
// And so if a thread observes zero, it must be because it has observed an equal // And so if a thread observes zero, it must be because it has observed an equal
// number of exits as entries. // number of exits as entries.
class AtomicEntryFlag { class AtomicEntryFlag {
DISALLOW_NEW();
public: public:
inline void Enter() { entries_.fetch_add(1, std::memory_order_relaxed); } inline void Enter() { entries_.fetch_add(1, std::memory_order_relaxed); }
inline void Exit() { entries_.fetch_sub(1, std::memory_order_relaxed); } inline void Exit() { entries_.fetch_sub(1, std::memory_order_relaxed); }
......
...@@ -77,6 +77,8 @@ using WeakCallbackWorklist = ...@@ -77,6 +77,8 @@ using WeakCallbackWorklist =
Worklist<CustomCallbackItem, 256 /* local entries */>; Worklist<CustomCallbackItem, 256 /* local entries */>;
class PLATFORM_EXPORT HeapAllocHooks { class PLATFORM_EXPORT HeapAllocHooks {
STATIC_ONLY(HeapAllocHooks);
public: public:
// TODO(hajimehoshi): Pass a type name of the allocated object. // TODO(hajimehoshi): Pass a type name of the allocated object.
typedef void AllocationHook(Address, size_t, const char*); typedef void AllocationHook(Address, size_t, const char*);
...@@ -157,6 +159,8 @@ class ObjectAliveTrait<T, true> { ...@@ -157,6 +159,8 @@ class ObjectAliveTrait<T, true> {
} // namespace internal } // namespace internal
class PLATFORM_EXPORT ThreadHeap { class PLATFORM_EXPORT ThreadHeap {
USING_FAST_MALLOC(ThreadHeap);
public: public:
explicit ThreadHeap(ThreadState*); explicit ThreadHeap(ThreadState*);
~ThreadHeap(); ~ThreadHeap();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h" #include "third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h"
#include "third_party/blink/renderer/platform/histogram.h" #include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/time.h" #include "third_party/blink/renderer/platform/wtf/time.h"
...@@ -28,6 +29,8 @@ bool HeapCompact::force_compaction_gc_ = false; ...@@ -28,6 +29,8 @@ bool HeapCompact::force_compaction_gc_ = false;
// The "fixups" object is created and maintained for the lifetime of one // The "fixups" object is created and maintained for the lifetime of one
// heap compaction-enhanced GC. // heap compaction-enhanced GC.
class HeapCompact::MovableObjectFixups final { class HeapCompact::MovableObjectFixups final {
USING_FAST_MALLOC(HeapCompact::MovableObjectFixups);
public: public:
static std::unique_ptr<MovableObjectFixups> Create(ThreadHeap* heap) { static std::unique_ptr<MovableObjectFixups> Create(ThreadHeap* heap) {
return base::WrapUnique(new MovableObjectFixups(heap)); return base::WrapUnique(new MovableObjectFixups(heap));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/platform/heap/blink_gc.h" #include "third_party/blink/renderer/platform/heap/blink_gc.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/time.h" #include "third_party/blink/renderer/platform/wtf/time.h"
namespace blink { namespace blink {
...@@ -23,6 +24,8 @@ namespace blink { ...@@ -23,6 +24,8 @@ namespace blink {
// stats_collector.NotifySweepingFinished(); // stats_collector.NotifySweepingFinished();
// // Previous event is available using stats_collector.previous(). // // Previous event is available using stats_collector.previous().
class PLATFORM_EXPORT ThreadHeapStatsCollector { class PLATFORM_EXPORT ThreadHeapStatsCollector {
USING_FAST_MALLOC(ThreadHeapStatsCollector);
public: public:
// These ids will form human readable names when used in Scopes. // These ids will form human readable names when used in Scopes.
enum Id { enum Id {
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/allocator.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/linked_hash_set.h" #include "third_party/blink/renderer/platform/wtf/linked_hash_set.h"
...@@ -113,6 +114,8 @@ static_assert(WTF::IsTraceable<HeapHashMap<int, IntWrapper>>::value, ...@@ -113,6 +114,8 @@ static_assert(WTF::IsTraceable<HeapHashMap<int, IntWrapper>>::value,
"HeapHashMap<int, IntWrapper> must be traceable."); "HeapHashMap<int, IntWrapper> must be traceable.");
class KeyWithCopyingMoveConstructor final { class KeyWithCopyingMoveConstructor final {
DISALLOW_NEW();
public: public:
struct Hash final { struct Hash final {
STATIC_ONLY(Hash); STATIC_ONLY(Hash);
...@@ -163,6 +166,8 @@ static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent), ...@@ -163,6 +166,8 @@ static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent),
"Persistent handle should stay small"); "Persistent handle should stay small");
class ThreadMarker { class ThreadMarker {
DISALLOW_NEW();
public: public:
ThreadMarker() ThreadMarker()
: creating_thread_(reinterpret_cast<ThreadState*>(0)), num_(0) {} : creating_thread_(reinterpret_cast<ThreadState*>(0)), num_(0) {}
...@@ -361,6 +366,8 @@ struct HashTraits<blink::KeyWithCopyingMoveConstructor> ...@@ -361,6 +366,8 @@ struct HashTraits<blink::KeyWithCopyingMoveConstructor>
namespace blink { namespace blink {
class TestGCCollectGarbageScope { class TestGCCollectGarbageScope {
STACK_ALLOCATED();
public: public:
explicit TestGCCollectGarbageScope(BlinkGC::StackState state) { explicit TestGCCollectGarbageScope(BlinkGC::StackState state) {
DCHECK(ThreadState::Current()->CheckThread()); DCHECK(ThreadState::Current()->CheckThread());
...@@ -468,6 +475,8 @@ class HeapAllocatedArray : public GarbageCollected<HeapAllocatedArray> { ...@@ -468,6 +475,8 @@ class HeapAllocatedArray : public GarbageCollected<HeapAllocatedArray> {
}; };
class OffHeapInt : public RefCounted<OffHeapInt> { class OffHeapInt : public RefCounted<OffHeapInt> {
USING_FAST_MALLOC(OffHeapInt);
public: public:
static scoped_refptr<OffHeapInt> Create(int x) { static scoped_refptr<OffHeapInt> Create(int x) {
return base::AdoptRef(new OffHeapInt(x)); return base::AdoptRef(new OffHeapInt(x));
...@@ -3366,6 +3375,8 @@ TEST(HeapTest, HeapWeakLinkedHashSet) { ...@@ -3366,6 +3375,8 @@ TEST(HeapTest, HeapWeakLinkedHashSet) {
} }
class ThingWithDestructor { class ThingWithDestructor {
DISALLOW_NEW();
public: public:
ThingWithDestructor() : x_(kEmptyValue) { live_things_with_destructor_++; } ThingWithDestructor() : x_(kEmptyValue) { live_things_with_destructor_++; }
......
...@@ -120,6 +120,8 @@ class ThreadStateFor; ...@@ -120,6 +120,8 @@ class ThreadStateFor;
using UsingPreFinalizerMacroNeedsTrailingSemiColon = char using UsingPreFinalizerMacroNeedsTrailingSemiColon = char
class PLATFORM_EXPORT BlinkGCObserver { class PLATFORM_EXPORT BlinkGCObserver {
USING_FAST_MALLOC(BlinkGCObserver);
public: public:
// The constructor automatically register this object to ThreadState's // The constructor automatically register this object to ThreadState's
// observer lists. The argument must not be null. // observer lists. The argument must not be null.
...@@ -407,6 +409,8 @@ class PLATFORM_EXPORT ThreadState final ...@@ -407,6 +409,8 @@ class PLATFORM_EXPORT ThreadState final
// USING_PRE_FINALIZER(). // USING_PRE_FINALIZER().
template <typename T> template <typename T>
class PrefinalizerRegistration final { class PrefinalizerRegistration final {
DISALLOW_NEW();
public: public:
PrefinalizerRegistration(T* self) { PrefinalizerRegistration(T* self) {
static_assert(sizeof(&T::InvokePreFinalizer) > 0, static_assert(sizeof(&T::InvokePreFinalizer) > 0,
......
...@@ -92,6 +92,8 @@ class ThreadState::GCForbiddenScope final { ...@@ -92,6 +92,8 @@ class ThreadState::GCForbiddenScope final {
// Used to mark when we are in an atomic pause for GC. // Used to mark when we are in an atomic pause for GC.
class ThreadState::AtomicPauseScope final { class ThreadState::AtomicPauseScope final {
STACK_ALLOCATED();
public: public:
explicit AtomicPauseScope(ThreadState* thread_state) explicit AtomicPauseScope(ThreadState* thread_state)
: thread_state_(thread_state), gc_forbidden_scope(thread_state) { : thread_state_(thread_state), gc_forbidden_scope(thread_state) {
......
...@@ -75,6 +75,8 @@ struct TraceMethodDelegate { ...@@ -75,6 +75,8 @@ struct TraceMethodDelegate {
// Visitor is used to traverse Oilpan's object graph. // Visitor is used to traverse Oilpan's object graph.
class PLATFORM_EXPORT Visitor { class PLATFORM_EXPORT Visitor {
USING_FAST_MALLOC(Visitor);
public: public:
explicit Visitor(ThreadState* state) : state_(state) {} explicit Visitor(ThreadState* state) : state_(state) {}
virtual ~Visitor() = default; virtual ~Visitor() = default;
......
...@@ -39,6 +39,8 @@ class Worklist { ...@@ -39,6 +39,8 @@ class Worklist {
using EntryType = _EntryType; using EntryType = _EntryType;
class View { class View {
DISALLOW_NEW();
public: public:
View(WorklistType* worklist, int task_id) View(WorklistType* worklist, int task_id)
: worklist_(worklist), task_id_(task_id) {} : worklist_(worklist), task_id_(task_id) {}
...@@ -259,6 +261,8 @@ class Worklist { ...@@ -259,6 +261,8 @@ class Worklist {
}; };
class GlobalPool { class GlobalPool {
DISALLOW_NEW();
public: public:
GlobalPool() : top_(nullptr) {} GlobalPool() : top_(nullptr) {}
......
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