Skip to content

Commit ebe5675

Browse files
tebbiV8 LUCI CQ
authored andcommitted
[turbofan] validate more concurrent reads
Bug: chromium:1369871 Change-Id: Ib8786b97b2f9555cfcb84a197182c4f2ab5c30e8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3936273 Reviewed-by: Jakob Linke <[email protected]> Auto-Submit: Tobias Tebbi <[email protected]> Commit-Queue: Tobias Tebbi <[email protected]> Cr-Commit-Position: refs/heads/main@{#83555}
1 parent b050bfd commit ebe5675

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/compiler/compilation-dependencies.cc

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace compiler {
3434
V(Protector) \
3535
V(PrototypeProperty) \
3636
V(StableMap) \
37-
V(Transition)
37+
V(Transition) \
38+
V(ObjectSlotValue)
3839

3940
CompilationDependencies::CompilationDependencies(JSHeapBroker* broker,
4041
Zone* zone)
@@ -868,6 +869,42 @@ class ProtectorDependency final : public CompilationDependency {
868869
const PropertyCellRef cell_;
869870
};
870871

872+
// Check that an object slot will not change during compilation.
873+
class ObjectSlotValueDependency final : public CompilationDependency {
874+
public:
875+
explicit ObjectSlotValueDependency(const HeapObjectRef& object, int offset,
876+
const ObjectRef& value)
877+
: CompilationDependency(kObjectSlotValue),
878+
object_(object.object()),
879+
offset_(offset),
880+
value_(value.object()) {}
881+
882+
bool IsValid() const override {
883+
PtrComprCageBase cage_base = GetPtrComprCageBase(*object_);
884+
Object current_value =
885+
offset_ == HeapObject::kMapOffset
886+
? object_->map()
887+
: TaggedField<Object>::Relaxed_Load(cage_base, *object_, offset_);
888+
return *value_ == current_value;
889+
}
890+
void Install(PendingDependencies* deps) const override {}
891+
892+
private:
893+
size_t Hash() const override {
894+
return base::hash_combine(object_.address(), offset_, value_.address());
895+
}
896+
897+
bool Equals(const CompilationDependency* that) const override {
898+
const ObjectSlotValueDependency* const zat = that->AsObjectSlotValue();
899+
return object_->address() == zat->object_->address() &&
900+
offset_ == zat->offset_ && value_.address() == zat->value_.address();
901+
}
902+
903+
Handle<HeapObject> object_;
904+
int offset_;
905+
Handle<Object> value_;
906+
};
907+
871908
class ElementsKindDependency final : public CompilationDependency {
872909
public:
873910
ElementsKindDependency(const AllocationSiteRef& site, ElementsKind kind)
@@ -1120,6 +1157,12 @@ void CompilationDependencies::DependOnElementsKind(
11201157
}
11211158
}
11221159

1160+
void CompilationDependencies::DependOnObjectSlotValue(
1161+
const HeapObjectRef& object, int offset, const ObjectRef& value) {
1162+
RecordDependency(
1163+
zone_->New<ObjectSlotValueDependency>(object, offset, value));
1164+
}
1165+
11231166
void CompilationDependencies::DependOnOwnConstantElement(
11241167
const JSObjectRef& holder, uint32_t index, const ObjectRef& element) {
11251168
RecordDependency(

src/compiler/compilation-dependencies.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class V8_EXPORT_PRIVATE CompilationDependencies : public ZoneObject {
9393
// Record the assumption that {site}'s {ElementsKind} doesn't change.
9494
void DependOnElementsKind(const AllocationSiteRef& site);
9595

96+
// Check that an object slot will not change during compilation.
97+
void DependOnObjectSlotValue(const HeapObjectRef& object, int offset,
98+
const ObjectRef& value);
99+
96100
void DependOnOwnConstantElement(const JSObjectRef& holder, uint32_t index,
97101
const ObjectRef& element);
98102

src/compiler/js-create-lowering.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,10 @@ base::Optional<Node*> JSCreateLowering::TryAllocateFastLiteral(
16731673

16741674
// Now that we hold the migration lock, get the current map.
16751675
MapRef boilerplate_map = boilerplate.map();
1676+
// Protect against concurrent changes to the boilerplate object by checking
1677+
// for an identical value at the end of the compilation.
1678+
dependencies()->DependOnObjectSlotValue(boilerplate, HeapObject::kMapOffset,
1679+
boilerplate_map);
16761680
{
16771681
base::Optional<MapRef> current_boilerplate_map =
16781682
boilerplate.map_direct_read();
@@ -1838,10 +1842,18 @@ base::Optional<Node*> JSCreateLowering::TryAllocateFastLiteralElements(
18381842
boilerplate.elements(kRelaxedLoad);
18391843
if (!maybe_boilerplate_elements.has_value()) return {};
18401844
FixedArrayBaseRef boilerplate_elements = maybe_boilerplate_elements.value();
1845+
// Protect against concurrent changes to the boilerplate object by checking
1846+
// for an identical value at the end of the compilation.
1847+
dependencies()->DependOnObjectSlotValue(
1848+
boilerplate, JSObject::kElementsOffset, boilerplate_elements);
18411849

18421850
// Empty or copy-on-write elements just store a constant.
18431851
int const elements_length = boilerplate_elements.length();
18441852
MapRef elements_map = boilerplate_elements.map();
1853+
// Protect against concurrent changes to the boilerplate object by checking
1854+
// for an identical value at the end of the compilation.
1855+
dependencies()->DependOnObjectSlotValue(boilerplate_elements,
1856+
HeapObject::kMapOffset, elements_map);
18451857
if (boilerplate_elements.length() == 0 || elements_map.IsFixedCowArrayMap()) {
18461858
if (allocation == AllocationType::kOld &&
18471859
!boilerplate.IsElementsTenured(boilerplate_elements)) {

0 commit comments

Comments
 (0)