Skip to content

Commit 0aadba1

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
Revert "[vm] Enable type stubs based type checks in JIT mode for some types."
This reverts commit 4be50d6. Reason for revert: Failures on SIMDBC64 and Analyzer bots. Original change's description: > [vm] Enable type stubs based type checks in JIT mode for some types. > > For now we are limiting this to type checks against type parameter types. > > # Performance improvements > > In Dart 1 mode Dart2JS compiles itself in 28s when running from source > and in 23s when running from ideal app-jit snapshot (trained on the > same workload). > > Before this change in Dart 2 mode numbers were 51s and 57s respectively. > > After this change in Dart 2 mode numbers are 38s and 32s. Meaning > that regression is reduced by 50%. > > Issue #31798 > Issue #33257 > > Change-Id: I34bf5385a5cc3c7702dc281c6dfa89da85d3dde1 > Reviewed-on: https://dart-review.googlesource.com/57601 > Reviewed-by: Régis Crelier <[email protected]> > Commit-Queue: Vyacheslav Egorov <[email protected]> [email protected],[email protected],[email protected] Change-Id: I85a30c962b0cd556310e19193f5993ab76ecf2e7 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/57840 Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Vyacheslav Egorov <[email protected]>
1 parent 4be50d6 commit 0aadba1

31 files changed

+223
-440
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ static RawObject* AllocateUninitialized(PageSpace* old_space, intptr_t size) {
3333
return RawObject::FromAddr(address);
3434
}
3535

36-
static bool SnapshotContainsTypeTestingStubs(Snapshot::Kind kind) {
37-
return kind == Snapshot::kFullAOT || kind == Snapshot::kFullJIT;
38-
}
39-
4036
void Deserializer::InitializeHeader(RawObject* raw,
4137
intptr_t class_id,
4238
intptr_t size,
@@ -3062,8 +3058,6 @@ class TypeSerializationCluster : public SerializationCluster {
30623058

30633059
void WriteFill(Serializer* s) {
30643060
const bool is_vm_isolate = s->isolate() == Dart::vm_isolate();
3065-
const bool should_write_type_testing_stub =
3066-
SnapshotContainsTypeTestingStubs(s->kind());
30673061

30683062
intptr_t count = canonical_objects_.length();
30693063
for (intptr_t i = 0; i < count; i++) {
@@ -3075,7 +3069,7 @@ class TypeSerializationCluster : public SerializationCluster {
30753069
}
30763070
s->WriteTokenPosition(type->ptr()->token_pos_);
30773071
s->Write<int8_t>(type->ptr()->type_state_);
3078-
if (should_write_type_testing_stub) {
3072+
if (s->kind() == Snapshot::kFullAOT) {
30793073
RawInstructions* instr = type_testing_stubs_.LookupByAddresss(
30803074
type->ptr()->type_test_stub_entry_point_);
30813075
s->WriteInstructions(instr, Code::null());
@@ -3091,7 +3085,7 @@ class TypeSerializationCluster : public SerializationCluster {
30913085
}
30923086
s->WriteTokenPosition(type->ptr()->token_pos_);
30933087
s->Write<int8_t>(type->ptr()->type_state_);
3094-
if (should_write_type_testing_stub) {
3088+
if (s->kind() == Snapshot::kFullAOT) {
30953089
RawInstructions* instr = type_testing_stubs_.LookupByAddresss(
30963090
type->ptr()->type_test_stub_entry_point_);
30973091
s->WriteInstructions(instr, Code::null());
@@ -3100,7 +3094,7 @@ class TypeSerializationCluster : public SerializationCluster {
31003094

31013095
// The dynamic/void objects are not serialized, so we manually send
31023096
// the type testing stub for it.
3103-
if (should_write_type_testing_stub && is_vm_isolate) {
3097+
if (s->kind() == Snapshot::kFullAOT && is_vm_isolate) {
31043098
RawInstructions* dynamic_instr = type_testing_stubs_.LookupByAddresss(
31053099
Type::dynamic_type().type_test_stub_entry_point());
31063100
s->WriteInstructions(dynamic_instr, Code::null());
@@ -3143,8 +3137,6 @@ class TypeDeserializationCluster : public DeserializationCluster {
31433137

31443138
void ReadFill(Deserializer* d) {
31453139
const bool is_vm_isolate = d->isolate() == Dart::vm_isolate();
3146-
const bool should_read_type_testing_stub =
3147-
SnapshotContainsTypeTestingStubs(d->kind());
31483140

31493141
for (intptr_t id = canonical_start_index_; id < canonical_stop_index_;
31503142
id++) {
@@ -3158,7 +3150,7 @@ class TypeDeserializationCluster : public DeserializationCluster {
31583150
}
31593151
type->ptr()->token_pos_ = d->ReadTokenPosition();
31603152
type->ptr()->type_state_ = d->Read<int8_t>();
3161-
if (should_read_type_testing_stub) {
3153+
if (d->kind() == Snapshot::kFullAOT) {
31623154
instr_ = d->ReadInstructions();
31633155
type_ = type;
31643156
type_.SetTypeTestingStub(instr_);
@@ -3176,7 +3168,7 @@ class TypeDeserializationCluster : public DeserializationCluster {
31763168
}
31773169
type->ptr()->token_pos_ = d->ReadTokenPosition();
31783170
type->ptr()->type_state_ = d->Read<int8_t>();
3179-
if (should_read_type_testing_stub) {
3171+
if (d->kind() == Snapshot::kFullAOT) {
31803172
instr_ = d->ReadInstructions();
31813173
type_ = type;
31823174
type_.SetTypeTestingStub(instr_);
@@ -3185,7 +3177,7 @@ class TypeDeserializationCluster : public DeserializationCluster {
31853177

31863178
// The dynamic/void objects are not serialized, so we manually send
31873179
// the type testing stub for it.
3188-
if (should_read_type_testing_stub && is_vm_isolate) {
3180+
if (d->kind() == Snapshot::kFullAOT && is_vm_isolate) {
31893181
instr_ = d->ReadInstructions();
31903182
Type::dynamic_type().SetTypeTestingStub(instr_);
31913183
instr_ = d->ReadInstructions();
@@ -3194,7 +3186,7 @@ class TypeDeserializationCluster : public DeserializationCluster {
31943186
}
31953187

31963188
void PostLoad(const Array& refs, Snapshot::Kind kind, Zone* zone) {
3197-
if (!SnapshotContainsTypeTestingStubs(kind)) {
3189+
if (kind != Snapshot::kFullAOT) {
31983190
for (intptr_t id = canonical_start_index_; id < canonical_stop_index_;
31993191
id++) {
32003192
type_ ^= refs.At(id);
@@ -3245,9 +3237,6 @@ class TypeRefSerializationCluster : public SerializationCluster {
32453237
}
32463238

32473239
void WriteFill(Serializer* s) {
3248-
const bool should_write_type_testing_stub =
3249-
SnapshotContainsTypeTestingStubs(s->kind());
3250-
32513240
intptr_t count = objects_.length();
32523241
for (intptr_t i = 0; i < count; i++) {
32533242
RawTypeRef* type = objects_[i];
@@ -3256,7 +3245,7 @@ class TypeRefSerializationCluster : public SerializationCluster {
32563245
for (RawObject** p = from; p <= to; p++) {
32573246
s->WriteRef(*p);
32583247
}
3259-
if (should_write_type_testing_stub) {
3248+
if (s->kind() == Snapshot::kFullAOT) {
32603249
RawInstructions* instr = type_testing_stubs_.LookupByAddresss(
32613250
type->ptr()->type_test_stub_entry_point_);
32623251
s->WriteInstructions(instr, Code::null());
@@ -3287,9 +3276,7 @@ class TypeRefDeserializationCluster : public DeserializationCluster {
32873276
}
32883277

32893278
void ReadFill(Deserializer* d) {
3290-
const bool is_vm_object = d->isolate() == Dart::vm_isolate();
3291-
const bool should_read_type_testing_stub =
3292-
SnapshotContainsTypeTestingStubs(d->kind());
3279+
bool is_vm_object = d->isolate() == Dart::vm_isolate();
32933280

32943281
for (intptr_t id = start_index_; id < stop_index_; id++) {
32953282
RawTypeRef* type = reinterpret_cast<RawTypeRef*>(d->Ref(id));
@@ -3300,24 +3287,14 @@ class TypeRefDeserializationCluster : public DeserializationCluster {
33003287
for (RawObject** p = from; p <= to; p++) {
33013288
*p = d->ReadRef();
33023289
}
3303-
if (should_read_type_testing_stub) {
3290+
if (d->kind() == Snapshot::kFullAOT) {
33043291
instr_ = d->ReadInstructions();
33053292
type_ = type;
33063293
type_.SetTypeTestingStub(instr_);
33073294
}
33083295
}
33093296
}
33103297

3311-
void PostLoad(const Array& refs, Snapshot::Kind kind, Zone* zone) {
3312-
if (!SnapshotContainsTypeTestingStubs(kind)) {
3313-
for (intptr_t id = start_index_; id < stop_index_; id++) {
3314-
type_ ^= refs.At(id);
3315-
instr_ = TypeTestingStubGenerator::DefaultCodeForType(type_);
3316-
type_.SetTypeTestingStub(instr_);
3317-
}
3318-
}
3319-
}
3320-
33213298
private:
33223299
AbstractType& type_;
33233300
Instructions& instr_;
@@ -3354,9 +3331,6 @@ class TypeParameterSerializationCluster : public SerializationCluster {
33543331
}
33553332

33563333
void WriteFill(Serializer* s) {
3357-
const bool should_write_type_testing_stub =
3358-
SnapshotContainsTypeTestingStubs(s->kind());
3359-
33603334
intptr_t count = objects_.length();
33613335
for (intptr_t i = 0; i < count; i++) {
33623336
RawTypeParameter* type = objects_[i];
@@ -3369,7 +3343,7 @@ class TypeParameterSerializationCluster : public SerializationCluster {
33693343
s->WriteTokenPosition(type->ptr()->token_pos_);
33703344
s->Write<int16_t>(type->ptr()->index_);
33713345
s->Write<int8_t>(type->ptr()->type_state_);
3372-
if (should_write_type_testing_stub) {
3346+
if (s->kind() == Snapshot::kFullAOT) {
33733347
RawInstructions* instr = type_testing_stubs_.LookupByAddresss(
33743348
type->ptr()->type_test_stub_entry_point_);
33753349
s->WriteInstructions(instr, Code::null());
@@ -3402,8 +3376,6 @@ class TypeParameterDeserializationCluster : public DeserializationCluster {
34023376

34033377
void ReadFill(Deserializer* d) {
34043378
bool is_vm_object = d->isolate() == Dart::vm_isolate();
3405-
const bool should_read_type_testing_stub =
3406-
SnapshotContainsTypeTestingStubs(d->kind());
34073379

34083380
for (intptr_t id = start_index_; id < stop_index_; id++) {
34093381
RawTypeParameter* type = reinterpret_cast<RawTypeParameter*>(d->Ref(id));
@@ -3418,7 +3390,7 @@ class TypeParameterDeserializationCluster : public DeserializationCluster {
34183390
type->ptr()->token_pos_ = d->ReadTokenPosition();
34193391
type->ptr()->index_ = d->Read<int16_t>();
34203392
type->ptr()->type_state_ = d->Read<int8_t>();
3421-
if (should_read_type_testing_stub) {
3393+
if (d->kind() == Snapshot::kFullAOT) {
34223394
instr_ = d->ReadInstructions();
34233395
type_ = type;
34243396
type_.SetTypeTestingStub(instr_);
@@ -3427,7 +3399,7 @@ class TypeParameterDeserializationCluster : public DeserializationCluster {
34273399
}
34283400

34293401
void PostLoad(const Array& refs, Snapshot::Kind kind, Zone* zone) {
3430-
if (!SnapshotContainsTypeTestingStubs(kind)) {
3402+
if (kind != Snapshot::kFullAOT) {
34313403
for (intptr_t id = start_index_; id < stop_index_; id++) {
34323404
type_ ^= refs.At(id);
34333405
instr_ = TypeTestingStubGenerator::DefaultCodeForType(type_);

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,12 +1934,7 @@ void FlowGraphCompiler::GenerateCidRangesCheck(Assembler* assembler,
19341934
}
19351935
}
19361936

1937-
bool FlowGraphCompiler::ShouldUseTypeTestingStubFor(bool optimizing,
1938-
const AbstractType& type) {
1939-
return FLAG_precompiled_mode || (optimizing && type.IsTypeParameter());
1940-
}
1941-
1942-
void FlowGraphCompiler::GenerateAssertAssignableViaTypeTestingStub(
1937+
void FlowGraphCompiler::GenerateAssertAssignableAOT(
19431938
const AbstractType& dst_type,
19441939
const String& dst_name,
19451940
const Register instance_reg,

runtime/vm/compiler/backend/flow_graph_compiler.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -364,28 +364,21 @@ class FlowGraphCompiler : public ValueObject {
364364
const AbstractType& dst_type,
365365
const String& dst_name,
366366
LocationSummary* locs);
367-
368-
// Returns true if we can use a type testing stub based assert
369-
// assignable code pattern for the given type.
370-
static bool ShouldUseTypeTestingStubFor(bool optimizing,
371-
const AbstractType& type);
372-
373-
void GenerateAssertAssignableViaTypeTestingStub(TokenPosition token_pos,
374-
intptr_t deopt_id,
375-
const AbstractType& dst_type,
376-
const String& dst_name,
377-
LocationSummary* locs);
378-
379-
void GenerateAssertAssignableViaTypeTestingStub(
380-
const AbstractType& dst_type,
381-
const String& dst_name,
382-
const Register instance_reg,
383-
const Register instantiator_type_args_reg,
384-
const Register function_type_args_reg,
385-
const Register subtype_cache_reg,
386-
const Register dst_type_reg,
387-
const Register scratch_reg,
388-
Label* done);
367+
void GenerateAssertAssignableAOT(TokenPosition token_pos,
368+
intptr_t deopt_id,
369+
const AbstractType& dst_type,
370+
const String& dst_name,
371+
LocationSummary* locs);
372+
373+
void GenerateAssertAssignableAOT(const AbstractType& dst_type,
374+
const String& dst_name,
375+
const Register instance_reg,
376+
const Register instantiator_type_args_reg,
377+
const Register function_type_args_reg,
378+
const Register subtype_cache_reg,
379+
const Register dst_type_reg,
380+
const Register scratch_reg,
381+
Label* done);
389382

390383
// DBC emits calls very differently from all other architectures due to its
391384
// interpreted nature.

runtime/vm/compiler/backend/flow_graph_compiler_arm.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
663663
}
664664

665665
if (FLAG_precompiled_mode) {
666-
GenerateAssertAssignableViaTypeTestingStub(token_pos, deopt_id, dst_type,
667-
dst_name, locs);
666+
GenerateAssertAssignableAOT(token_pos, deopt_id, dst_type, dst_name, locs);
668667
} else {
669668
Label is_assignable_fast, is_assignable, runtime_call;
670669

@@ -692,11 +691,10 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
692691
__ PushObject(dst_name); // Push the name of the destination.
693692
__ LoadUniqueObject(R0, test_cache);
694693
__ Push(R0);
695-
__ PushObject(Smi::ZoneHandle(zone(), Smi::New(kTypeCheckFromInline)));
696-
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 7, locs);
694+
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 6, locs);
697695
// Pop the parameters supplied to the runtime entry. The result of the
698696
// type check runtime call is the checked value.
699-
__ Drop(7);
697+
__ Drop(6);
700698
__ Pop(R0);
701699
__ Bind(&is_assignable);
702700
__ PopList((1 << kFunctionTypeArgumentsReg) |
@@ -705,7 +703,7 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
705703
}
706704
}
707705

708-
void FlowGraphCompiler::GenerateAssertAssignableViaTypeTestingStub(
706+
void FlowGraphCompiler::GenerateAssertAssignableAOT(
709707
TokenPosition token_pos,
710708
intptr_t deopt_id,
711709
const AbstractType& dst_type,
@@ -721,10 +719,10 @@ void FlowGraphCompiler::GenerateAssertAssignableViaTypeTestingStub(
721719

722720
Label done;
723721

724-
GenerateAssertAssignableViaTypeTestingStub(
725-
dst_type, dst_name, kInstanceReg, kInstantiatorTypeArgumentsReg,
726-
kFunctionTypeArgumentsReg, kSubtypeTestCacheReg, kDstTypeReg, kScratchReg,
727-
&done);
722+
GenerateAssertAssignableAOT(dst_type, dst_name, kInstanceReg,
723+
kInstantiatorTypeArgumentsReg,
724+
kFunctionTypeArgumentsReg, kSubtypeTestCacheReg,
725+
kDstTypeReg, kScratchReg, &done);
728726
// We use 2 consecutive entries in the pool for the subtype cache and the
729727
// destination name. The second entry, namely [dst_name] seems to be unused,
730728
// but it will be used by the code throwing a TypeError if the type test fails

runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,8 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
643643
return;
644644
}
645645

646-
if (ShouldUseTypeTestingStubFor(is_optimizing(), dst_type)) {
647-
GenerateAssertAssignableViaTypeTestingStub(token_pos, deopt_id, dst_type,
648-
dst_name, locs);
646+
if (FLAG_precompiled_mode) {
647+
GenerateAssertAssignableAOT(token_pos, deopt_id, dst_type, dst_name, locs);
649648
} else {
650649
Label is_assignable_fast, is_assignable, runtime_call;
651650

@@ -670,19 +669,18 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
670669
__ PushObject(dst_name); // Push the name of the destination.
671670
__ LoadUniqueObject(R0, test_cache);
672671
__ Push(R0);
673-
__ PushObject(Smi::ZoneHandle(zone(), Smi::New(kTypeCheckFromInline)));
674-
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 7, locs);
672+
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 6, locs);
675673
// Pop the parameters supplied to the runtime entry. The result of the
676674
// type check runtime call is the checked value.
677-
__ Drop(7);
675+
__ Drop(6);
678676
__ Pop(R0);
679677
__ Bind(&is_assignable);
680678
__ PopPair(kFunctionTypeArgumentsReg, kInstantiatorTypeArgumentsReg);
681679
__ Bind(&is_assignable_fast);
682680
}
683681
}
684682

685-
void FlowGraphCompiler::GenerateAssertAssignableViaTypeTestingStub(
683+
void FlowGraphCompiler::GenerateAssertAssignableAOT(
686684
TokenPosition token_pos,
687685
intptr_t deopt_id,
688686
const AbstractType& dst_type,
@@ -698,10 +696,10 @@ void FlowGraphCompiler::GenerateAssertAssignableViaTypeTestingStub(
698696

699697
Label done;
700698

701-
GenerateAssertAssignableViaTypeTestingStub(
702-
dst_type, dst_name, kInstanceReg, kInstantiatorTypeArgumentsReg,
703-
kFunctionTypeArgumentsReg, kSubtypeTestCacheReg, kDstTypeReg, kScratchReg,
704-
&done);
699+
GenerateAssertAssignableAOT(dst_type, dst_name, kInstanceReg,
700+
kInstantiatorTypeArgumentsReg,
701+
kFunctionTypeArgumentsReg, kSubtypeTestCacheReg,
702+
kDstTypeReg, kScratchReg, &done);
705703

706704
// We use 2 consecutive entries in the pool for the subtype cache and the
707705
// destination name. The second entry, namely [dst_name] seems to be unused,

runtime/vm/compiler/backend/flow_graph_compiler_ia32.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,10 @@ void FlowGraphCompiler::GenerateAssertAssignable(TokenPosition token_pos,
686686
__ PushObject(dst_name); // Push the name of the destination.
687687
__ LoadObject(EAX, test_cache);
688688
__ pushl(EAX);
689-
__ PushObject(Smi::ZoneHandle(zone(), Smi::New(kTypeCheckFromInline)));
690-
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 7, locs);
689+
GenerateRuntimeCall(token_pos, deopt_id, kTypeCheckRuntimeEntry, 6, locs);
691690
// Pop the parameters supplied to the runtime entry. The result of the
692691
// type check runtime call is the checked value.
693-
__ Drop(7);
692+
__ Drop(6);
694693
__ popl(EAX);
695694

696695
__ Bind(&is_assignable);

0 commit comments

Comments
 (0)