Skip to content

Commit 77ad150

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
Reland "[VM] Introduction of type testing stubs - Part 1-4"
Relands 165c583 [VM] Introduction of type testing stubs - Part 1 This CL: * Adds a field to [RawAbstractType] which will always hold a pointer to the entrypoint of a type testing stub * Makes this new field be initialized to a default stub whenever a instances are created (e.g. via Type::New(), snapshot reader, ...) * Makes the clustered snapshotter write a reference to the corresponding [RawInstructions] object when writing the field and do the reverse when reading it. * Makes us call the type testing stub for performing assert-assignable checks. To reduce unnecessary loads on callsites, we store the entrypoint of the type testing stubs directly in the type objects. This means that the caller of type testing stubs can simply branch there without populating a code object first. This also means that the type testing stubs themselves have no access to a pool and we therefore also don't hold on to the [Code] object, only the [Instruction] object is necessary. The type testing stubs do not setup a frame themselves and also have no safepoint. In the case when the type testing stubs could not determine a positive answer they will tail-call a general-purpose stub. The general-purpose stub sets up a stub frame, tries to consult a [SubtypeTestCache] and bails out to runtime if this was unsuccessful. This CL is just the the first, for ease of reviewing. The actual type-specialized type testing stubs will be generated in later CLs. Reviewed-on: https://dart-review.googlesource.com/44787 Relands f226c22 [VM] Introduction of type testing stubs - Part 2 This CL starts building type testing stubs specialzed for [Type] objects we test against. More specifically, it adds support for: * Handling obvious fast cases on the call sites (while still having a call to stub for negative case) * Handling type tests against type parameters, by loading the value of the type parameter on the call sites and invoking it's type testing stub. * Specialzed type testing stubs for instantiated types where we can do [CidRange]-based subtype-checks. ==> e.g. String/List<dynamic> * Specialzed type testing stubs for instantiated types where we can do [CidRange]-based subclass-checks for the class and [CidRange]-based subtype-checks for the type arguments. ==> e.g. Widget<State>, where we know [Widget] is only extended and not implemented. * Specialzed type testing stubs for certain non-instantiated types where we can do [CidRange]-based subclass-checks for the class and [CidRange]-based subtype-checks for the instantiated type arguments and cid based comparisons for type parameters. (Note that this fast-case migth result in some false-negatives!) ==> e.g. _HashMapEntry<K, V>, where we know [_HashMapEntry] is only extended and not implemented. This optimizes cases where the caller uses `new HashMap<A, B>()` and only uses `A` and `B` as key/values (and not subclasses of it). The false-negative can occur when subtypes of A or B are used. In such cases we fall back to the [SubtypeTestCache]-based imlementation. Reviewed-on: https://dart-review.googlesource.com/44788 Relands 25f98bc [VM] Introduction of type testing stubs - Part 3 The changes include: * Make AssertAssignableInstr no longer have a call-summary, which helps methods with several parameter checks by not having to re-load/re-initialize type arguments registers * Lazily create SubtypeTestCaches: We already go to runtime to warm up the caches, so we now also create the caches on the first runtime call and patch the pool entries. * No longer load the destination name into a register: We only need the name when we throw an exception, so it is not on the hot path. Instead we let the runtime look at the call site, decoding a pool index from the instructions stream. The destination name will be available in the pool, at a consecutive index to the subtype cache. * Remove the fall-through to N=1 case for probing subtypeing tests, since those will always be handled by the optimized stubs. * Do not generate optimized stubs for FutureOr<T> (so far it just falled-through to TTS). We can make optimzed version of that later, but it requires special subtyping rules. * Local code quality improvement in the type-testing-stubs: Avoid extra jump at last case of cid-class-range checks. There are still a number of optimization opportunities we can do in future changes. Reviewed-on: https://dart-review.googlesource.com/46984 Relands 2c52480 [VM] Introduction of type testing stubs - Part 4 In order to avoid generating type testing stubs for too many types in the system - and thereby potentially cause an increase in code size - this change introduces a smarter way to decide for which types we should generate optimized type testing stubs. The precompiler creates a [TypeUsageInfo] which we use to collect information. More specifically: a) We collect the destination types for all type checks we emit (we do this inside AssertAssignableInstr::EmitNativeCode). -> These are types we might want to generate optimized type testing stubs for. b) We collect type argument vectors used in instance creations (we do this inside AllocateObjectInstr::EmitNativeCode) and keep a set of of used type argument vectors for each class. After the precompiler has finished compiling normal code we scan the set of destination types collected in a) for uninstantiated types (or more specifically, type parameter types). We then propagate the type argument vectors used on object allocation sites, which were collected in b), in order to find out what kind of types are flowing into those type parameters. This allows us to extend the set of types which we test against, by adding the types that flow into type parameters. We use this final augmented set of destination types as a "filter" when making the decision whether to generate an optimized type testing stub for a given type. Reviewed-on: https://dart-review.googlesource.com/48640 Issue dart-lang#32603 Closes dart-lang#32852 Change-Id: Ib79fbe7f043aa88f32bddad62d7656c638914b44 Reviewed-on: https://dart-review.googlesource.com/50944 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Régis Crelier <[email protected]>
1 parent a6a22eb commit 77ad150

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

assembler_arm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ class Assembler : public ValueObject {
353353
void Bind(Label* label);
354354
void Jump(Label* label) { b(label); }
355355

356+
void LoadField(Register dst, FieldAddress address) { ldr(dst, address); }
357+
358+
void CompareWithFieldValue(Register value, FieldAddress address) {
359+
ldr(TMP, address);
360+
cmp(value, Operand(TMP));
361+
}
362+
356363
// Misc. functionality
357364
intptr_t CodeSize() const { return buffer_.Size(); }
358365
intptr_t prologue_offset() const { return prologue_offset_; }

assembler_arm64.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ class Assembler : public ValueObject {
438438
void Bind(Label* label);
439439
void Jump(Label* label) { b(label); }
440440

441+
void LoadField(Register dst, FieldAddress address) { ldr(dst, address); }
442+
443+
void CompareWithFieldValue(Register value, FieldAddress address) {
444+
ldr(TMP, address);
445+
cmp(value, Operand(TMP));
446+
}
447+
441448
// Misc. functionality
442449
intptr_t CodeSize() const { return buffer_.Size(); }
443450
intptr_t prologue_offset() const { return prologue_offset_; }
@@ -1506,6 +1513,7 @@ class Assembler : public ValueObject {
15061513

15071514
void EnterFrame(intptr_t frame_size);
15081515
void LeaveFrame();
1516+
void Ret() { ret(LR); }
15091517

15101518
void CheckCodePointer();
15111519
void RestoreCodePointer();

assembler_ia32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ class Assembler : public ValueObject {
566566

567567
void CompareRegisters(Register a, Register b);
568568
void BranchIf(Condition condition, Label* label) { j(condition, label); }
569+
void LoadField(Register dst, FieldAddress address) { movw(dst, address); }
569570

570571
// Issues a move instruction if 'to' is not the same as 'from'.
571572
void MoveRegister(Register to, Register from);

assembler_x64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ class Assembler : public ValueObject {
651651
}
652652

653653
// Methods for High-level operations and implemented on all architectures.
654+
void Ret() { ret(); }
654655
void CompareRegisters(Register a, Register b);
655656
void BranchIf(Condition condition, Label* label) { j(condition, label); }
656657

@@ -799,6 +800,12 @@ class Assembler : public ValueObject {
799800
void Bind(Label* label);
800801
void Jump(Label* label) { jmp(label); }
801802

803+
void LoadField(Register dst, FieldAddress address) { movq(dst, address); }
804+
805+
void CompareWithFieldValue(Register value, FieldAddress address) {
806+
cmpq(value, address);
807+
}
808+
802809
void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
803810
static bool EmittingComments();
804811

assembler_x64_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ ASSEMBLER_TEST_RUN(PackedDoubleNegate, test) {
32263226
EXPECT_FLOAT_EQ(-1.0, res, 0.000001f);
32273227
EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(
32283228
"movups xmm10,[rax]\n"
3229-
"movq r11,[thr+0xf8]\n"
3229+
"movq r11,[thr+0x...]\n"
32303230
"xorpd xmm10,[r11]\n"
32313231
"movaps xmm0,xmm10\n"
32323232
"pop thr\n"

0 commit comments

Comments
 (0)