summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-07-14 16:34:41 +0200
committerMyles Borins <mylesborins@github.com>2020-07-16 17:09:18 -0400
commit2c9fd6ebd4390b5e0861cf987de1d5c1c4ef7be0 (patch)
tree38833f51bc7fcbe72de0c63b7e11ceef40f41459
parent447b1e86a5f61a357fa61ec7fa4bc8896d9281c0 (diff)
downloadnode-new-2c9fd6ebd4390b5e0861cf987de1d5c1c4ef7be0.tar.gz
deps: V8: revert de4c0042cbe6 from upstream V8
Original commit message: [weakrefs] Remove deprecated FinalizationGroup V8 API Bug: v8:8179 Change-Id: I16170a197028beb35309b15613004b29a956896c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2171696 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Commit-Queue: Ross McIlroy <rmcilroy@chromium.org> Auto-Submit: Shu-yu Guo <syg@chromium.org> Cr-Commit-Position: refs/heads/master@{#67492} Refs: https://github.com/v8/v8/commit/de4c0042cbe6772ac034d1bef4c4c3b925afeec2 PR-URL: https://github.com/nodejs/node/pull/34356 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
-rw-r--r--deps/v8/include/v8.h56
-rw-r--r--deps/v8/src/api/api-inl.h1
-rw-r--r--deps/v8/src/api/api.cc27
-rw-r--r--deps/v8/src/api/api.h3
-rw-r--r--deps/v8/src/execution/isolate.cc15
-rw-r--r--deps/v8/src/execution/isolate.h10
-rw-r--r--deps/v8/src/heap/finalization-registry-cleanup-task.cc1
-rw-r--r--deps/v8/src/heap/heap.cc12
-rw-r--r--deps/v8/src/heap/mark-compact.cc4
-rw-r--r--deps/v8/src/logging/counters.h1
10 files changed, 129 insertions, 1 deletions
diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h
index 2f312e9b62..dcdfbfc7ec 100644
--- a/deps/v8/include/v8.h
+++ b/deps/v8/include/v8.h
@@ -5946,6 +5946,37 @@ class V8_EXPORT RegExp : public Object {
};
/**
+ * An instance of the built-in FinalizationRegistry constructor.
+ *
+ * The C++ name is FinalizationGroup for backwards compatibility. This API is
+ * experimental and deprecated.
+ */
+class V8_EXPORT FinalizationGroup : public Object {
+ public:
+ /**
+ * Runs the cleanup callback of the given FinalizationRegistry.
+ *
+ * V8 will inform the embedder that there are finalizer callbacks be
+ * called through HostCleanupFinalizationGroupCallback.
+ *
+ * HostCleanupFinalizationGroupCallback should schedule a task to
+ * call FinalizationGroup::Cleanup() at some point in the
+ * future. It's the embedders responsiblity to make this call at a
+ * time which does not interrupt synchronous ECMAScript code
+ * execution.
+ *
+ * If the result is Nothing<bool> then an exception has
+ * occurred. Otherwise the result is |true| if the cleanup callback
+ * was called successfully. The result is never |false|.
+ */
+ V8_DEPRECATED(
+ "FinalizationGroup cleanup is automatic if "
+ "HostCleanupFinalizationGroupCallback is not set")
+ static V8_WARN_UNUSED_RESULT Maybe<bool> Cleanup(
+ Local<FinalizationGroup> finalization_group);
+};
+
+/**
* A JavaScript value that wraps a C++ void*. This type of value is mainly used
* to associate C++ data structures with JavaScript objects.
*/
@@ -7198,6 +7229,20 @@ typedef void (*BeforeCallEnteredCallback)(Isolate*);
typedef void (*CallCompletedCallback)(Isolate*);
/**
+ * HostCleanupFinalizationGroupCallback is called when we require the
+ * embedder to enqueue a task that would call
+ * FinalizationGroup::Cleanup().
+ *
+ * The FinalizationGroup is the one for which the embedder needs to
+ * call FinalizationGroup::Cleanup() on.
+ *
+ * The context provided is the one in which the FinalizationGroup was
+ * created in.
+ */
+typedef void (*HostCleanupFinalizationGroupCallback)(
+ Local<Context> context, Local<FinalizationGroup> fg);
+
+/**
* HostImportModuleDynamicallyCallback is called when we require the
* embedder to load a module. This is used as part of the dynamic
* import syntax.
@@ -8537,6 +8582,17 @@ class V8_EXPORT Isolate {
AbortOnUncaughtExceptionCallback callback);
/**
+ * This specifies the callback to be called when FinalizationRegistries
+ * are ready to be cleaned up and require FinalizationGroup::Cleanup()
+ * to be called in a future task.
+ */
+ V8_DEPRECATED(
+ "FinalizationRegistry cleanup is automatic if "
+ "HostCleanupFinalizationGroupCallback is not set")
+ void SetHostCleanupFinalizationGroupCallback(
+ HostCleanupFinalizationGroupCallback callback);
+
+ /**
* This specifies the callback called by the upcoming dynamic
* import() language feature to load modules.
*/
diff --git a/deps/v8/src/api/api-inl.h b/deps/v8/src/api/api-inl.h
index f686424286..0d2ad2f8a0 100644
--- a/deps/v8/src/api/api-inl.h
+++ b/deps/v8/src/api/api-inl.h
@@ -86,6 +86,7 @@ MAKE_TO_LOCAL(ToLocal, JSArrayBufferView, ArrayBufferView)
MAKE_TO_LOCAL(ToLocal, JSDataView, DataView)
MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray)
MAKE_TO_LOCAL(ToLocalShared, JSArrayBuffer, SharedArrayBuffer)
+MAKE_TO_LOCAL(ToLocal, JSFinalizationRegistry, FinalizationGroup)
TYPED_ARRAYS(MAKE_TO_LOCAL_TYPED_ARRAY)
diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc
index 5b1c2b156b..7f3c4bd362 100644
--- a/deps/v8/src/api/api.cc
+++ b/deps/v8/src/api/api.cc
@@ -8298,6 +8298,33 @@ void Isolate::SetAbortOnUncaughtExceptionCallback(
isolate->SetAbortOnUncaughtExceptionCallback(callback);
}
+void Isolate::SetHostCleanupFinalizationGroupCallback(
+ HostCleanupFinalizationGroupCallback callback) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ isolate->SetHostCleanupFinalizationGroupCallback(callback);
+}
+
+Maybe<bool> FinalizationGroup::Cleanup(
+ Local<FinalizationGroup> finalization_group) {
+ i::Handle<i::JSFinalizationRegistry> fr =
+ Utils::OpenHandle(*finalization_group);
+ i::Isolate* isolate = fr->native_context().GetIsolate();
+ i::Handle<i::Context> i_context(fr->native_context(), isolate);
+ Local<Context> context = Utils::ToLocal(i_context);
+ ENTER_V8(isolate, context, FinalizationGroup, Cleanup, Nothing<bool>(),
+ i::HandleScope);
+ i::Handle<i::Object> callback(fr->cleanup(), isolate);
+ i::Handle<i::Object> argv[] = {callback};
+ fr->set_scheduled_for_cleanup(false);
+ has_pending_exception =
+ i::Execution::CallBuiltin(isolate,
+ isolate->finalization_registry_cleanup_some(),
+ fr, arraysize(argv), argv)
+ .is_null();
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
+ return Just(true);
+}
+
void Isolate::SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamicallyCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
diff --git a/deps/v8/src/api/api.h b/deps/v8/src/api/api.h
index ad879657c9..29cc4eacfd 100644
--- a/deps/v8/src/api/api.h
+++ b/deps/v8/src/api/api.h
@@ -94,6 +94,7 @@ class RegisteredExtension {
V(Data, Object) \
V(RegExp, JSRegExp) \
V(Object, JSReceiver) \
+ V(FinalizationGroup, JSFinalizationRegistry) \
V(Array, JSArray) \
V(Map, JSMap) \
V(Set, JSSet) \
@@ -206,6 +207,8 @@ class Utils {
v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<BigUint64Array> ToLocalBigUint64Array(
v8::internal::Handle<v8::internal::JSTypedArray> obj);
+ static inline Local<FinalizationGroup> ToLocal(
+ v8::internal::Handle<v8::internal::JSFinalizationRegistry> obj);
static inline Local<SharedArrayBuffer> ToLocalShared(
v8::internal::Handle<v8::internal::JSArrayBuffer> obj);
diff --git a/deps/v8/src/execution/isolate.cc b/deps/v8/src/execution/isolate.cc
index bea08a16b8..2008bccb40 100644
--- a/deps/v8/src/execution/isolate.cc
+++ b/deps/v8/src/execution/isolate.cc
@@ -3952,6 +3952,21 @@ MaybeHandle<JSPromise> Isolate::RunHostImportModuleDynamicallyCallback(
void Isolate::ClearKeptObjects() { heap()->ClearKeptObjects(); }
+void Isolate::SetHostCleanupFinalizationGroupCallback(
+ HostCleanupFinalizationGroupCallback callback) {
+ host_cleanup_finalization_group_callback_ = callback;
+}
+
+void Isolate::RunHostCleanupFinalizationGroupCallback(
+ Handle<JSFinalizationRegistry> fr) {
+ if (host_cleanup_finalization_group_callback_ != nullptr) {
+ v8::Local<v8::Context> api_context =
+ v8::Utils::ToLocal(handle(Context::cast(fr->native_context()), this));
+ host_cleanup_finalization_group_callback_(api_context,
+ v8::Utils::ToLocal(fr));
+ }
+}
+
void Isolate::SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamicallyCallback callback) {
host_import_module_dynamically_callback_ = callback;
diff --git a/deps/v8/src/execution/isolate.h b/deps/v8/src/execution/isolate.h
index de00d862a3..78c6ca4b47 100644
--- a/deps/v8/src/execution/isolate.h
+++ b/deps/v8/src/execution/isolate.h
@@ -1416,6 +1416,14 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool IsInAnyContext(Object object, uint32_t index);
void ClearKeptObjects();
+ void SetHostCleanupFinalizationGroupCallback(
+ HostCleanupFinalizationGroupCallback callback);
+ HostCleanupFinalizationGroupCallback
+ host_cleanup_finalization_group_callback() const {
+ return host_cleanup_finalization_group_callback_;
+ }
+ void RunHostCleanupFinalizationGroupCallback(
+ Handle<JSFinalizationRegistry> fr);
void SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamicallyCallback callback);
@@ -1672,6 +1680,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
v8::Isolate::AtomicsWaitCallback atomics_wait_callback_ = nullptr;
void* atomics_wait_callback_data_ = nullptr;
PromiseHook promise_hook_ = nullptr;
+ HostCleanupFinalizationGroupCallback
+ host_cleanup_finalization_group_callback_ = nullptr;
HostImportModuleDynamicallyCallback host_import_module_dynamically_callback_ =
nullptr;
HostInitializeImportMetaObjectCallback
diff --git a/deps/v8/src/heap/finalization-registry-cleanup-task.cc b/deps/v8/src/heap/finalization-registry-cleanup-task.cc
index 2acfa31ffb..93997c91b6 100644
--- a/deps/v8/src/heap/finalization-registry-cleanup-task.cc
+++ b/deps/v8/src/heap/finalization-registry-cleanup-task.cc
@@ -37,6 +37,7 @@ void FinalizationRegistryCleanupTask::SlowAssertNoActiveJavaScript() {
void FinalizationRegistryCleanupTask::RunInternal() {
Isolate* isolate = heap_->isolate();
+ DCHECK(!isolate->host_cleanup_finalization_group_callback());
SlowAssertNoActiveJavaScript();
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8",
diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc
index 606ba0fe65..d035fece83 100644
--- a/deps/v8/src/heap/heap.cc
+++ b/deps/v8/src/heap/heap.cc
@@ -1201,6 +1201,16 @@ void Heap::GarbageCollectionEpilogue() {
TRACE_GC(tracer(), GCTracer::Scope::HEAP_EPILOGUE_REDUCE_NEW_SPACE);
ReduceNewSpaceSize();
}
+
+ if (FLAG_harmony_weak_refs &&
+ isolate()->host_cleanup_finalization_group_callback()) {
+ HandleScope handle_scope(isolate());
+ Handle<JSFinalizationRegistry> finalization_registry;
+ while (
+ DequeueDirtyJSFinalizationRegistry().ToHandle(&finalization_registry)) {
+ isolate()->RunHostCleanupFinalizationGroupCallback(finalization_registry);
+ }
+ }
}
class GCCallbacksScope {
@@ -6208,6 +6218,7 @@ void Heap::SetInterpreterEntryTrampolineForProfiling(Code code) {
}
void Heap::PostFinalizationRegistryCleanupTaskIfNeeded() {
+ DCHECK(!isolate()->host_cleanup_finalization_group_callback());
// Only one cleanup task is posted at a time.
if (!HasDirtyJSFinalizationRegistries() ||
is_finalization_registry_cleanup_task_posted_) {
@@ -6267,6 +6278,7 @@ MaybeHandle<JSFinalizationRegistry> Heap::DequeueDirtyJSFinalizationRegistry() {
void Heap::RemoveDirtyFinalizationRegistriesOnContext(NativeContext context) {
if (!FLAG_harmony_weak_refs) return;
+ if (isolate()->host_cleanup_finalization_group_callback()) return;
DisallowHeapAllocation no_gc;
diff --git a/deps/v8/src/heap/mark-compact.cc b/deps/v8/src/heap/mark-compact.cc
index a7e1c93e1f..53c215e234 100644
--- a/deps/v8/src/heap/mark-compact.cc
+++ b/deps/v8/src/heap/mark-compact.cc
@@ -2537,7 +2537,9 @@ void MarkCompactCollector::ClearJSWeakRefs() {
RecordSlot(weak_cell, slot, HeapObject::cast(*slot));
}
}
- heap()->PostFinalizationRegistryCleanupTaskIfNeeded();
+ if (!isolate()->host_cleanup_finalization_group_callback()) {
+ heap()->PostFinalizationRegistryCleanupTaskIfNeeded();
+ }
}
void MarkCompactCollector::AbortWeakObjects() {
diff --git a/deps/v8/src/logging/counters.h b/deps/v8/src/logging/counters.h
index 02a6feee2e..5c1aa81788 100644
--- a/deps/v8/src/logging/counters.h
+++ b/deps/v8/src/logging/counters.h
@@ -772,6 +772,7 @@ class RuntimeCallTimer final {
V(Int8Array_New) \
V(Isolate_DateTimeConfigurationChangeNotification) \
V(Isolate_LocaleConfigurationChangeNotification) \
+ V(FinalizationGroup_Cleanup) \
V(JSON_Parse) \
V(JSON_Stringify) \
V(Map_AsArray) \