Skip to content

Commit 212e6bb

Browse files
laverdettargos
authored andcommitted
deps: cherry-pick 22116dd from upstream V8
Refs: v8/v8@22116dd Original commit message: [snapshot] fix resetting function code. Unconditionally setting the JSFunction code to that of the SFI may skip initializing the feedback vector. [email protected] Bug: v8:7857 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: I65d4bf32493be4cade2eaf3d665d44f93e80f809 Reviewed-on: https://chromium-review.googlesource.com/1107618 Commit-Queue: Yang Guo <[email protected]> Reviewed-by: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/master@{#53881} PR-URL: #21992 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent f729549 commit 212e6bb

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Reset this number to 0 on major V8 upgrades.
3131
# Increment by one for each non-official patch applied to deps/v8.
32-
'v8_embedder_string': '-node.25',
32+
'v8_embedder_string': '-node.26',
3333

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/src/api.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,11 @@ StartupData SnapshotCreator::CreateBlob(
766766
// Complete in-object slack tracking for all functions.
767767
fun->CompleteInobjectSlackTrackingIfActive();
768768

769-
// Also, clear out feedback vectors.
770-
fun->feedback_cell()->set_value(isolate->heap()->undefined_value());
769+
// Also, clear out feedback vectors, or any optimized code.
770+
if (fun->has_feedback_vector()) {
771+
fun->feedback_cell()->set_value(isolate->heap()->undefined_value());
772+
fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
773+
}
771774
}
772775

773776
// Clear out re-compilable data from all shared function infos. Any

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
105105
// Unconditionally reset the JSFunction to its SFI's code, since we can't
106106
// serialize optimized code anyway.
107107
JSFunction* closure = JSFunction::cast(obj);
108-
closure->set_code(closure->shared()->GetCode());
108+
if (closure->is_compiled()) closure->set_code(closure->shared()->GetCode());
109109
}
110110

111111
CheckRehashability(obj);

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

+41
Original file line numberDiff line numberDiff line change
@@ -2640,6 +2640,47 @@ TEST(SnapshotCreatorNoExternalReferencesDefault) {
26402640
delete[] blob.data;
26412641
}
26422642

2643+
v8::StartupData CreateCustomSnapshotArrayJoinWithKeep() {
2644+
v8::SnapshotCreator creator;
2645+
v8::Isolate* isolate = creator.GetIsolate();
2646+
{
2647+
v8::HandleScope handle_scope(isolate);
2648+
{
2649+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2650+
v8::Context::Scope context_scope(context);
2651+
CompileRun(
2652+
"[].join('');\n"
2653+
"function g() { return String([1,2,3]); }\n");
2654+
ExpectString("g()", "1,2,3");
2655+
creator.SetDefaultContext(context);
2656+
}
2657+
}
2658+
return creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep);
2659+
}
2660+
2661+
TEST(SnapshotCreatorArrayJoinWithKeep) {
2662+
DisableAlwaysOpt();
2663+
v8::StartupData blob = CreateCustomSnapshotArrayJoinWithKeep();
2664+
2665+
// Deserialize with an incomplete list of external references.
2666+
{
2667+
v8::Isolate::CreateParams params;
2668+
params.snapshot_blob = &blob;
2669+
params.array_buffer_allocator = CcTest::array_buffer_allocator();
2670+
// Test-appropriate equivalent of v8::Isolate::New.
2671+
v8::Isolate* isolate = TestIsolate::New(params);
2672+
{
2673+
v8::Isolate::Scope isolate_scope(isolate);
2674+
v8::HandleScope handle_scope(isolate);
2675+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2676+
v8::Context::Scope context_scope(context);
2677+
ExpectString("g()", "1,2,3");
2678+
}
2679+
isolate->Dispose();
2680+
}
2681+
delete[] blob.data;
2682+
}
2683+
26432684
TEST(SnapshotCreatorNoExternalReferencesCustomFail1) {
26442685
DisableAlwaysOpt();
26452686
v8::StartupData blob = CreateSnapshotWithDefaultAndCustom();

0 commit comments

Comments
 (0)