Skip to content

Commit 165dd87

Browse files
victorgomesV8 LUCI CQ
authored andcommitted
[maglev] Record phi use as smi when eliding a write barrier
We can only elide the write barrier under the assumption that the phi's type will remain a Smi. If we don't record its tagged usage at this bytecode offset, the phi representation selector might later change its representation to int32. It will then emit a `Int32ToNumber` before `StoreTaggedFieldNoWriteBarrier`. This is incorrect because it could allocate a heap number, potentially promoting it to old space during a GC and requiring a write barrier. Fixed: 362784006 Change-Id: I775d7cc151189c12f59fc5ff0edccada1665f230 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5830348 Auto-Submit: Victor Gomes <[email protected]> Reviewed-by: Patrick Thier <[email protected]> Commit-Queue: Victor Gomes <[email protected]> Commit-Queue: Patrick Thier <[email protected]> Cr-Commit-Position: refs/heads/main@{#95916}
1 parent 6210313 commit 165dd87

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/maglev/maglev-graph-builder.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4307,7 +4307,10 @@ AllocationBlock* GetAllocation(ValueNode* object) {
43074307
bool MaglevGraphBuilder::CanElideWriteBarrier(ValueNode* object,
43084308
ValueNode* value) {
43094309
if (value->Is<RootConstant>()) return true;
4310-
if (CheckType(value, NodeType::kSmi)) return true;
4310+
if (CheckType(value, NodeType::kSmi)) {
4311+
RecordUseReprHintIfPhi(value, UseRepresentation::kTagged);
4312+
return true;
4313+
}
43114314

43124315
// No need for a write barrier if both object and value are part of the same
43134316
// folded young allocation.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2024 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
// Flags: --invocation-count-for-maglev-osr=1 --invocation-count-for-maglev=1
6+
// Flags: --minimum-invocations-after-ic-update=1 --deopt-every-n-times=250
7+
// Flags: --single-threaded --verify-heap
8+
9+
// The flags ensure that we verify the heap just before we deopt the first
10+
// Maglev OSR synchronously.
11+
// --deopt-every-n-times > 0 forces MaterializeHeapObjects to call GC.
12+
13+
let v0 = 1;
14+
let vn = 1000;
15+
for (let i1 = v0; i1 <= vn; i1 += v0) {
16+
v0 = v0 && i1;
17+
let v8 = "";
18+
[v8,] = v8;
19+
}

0 commit comments

Comments
 (0)