// --- Garbage Collection Callbacks ---
/**
- * Applications can register callback functions which will be called
- * before and after a garbage collection. Allocations are not
- * allowed in the callback functions, you therefore cannot manipulate
- * objects (set or delete properties for example) since it is possible
- * such operations will result in the allocation of objects.
+ * Applications can register callback functions which will be called before and
+ * after certain garbage collection operations. Allocations are not allowed in
+ * the callback functions, you therefore cannot manipulate objects (set or
+ * delete properties for example) since it is possible such operations will
+ * result in the allocation of objects.
*/
enum GCType {
kGCTypeScavenge = 1 << 0,
kGCTypeMarkSweepCompact = 1 << 1,
- kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
+ kGCTypeIncrementalMarking = 1 << 2,
+ kGCTypeProcessWeakCallbacks = 1 << 3,
+ kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
+ kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
};
enum GCCallbackFlags {
kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3
};
-typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
-typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
+V8_DEPRECATE_SOON("Use GCCallBack instead",
+ typedef void (*GCPrologueCallback)(GCType type,
+ GCCallbackFlags flags));
+V8_DEPRECATE_SOON("Use GCCallBack instead",
+ typedef void (*GCEpilogueCallback)(GCType type,
+ GCCallbackFlags flags));
+typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
typedef void (*InterruptCallback)(Isolate* isolate, void* data);
template<typename T, typename S>
void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
- typedef void (*GCPrologueCallback)(Isolate* isolate,
- GCType type,
- GCCallbackFlags flags);
- typedef void (*GCEpilogueCallback)(Isolate* isolate,
- GCType type,
- GCCallbackFlags flags);
+ V8_DEPRECATE_SOON("Use GCCallBack instead",
+ typedef void (*GCPrologueCallback)(Isolate* isolate,
+ GCType type,
+ GCCallbackFlags flags));
+ V8_DEPRECATE_SOON("Use GCCallBack instead",
+ typedef void (*GCEpilogueCallback)(Isolate* isolate,
+ GCType type,
+ GCCallbackFlags flags));
+ typedef void (*GCCallback)(Isolate* isolate, GCType type,
+ GCCallbackFlags flags);
/**
* Enables the host application to receive a notification before a
* not possible to register the same callback function two times with
* different GCType filters.
*/
- void AddGCPrologueCallback(
- GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
+ void AddGCPrologueCallback(GCCallback callback,
+ GCType gc_type_filter = kGCTypeAll);
/**
* This function removes callback which was installed by
* AddGCPrologueCallback function.
*/
- void RemoveGCPrologueCallback(GCPrologueCallback callback);
+ void RemoveGCPrologueCallback(GCCallback callback);
/**
* Enables the host application to receive a notification after a
* not possible to register the same callback function two times with
* different GCType filters.
*/
- void AddGCEpilogueCallback(
- GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
+ void AddGCEpilogueCallback(GCCallback callback,
+ GCType gc_type_filter = kGCTypeAll);
/**
* This function removes callback which was installed by
* AddGCEpilogueCallback function.
*/
- void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
-
+ void RemoveGCEpilogueCallback(GCCallback callback);
/**
* Forcefully terminate the current thread of JavaScript execution
*/
static V8_DEPRECATE_SOON(
"Use isolate version",
- void AddGCPrologueCallback(GCPrologueCallback callback,
+ void AddGCPrologueCallback(GCCallback callback,
GCType gc_type_filter = kGCTypeAll));
/**
*/
V8_INLINE static V8_DEPRECATE_SOON(
"Use isolate version",
- void RemoveGCPrologueCallback(GCPrologueCallback callback));
+ void RemoveGCPrologueCallback(GCCallback callback));
/**
* Enables the host application to receive a notification after a
*/
static V8_DEPRECATE_SOON(
"Use isolate version",
- void AddGCEpilogueCallback(GCEpilogueCallback callback,
+ void AddGCEpilogueCallback(GCCallback callback,
GCType gc_type_filter = kGCTypeAll));
/**
*/
V8_INLINE static V8_DEPRECATE_SOON(
"Use isolate version",
- void RemoveGCEpilogueCallback(GCEpilogueCallback callback));
+ void RemoveGCEpilogueCallback(GCCallback callback));
/**
* Enables the host application to provide a mechanism to be notified
}
-void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) {
+void V8::RemoveGCPrologueCallback(GCCallback callback) {
Isolate* isolate = Isolate::GetCurrent();
isolate->RemoveGCPrologueCallback(
- reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback));
+ reinterpret_cast<v8::Isolate::GCCallback>(callback));
}
-void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
+void V8::RemoveGCEpilogueCallback(GCCallback callback) {
Isolate* isolate = Isolate::GetCurrent();
isolate->RemoveGCEpilogueCallback(
- reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback));
+ reinterpret_cast<v8::Isolate::GCCallback>(callback));
}
}
-void Isolate::AddGCPrologueCallback(GCPrologueCallback callback,
- GCType gc_type) {
+void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->AddGCPrologueCallback(callback, gc_type);
}
-void Isolate::RemoveGCPrologueCallback(GCPrologueCallback callback) {
+void Isolate::RemoveGCPrologueCallback(GCCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->RemoveGCPrologueCallback(callback);
}
-void Isolate::AddGCEpilogueCallback(GCEpilogueCallback callback,
- GCType gc_type) {
+void Isolate::AddGCEpilogueCallback(GCCallback callback, GCType gc_type) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
}
-void Isolate::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
+void Isolate::RemoveGCEpilogueCallback(GCCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->RemoveGCEpilogueCallback(callback);
}
-void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) {
+void V8::AddGCPrologueCallback(GCCallback callback, GCType gc_type) {
i::Isolate* isolate = i::Isolate::Current();
isolate->heap()->AddGCPrologueCallback(
- reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback),
- gc_type,
- false);
+ reinterpret_cast<v8::Isolate::GCCallback>(callback), gc_type, false);
}
-void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) {
+void V8::AddGCEpilogueCallback(GCCallback callback, GCType gc_type) {
i::Isolate* isolate = i::Isolate::Current();
isolate->heap()->AddGCEpilogueCallback(
- reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback),
- gc_type,
- false);
+ reinterpret_cast<v8::Isolate::GCCallback>(callback), gc_type, false);
}
}
void RunInternal() override {
+ isolate_->heap()->CallGCPrologueCallbacks(
+ GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate_);
+ isolate_->heap()->CallGCEpilogueCallbacks(
+ GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
}
private:
}
if (pending_phantom_callbacks_.length() > 0) {
if (FLAG_optimize_for_size || FLAG_predictable || synchronous_second_pass) {
+ isolate()->heap()->CallGCPrologueCallbacks(
+ GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate());
+ isolate()->heap()->CallGCEpilogueCallbacks(
+ GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
} else {
auto task = new PendingPhantomCallbacksSecondPassTask(
&pending_phantom_callbacks_, isolate());
GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL);
VMState<EXTERNAL> state(isolate_);
HandleScope handle_scope(isolate_);
+ // TODO(mlippautz): Report kGCTypeIncremental once blink updates its
+ // filtering.
CallGCPrologueCallbacks(kGCTypeMarkSweepCompact, kNoGCCallbackFlags);
}
}
GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL);
VMState<EXTERNAL> state(isolate_);
HandleScope handle_scope(isolate_);
+ // TODO(mlippautz): Report kGCTypeIncremental once blink updates its
+ // filtering.
CallGCEpilogueCallbacks(kGCTypeMarkSweepCompact, kNoGCCallbackFlags);
}
}
void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) {
for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) {
if (gc_type & gc_prologue_callbacks_[i].gc_type) {
- if (!gc_prologue_callbacks_[i].pass_isolate_) {
- v8::GCPrologueCallback callback =
- reinterpret_cast<v8::GCPrologueCallback>(
- gc_prologue_callbacks_[i].callback);
+ if (!gc_prologue_callbacks_[i].pass_isolate) {
+ v8::GCCallback callback = reinterpret_cast<v8::GCCallback>(
+ gc_prologue_callbacks_[i].callback);
callback(gc_type, flags);
} else {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate());
GCCallbackFlags gc_callback_flags) {
for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) {
if (gc_type & gc_epilogue_callbacks_[i].gc_type) {
- if (!gc_epilogue_callbacks_[i].pass_isolate_) {
- v8::GCPrologueCallback callback =
- reinterpret_cast<v8::GCPrologueCallback>(
- gc_epilogue_callbacks_[i].callback);
+ if (!gc_epilogue_callbacks_[i].pass_isolate) {
+ v8::GCCallback callback = reinterpret_cast<v8::GCCallback>(
+ gc_epilogue_callbacks_[i].callback);
callback(gc_type, gc_callback_flags);
} else {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate());
}
-void Heap::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback,
+void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback,
GCType gc_type, bool pass_isolate) {
DCHECK(callback != NULL);
- GCPrologueCallbackPair pair(callback, gc_type, pass_isolate);
+ GCCallbackPair pair(callback, gc_type, pass_isolate);
DCHECK(!gc_prologue_callbacks_.Contains(pair));
return gc_prologue_callbacks_.Add(pair);
}
-void Heap::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback) {
+void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) {
DCHECK(callback != NULL);
for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) {
if (gc_prologue_callbacks_[i].callback == callback) {
}
-void Heap::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback,
+void Heap::AddGCEpilogueCallback(v8::Isolate::GCCallback callback,
GCType gc_type, bool pass_isolate) {
DCHECK(callback != NULL);
- GCEpilogueCallbackPair pair(callback, gc_type, pass_isolate);
+ GCCallbackPair pair(callback, gc_type, pass_isolate);
DCHECK(!gc_epilogue_callbacks_.Contains(pair));
return gc_epilogue_callbacks_.Add(pair);
}
-void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback) {
+void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallback callback) {
DCHECK(callback != NULL);
for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) {
if (gc_epilogue_callbacks_[i].callback == callback) {
PromotionQueue* promotion_queue() { return &promotion_queue_; }
- void AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback,
+ void AddGCPrologueCallback(v8::Isolate::GCCallback callback,
GCType gc_type_filter, bool pass_isolate = true);
- void RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback);
+ void RemoveGCPrologueCallback(v8::Isolate::GCCallback callback);
- void AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback,
+ void AddGCEpilogueCallback(v8::Isolate::GCCallback callback,
GCType gc_type_filter, bool pass_isolate = true);
- void RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback);
+ void RemoveGCEpilogueCallback(v8::Isolate::GCCallback callback);
// Heap root getters. We have versions with and without type::cast() here.
// You can't use type::cast during GC because the assert fails.
void AddPrivateGlobalSymbols(Handle<Object> private_intern_table);
- // GC callback function, called before and after mark-compact GC.
- // Allocations in the callback function are disallowed.
- struct GCPrologueCallbackPair {
- GCPrologueCallbackPair(v8::Isolate::GCPrologueCallback callback,
- GCType gc_type, bool pass_isolate)
- : callback(callback), gc_type(gc_type), pass_isolate_(pass_isolate) {}
- bool operator==(const GCPrologueCallbackPair& pair) const {
- return pair.callback == callback;
- }
- v8::Isolate::GCPrologueCallback callback;
- GCType gc_type;
- // TODO(dcarney): remove variable
- bool pass_isolate_;
- };
- List<GCPrologueCallbackPair> gc_prologue_callbacks_;
-
- struct GCEpilogueCallbackPair {
- GCEpilogueCallbackPair(v8::Isolate::GCPrologueCallback callback,
- GCType gc_type, bool pass_isolate)
- : callback(callback), gc_type(gc_type), pass_isolate_(pass_isolate) {}
- bool operator==(const GCEpilogueCallbackPair& pair) const {
- return pair.callback == callback;
+ struct GCCallbackPair {
+ GCCallbackPair(v8::Isolate::GCCallback callback, GCType gc_type,
+ bool pass_isolate)
+ : callback(callback), gc_type(gc_type), pass_isolate(pass_isolate) {}
+
+ bool operator==(const GCCallbackPair& other) const {
+ return other.callback == callback;
}
- v8::Isolate::GCPrologueCallback callback;
+
+ v8::Isolate::GCCallback callback;
GCType gc_type;
- // TODO(dcarney): remove variable
- bool pass_isolate_;
+ bool pass_isolate;
};
- List<GCEpilogueCallbackPair> gc_epilogue_callbacks_;
+
+ List<GCCallbackPair> gc_epilogue_callbacks_;
+ List<GCCallbackPair> gc_prologue_callbacks_;
// Code that should be run before and after each GC. Includes some
// reporting/verification activities when compiled with DEBUG set.