v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
gc-info-table.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_CPPGC_GC_INFO_TABLE_H_
6#define V8_HEAP_CPPGC_GC_INFO_TABLE_H_
7
8#include <stdint.h>
9
12#include "include/v8config.h"
13#include "src/base/logging.h"
14#include "src/base/macros.h"
18
19namespace cppgc {
20namespace internal {
21
22// GCInfo contains metadata for objects that are instantiated from classes that
23// inherit from GarbageCollected.
24struct GCInfo final {
26 NameCallback name)
27 : finalize(finalize), trace(trace), name(name) {}
28
32 size_t padding = 0;
33};
34
36 public:
37 // At maximum |kMaxIndex - 1| indices are supported.
38 //
39 // We assume that 14 bits are enough to represent all possible types.
40 //
41 // For Blink during telemetry runs, we see about 1,000 different types;
42 // looking at the output of the Oilpan GC clang plugin, there appear to be at
43 // most about 6,000 types. Thus 14 bits should be more than twice as many bits
44 // as we will ever need. Different contexts may require adjusting this limit.
45 static constexpr GCInfoIndex kMaxIndex = 1 << 14;
46
47 // Minimum index returned. Values smaller |kMinIndex| may be used as
48 // sentinels.
49 static constexpr GCInfoIndex kMinIndex = 1;
50
51 // (Light) experimentation suggests that Blink doesn't need more than this
52 // while handling content on popular web properties.
53 static constexpr GCInfoIndex kInitialWantedLimit = 512;
54
55 // Refer through GlobalGCInfoTable for retrieving the global table outside
56 // of testing code.
57 GCInfoTable(PageAllocator& page_allocator,
58 FatalOutOfMemoryHandler& oom_handler);
60 GCInfoTable(const GCInfoTable&) = delete;
62
63 GCInfoIndex RegisterNewGCInfo(std::atomic<uint16_t>&, const GCInfo& info);
64
65 const GCInfo& GCInfoFromIndex(GCInfoIndex index) const {
66 DCHECK_GE(index, kMinIndex);
67 DCHECK_LT(index, kMaxIndex);
69 return table_[index];
70 }
71
72 GCInfoIndex NumberOfGCInfos() const { return current_index_; }
73
76
78
79 private:
80 void Resize();
81
82 GCInfoIndex InitialTableLimit() const;
83 size_t MaxTableSize() const;
84
85 void CheckMemoryIsZeroed(uintptr_t* base, size_t len);
86
89 // Holds the per-class GCInfo descriptors; each HeapObjectHeader keeps an
90 // index into this table.
93 // Current index used when requiring a new GCInfo object.
94 GCInfoIndex current_index_ = kMinIndex;
95 // The limit (exclusive) of the currently allocated table.
97
99};
100
102 public:
105
106 // Sets up the table with the provided `page_allocator`. Will use an internal
107 // allocator in case no PageAllocator is provided. May be called multiple
108 // times with the same `page_allocator` argument.
109 static void Initialize(PageAllocator& page_allocator);
110
111 // Accessors for the singleton table.
112 static GCInfoTable& GetMutable() { return *global_table_; }
113 static const GCInfoTable& Get() { return *global_table_; }
114
115 static const GCInfo& GCInfoFromIndex(GCInfoIndex index) {
116 return Get().GCInfoFromIndex(index);
117 }
118
119 private:
120 // Singleton for each process. Retrieved through Get().
122
124};
125
126} // namespace internal
127} // namespace cppgc
128
129#endif // V8_HEAP_CPPGC_GC_INFO_TABLE_H_
const GCInfo & GCInfoFromIndex(GCInfoIndex index) const
FatalOutOfMemoryHandler & oom_handler_
GCInfoIndex NumberOfGCInfos() const
GCInfo & TableSlotForTesting(GCInfoIndex index)
PageAllocator & allocator() const
GCInfoTable & operator=(const GCInfoTable &)=delete
GCInfoIndex LimitForTesting() const
PageAllocator & page_allocator_
GCInfoTable(const GCInfoTable &)=delete
GlobalGCInfoTable(const GlobalGCInfoTable &)=delete
static const GCInfo & GCInfoFromIndex(GCInfoIndex index)
static const GCInfoTable & Get()
GlobalGCInfoTable & operator=(const GlobalGCInfoTable &)=delete
static GCInfoTable & GetMutable()
cppgc::PageAllocator * page_allocator_
Definition cpp-heap.cc:194
OptionalOpIndex index
const int limit_
Definition isolate.cc:1114
void(*)(void *) FinalizationCallback
HeapObjectName(*)(const void *, HeapObjectNameForUnnamedObject) NameCallback
Definition name-trait.h:133
uint16_t GCInfoIndex
Definition gc-info.h:21
void(*)(Visitor *visitor, const void *object) TraceCallback
Definition trace-trait.h:38
SourcePositionTable *const table_
Definition pipeline.cc:227
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DISALLOW_NEW_AND_DELETE()
Definition macros.h:155
FinalizationCallback finalize
constexpr GCInfo(FinalizationCallback finalize, TraceCallback trace, NameCallback name)
#define V8_EXPORT
Definition v8config.h:800