Skip to content

Commit 83eb4f2

Browse files
committed
deps: V8: cherry-pick cd10ad7cdbe5
Original commit message: [compiler] reset script details in functions deserialized from code cache During the serialization of the code cache, V8 would wipe out the host-defined options, so after a script id deserialized from the code cache, the host-defined options need to be reset on the script using what's provided by the embedder when doing the deserializing compilation, otherwise the HostImportModuleDynamically callbacks can't get the data it needs to implement dynamic import(). Change-Id: I33cc6a5e43b6469d3527242e083f7ae6d8ed0c6a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5401780 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Joyee Cheung <joyee@igalia.com> Cr-Commit-Position: refs/heads/main@{#93323} Refs: v8/v8@cd10ad7 PR-URL: #52535 Refs: #47472 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent 3d4c520 commit 83eb4f2

File tree

7 files changed

+247
-27
lines changed

7 files changed

+247
-27
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

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

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

deps/v8/src/codegen/compiler.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,8 @@ BackgroundCompileTask::BackgroundCompileTask(
17201720

17211721
BackgroundCompileTask::~BackgroundCompileTask() = default;
17221722

1723-
namespace {
1724-
17251723
void SetScriptFieldsFromDetails(Isolate* isolate, Tagged<Script> script,
1726-
ScriptDetails script_details,
1724+
const ScriptDetails& script_details,
17271725
DisallowGarbageCollection* no_gc) {
17281726
Handle<Object> script_name;
17291727
if (script_details.name_obj.ToHandle(&script_name)) {
@@ -1749,6 +1747,8 @@ void SetScriptFieldsFromDetails(Isolate* isolate, Tagged<Script> script,
17491747
}
17501748
}
17511749

1750+
namespace {
1751+
17521752
#ifdef ENABLE_SLOW_DCHECKS
17531753

17541754
// A class which traverses the object graph for a newly compiled Script and
@@ -2450,10 +2450,10 @@ void BackgroundDeserializeTask::MergeWithExistingScript() {
24502450

24512451
MaybeHandle<SharedFunctionInfo> BackgroundDeserializeTask::Finish(
24522452
Isolate* isolate, Handle<String> source,
2453-
ScriptOriginOptions origin_options) {
2453+
const ScriptDetails& script_details) {
24542454
return CodeSerializer::FinishOffThreadDeserialize(
24552455
isolate, std::move(off_thread_data_), &cached_data_, source,
2456-
origin_options, &background_merge_task_);
2456+
script_details, &background_merge_task_);
24572457
}
24582458

24592459
// ----------------------------------------------------------------------------
@@ -3630,8 +3630,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
36303630
"V8.CompileDeserialize");
36313631
if (deserialize_task) {
36323632
// If there's a cache consume task, finish it.
3633-
maybe_result = deserialize_task->Finish(isolate, source,
3634-
script_details.origin_options);
3633+
maybe_result =
3634+
deserialize_task->Finish(isolate, source, script_details);
36353635
// It is possible at this point that there is a Script object for this
36363636
// script in the compilation cache (held in the variable maybe_script),
36373637
// which does not match maybe_result->script(). This could happen any of
@@ -3652,8 +3652,7 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
36523652
// would be non-trivial.
36533653
} else {
36543654
maybe_result = CodeSerializer::Deserialize(
3655-
isolate, cached_data, source, script_details.origin_options,
3656-
maybe_script);
3655+
isolate, cached_data, source, script_details, maybe_script);
36573656
}
36583657

36593658
bool consuming_code_cache_succeeded = false;
@@ -3829,7 +3828,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38293828
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
38303829
"V8.CompileDeserialize");
38313830
maybe_result = CodeSerializer::Deserialize(isolate, cached_data, source,
3832-
script_details.origin_options);
3831+
script_details);
38333832
bool consuming_code_cache_succeeded = false;
38343833
if (maybe_result.ToHandle(&result)) {
38353834
is_compiled_scope = result->is_compiled_scope(isolate);

deps/v8/src/codegen/compiler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ class V8_EXPORT_PRIVATE BackgroundDeserializeTask {
682682

683683
MaybeHandle<SharedFunctionInfo> Finish(Isolate* isolate,
684684
Handle<String> source,
685-
ScriptOriginOptions origin_options);
685+
const ScriptDetails& script_details);
686686

687687
bool rejected() const { return cached_data_.rejected(); }
688688

deps/v8/src/codegen/script-details.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct ScriptDetails {
3535
const ScriptOriginOptions origin_options;
3636
};
3737

38+
void SetScriptFieldsFromDetails(Isolate* isolate, Tagged<Script> script,
39+
const ScriptDetails& script_details,
40+
DisallowGarbageCollection* no_gc);
3841
} // namespace internal
3942
} // namespace v8
4043

deps/v8/src/snapshot/code-serializer.cc

+21-13
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ class StressOffThreadDeserializeThread final : public base::Thread {
314314
CodeSerializer::StartDeserializeOffThread(&local_isolate, cached_data_);
315315
}
316316

317-
MaybeHandle<SharedFunctionInfo> Finalize(Isolate* isolate,
318-
Handle<String> source,
319-
ScriptOriginOptions origin_options) {
317+
MaybeHandle<SharedFunctionInfo> Finalize(
318+
Isolate* isolate, Handle<String> source,
319+
const ScriptDetails& script_details) {
320320
return CodeSerializer::FinishOffThreadDeserialize(
321321
isolate, std::move(off_thread_data_), cached_data_, source,
322-
origin_options);
322+
script_details);
323323
}
324324

325325
private:
@@ -330,7 +330,8 @@ class StressOffThreadDeserializeThread final : public base::Thread {
330330

331331
void FinalizeDeserialization(Isolate* isolate,
332332
Handle<SharedFunctionInfo> result,
333-
const base::ElapsedTimer& timer) {
333+
const base::ElapsedTimer& timer,
334+
const ScriptDetails& script_details) {
334335
// Devtools can report time in this function as profiler overhead, since none
335336
// of the following tasks would need to happen normally.
336337
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
@@ -343,10 +344,16 @@ void FinalizeDeserialization(Isolate* isolate,
343344
log_code_creation);
344345
}
345346

347+
Handle<Script> script(Script::cast(result->script()), isolate);
348+
// Reset the script details, including host-defined options.
349+
{
350+
DisallowGarbageCollection no_gc;
351+
SetScriptFieldsFromDetails(isolate, *script, script_details, &no_gc);
352+
}
353+
346354
bool needs_source_positions = isolate->NeedsSourcePositions();
347355
if (!log_code_creation && !needs_source_positions) return;
348356

349-
Handle<Script> script(Script::cast(result->script()), isolate);
350357
if (needs_source_positions) {
351358
Script::InitLineEnds(isolate, script);
352359
}
@@ -430,13 +437,13 @@ const char* ToString(SerializedCodeSanityCheckResult result) {
430437

431438
MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
432439
Isolate* isolate, AlignedCachedData* cached_data, Handle<String> source,
433-
ScriptOriginOptions origin_options,
440+
const ScriptDetails& script_details,
434441
MaybeHandle<Script> maybe_cached_script) {
435442
if (v8_flags.stress_background_compile) {
436443
StressOffThreadDeserializeThread thread(isolate, cached_data);
437444
CHECK(thread.Start());
438445
thread.Join();
439-
return thread.Finalize(isolate, source, origin_options);
446+
return thread.Finalize(isolate, source, script_details);
440447
// TODO(leszeks): Compare off-thread deserialized data to on-thread.
441448
}
442449

@@ -451,7 +458,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
451458
SerializedCodeSanityCheckResult::kSuccess;
452459
const SerializedCodeData scd = SerializedCodeData::FromCachedData(
453460
isolate, cached_data,
454-
SerializedCodeData::SourceHash(source, origin_options),
461+
SerializedCodeData::SourceHash(source, script_details.origin_options),
455462
&sanity_check_result);
456463
if (sanity_check_result != SerializedCodeSanityCheckResult::kSuccess) {
457464
if (v8_flags.profile_deserialization) {
@@ -498,7 +505,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
498505
PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
499506
}
500507

501-
FinalizeDeserialization(isolate, result, timer);
508+
FinalizeDeserialization(isolate, result, timer, script_details);
502509

503510
return scope.CloseAndEscape(result);
504511
}
@@ -553,7 +560,7 @@ CodeSerializer::StartDeserializeOffThread(LocalIsolate* local_isolate,
553560
MaybeHandle<SharedFunctionInfo> CodeSerializer::FinishOffThreadDeserialize(
554561
Isolate* isolate, OffThreadDeserializeData&& data,
555562
AlignedCachedData* cached_data, Handle<String> source,
556-
ScriptOriginOptions origin_options,
563+
const ScriptDetails& script_details,
557564
BackgroundMergeTask* background_merge_task) {
558565
base::ElapsedTimer timer;
559566
if (v8_flags.profile_deserialization || v8_flags.log_function_events) {
@@ -569,7 +576,8 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::FinishOffThreadDeserialize(
569576
data.sanity_check_result;
570577
const SerializedCodeData scd =
571578
SerializedCodeData::FromPartiallySanityCheckedCachedData(
572-
cached_data, SerializedCodeData::SourceHash(source, origin_options),
579+
cached_data,
580+
SerializedCodeData::SourceHash(source, script_details.origin_options),
573581
&sanity_check_result);
574582
if (sanity_check_result != SerializedCodeSanityCheckResult::kSuccess) {
575583
// The only case where the deserialization result could exist despite a
@@ -642,7 +650,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::FinishOffThreadDeserialize(
642650
length, ms);
643651
}
644652

645-
FinalizeDeserialization(isolate, result, timer);
653+
FinalizeDeserialization(isolate, result, timer, script_details);
646654

647655
DCHECK(!background_merge_task ||
648656
!background_merge_task->HasPendingForegroundWork());

deps/v8/src/snapshot/code-serializer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define V8_SNAPSHOT_CODE_SERIALIZER_H_
77

88
#include "src/base/macros.h"
9+
#include "src/codegen/script-details.h"
910
#include "src/snapshot/serializer.h"
1011
#include "src/snapshot/snapshot-data.h"
1112

@@ -81,7 +82,7 @@ class CodeSerializer : public Serializer {
8182

8283
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
8384
Isolate* isolate, AlignedCachedData* cached_data, Handle<String> source,
84-
ScriptOriginOptions origin_options,
85+
const ScriptDetails& script_details,
8586
MaybeHandle<Script> maybe_cached_script = {});
8687

8788
V8_WARN_UNUSED_RESULT static OffThreadDeserializeData
@@ -92,7 +93,7 @@ class CodeSerializer : public Serializer {
9293
FinishOffThreadDeserialize(
9394
Isolate* isolate, OffThreadDeserializeData&& data,
9495
AlignedCachedData* cached_data, Handle<String> source,
95-
ScriptOriginOptions origin_options,
96+
const ScriptDetails& script_details,
9697
BackgroundMergeTask* background_merge_task = nullptr);
9798

9899
uint32_t source_hash() const { return source_hash_; }

0 commit comments

Comments
 (0)