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