[compiler] Simplify DependentCode API and make it type-safe

Bug: v8:11879, v8:11880
Change-Id: I6b37148ae2a971bda0cbb6636f64561ab0a02ba5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2960215
Auto-Submit: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75142}
This commit is contained in:
Igor Sheludko 2021-06-14 14:58:13 +02:00 committed by V8 LUCI CQ
parent 76a42474d2
commit 4b4037308b
5 changed files with 55 additions and 57 deletions

View File

@ -37,7 +37,7 @@ class InitialMapDependency final : public CompilationDependency {
function->initial_map() == *initial_map_.object();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(function_.isolate(), code,
initial_map_.object(),
@ -74,7 +74,7 @@ class PrototypePropertyDependency final : public CompilationDependency {
if (!function->has_initial_map()) JSFunction::EnsureHasInitialMap(function);
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
Handle<JSFunction> function = function_.object();
DCHECK(function->has_initial_map());
@ -96,7 +96,7 @@ class StableMapDependency final : public CompilationDependency {
bool IsValid() const override { return map_.object()->is_stable(); }
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(map_.isolate(), code, map_.object(),
DependentCode::kPrototypeCheckGroup);
@ -123,7 +123,7 @@ class ConstantInDictionaryPrototypeChainDependency final
// starting at |receiver_map_|.
bool IsValid() const override { return !GetHolderIfValid().is_null(); }
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
Isolate* isolate = receiver_map_.isolate();
Handle<JSObject> holder = GetHolderIfValid().ToHandleChecked();
@ -236,7 +236,7 @@ class TransitionDependency final : public CompilationDependency {
bool IsValid() const override { return !map_.object()->is_deprecated(); }
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(map_.isolate(), code, map_.object(),
DependentCode::kTransitionGroup);
@ -260,7 +260,7 @@ class PretenureModeDependency final : public CompilationDependency {
return allocation_ == site_.object()->GetAllocationType();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(
site_.isolate(), code, site_.object(),
@ -298,7 +298,7 @@ class FieldRepresentationDependency final : public CompilationDependency {
.representation());
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(owner_.isolate(), code, owner_.object(),
DependentCode::kFieldRepresentationGroup);
@ -336,7 +336,7 @@ class FieldTypeDependency final : public CompilationDependency {
.GetFieldType(descriptor_);
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(owner_.isolate(), code, owner_.object(),
DependentCode::kFieldTypeGroup);
@ -366,7 +366,7 @@ class FieldConstnessDependency final : public CompilationDependency {
.constness();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(owner_.isolate(), code, owner_.object(),
DependentCode::kFieldConstGroup);
@ -397,7 +397,7 @@ class GlobalPropertyDependency final : public CompilationDependency {
read_only_ == cell->property_details().IsReadOnly();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(cell_.isolate(), code, cell_.object(),
DependentCode::kPropertyCellChangedGroup);
@ -420,7 +420,7 @@ class ProtectorDependency final : public CompilationDependency {
return cell->value() == Smi::FromInt(Protectors::kProtectorValid);
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(cell_.isolate(), code, cell_.object(),
DependentCode::kPropertyCellChangedGroup);
@ -451,7 +451,7 @@ class ElementsKindDependency final : public CompilationDependency {
return kind_ == kind;
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DependentCode::InstallDependency(
site_.isolate(), code, site_.object(),
@ -482,7 +482,7 @@ class OwnConstantElementDependency final : public CompilationDependency {
return maybe_element.value() == *element_.object();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
// This dependency has no effect after code finalization.
}
@ -513,7 +513,7 @@ class InitialMapInstanceSizePredictionDependency final
function_.object()->CompleteInobjectSlackTrackingIfActive();
}
void Install(const MaybeObjectHandle& code) const override {
void Install(Handle<Code> code) const override {
SLOW_DCHECK(IsValid());
DCHECK(
!function_.object()->initial_map().IsInobjectSlackTrackingInProgress());
@ -693,7 +693,7 @@ bool CompilationDependencies::Commit(Handle<Code> code) {
dependencies_.clear();
return false;
}
dep->Install(MaybeObjectHandle::Weak(code));
dep->Install(code);
}
// It is even possible that a GC during the above installations invalidated

View File

@ -18,7 +18,7 @@ class CompilationDependency : public ZoneObject {
public:
virtual bool IsValid() const = 0;
virtual void PrepareInstall() const {}
virtual void Install(const MaybeObjectHandle& code) const = 0;
virtual void Install(Handle<Code> code) const = 0;
#ifdef DEBUG
virtual bool IsPretenureModeDependency() const { return false; }

View File

@ -745,8 +745,7 @@ void DependentCode::SetDependentCode(Handle<HeapObject> object,
}
}
void DependentCode::InstallDependency(Isolate* isolate,
const MaybeObjectHandle& code,
void DependentCode::InstallDependency(Isolate* isolate, Handle<Code> code,
Handle<HeapObject> object,
DependencyGroup group) {
if (V8_UNLIKELY(FLAG_trace_code_dependencies)) {
@ -765,7 +764,7 @@ void DependentCode::InstallDependency(Isolate* isolate,
Handle<DependentCode> DependentCode::InsertWeakCode(
Isolate* isolate, Handle<DependentCode> entries, DependencyGroup group,
const MaybeObjectHandle& code) {
Handle<Code> code) {
if (entries->length() == 0 || entries->group() > group) {
// There is no such group.
return DependentCode::New(isolate, group, code, entries);
@ -780,32 +779,41 @@ Handle<DependentCode> DependentCode::InsertWeakCode(
}
return entries;
}
DCHECK_EQ(group, entries->group());
int count = entries->count();
// Check for existing entry to avoid duplicates.
for (int i = 0; i < count; i++) {
if (entries->object_at(i) == *code) return entries;
{
DisallowHeapAllocation no_gc;
HeapObjectReference weak_code_entry = HeapObjectReference::Weak(*code);
for (int i = 0; i < count; i++) {
if (entries->object_at(i) == weak_code_entry) return entries;
}
}
if (entries->length() < kCodesStartIndex + count + 1) {
entries = EnsureSpace(isolate, entries);
// Count could have changed, reload it.
count = entries->count();
}
entries->set_object_at(count, *code);
DisallowHeapAllocation no_gc;
HeapObjectReference weak_code_entry = HeapObjectReference::Weak(*code);
entries->set_object_at(count, weak_code_entry);
entries->set_count(count + 1);
return entries;
}
Handle<DependentCode> DependentCode::New(Isolate* isolate,
DependencyGroup group,
const MaybeObjectHandle& object,
Handle<Code> code,
Handle<DependentCode> next) {
Handle<DependentCode> result =
Handle<DependentCode>::cast(isolate->factory()->NewWeakFixedArray(
kCodesStartIndex + 1, AllocationType::kOld));
result->set_next_link(*next);
result->set_flags(GroupField::encode(group) | CountField::encode(1));
result->set_object_at(0, *object);
HeapObjectReference weak_code_entry = HeapObjectReference::Weak(*code);
result->set_object_at(0, weak_code_entry);
return result;
}

View File

@ -714,7 +714,7 @@ class DependentCode : public WeakFixedArray {
// Register a dependency of {code} on {object}, of the kind given by {group}.
V8_EXPORT_PRIVATE static void InstallDependency(Isolate* isolate,
const MaybeObjectHandle& code,
Handle<Code> code,
Handle<HeapObject> object,
DependencyGroup group);
@ -737,14 +737,14 @@ class DependentCode : public WeakFixedArray {
Handle<DependentCode> dep);
static Handle<DependentCode> New(Isolate* isolate, DependencyGroup group,
const MaybeObjectHandle& object,
Handle<Code> code,
Handle<DependentCode> next);
static Handle<DependentCode> EnsureSpace(Isolate* isolate,
Handle<DependentCode> entries);
static Handle<DependentCode> InsertWeakCode(Isolate* isolate,
Handle<DependentCode> entries,
DependencyGroup group,
const MaybeObjectHandle& code);
Handle<Code> code);
// Compact by removing cleared weak cells and return true if there was
// any cleared weak cell.

View File

@ -708,15 +708,12 @@ void TestGeneralizeField(int detach_property_at_index, int property_index,
Handle<Code> code_field_const = CreateDummyOptimizedCode(isolate);
Handle<Map> field_owner(
map->FindFieldOwner(isolate, InternalIndex(property_index)), isolate);
DependentCode::InstallDependency(isolate,
MaybeObjectHandle::Weak(code_field_type),
field_owner, DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_repr), field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_const), field_owner,
DependentCode::kFieldConstGroup);
DependentCode::InstallDependency(isolate, code_field_type, field_owner,
DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(isolate, code_field_repr, field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(isolate, code_field_const, field_owner,
DependentCode::kFieldConstGroup);
CHECK(!code_field_type->marked_for_deoptimization());
CHECK(!code_field_repr->marked_for_deoptimization());
CHECK(!code_field_const->marked_for_deoptimization());
@ -1091,22 +1088,18 @@ void TestReconfigureDataFieldAttribute_GeneralizeField(
{
Handle<Map> field_owner(
map->FindFieldOwner(isolate, InternalIndex(kSplitProp)), isolate);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_type), field_owner,
DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_repr), field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_const), field_owner,
DependentCode::kFieldConstGroup);
DependentCode::InstallDependency(isolate, code_field_type, field_owner,
DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(isolate, code_field_repr, field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(isolate, code_field_const, field_owner,
DependentCode::kFieldConstGroup);
}
{
Handle<Map> field_owner(
map2->FindFieldOwner(isolate, InternalIndex(kSplitProp)), isolate);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_src_field_const), field_owner,
DependentCode::kFieldConstGroup);
DependentCode::InstallDependency(isolate, code_src_field_const, field_owner,
DependentCode::kFieldConstGroup);
}
CHECK(!code_field_type->marked_for_deoptimization());
CHECK(!code_field_repr->marked_for_deoptimization());
@ -1793,15 +1786,12 @@ static void TestReconfigureElementsKind_GeneralizeFieldInPlace(
Handle<Code> code_field_const = CreateDummyOptimizedCode(isolate);
Handle<Map> field_owner(
map->FindFieldOwner(isolate, InternalIndex(kDiffProp)), isolate);
DependentCode::InstallDependency(isolate,
MaybeObjectHandle::Weak(code_field_type),
field_owner, DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_repr), field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(
isolate, MaybeObjectHandle::Weak(code_field_const), field_owner,
DependentCode::kFieldConstGroup);
DependentCode::InstallDependency(isolate, code_field_type, field_owner,
DependentCode::kFieldTypeGroup);
DependentCode::InstallDependency(isolate, code_field_repr, field_owner,
DependentCode::kFieldRepresentationGroup);
DependentCode::InstallDependency(isolate, code_field_const, field_owner,
DependentCode::kFieldConstGroup);
CHECK(!code_field_type->marked_for_deoptimization());
CHECK(!code_field_repr->marked_for_deoptimization());
CHECK(!code_field_const->marked_for_deoptimization());