diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-11-28 22:11:40 +0100 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-11-29 14:19:05 +0530 |
commit | 29b5432c645ef250030dde5a4f042ae69fcbbe89 (patch) | |
tree | 8a1f0e71a1d66eb24c54e8ab487a05f4199626b1 /deps | |
parent | 99d1f6fea49e92bc3b3993d1f74ca9a8772c5d02 (diff) | |
download | android-node-v8-29b5432c645ef250030dde5a4f042ae69fcbbe89.tar.gz android-node-v8-29b5432c645ef250030dde5a4f042ae69fcbbe89.tar.bz2 android-node-v8-29b5432c645ef250030dde5a4f042ae69fcbbe89.zip |
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: https://github.com/nodejs/node/issues/30498
Refs: https://github.com/nodejs/node/issues/30648
Change-Id: I32da4b7bd888c6ec1421f34f5bd52e7bad154c1e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1939752
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65247}
Refs: https://github.com/v8/v8/commit/ \
ca5b0ec2722d2af4551c01ca78921fa16a26ae72
Fixes: https://github.com/nodejs/node/issues/30498
Fixes: https://github.com/nodejs/node/issues/30648
PR-URL: https://github.com/nodejs/node/pull/30708
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'deps')
-rw-r--r-- | deps/v8/src/heap/factory.cc | 10 | ||||
-rw-r--r-- | deps/v8/test/cctest/test-api.cc | 25 |
2 files changed, 31 insertions, 4 deletions
diff --git a/deps/v8/src/heap/factory.cc b/deps/v8/src/heap/factory.cc index 721682f00f..7e434ea041 100644 --- a/deps/v8/src/heap/factory.cc +++ b/deps/v8/src/heap/factory.cc @@ -3070,20 +3070,22 @@ Handle<SyntheticModule> Factory::NewSyntheticModule( Handle<String> module_name, Handle<FixedArray> export_names, v8::Module::SyntheticModuleEvaluationSteps evaluation_steps) { ReadOnlyRoots roots(isolate()); - Handle<SyntheticModule> module( - SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)), - isolate()); + Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate(), static_cast<int>(export_names->length())); Handle<Foreign> evaluation_steps_foreign = NewForeign(reinterpret_cast<i::Address>(evaluation_steps)); - module->set_exports(*exports); + + Handle<SyntheticModule> module( + SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)), + isolate()); module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue)); module->set_module_namespace(roots.undefined_value()); module->set_status(Module::kUninstantiated); module->set_exception(roots.the_hole_value()); module->set_name(*module_name); module->set_export_names(*export_names); + module->set_exports(*exports); module->set_evaluation_steps(*evaluation_steps_foreign); return module; } diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 12faaff39c..bafdd6ce3b 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -23918,6 +23918,31 @@ TEST(CreateSyntheticModule) { CHECK_EQ(i_module->status(), i::Module::kInstantiated); } +TEST(CreateSyntheticModuleGC) { + // Try to make sure that CreateSyntheticModule() deals well with a GC + // happening during its execution. + i::FLAG_gc_interval = 10; + i::FLAG_inline_new = false; + + LocalContext env; + v8::Isolate* isolate = env->GetIsolate(); + v8::Isolate::Scope iscope(isolate); + v8::HandleScope scope(isolate); + v8::Local<v8::Context> context = v8::Context::New(isolate); + v8::Context::Scope cscope(context); + + std::vector<v8::Local<v8::String>> export_names{v8_str("default")}; + v8::Local<v8::String> module_name = + v8_str("CreateSyntheticModule-TestSyntheticModuleGC"); + + for (int i = 0; i < 200; i++) { + Local<Module> module = v8::Module::CreateSyntheticModule( + isolate, module_name, export_names, + UnexpectedSyntheticModuleEvaluationStepsCallback); + USE(module); + } +} + TEST(SyntheticModuleSetExports) { LocalContext env; v8::Isolate* isolate = env->GetIsolate(); |