5 #ifndef V8_GLOBAL_HANDLES_H_ 6 #define V8_GLOBAL_HANDLES_H_ 11 #include "include/v8.h" 12 #include "include/v8-profiler.h" 14 #include "src/handles.h" 15 #include "src/utils.h" 38 PHANTOM_WEAK_2_EMBEDDER_FIELDS,
41 PHANTOM_WEAK_RESET_HANDLE
56 static_assert(std::is_base_of<Object, T>::value,
"static type violation");
58 static_assert(!std::is_same<Object, T>::value,
"compiler error");
66 static void Destroy(
Address* location);
77 static void MakeWeak(
Address* location,
void* parameter,
79 v8::WeakCallbackType
type);
81 static void MakeWeak(
Address** location_addr);
83 static void AnnotateStrongRetainer(
Address* location,
const char* label);
88 int global_handles_count()
const {
89 return number_of_global_handles_;
92 size_t NumberOfPhantomHandleResets() {
93 return number_of_phantom_handle_resets_;
96 void ResetNumberOfPhantomHandleResets() {
97 number_of_phantom_handle_resets_ = 0;
100 size_t NumberOfNewSpaceNodes() {
return new_space_nodes_.size(); }
103 static void* ClearWeakness(
Address* location);
106 static bool IsNearDeath(
Address* location);
109 static bool IsWeak(
Address* location);
111 int InvokeFirstPassWeakCallbacks();
115 int PostGarbageCollectionProcessing(
116 GarbageCollector collector,
const v8::GCCallbackFlags gc_callback_flags);
125 void IterateNewSpaceRoots(
RootVisitor* v,
size_t start,
size_t end);
128 void IterateAllRootsWithClassIds(v8::PersistentHandleVisitor* v);
132 void IterateAllRootsInNewSpaceWithClassIds(v8::PersistentHandleVisitor* v);
136 void IterateWeakRootsInNewSpaceWithClassIds(v8::PersistentHandleVisitor* v);
139 void IterateWeakRootsForFinalizers(
RootVisitor* v);
140 void IterateWeakRootsForPhantomHandles(
141 WeakSlotCallbackWithHeap should_reset_handle);
145 void IdentifyWeakHandles(WeakSlotCallbackWithHeap should_reset_handle);
153 void IterateNewSpaceStrongAndDependentRoots(
RootVisitor* v);
157 void IterateNewSpaceStrongAndDependentRootsAndIdentifyUnmodified(
161 void MarkNewSpaceWeakUnmodifiedObjectsPending(
162 WeakSlotCallbackWithHeap is_dead);
166 void IterateNewSpaceWeakUnmodifiedRootsForFinalizers(
RootVisitor* v);
167 void IterateNewSpaceWeakUnmodifiedRootsForPhantomHandles(
168 RootVisitor* v, WeakSlotCallbackWithHeap should_reset_handle);
172 void IdentifyWeakUnmodifiedObjects(WeakSlotCallback is_unmodified);
177 Isolate* isolate() {
return isolate_; }
184 void InvokeSecondPassPhantomCallbacks();
195 void InvokeSecondPassPhantomCallbacksFromTask();
196 int PostScavengeProcessing(
int initial_post_gc_processing_count);
197 int PostMarkSweepProcessing(
int initial_post_gc_processing_count);
198 void InvokeOrScheduleSecondPassPhantomCallbacks(
bool synchronous_second_pass);
199 void UpdateListOfNewSpaceNodes();
200 void ApplyPersistentHandleVisitor(v8::PersistentHandleVisitor* visitor,
216 std::vector<Node*> new_space_nodes_;
219 int number_of_global_handles_;
221 int post_gc_processing_count_;
223 size_t number_of_phantom_handle_resets_;
225 std::vector<PendingPhantomCallback> pending_phantom_callbacks_;
226 std::vector<PendingPhantomCallback> second_pass_callbacks_;
227 bool second_pass_callbacks_task_posted_ =
false;
239 Node* node, Data::Callback callback,
void* parameter,
240 void* embedder_fields[v8::kEmbedderFieldsInWeakCallback])
241 : node_(node), callback_(callback), parameter_(parameter) {
242 for (
int i = 0;
i < v8::kEmbedderFieldsInWeakCallback; ++
i) {
243 embedder_fields_[
i] = embedder_fields[
i];
249 Node* node() {
return node_; }
250 Data::Callback callback() {
return callback_; }
254 Data::Callback callback_;
256 void* embedder_fields_[v8::kEmbedderFieldsInWeakCallback];
265 int NumberOfHandles() {
return size_; }
280 void PostGarbageCollectionProcessing();
283 static const int kInvalidIndex = -1;
284 static const int kShift = 8;
285 static const int kSize = 1 << kShift;
286 static const int kMask = 0xff;
290 inline Address* GetLocation(
int index) {
291 DCHECK(index >= 0 && index < size_);
292 return &blocks_[index >> kShift][index & kMask];
296 std::vector<Address*> blocks_;
297 std::vector<int> new_space_indices_;
306 #endif // V8_GLOBAL_HANDLES_H_