Skip to content

Commit

Permalink
deps: V8: backport d59db06bf542
Browse files Browse the repository at this point in the history
Original commit message:

    [weakrefs] Remove --no-harmony-weak-refs flag

    Bug: v8:8179
    Change-Id: I7f699073807d1874d0c10a4f1641de6bfb0efe6f
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2741582
    Commit-Queue: Shu-yu Guo <syg@chromium.org>
    Reviewed-by: Shu-yu Guo <syg@chromium.org>
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#73871}

Refs: v8/v8@d59db06

PR-URL: #38162
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and jasnell committed Apr 12, 2021
1 parent 3da003c commit 2468e4e
Show file tree
Hide file tree
Showing 47 changed files with 104 additions and 161 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.9',
'v8_embedder_string': '-node.10',

##### V8 defaults for Node.js #####

Expand Down
3 changes: 0 additions & 3 deletions deps/v8/src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ DEFINE_BOOL(use_strict, false, "enforce strict mode")

DEFINE_BOOL(harmony, false, "enable all completed harmony features")
DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features")
// Enabling FinalizationRegistry#cleanupSome also enables weak refs
DEFINE_IMPLICATION(harmony_weak_refs_with_cleanup_some, harmony_weak_refs)

// Update bootstrapper.cc whenever adding a new feature flag.

Expand Down Expand Up @@ -286,7 +284,6 @@ DEFINE_IMPLICATION(harmony_weak_refs_with_cleanup_some, harmony_weak_refs)
#define HARMONY_SHIPPING_BASE(V) \
V(harmony_sharedarraybuffer, "harmony sharedarraybuffer") \
V(harmony_atomics, "harmony atomics") \
V(harmony_weak_refs, "harmony weak references") \
V(harmony_string_replaceall, "harmony String.prototype.replaceAll") \
V(harmony_logical_assignment, "harmony logical assignment") \
V(harmony_atomics_waitasync, "harmony Atomics.waitAsync") \
Expand Down
3 changes: 0 additions & 3 deletions deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6228,8 +6228,6 @@ MaybeHandle<JSFinalizationRegistry> Heap::DequeueDirtyJSFinalizationRegistry() {
}

void Heap::RemoveDirtyFinalizationRegistriesOnContext(NativeContext context) {
if (!FLAG_harmony_weak_refs) return;

DisallowGarbageCollection no_gc;

Isolate* isolate = this->isolate();
Expand Down Expand Up @@ -6259,7 +6257,6 @@ void Heap::RemoveDirtyFinalizationRegistriesOnContext(NativeContext context) {
}

void Heap::KeepDuringJob(Handle<JSReceiver> target) {
DCHECK(FLAG_harmony_weak_refs);
DCHECK(weak_refs_keep_during_job().IsUndefined() ||
weak_refs_keep_during_job().IsOrderedHashSet());
Handle<OrderedHashSet> table;
Expand Down
3 changes: 0 additions & 3 deletions deps/v8/src/heap/mark-compact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2480,9 +2480,6 @@ void MarkCompactCollector::ClearWeakReferences() {
}

void MarkCompactCollector::ClearJSWeakRefs() {
if (!FLAG_harmony_weak_refs) {
return;
}
JSWeakRef weak_ref;
while (weak_objects_.js_weak_refs.Pop(kMainThreadTask, &weak_ref)) {
HeapObject target = HeapObject::cast(weak_ref.target());
Expand Down
24 changes: 11 additions & 13 deletions deps/v8/src/heap/weak-object-worklists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,17 @@ void WeakObjects::UpdateWeakObjectsInCode(

void WeakObjects::UpdateJSWeakRefs(
WeakObjectWorklist<JSWeakRef>& js_weak_refs) {
if (FLAG_harmony_weak_refs) {
js_weak_refs.Update(
[](JSWeakRef js_weak_ref_in, JSWeakRef* js_weak_ref_out) -> bool {
JSWeakRef forwarded = ForwardingAddress(js_weak_ref_in);

if (!forwarded.is_null()) {
*js_weak_ref_out = forwarded;
return true;
}

return false;
});
}
js_weak_refs.Update(
[](JSWeakRef js_weak_ref_in, JSWeakRef* js_weak_ref_out) -> bool {
JSWeakRef forwarded = ForwardingAddress(js_weak_ref_in);

if (!forwarded.is_null()) {
*js_weak_ref_out = forwarded;
return true;
}

return false;
});
}

void WeakObjects::UpdateWeakCells(WeakObjectWorklist<WeakCell>& weak_cells) {
Expand Down
122 changes: 55 additions & 67 deletions deps/v8/src/init/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,61 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_bound_function_with_constructor_map(*map);
}

{ // -- F i n a l i z a t i o n R e g i s t r y
Handle<JSFunction> finalization_registry_fun = InstallFunction(
isolate_, global, factory->FinalizationRegistry_string(),
JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
factory->the_hole_value(), Builtins::kFinalizationRegistryConstructor);
InstallWithIntrinsicDefaultProto(
isolate_, finalization_registry_fun,
Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);

finalization_registry_fun->shared().DontAdaptArguments();
finalization_registry_fun->shared().set_length(1);

Handle<JSObject> finalization_registry_prototype(
JSObject::cast(finalization_registry_fun->instance_prototype()),
isolate());

InstallToStringTag(isolate_, finalization_registry_prototype,
factory->FinalizationRegistry_string());

SimpleInstallFunction(isolate_, finalization_registry_prototype, "register",
Builtins::kFinalizationRegistryRegister, 2, false);

SimpleInstallFunction(isolate_, finalization_registry_prototype,
"unregister",
Builtins::kFinalizationRegistryUnregister, 1, false);

// The cleanupSome function is created but not exposed, as it is used
// internally by InvokeFinalizationRegistryCleanupFromTask.
//
// It is exposed by FLAG_harmony_weak_refs_with_cleanup_some.
Handle<JSFunction> cleanup_some_fun = SimpleCreateFunction(
isolate_, factory->InternalizeUtf8String("cleanupSome"),
Builtins::kFinalizationRegistryPrototypeCleanupSome, 0, false);
native_context()->set_finalization_registry_cleanup_some(*cleanup_some_fun);
}

{ // -- W e a k R e f
Handle<JSFunction> weak_ref_fun = InstallFunction(
isolate_, global, "WeakRef", JS_WEAK_REF_TYPE, JSWeakRef::kHeaderSize,
0, factory->the_hole_value(), Builtins::kWeakRefConstructor);
InstallWithIntrinsicDefaultProto(isolate_, weak_ref_fun,
Context::JS_WEAK_REF_FUNCTION_INDEX);

weak_ref_fun->shared().DontAdaptArguments();
weak_ref_fun->shared().set_length(1);

Handle<JSObject> weak_ref_prototype(
JSObject::cast(weak_ref_fun->instance_prototype()), isolate());

InstallToStringTag(isolate_, weak_ref_prototype, factory->WeakRef_string());

SimpleInstallFunction(isolate_, weak_ref_prototype, "deref",
Builtins::kWeakRefDeref, 0, true);
}

{ // --- sloppy arguments map
Handle<String> arguments_string = factory->Arguments_string();
Handle<JSFunction> function = CreateFunctionForBuiltinWithPrototype(
Expand Down Expand Up @@ -4351,75 +4406,8 @@ void Genesis::InitializeGlobal_harmony_atomics() {
InstallToStringTag(isolate_, isolate()->atomics_object(), "Atomics");
}

void Genesis::InitializeGlobal_harmony_weak_refs() {
if (!FLAG_harmony_weak_refs) return;

Factory* factory = isolate()->factory();
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());

{
// Create %FinalizationRegistry%
Handle<JSFunction> finalization_registry_fun = InstallFunction(
isolate(), global, factory->FinalizationRegistry_string(),
JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
factory->the_hole_value(), Builtins::kFinalizationRegistryConstructor);
InstallWithIntrinsicDefaultProto(
isolate(), finalization_registry_fun,
Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);

finalization_registry_fun->shared().DontAdaptArguments();
finalization_registry_fun->shared().set_length(1);

Handle<JSObject> finalization_registry_prototype(
JSObject::cast(finalization_registry_fun->instance_prototype()),
isolate());

InstallToStringTag(isolate(), finalization_registry_prototype,
factory->FinalizationRegistry_string());

SimpleInstallFunction(isolate(), finalization_registry_prototype,
"register", Builtins::kFinalizationRegistryRegister,
2, false);

SimpleInstallFunction(isolate(), finalization_registry_prototype,
"unregister",
Builtins::kFinalizationRegistryUnregister, 1, false);

// The cleanupSome function is created but not exposed, as it is used
// internally by InvokeFinalizationRegistryCleanupFromTask.
//
// It is exposed by FLAG_harmony_weak_refs_with_cleanup_some.
Handle<JSFunction> cleanup_some_fun = SimpleCreateFunction(
isolate(), factory->InternalizeUtf8String("cleanupSome"),
Builtins::kFinalizationRegistryPrototypeCleanupSome, 0, false);
native_context()->set_finalization_registry_cleanup_some(*cleanup_some_fun);
}
{
// Create %WeakRef%
Handle<JSFunction> weak_ref_fun = InstallFunction(
isolate(), global, factory->WeakRef_string(), JS_WEAK_REF_TYPE,
JSWeakRef::kHeaderSize, 0, factory->the_hole_value(),
Builtins::kWeakRefConstructor);
InstallWithIntrinsicDefaultProto(isolate(), weak_ref_fun,
Context::JS_WEAK_REF_FUNCTION_INDEX);

weak_ref_fun->shared().DontAdaptArguments();
weak_ref_fun->shared().set_length(1);

Handle<JSObject> weak_ref_prototype(
JSObject::cast(weak_ref_fun->instance_prototype()), isolate());

InstallToStringTag(isolate(), weak_ref_prototype,
factory->WeakRef_string());

SimpleInstallFunction(isolate(), weak_ref_prototype, "deref",
Builtins::kWeakRefDeref, 0, true);
}
}

void Genesis::InitializeGlobal_harmony_weak_refs_with_cleanup_some() {
if (!FLAG_harmony_weak_refs_with_cleanup_some) return;
DCHECK(FLAG_harmony_weak_refs);

Handle<JSFunction> finalization_registry_fun =
isolate()->js_finalization_registry_fun();
Expand Down
19 changes: 0 additions & 19 deletions deps/v8/test/cctest/test-js-weak-refs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ Handle<JSWeakRef> MakeWeakRefAndKeepDuringJob(Isolate* isolate) {
} // namespace

TEST(TestRegister) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -247,7 +246,6 @@ TEST(TestRegister) {
}

TEST(TestRegisterWithKey) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -300,7 +298,6 @@ TEST(TestRegisterWithKey) {
}

TEST(TestWeakCellNullify1) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -335,7 +332,6 @@ TEST(TestWeakCellNullify1) {
}

TEST(TestWeakCellNullify2) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -369,7 +365,6 @@ TEST(TestWeakCellNullify2) {
}

TEST(TestJSFinalizationRegistryPopClearedCellHoldings1) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -425,7 +420,6 @@ TEST(TestJSFinalizationRegistryPopClearedCellHoldings1) {
TEST(TestJSFinalizationRegistryPopClearedCellHoldings2) {
// Test that when all WeakCells for a key are popped, the key is removed from
// the key map.
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -476,7 +470,6 @@ TEST(TestJSFinalizationRegistryPopClearedCellHoldings2) {
}

TEST(TestUnregisterActiveCells) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -529,7 +522,6 @@ TEST(TestUnregisterActiveCells) {
}

TEST(TestUnregisterActiveAndClearedCells) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -585,7 +577,6 @@ TEST(TestUnregisterActiveAndClearedCells) {
}

TEST(TestWeakCellUnregisterTwice) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -633,7 +624,6 @@ TEST(TestWeakCellUnregisterTwice) {
}

TEST(TestWeakCellUnregisterPopped) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -674,7 +664,6 @@ TEST(TestWeakCellUnregisterPopped) {
}

TEST(TestWeakCellUnregisterNonexistentKey) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand All @@ -687,7 +676,6 @@ TEST(TestWeakCellUnregisterNonexistentKey) {
}

TEST(TestJSWeakRef) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;

Expand Down Expand Up @@ -716,7 +704,6 @@ TEST(TestJSWeakRef) {
}

TEST(TestJSWeakRefIncrementalMarking) {
FLAG_harmony_weak_refs = true;
if (!FLAG_incremental_marking) {
return;
}
Expand Down Expand Up @@ -752,7 +739,6 @@ TEST(TestJSWeakRefIncrementalMarking) {
}

TEST(TestJSWeakRefKeepDuringJob) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;

Expand Down Expand Up @@ -790,7 +776,6 @@ TEST(TestJSWeakRefKeepDuringJob) {
}

TEST(TestJSWeakRefKeepDuringJobIncrementalMarking) {
FLAG_harmony_weak_refs = true;
if (!FLAG_incremental_marking) {
return;
}
Expand Down Expand Up @@ -819,7 +804,6 @@ TEST(TestJSWeakRefKeepDuringJobIncrementalMarking) {
}

TEST(TestRemoveUnregisterToken) {
FLAG_harmony_weak_refs = true;
CcTest::InitializeVM();
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Expand Down Expand Up @@ -883,7 +867,6 @@ TEST(TestRemoveUnregisterToken) {
}

TEST(JSWeakRefScavengedInWorklist) {
FLAG_harmony_weak_refs = true;
if (!FLAG_incremental_marking || FLAG_single_generation) {
return;
}
Expand Down Expand Up @@ -928,7 +911,6 @@ TEST(JSWeakRefScavengedInWorklist) {
}

TEST(JSWeakRefTenuredInWorklist) {
FLAG_harmony_weak_refs = true;
if (!FLAG_incremental_marking || FLAG_single_generation) {
return;
}
Expand Down Expand Up @@ -976,7 +958,6 @@ TEST(JSWeakRefTenuredInWorklist) {
}

TEST(UnregisterTokenHeapVerifier) {
FLAG_harmony_weak_refs = true;
if (!FLAG_incremental_marking) return;
ManualGCScope manual_gc_scope;
#ifdef VERIFY_HEAP
Expand Down
2 changes: 0 additions & 2 deletions deps/v8/test/message/fail/weak-refs-finalizationregistry1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-weak-refs

let fg = new FinalizationRegistry();
4 changes: 2 additions & 2 deletions deps/v8/test/message/fail/weak-refs-finalizationregistry1.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*%(basename)s:7: TypeError: FinalizationRegistry: cleanup must be callable
*%(basename)s:*: TypeError: FinalizationRegistry: cleanup must be callable
let fg = new FinalizationRegistry();
^
TypeError: FinalizationRegistry: cleanup must be callable
at new FinalizationRegistry (<anonymous>)
at *%(basename)s:7:10
at *%(basename)s:*:10
2 changes: 0 additions & 2 deletions deps/v8/test/message/fail/weak-refs-finalizationregistry2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-weak-refs

let fg = new FinalizationRegistry({});
Loading

0 comments on commit 2468e4e

Please sign in to comment.