Skip to content

Commit 72e8eab

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Reduce public API surface of ICData, remove unused methods, 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 #36097 Change-Id: Ic543e0a87471f8ecd706c44c4014d347ac100ebd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173728 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent 94f6532 commit 72e8eab

File tree

4 files changed

+65
-98
lines changed

4 files changed

+65
-98
lines changed

runtime/vm/isolate.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,16 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
563563
}
564564

565565
void DeleteReloadContext();
566-
567-
bool IsReloading() const { return group_reload_context_ != nullptr; }
568566
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
569567

568+
bool IsReloading() const {
569+
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
570+
return group_reload_context_ != nullptr;
571+
#else
572+
return false;
573+
#endif
574+
}
575+
570576
uint64_t id() { return id_; }
571577

572578
static void Init();

runtime/vm/object.cc

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14962,27 +14962,27 @@ void ICData::SetNumArgsTested(intptr_t value) const {
1496214962
NumArgsTestedBits::update(value, raw_ptr()->state_bits_));
1496314963
}
1496414964

14965-
intptr_t ICData::TypeArgsLen() const {
14965+
intptr_t CallSiteData::TypeArgsLen() const {
1496614966
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
1496714967
return args_desc.TypeArgsLen();
1496814968
}
1496914969

14970-
intptr_t ICData::CountWithTypeArgs() const {
14970+
intptr_t CallSiteData::CountWithTypeArgs() const {
1497114971
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
1497214972
return args_desc.CountWithTypeArgs();
1497314973
}
1497414974

14975-
intptr_t ICData::CountWithoutTypeArgs() const {
14975+
intptr_t CallSiteData::CountWithoutTypeArgs() const {
1497614976
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
1497714977
return args_desc.Count();
1497814978
}
1497914979

14980-
intptr_t ICData::SizeWithoutTypeArgs() const {
14980+
intptr_t CallSiteData::SizeWithoutTypeArgs() const {
1498114981
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
1498214982
return args_desc.Size();
1498314983
}
1498414984

14985-
intptr_t ICData::SizeWithTypeArgs() const {
14985+
intptr_t CallSiteData::SizeWithTypeArgs() const {
1498614986
ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
1498714987
return args_desc.SizeWithTypeArgs();
1498814988
}
@@ -15134,11 +15134,14 @@ intptr_t ICData::FindCheck(const GrowableArray<intptr_t>& cids) const {
1513415134
return -1;
1513515135
}
1513615136

15137-
void ICData::WriteSentinelAt(intptr_t index) const {
15137+
void ICData::WriteSentinelAt(intptr_t index,
15138+
const CallSiteResetter& proof_of_reload) const {
15139+
USE(proof_of_reload); // This method can only be called during reload.
15140+
15141+
Thread* thread = Thread::Current();
1513815142
const intptr_t len = Length();
1513915143
ASSERT(index >= 0);
1514015144
ASSERT(index < len);
15141-
Thread* thread = Thread::Current();
1514215145
REUSABLE_ARRAY_HANDLESCOPE(thread);
1514315146
Array& data = thread->ArrayHandle();
1514415147
data = entries();
@@ -15149,26 +15152,34 @@ void ICData::WriteSentinelAt(intptr_t index) const {
1514915152
}
1515015153
}
1515115154

15152-
void ICData::ClearCountAt(intptr_t index) const {
15155+
void ICData::ClearCountAt(intptr_t index,
15156+
const CallSiteResetter& proof_of_reload) const {
15157+
USE(proof_of_reload); // This method can only be called during reload.
15158+
1515315159
ASSERT(index >= 0);
1515415160
ASSERT(index < NumberOfChecks());
1515515161
SetCountAt(index, 0);
1515615162
}
1515715163

15158-
void ICData::ClearAndSetStaticTarget(const Function& func) const {
15164+
void ICData::ClearAndSetStaticTarget(
15165+
const Function& func,
15166+
const CallSiteResetter& proof_of_reload) const {
15167+
USE(proof_of_reload); // This method can only be called during reload.
15168+
1515915169
if (IsImmutable()) {
1516015170
return;
1516115171
}
1516215172
const intptr_t len = Length();
1516315173
if (len == 0) {
1516415174
return;
1516515175
}
15176+
Thread* thread = Thread::Current();
15177+
1516615178
// The final entry is always the sentinel.
1516715179
ASSERT(IsSentinelAt(len - 1));
1516815180
const intptr_t num_args_tested = NumArgsTested();
1516915181
if (num_args_tested == 0) {
1517015182
// No type feedback is being collected.
15171-
Thread* thread = Thread::Current();
1517215183
REUSABLE_ARRAY_HANDLESCOPE(thread);
1517315184
Array& data = thread->ArrayHandle();
1517415185
data = entries();
@@ -15186,9 +15197,8 @@ void ICData::ClearAndSetStaticTarget(const Function& func) const {
1518615197
// Type feedback on arguments is being collected.
1518715198
// Fill all but the first entry with the sentinel.
1518815199
for (intptr_t i = len - 1; i > 0; i--) {
15189-
WriteSentinelAt(i);
15200+
WriteSentinelAt(i, proof_of_reload);
1519015201
}
15191-
Thread* thread = Thread::Current();
1519215202
REUSABLE_ARRAY_HANDLESCOPE(thread);
1519315203
Array& data = thread->ArrayHandle();
1519415204
data = entries();
@@ -15557,15 +15567,6 @@ FunctionPtr ICData::GetTargetAt(intptr_t index) const {
1555715567
#endif
1555815568
}
1555915569

15560-
ObjectPtr ICData::GetTargetOrCodeAt(intptr_t index) const {
15561-
const intptr_t data_pos =
15562-
index * TestEntryLength() + TargetIndexFor(NumArgsTested());
15563-
15564-
NoSafepointScope no_safepoint;
15565-
ArrayPtr raw_data = entries();
15566-
return raw_data->ptr()->data()[data_pos];
15567-
}
15568-
1556915570
void ICData::IncrementCountAt(intptr_t index, intptr_t value) const {
1557015571
ASSERT(0 <= value);
1557115572
ASSERT(value <= Smi::kMaxValue);
@@ -15616,46 +15617,7 @@ intptr_t ICData::AggregateCount() const {
1561615617
return count;
1561715618
}
1561815619

15619-
void ICData::SetCodeAt(intptr_t index, const Code& value) const {
1562015620
#if !defined(DART_PRECOMPILED_RUNTIME)
15621-
UNREACHABLE();
15622-
#else
15623-
Thread* thread = Thread::Current();
15624-
REUSABLE_ARRAY_HANDLESCOPE(thread);
15625-
Array& data = thread->ArrayHandle();
15626-
data = entries();
15627-
const intptr_t data_pos =
15628-
index * TestEntryLength() + CodeIndexFor(NumArgsTested());
15629-
data.SetAt(data_pos, value);
15630-
#endif
15631-
}
15632-
15633-
void ICData::SetEntryPointAt(intptr_t index, const Smi& value) const {
15634-
#if !defined(DART_PRECOMPILED_RUNTIME)
15635-
UNREACHABLE();
15636-
#else
15637-
Thread* thread = Thread::Current();
15638-
REUSABLE_ARRAY_HANDLESCOPE(thread);
15639-
Array& data = thread->ArrayHandle();
15640-
data = entries();
15641-
const intptr_t data_pos =
15642-
index * TestEntryLength() + EntryPointIndexFor(NumArgsTested());
15643-
data.SetAt(data_pos, value);
15644-
#endif
15645-
}
15646-
15647-
#if !defined(DART_PRECOMPILED_RUNTIME)
15648-
ICDataPtr ICData::AsUnaryClassChecksForCid(intptr_t cid,
15649-
const Function& target) const {
15650-
ASSERT(!IsNull());
15651-
const intptr_t kNumArgsTested = 1;
15652-
ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested));
15653-
15654-
// Copy count so that we copy the state "count == 0" vs "count > 0".
15655-
result.AddReceiverCheck(cid, target, GetCountAt(0));
15656-
return result.raw();
15657-
}
15658-
1565915621
ICDataPtr ICData::AsUnaryClassChecksForArgNr(intptr_t arg_nr) const {
1566015622
ASSERT(!IsNull());
1566115623
ASSERT(NumArgsTested() > arg_nr);

runtime/vm/object.h

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class FinalizablePersistentHandle;
6363
class FlowGraphCompiler;
6464
class HierarchyInfo;
6565
class LocalScope;
66+
class CallSiteResetter;
6667
class CodeStatistics;
6768
class IsolateGroupReloadContext;
6869

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

1866+
intptr_t TypeArgsLen() const;
1867+
1868+
intptr_t CountWithTypeArgs() const;
1869+
1870+
intptr_t CountWithoutTypeArgs() const;
1871+
1872+
intptr_t SizeWithoutTypeArgs() const;
1873+
1874+
intptr_t SizeWithTypeArgs() const;
1875+
18651876
static intptr_t target_name_offset() {
18661877
return OFFSET_OF(CallSiteDataLayout, target_name_);
18671878
}
@@ -1921,16 +1932,6 @@ class ICData : public CallSiteData {
19211932

19221933
intptr_t NumArgsTested() const;
19231934

1924-
intptr_t TypeArgsLen() const;
1925-
1926-
intptr_t CountWithTypeArgs() const;
1927-
1928-
intptr_t CountWithoutTypeArgs() const;
1929-
1930-
intptr_t SizeWithoutTypeArgs() const;
1931-
1932-
intptr_t SizeWithTypeArgs() const;
1933-
19341935
intptr_t deopt_id() const {
19351936
#if defined(DART_PRECOMPILED_RUNTIME)
19361937
UNREACHABLE();
@@ -1946,21 +1947,13 @@ class ICData : public CallSiteData {
19461947
AbstractTypePtr receivers_static_type() const {
19471948
return raw_ptr()->receivers_static_type_;
19481949
}
1949-
void SetReceiversStaticType(const AbstractType& type) const;
19501950
bool is_tracking_exactness() const {
19511951
return TrackingExactnessBit::decode(raw_ptr()->state_bits_);
19521952
}
1953-
void set_tracking_exactness(bool value) const {
1954-
StoreNonPointer(
1955-
&raw_ptr()->state_bits_,
1956-
TrackingExactnessBit::update(value, raw_ptr()->state_bits_));
1957-
}
19581953
#else
19591954
bool is_tracking_exactness() const { return false; }
19601955
#endif
19611956

1962-
void Reset(Zone* zone) const;
1963-
19641957
// Note: only deopts with reasons before Unknown in this list are recorded in
19651958
// the ICData. All other reasons are used purely for informational messages
19661959
// printed during deoptimization itself.
@@ -2025,7 +2018,6 @@ class ICData : public CallSiteData {
20252018
static const char* RebindRuleToCString(RebindRule r);
20262019
static bool ParseRebindRule(const char* str, RebindRule* out);
20272020
RebindRule rebind_rule() const;
2028-
void set_rebind_rule(uint32_t rebind_rule) const;
20292021

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

20792071
// Replaces entry |index| with the sentinel.
2080-
void WriteSentinelAt(intptr_t index) const;
2072+
// NOTE: Can only be called during reload.
2073+
void WriteSentinelAt(intptr_t index,
2074+
const CallSiteResetter& proof_of_reload) const;
20812075

20822076
// Clears the count for entry |index|.
2083-
void ClearCountAt(intptr_t index) const;
2077+
// NOTE: Can only be called during reload.
2078+
void ClearCountAt(intptr_t index,
2079+
const CallSiteResetter& proof_of_reload) const;
20842080

20852081
// Clear all entries with the sentinel value and reset the first entry
20862082
// with the dummy target entry.
2087-
void ClearAndSetStaticTarget(const Function& func) const;
2083+
// NOTE: Can only be called during reload.
2084+
void ClearAndSetStaticTarget(const Function& func,
2085+
const CallSiteResetter& proof_of_reload) const;
20882086

20892087
void DebugDump() const;
20902088

@@ -2112,9 +2110,6 @@ class ICData : public CallSiteData {
21122110
StaticTypeExactnessState exactness =
21132111
StaticTypeExactnessState::NotTracking()) const;
21142112

2115-
// Does entry |index| contain the sentinel value?
2116-
bool IsSentinelAt(intptr_t index) const;
2117-
21182113
// Retrieving checks.
21192114

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

21352130
FunctionPtr GetTargetAt(intptr_t index) const;
21362131

2137-
ObjectPtr GetTargetOrCodeAt(intptr_t index) const;
2138-
void SetCodeAt(intptr_t index, const Code& value) const;
2139-
void SetEntryPointAt(intptr_t index, const Smi& value) const;
2140-
21412132
void IncrementCountAt(intptr_t index, intptr_t value) const;
21422133
void SetCountAt(intptr_t index, intptr_t value) const;
21432134
intptr_t GetCountAt(intptr_t index) const;
@@ -2148,8 +2139,6 @@ class ICData : public CallSiteData {
21482139
// Returns only used entries.
21492140
ICDataPtr AsUnaryClassChecksForArgNr(intptr_t arg_nr) const;
21502141
ICDataPtr AsUnaryClassChecks() const { return AsUnaryClassChecksForArgNr(0); }
2151-
ICDataPtr AsUnaryClassChecksForCid(intptr_t cid,
2152-
const Function& target) const;
21532142

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

2242-
void set_owner(const Function& value) const;
22432231
void set_deopt_id(intptr_t value) const;
2244-
void SetNumArgsTested(intptr_t value) const;
22452232
void set_entries(const Array& value) const;
2233+
void set_owner(const Function& value) const;
2234+
void set_rebind_rule(uint32_t rebind_rule) const;
22462235
void set_state_bits(uint32_t bits) const;
2236+
void set_tracking_exactness(bool value) const {
2237+
StoreNonPointer(
2238+
&raw_ptr()->state_bits_,
2239+
TrackingExactnessBit::update(value, raw_ptr()->state_bits_));
2240+
}
2241+
2242+
// Does entry |index| contain the sentinel value?
2243+
bool IsSentinelAt(intptr_t index) const;
2244+
void SetNumArgsTested(intptr_t value) const;
2245+
void SetReceiversStaticType(const AbstractType& type) const;
22472246

22482247
// This bit is set when a call site becomes megamorphic and starts using a
22492248
// MegamorphicCache instead of ICData. It means that the entries in the

runtime/vm/object_reload.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ void CallSiteResetter::Reset(const ICData& ic) {
904904
(class_ids[1] == kSmiCid)) {
905905
// The smi fast path case, preserve the initial entry but reset the
906906
// count.
907-
ic.ClearCountAt(0);
908-
ic.WriteSentinelAt(1);
907+
ic.ClearCountAt(0, *this);
908+
ic.WriteSentinelAt(1, *this);
909909
entries_ = ic.entries();
910910
entries_.Truncate(2 * ic.TestEntryLength());
911911
return;
@@ -955,7 +955,7 @@ void CallSiteResetter::Reset(const ICData& ic) {
955955
Object::Handle(zone_, ic.Owner()).ToCString());
956956
return;
957957
}
958-
ic.ClearAndSetStaticTarget(new_target_);
958+
ic.ClearAndSetStaticTarget(new_target_, *this);
959959
} else {
960960
FATAL("Unexpected rebind rule.");
961961
}

0 commit comments

Comments
 (0)