Skip to content

Commit 29b5432

Browse files
addaleaxgireeshpunathil
authored andcommittedNov 29, 2019
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 99d1f6f commit 29b5432

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
@@ -39,7 +39,7 @@
3939

4040
# Reset this number to 0 on major V8 upgrades.
4141
# Increment by one for each non-official patch applied to deps/v8.
42-
'v8_embedder_string': '-node.20',
42+
'v8_embedder_string': '-node.21',
4343

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

‎deps/v8/src/heap/factory.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -3070,20 +3070,22 @@ Handle<SyntheticModule> Factory::NewSyntheticModule(
30703070
Handle<String> module_name, Handle<FixedArray> export_names,
30713071
v8::Module::SyntheticModuleEvaluationSteps evaluation_steps) {
30723072
ReadOnlyRoots roots(isolate());
3073-
Handle<SyntheticModule> module(
3074-
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3075-
isolate());
3073+
30763074
Handle<ObjectHashTable> exports =
30773075
ObjectHashTable::New(isolate(), static_cast<int>(export_names->length()));
30783076
Handle<Foreign> evaluation_steps_foreign =
30793077
NewForeign(reinterpret_cast<i::Address>(evaluation_steps));
3080-
module->set_exports(*exports);
3078+
3079+
Handle<SyntheticModule> module(
3080+
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3081+
isolate());
30813082
module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
30823083
module->set_module_namespace(roots.undefined_value());
30833084
module->set_status(Module::kUninstantiated);
30843085
module->set_exception(roots.the_hole_value());
30853086
module->set_name(*module_name);
30863087
module->set_export_names(*export_names);
3088+
module->set_exports(*exports);
30873089
module->set_evaluation_steps(*evaluation_steps_foreign);
30883090
return module;
30893091
}

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

+25
Original file line numberDiff line numberDiff line change
@@ -23918,6 +23918,31 @@ TEST(CreateSyntheticModule) {
2391823918
CHECK_EQ(i_module->status(), i::Module::kInstantiated);
2391923919
}
2392023920

23921+
TEST(CreateSyntheticModuleGC) {
23922+
// Try to make sure that CreateSyntheticModule() deals well with a GC
23923+
// happening during its execution.
23924+
i::FLAG_gc_interval = 10;
23925+
i::FLAG_inline_new = false;
23926+
23927+
LocalContext env;
23928+
v8::Isolate* isolate = env->GetIsolate();
23929+
v8::Isolate::Scope iscope(isolate);
23930+
v8::HandleScope scope(isolate);
23931+
v8::Local<v8::Context> context = v8::Context::New(isolate);
23932+
v8::Context::Scope cscope(context);
23933+
23934+
std::vector<v8::Local<v8::String>> export_names{v8_str("default")};
23935+
v8::Local<v8::String> module_name =
23936+
v8_str("CreateSyntheticModule-TestSyntheticModuleGC");
23937+
23938+
for (int i = 0; i < 200; i++) {
23939+
Local<Module> module = v8::Module::CreateSyntheticModule(
23940+
isolate, module_name, export_names,
23941+
UnexpectedSyntheticModuleEvaluationStepsCallback);
23942+
USE(module);
23943+
}
23944+
}
23945+
2392123946
TEST(SyntheticModuleSetExports) {
2392223947
LocalContext env;
2392323948
v8::Isolate* isolate = env->GetIsolate();

0 commit comments

Comments
 (0)
Please sign in to comment.