Skip to content

Commit fcc4bf9

Browse files
addaleaxMylesBorins
authored andcommitted
deps: V8: cherry-pick ca5b0ec
Original commit message: [heap] Ensure SyntheticModule is initialized before next allocation Ensure that all fields of `SyntheticModule` are set before creating the exports hash table for it, because the latter may trigger garbage collection, leading to crashes. This has been causing failures in the Node.js CI over the last weeks, after making the creating of synthetic modules part of Node’s startup sequence. (I am generally not very familiar with this part of the V8 code and there might be a better way, or possibly a way to add a reliable regression test, that I am not aware of.) Refs: #30498 Refs: #30648 Change-Id: I32da4b7bd888c6ec1421f34f5bd52e7bad154c1e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1939752 Commit-Queue: Ulan Degenbaev <[email protected]> Reviewed-by: Ulan Degenbaev <[email protected]> Cr-Commit-Position: refs/heads/master@{#65247} Refs: https://github.com/v8/v8/commit/ \ ca5b0ec2722d2af4551c01ca78921fa16a26ae72 Fixes: #30498 Fixes: #30648 PR-URL: #30708 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent eb4b932 commit fcc4bf9

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.23',
41+
'v8_embedder_string': '-node.24',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/heap/factory.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -3068,20 +3068,22 @@ Handle<SyntheticModule> Factory::NewSyntheticModule(
30683068
Handle<String> module_name, Handle<FixedArray> export_names,
30693069
v8::Module::SyntheticModuleEvaluationSteps evaluation_steps) {
30703070
ReadOnlyRoots roots(isolate());
3071-
Handle<SyntheticModule> module(
3072-
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3073-
isolate());
3071+
30743072
Handle<ObjectHashTable> exports =
30753073
ObjectHashTable::New(isolate(), static_cast<int>(export_names->length()));
30763074
Handle<Foreign> evaluation_steps_foreign =
30773075
NewForeign(reinterpret_cast<i::Address>(evaluation_steps));
3078-
module->set_exports(*exports);
3076+
3077+
Handle<SyntheticModule> module(
3078+
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3079+
isolate());
30793080
module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
30803081
module->set_module_namespace(roots.undefined_value());
30813082
module->set_status(Module::kUninstantiated);
30823083
module->set_exception(roots.the_hole_value());
30833084
module->set_name(*module_name);
30843085
module->set_export_names(*export_names);
3086+
module->set_exports(*exports);
30853087
module->set_evaluation_steps(*evaluation_steps_foreign);
30863088
return module;
30873089
}

deps/v8/test/cctest/test-api.cc

+25
Original file line numberDiff line numberDiff line change
@@ -23874,6 +23874,31 @@ TEST(CreateSyntheticModule) {
2387423874
CHECK_EQ(i_module->status(), i::Module::kInstantiated);
2387523875
}
2387623876

23877+
TEST(CreateSyntheticModuleGC) {
23878+
// Try to make sure that CreateSyntheticModule() deals well with a GC
23879+
// happening during its execution.
23880+
i::FLAG_gc_interval = 10;
23881+
i::FLAG_inline_new = false;
23882+
23883+
LocalContext env;
23884+
v8::Isolate* isolate = env->GetIsolate();
23885+
v8::Isolate::Scope iscope(isolate);
23886+
v8::HandleScope scope(isolate);
23887+
v8::Local<v8::Context> context = v8::Context::New(isolate);
23888+
v8::Context::Scope cscope(context);
23889+
23890+
std::vector<v8::Local<v8::String>> export_names{v8_str("default")};
23891+
v8::Local<v8::String> module_name =
23892+
v8_str("CreateSyntheticModule-TestSyntheticModuleGC");
23893+
23894+
for (int i = 0; i < 200; i++) {
23895+
Local<Module> module = v8::Module::CreateSyntheticModule(
23896+
isolate, module_name, export_names,
23897+
UnexpectedSyntheticModuleEvaluationStepsCallback);
23898+
USE(module);
23899+
}
23900+
}
23901+
2387723902
TEST(SyntheticModuleSetExports) {
2387823903
LocalContext env;
2387923904
v8::Isolate* isolate = env->GetIsolate();

0 commit comments

Comments
 (0)