Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 95ad666

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Use ICData::NewWithCheck() when creating new ICData with initial checks
Issue dart-lang/sdk#36097 TEST=Refactoring, covered by existing test suite. Change-Id: Idb1a3e8024dc257bac31267d7f9657c6faa3cbcb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174464 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent 9cd7608 commit 95ad666

File tree

3 files changed

+61
-36
lines changed

3 files changed

+61
-36
lines changed

runtime/vm/object.cc

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14879,6 +14879,24 @@ void ICData::SetReceiversStaticType(const AbstractType& type) const {
1487914879
}
1488014880
#endif
1488114881

14882+
void ICData::SetTargetAtPos(const Array& data,
14883+
intptr_t data_pos,
14884+
intptr_t num_args_tested,
14885+
const Function& target) {
14886+
#if !defined(DART_PRECOMPILED_RUNTIME)
14887+
// JIT
14888+
data.SetAt(data_pos + TargetIndexFor(num_args_tested), target);
14889+
#else
14890+
// AOT
14891+
ASSERT(target.HasCode());
14892+
const Code& code = Code::Handle(target.CurrentCode());
14893+
const Smi& entry_point =
14894+
Smi::Handle(Smi::FromAlignedAddress(code.EntryPoint()));
14895+
data.SetAt(data_pos + CodeIndexFor(num_args_tested), code);
14896+
data.SetAt(data_pos + EntryPointIndexFor(num_args_tested), entry_point);
14897+
#endif
14898+
}
14899+
1488214900
const char* ICData::ToCString() const {
1488314901
Zone* zone = Thread::Current()->zone();
1488414902
const String& name = String::Handle(zone, target_name());
@@ -15330,24 +15348,15 @@ void ICData::AddReceiverCheck(intptr_t receiver_class_id,
1533015348
data_pos = 0;
1533115349
}
1533215350
data.SetAt(data_pos, Smi::Handle(Smi::New(receiver_class_id)));
15351+
SetTargetAtPos(data, data_pos, kNumArgsTested, target);
1533315352

1533415353
#if !defined(DART_PRECOMPILED_RUNTIME)
15335-
// JIT
15336-
data.SetAt(data_pos + TargetIndexFor(kNumArgsTested), target);
1533715354
data.SetAt(data_pos + CountIndexFor(kNumArgsTested),
1533815355
Smi::Handle(Smi::New(count)));
1533915356
if (is_tracking_exactness()) {
1534015357
data.SetAt(data_pos + ExactnessIndexFor(kNumArgsTested),
1534115358
Smi::Handle(Smi::New(exactness.Encode())));
1534215359
}
15343-
#else
15344-
// AOT
15345-
ASSERT(target.HasCode());
15346-
const Code& code = Code::Handle(target.CurrentCode());
15347-
const Smi& entry_point =
15348-
Smi::Handle(Smi::FromAlignedAddress(code.EntryPoint()));
15349-
data.SetAt(data_pos + CodeIndexFor(kNumArgsTested), code);
15350-
data.SetAt(data_pos + EntryPointIndexFor(kNumArgsTested), entry_point);
1535115360
#endif
1535215361

1535315362
// Multithreaded access to ICData requires setting of array to be the last
@@ -15822,9 +15831,13 @@ ICDataPtr ICData::NewWithCheck(const Function& owner,
1582215831
cid = Smi::New((*cids)[i]);
1582315832
array.SetAt(i, cid);
1582415833
}
15834+
15835+
SetTargetAtPos(array, 0, num_args_tested, target);
15836+
#if !defined(DART_PRECOMPILED_RUNTIME)
1582515837
array.SetAt(CountIndexFor(num_args_tested), Object::smi_zero());
15826-
array.SetAt(TargetIndexFor(num_args_tested), target);
15838+
#endif
1582715839
WriteSentinel(array, entry_len);
15840+
1582815841
result.set_entries(array);
1582915842

1583015843
return result.raw();

runtime/vm/object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,11 @@ class ICData : public CallSiteData {
22582258
void SetNumArgsTested(intptr_t value) const;
22592259
void SetReceiversStaticType(const AbstractType& type) const;
22602260

2261+
static void SetTargetAtPos(const Array& data,
2262+
intptr_t data_pos,
2263+
intptr_t num_args_tested,
2264+
const Function& target);
2265+
22612266
// This bit is set when a call site becomes megamorphic and starts using a
22622267
// MegamorphicCache instead of ICData. It means that the entries in the
22632268
// ICData are incomplete and the MegamorphicCache needs to also be consulted

runtime/vm/runtime_entry.cc

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,9 @@ class SwitchableCallHandler {
15961596
void DoMegamorphicMiss(const MegamorphicCache& data,
15971597
const Function& target_function);
15981598

1599+
ICDataPtr NewICData();
1600+
ICDataPtr NewICDataWithTarget(intptr_t cid, const Function& target);
1601+
15991602
Isolate* isolate_;
16001603
Thread* thread_;
16011604
Zone* zone_;
@@ -1613,16 +1616,11 @@ class SwitchableCallHandler {
16131616

16141617
void SwitchableCallHandler::DoUnlinkedCall(const UnlinkedCall& unlinked,
16151618
const Function& target_function) {
1616-
const String& name = String::Handle(zone_, unlinked.target_name());
1617-
const Array& descriptor =
1618-
Array::Handle(zone_, unlinked.arguments_descriptor());
1619-
const ICData& ic_data =
1620-
ICData::Handle(zone_, ICData::New(caller_function_, name, descriptor,
1621-
DeoptId::kNone, 1, /* args_tested */
1622-
ICData::kInstance));
1623-
if (!target_function.IsNull()) {
1624-
ic_data.AddReceiverCheck(receiver_.GetClassId(), target_function);
1625-
}
1619+
const auto& ic_data = ICData::Handle(
1620+
zone_,
1621+
target_function.IsNull()
1622+
? NewICData()
1623+
: NewICDataWithTarget(receiver_.GetClassId(), target_function));
16261624

16271625
Object& object = Object::Handle(zone_, ic_data.raw());
16281626
Code& code = Code::Handle(zone_, StubCode::ICCallThroughCode().raw());
@@ -1746,14 +1744,10 @@ void SwitchableCallHandler::DoMonomorphicMiss(const Object& data,
17461744
zone_,
17471745
Resolve(thread_, zone_, old_receiver_class, name_, args_descriptor_));
17481746

1749-
const ICData& ic_data = ICData::Handle(
1750-
zone_, ICData::New(caller_function_, name_, args_descriptor_,
1751-
DeoptId::kNone, 1, /* args_tested */
1752-
ICData::kInstance));
1753-
// Add the first target.
1754-
if (!old_target.IsNull()) {
1755-
ic_data.AddReceiverCheck(old_expected_cid, old_target);
1756-
}
1747+
const auto& ic_data = ICData::Handle(
1748+
zone_, old_target.IsNull()
1749+
? NewICData()
1750+
: NewICDataWithTarget(old_expected_cid, old_target));
17571751

17581752
if (is_monomorphic_hit) {
17591753
// The site just have been updated to monomorphic state with same
@@ -1794,6 +1788,7 @@ void SwitchableCallHandler::DoMonomorphicMiss(const Object& data,
17941788
arguments_.SetArgAt(0, stub);
17951789
arguments_.SetReturn(ic_data);
17961790
#else // JIT
1791+
17971792
const ICData& ic_data = ICData::Handle(
17981793
zone_,
17991794
FindICDataForInstanceCall(zone_, caller_code_, caller_frame_->pc()));
@@ -1836,13 +1831,11 @@ void SwitchableCallHandler::DoSingleTargetMiss(
18361831
Function::Handle(zone_, Function::RawCast(old_target_code.owner()));
18371832

18381833
// We lost the original ICData when we patched to the monomorphic case.
1839-
const ICData& ic_data = ICData::Handle(
1840-
zone_, ICData::New(caller_function_, name_, args_descriptor_,
1841-
DeoptId::kNone, 1, /* args_tested */
1842-
ICData::kInstance));
1843-
if (!target_function.IsNull()) {
1844-
ic_data.AddReceiverCheck(receiver_.GetClassId(), target_function);
1845-
}
1834+
const auto& ic_data = ICData::Handle(
1835+
zone_,
1836+
target_function.IsNull()
1837+
? NewICData()
1838+
: NewICDataWithTarget(receiver_.GetClassId(), target_function));
18461839

18471840
intptr_t lower = data.lower_limit();
18481841
intptr_t upper = data.upper_limit();
@@ -1957,6 +1950,20 @@ void SwitchableCallHandler::DoMegamorphicMiss(const MegamorphicCache& data,
19571950
arguments_.SetReturn(data);
19581951
}
19591952

1953+
ICDataPtr SwitchableCallHandler::NewICData() {
1954+
return ICData::New(caller_function_, name_, args_descriptor_, DeoptId::kNone,
1955+
/*num_args_tested=*/1, ICData::kInstance);
1956+
}
1957+
1958+
ICDataPtr SwitchableCallHandler::NewICDataWithTarget(intptr_t cid,
1959+
const Function& target) {
1960+
GrowableArray<intptr_t> cids(1);
1961+
cids.Add(cid);
1962+
return ICData::NewWithCheck(caller_function_, name_, args_descriptor_,
1963+
DeoptId::kNone, /*num_args_tested=*/1,
1964+
ICData::kInstance, &cids, target);
1965+
}
1966+
19601967
FunctionPtr SwitchableCallHandler::ResolveTargetFunction(const Object& data) {
19611968
switch (data.GetClassId()) {
19621969
case kUnlinkedCallCid: {

0 commit comments

Comments
 (0)