Skip to content

Commit 22116dd

Browse files
hashseedCommit Bot
authored andcommitted
[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}
1 parent a890034 commit 22116dd

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/api.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,11 @@ StartupData SnapshotCreator::CreateBlob(
770770
// Complete in-object slack tracking for all functions.
771771
fun->CompleteInobjectSlackTrackingIfActive();
772772

773-
// Also, clear out feedback vectors.
774-
fun->feedback_cell()->set_value(isolate->heap()->undefined_value());
773+
// Also, clear out feedback vectors, or any optimized code.
774+
if (fun->has_feedback_vector()) {
775+
fun->feedback_cell()->set_value(isolate->heap()->undefined_value());
776+
fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
777+
}
775778
}
776779

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

src/snapshot/partial-serializer.cc

Lines changed: 1 addition & 1 deletion
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);

test/cctest/test-serialize.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,47 @@ TEST(SnapshotCreatorPreparseDataAndNoOuterScope) {
26632663
delete[] blob.data;
26642664
}
26652665

2666+
v8::StartupData CreateCustomSnapshotArrayJoinWithKeep() {
2667+
v8::SnapshotCreator creator;
2668+
v8::Isolate* isolate = creator.GetIsolate();
2669+
{
2670+
v8::HandleScope handle_scope(isolate);
2671+
{
2672+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2673+
v8::Context::Scope context_scope(context);
2674+
CompileRun(
2675+
"[].join('');\n"
2676+
"function g() { return String([1,2,3]); }\n");
2677+
ExpectString("g()", "1,2,3");
2678+
creator.SetDefaultContext(context);
2679+
}
2680+
}
2681+
return creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep);
2682+
}
2683+
2684+
TEST(SnapshotCreatorArrayJoinWithKeep) {
2685+
DisableAlwaysOpt();
2686+
v8::StartupData blob = CreateCustomSnapshotArrayJoinWithKeep();
2687+
2688+
// Deserialize with an incomplete list of external references.
2689+
{
2690+
v8::Isolate::CreateParams params;
2691+
params.snapshot_blob = &blob;
2692+
params.array_buffer_allocator = CcTest::array_buffer_allocator();
2693+
// Test-appropriate equivalent of v8::Isolate::New.
2694+
v8::Isolate* isolate = TestIsolate::New(params);
2695+
{
2696+
v8::Isolate::Scope isolate_scope(isolate);
2697+
v8::HandleScope handle_scope(isolate);
2698+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2699+
v8::Context::Scope context_scope(context);
2700+
ExpectString("g()", "1,2,3");
2701+
}
2702+
isolate->Dispose();
2703+
}
2704+
delete[] blob.data;
2705+
}
2706+
26662707
TEST(SnapshotCreatorNoExternalReferencesCustomFail1) {
26672708
DisableAlwaysOpt();
26682709
v8::StartupData blob = CreateSnapshotWithDefaultAndCustom();

0 commit comments

Comments
 (0)