Skip to content

Commit

Permalink
[vm/concurrency] Reduce public API surface of ICData, remove unused m…
Browse files Browse the repository at this point in the history
…ethods, make methods private

This is a small refactoring for ICData to remove unused code,
make methods private (if they can be) and add assertions to
ICData-modifying methods that we are in reloading mode.

TEST=Refactoring of already tested code.

Issue dart-lang/sdk#36097

Change-Id: Ic543e0a87471f8ecd706c44c4014d347ac100ebd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173728
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
  • Loading branch information
mkustermann authored and commit-bot@chromium.org committed Nov 25, 2020
1 parent 94f6532 commit 72e8eab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 98 deletions.
10 changes: 8 additions & 2 deletions runtime/vm/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,16 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
}

void DeleteReloadContext();

bool IsReloading() const { return group_reload_context_ != nullptr; }
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)

bool IsReloading() const {
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
return group_reload_context_ != nullptr;
#else
return false;
#endif
}

uint64_t id() { return id_; }

static void Init();
Expand Down
82 changes: 22 additions & 60 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14962,27 +14962,27 @@ void ICData::SetNumArgsTested(intptr_t value) const {
NumArgsTestedBits::update(value, raw_ptr()->state_bits_));
}

intptr_t ICData::TypeArgsLen() const {
intptr_t CallSiteData::TypeArgsLen() const {
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
return args_desc.TypeArgsLen();
}

intptr_t ICData::CountWithTypeArgs() const {
intptr_t CallSiteData::CountWithTypeArgs() const {
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
return args_desc.CountWithTypeArgs();
}

intptr_t ICData::CountWithoutTypeArgs() const {
intptr_t CallSiteData::CountWithoutTypeArgs() const {
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
return args_desc.Count();
}

intptr_t ICData::SizeWithoutTypeArgs() const {
intptr_t CallSiteData::SizeWithoutTypeArgs() const {
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
return args_desc.Size();
}

intptr_t ICData::SizeWithTypeArgs() const {
intptr_t CallSiteData::SizeWithTypeArgs() const {
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
return args_desc.SizeWithTypeArgs();
}
Expand Down Expand Up @@ -15134,11 +15134,14 @@ intptr_t ICData::FindCheck(const GrowableArray<intptr_t>& cids) const {
return -1;
}

void ICData::WriteSentinelAt(intptr_t index) const {
void ICData::WriteSentinelAt(intptr_t index,
const CallSiteResetter& proof_of_reload) const {
USE(proof_of_reload); // This method can only be called during reload.

Thread* thread = Thread::Current();
const intptr_t len = Length();
ASSERT(index >= 0);
ASSERT(index < len);
Thread* thread = Thread::Current();
REUSABLE_ARRAY_HANDLESCOPE(thread);
Array& data = thread->ArrayHandle();
data = entries();
Expand All @@ -15149,26 +15152,34 @@ void ICData::WriteSentinelAt(intptr_t index) const {
}
}

void ICData::ClearCountAt(intptr_t index) const {
void ICData::ClearCountAt(intptr_t index,
const CallSiteResetter& proof_of_reload) const {
USE(proof_of_reload); // This method can only be called during reload.

ASSERT(index >= 0);
ASSERT(index < NumberOfChecks());
SetCountAt(index, 0);
}

void ICData::ClearAndSetStaticTarget(const Function& func) const {
void ICData::ClearAndSetStaticTarget(
const Function& func,
const CallSiteResetter& proof_of_reload) const {
USE(proof_of_reload); // This method can only be called during reload.

if (IsImmutable()) {
return;
}
const intptr_t len = Length();
if (len == 0) {
return;
}
Thread* thread = Thread::Current();

// The final entry is always the sentinel.
ASSERT(IsSentinelAt(len - 1));
const intptr_t num_args_tested = NumArgsTested();
if (num_args_tested == 0) {
// No type feedback is being collected.
Thread* thread = Thread::Current();
REUSABLE_ARRAY_HANDLESCOPE(thread);
Array& data = thread->ArrayHandle();
data = entries();
Expand All @@ -15186,9 +15197,8 @@ void ICData::ClearAndSetStaticTarget(const Function& func) const {
// Type feedback on arguments is being collected.
// Fill all but the first entry with the sentinel.
for (intptr_t i = len - 1; i > 0; i--) {
WriteSentinelAt(i);
WriteSentinelAt(i, proof_of_reload);
}
Thread* thread = Thread::Current();
REUSABLE_ARRAY_HANDLESCOPE(thread);
Array& data = thread->ArrayHandle();
data = entries();
Expand Down Expand Up @@ -15557,15 +15567,6 @@ FunctionPtr ICData::GetTargetAt(intptr_t index) const {
#endif
}

ObjectPtr ICData::GetTargetOrCodeAt(intptr_t index) const {
const intptr_t data_pos =
index * TestEntryLength() + TargetIndexFor(NumArgsTested());

NoSafepointScope no_safepoint;
ArrayPtr raw_data = entries();
return raw_data->ptr()->data()[data_pos];
}

void ICData::IncrementCountAt(intptr_t index, intptr_t value) const {
ASSERT(0 <= value);
ASSERT(value <= Smi::kMaxValue);
Expand Down Expand Up @@ -15616,46 +15617,7 @@ intptr_t ICData::AggregateCount() const {
return count;
}

void ICData::SetCodeAt(intptr_t index, const Code& value) const {
#if !defined(DART_PRECOMPILED_RUNTIME)
UNREACHABLE();
#else
Thread* thread = Thread::Current();
REUSABLE_ARRAY_HANDLESCOPE(thread);
Array& data = thread->ArrayHandle();
data = entries();
const intptr_t data_pos =
index * TestEntryLength() + CodeIndexFor(NumArgsTested());
data.SetAt(data_pos, value);
#endif
}

void ICData::SetEntryPointAt(intptr_t index, const Smi& value) const {
#if !defined(DART_PRECOMPILED_RUNTIME)
UNREACHABLE();
#else
Thread* thread = Thread::Current();
REUSABLE_ARRAY_HANDLESCOPE(thread);
Array& data = thread->ArrayHandle();
data = entries();
const intptr_t data_pos =
index * TestEntryLength() + EntryPointIndexFor(NumArgsTested());
data.SetAt(data_pos, value);
#endif
}

#if !defined(DART_PRECOMPILED_RUNTIME)
ICDataPtr ICData::AsUnaryClassChecksForCid(intptr_t cid,
const Function& target) const {
ASSERT(!IsNull());
const intptr_t kNumArgsTested = 1;
ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested));

// Copy count so that we copy the state "count == 0" vs "count > 0".
result.AddReceiverCheck(cid, target, GetCountAt(0));
return result.raw();
}

ICDataPtr ICData::AsUnaryClassChecksForArgNr(intptr_t arg_nr) const {
ASSERT(!IsNull());
ASSERT(NumArgsTested() > arg_nr);
Expand Down
65 changes: 32 additions & 33 deletions runtime/vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FinalizablePersistentHandle;
class FlowGraphCompiler;
class HierarchyInfo;
class LocalScope;
class CallSiteResetter;
class CodeStatistics;
class IsolateGroupReloadContext;

Expand Down Expand Up @@ -1862,6 +1863,16 @@ class CallSiteData : public Object {
StringPtr target_name() const { return raw_ptr()->target_name_; }
ArrayPtr arguments_descriptor() const { return raw_ptr()->args_descriptor_; }

intptr_t TypeArgsLen() const;

intptr_t CountWithTypeArgs() const;

intptr_t CountWithoutTypeArgs() const;

intptr_t SizeWithoutTypeArgs() const;

intptr_t SizeWithTypeArgs() const;

static intptr_t target_name_offset() {
return OFFSET_OF(CallSiteDataLayout, target_name_);
}
Expand Down Expand Up @@ -1921,16 +1932,6 @@ class ICData : public CallSiteData {

intptr_t NumArgsTested() const;

intptr_t TypeArgsLen() const;

intptr_t CountWithTypeArgs() const;

intptr_t CountWithoutTypeArgs() const;

intptr_t SizeWithoutTypeArgs() const;

intptr_t SizeWithTypeArgs() const;

intptr_t deopt_id() const {
#if defined(DART_PRECOMPILED_RUNTIME)
UNREACHABLE();
Expand All @@ -1946,21 +1947,13 @@ class ICData : public CallSiteData {
AbstractTypePtr receivers_static_type() const {
return raw_ptr()->receivers_static_type_;
}
void SetReceiversStaticType(const AbstractType& type) const;
bool is_tracking_exactness() const {
return TrackingExactnessBit::decode(raw_ptr()->state_bits_);
}
void set_tracking_exactness(bool value) const {
StoreNonPointer(
&raw_ptr()->state_bits_,
TrackingExactnessBit::update(value, raw_ptr()->state_bits_));
}
#else
bool is_tracking_exactness() const { return false; }
#endif

void Reset(Zone* zone) const;

// Note: only deopts with reasons before Unknown in this list are recorded in
// the ICData. All other reasons are used purely for informational messages
// printed during deoptimization itself.
Expand Down Expand Up @@ -2025,7 +2018,6 @@ class ICData : public CallSiteData {
static const char* RebindRuleToCString(RebindRule r);
static bool ParseRebindRule(const char* str, RebindRule* out);
RebindRule rebind_rule() const;
void set_rebind_rule(uint32_t rebind_rule) const;

void set_is_megamorphic(bool value) const {
// We don't have concurrent RW access to [state_bits_].
Expand Down Expand Up @@ -2077,14 +2069,20 @@ class ICData : public CallSiteData {
#endif

// Replaces entry |index| with the sentinel.
void WriteSentinelAt(intptr_t index) const;
// NOTE: Can only be called during reload.
void WriteSentinelAt(intptr_t index,
const CallSiteResetter& proof_of_reload) const;

// Clears the count for entry |index|.
void ClearCountAt(intptr_t index) const;
// NOTE: Can only be called during reload.
void ClearCountAt(intptr_t index,
const CallSiteResetter& proof_of_reload) const;

// Clear all entries with the sentinel value and reset the first entry
// with the dummy target entry.
void ClearAndSetStaticTarget(const Function& func) const;
// NOTE: Can only be called during reload.
void ClearAndSetStaticTarget(const Function& func,
const CallSiteResetter& proof_of_reload) const;

void DebugDump() const;

Expand Down Expand Up @@ -2112,9 +2110,6 @@ class ICData : public CallSiteData {
StaticTypeExactnessState exactness =
StaticTypeExactnessState::NotTracking()) const;

// Does entry |index| contain the sentinel value?
bool IsSentinelAt(intptr_t index) const;

// Retrieving checks.

void GetCheckAt(intptr_t index,
Expand All @@ -2134,10 +2129,6 @@ class ICData : public CallSiteData {

FunctionPtr GetTargetAt(intptr_t index) const;

ObjectPtr GetTargetOrCodeAt(intptr_t index) const;
void SetCodeAt(intptr_t index, const Code& value) const;
void SetEntryPointAt(intptr_t index, const Smi& value) const;

void IncrementCountAt(intptr_t index, intptr_t value) const;
void SetCountAt(intptr_t index, intptr_t value) const;
intptr_t GetCountAt(intptr_t index) const;
Expand All @@ -2148,8 +2139,6 @@ class ICData : public CallSiteData {
// Returns only used entries.
ICDataPtr AsUnaryClassChecksForArgNr(intptr_t arg_nr) const;
ICDataPtr AsUnaryClassChecks() const { return AsUnaryClassChecksForArgNr(0); }
ICDataPtr AsUnaryClassChecksForCid(intptr_t cid,
const Function& target) const;

// Returns ICData with aggregated receiver count, sorted by highest count.
// Smi not first!! (the convention for ICData used in code generation is that
Expand Down Expand Up @@ -2239,11 +2228,21 @@ class ICData : public CallSiteData {
// for the new entry.
ArrayPtr Grow(intptr_t* index) const;

void set_owner(const Function& value) const;
void set_deopt_id(intptr_t value) const;
void SetNumArgsTested(intptr_t value) const;
void set_entries(const Array& value) const;
void set_owner(const Function& value) const;
void set_rebind_rule(uint32_t rebind_rule) const;
void set_state_bits(uint32_t bits) const;
void set_tracking_exactness(bool value) const {
StoreNonPointer(
&raw_ptr()->state_bits_,
TrackingExactnessBit::update(value, raw_ptr()->state_bits_));
}

// Does entry |index| contain the sentinel value?
bool IsSentinelAt(intptr_t index) const;
void SetNumArgsTested(intptr_t value) const;
void SetReceiversStaticType(const AbstractType& type) const;

// This bit is set when a call site becomes megamorphic and starts using a
// MegamorphicCache instead of ICData. It means that the entries in the
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/object_reload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,8 @@ void CallSiteResetter::Reset(const ICData& ic) {
(class_ids[1] == kSmiCid)) {
// The smi fast path case, preserve the initial entry but reset the
// count.
ic.ClearCountAt(0);
ic.WriteSentinelAt(1);
ic.ClearCountAt(0, *this);
ic.WriteSentinelAt(1, *this);
entries_ = ic.entries();
entries_.Truncate(2 * ic.TestEntryLength());
return;
Expand Down Expand Up @@ -955,7 +955,7 @@ void CallSiteResetter::Reset(const ICData& ic) {
Object::Handle(zone_, ic.Owner()).ToCString());
return;
}
ic.ClearAndSetStaticTarget(new_target_);
ic.ClearAndSetStaticTarget(new_target_, *this);
} else {
FATAL("Unexpected rebind rule.");
}
Expand Down

0 comments on commit 72e8eab

Please sign in to comment.