Skip to content

Commit ca5b0ec

Browse files
addaleaxCommit Bot
authored andcommitted
[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: nodejs/node#30498 Refs: nodejs/node#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}
1 parent bb118e5 commit ca5b0ec

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/heap/factory.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,20 +3056,22 @@ Handle<SyntheticModule> Factory::NewSyntheticModule(
30563056
Handle<String> module_name, Handle<FixedArray> export_names,
30573057
v8::Module::SyntheticModuleEvaluationSteps evaluation_steps) {
30583058
ReadOnlyRoots roots(isolate());
3059-
Handle<SyntheticModule> module(
3060-
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3061-
isolate());
3059+
30623060
Handle<ObjectHashTable> exports =
30633061
ObjectHashTable::New(isolate(), static_cast<int>(export_names->length()));
30643062
Handle<Foreign> evaluation_steps_foreign =
30653063
NewForeign(reinterpret_cast<i::Address>(evaluation_steps));
3066-
module->set_exports(*exports);
3064+
3065+
Handle<SyntheticModule> module(
3066+
SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
3067+
isolate());
30673068
module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
30683069
module->set_module_namespace(roots.undefined_value());
30693070
module->set_status(Module::kUninstantiated);
30703071
module->set_exception(roots.the_hole_value());
30713072
module->set_name(*module_name);
30723073
module->set_export_names(*export_names);
3074+
module->set_exports(*exports);
30733075
module->set_evaluation_steps(*evaluation_steps_foreign);
30743076
return module;
30753077
}

test/cctest/test-api.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23979,6 +23979,31 @@ TEST(CreateSyntheticModule) {
2397923979
CHECK_EQ(i_module->status(), i::Module::kInstantiated);
2398023980
}
2398123981

23982+
TEST(CreateSyntheticModuleGC) {
23983+
// Try to make sure that CreateSyntheticModule() deals well with a GC
23984+
// happening during its execution.
23985+
i::FLAG_gc_interval = 10;
23986+
i::FLAG_inline_new = false;
23987+
23988+
LocalContext env;
23989+
v8::Isolate* isolate = env->GetIsolate();
23990+
v8::Isolate::Scope iscope(isolate);
23991+
v8::HandleScope scope(isolate);
23992+
v8::Local<v8::Context> context = v8::Context::New(isolate);
23993+
v8::Context::Scope cscope(context);
23994+
23995+
std::vector<v8::Local<v8::String>> export_names{v8_str("default")};
23996+
v8::Local<v8::String> module_name =
23997+
v8_str("CreateSyntheticModule-TestSyntheticModuleGC");
23998+
23999+
for (int i = 0; i < 200; i++) {
24000+
Local<Module> module = v8::Module::CreateSyntheticModule(
24001+
isolate, module_name, export_names,
24002+
UnexpectedSyntheticModuleEvaluationStepsCallback);
24003+
USE(module);
24004+
}
24005+
}
24006+
2398224007
TEST(SyntheticModuleSetExports) {
2398324008
LocalContext env;
2398424009
v8::Isolate* isolate = env->GetIsolate();

0 commit comments

Comments
 (0)