@@ -3014,7 +3014,8 @@ class LibraryPrefixDeserializationCluster : public DeserializationCluster {
3014
3014
#if !defined(DART_PRECOMPILED_RUNTIME)
3015
3015
class TypeSerializationCluster : public SerializationCluster {
3016
3016
public:
3017
- TypeSerializationCluster () : SerializationCluster(" Type" ) {}
3017
+ explicit TypeSerializationCluster (const TypeTestingStubFinder& ttsf)
3018
+ : SerializationCluster(" Type" ), type_testing_stubs_(ttsf) {}
3018
3019
virtual ~TypeSerializationCluster () {}
3019
3020
3020
3021
void Trace (Serializer* s, RawObject* object) {
@@ -3069,6 +3070,12 @@ class TypeSerializationCluster : public SerializationCluster {
3069
3070
}
3070
3071
s->WriteTokenPosition (type->ptr ()->token_pos_ );
3071
3072
s->Write <int8_t >(type->ptr ()->type_state_ );
3073
+ if (s->kind () == Snapshot::kFullAOT ) {
3074
+ RawInstructions* instr = type_testing_stubs_.LookupByAddresss (
3075
+ type->ptr ()->type_test_stub_entry_point_ );
3076
+ const int32_t text_offset = s->GetTextOffset (instr, Code::null ());
3077
+ s->Write <int32_t >(text_offset);
3078
+ }
3072
3079
}
3073
3080
count = objects_.length ();
3074
3081
for (intptr_t i = 0 ; i < count; i++) {
@@ -3080,18 +3087,35 @@ class TypeSerializationCluster : public SerializationCluster {
3080
3087
}
3081
3088
s->WriteTokenPosition (type->ptr ()->token_pos_ );
3082
3089
s->Write <int8_t >(type->ptr ()->type_state_ );
3090
+ if (s->kind () == Snapshot::kFullAOT ) {
3091
+ RawInstructions* instr = type_testing_stubs_.LookupByAddresss (
3092
+ type->ptr ()->type_test_stub_entry_point_ );
3093
+ const int32_t text_offset = s->GetTextOffset (instr, Code::null ());
3094
+ s->Write <int32_t >(text_offset);
3095
+ }
3096
+ }
3097
+
3098
+ // The [Type::dynamic_type()] object is not serialized, so we manually send
3099
+ // the type testing stub for it.
3100
+ if (s->kind () == Snapshot::kFullAOT && s->for_vm_isolate ()) {
3101
+ RawInstructions* instr = type_testing_stubs_.LookupByAddresss (
3102
+ Type::dynamic_type ().type_test_stub_entry_point ());
3103
+ const int32_t text_offset = s->GetTextOffset (instr, Code::null ());
3104
+ s->Write <int32_t >(text_offset);
3083
3105
}
3084
3106
}
3085
3107
3086
3108
private:
3087
3109
GrowableArray<RawType*> canonical_objects_;
3088
3110
GrowableArray<RawType*> objects_;
3111
+ const TypeTestingStubFinder& type_testing_stubs_;
3089
3112
};
3090
3113
#endif // !DART_PRECOMPILED_RUNTIME
3091
3114
3092
3115
class TypeDeserializationCluster : public DeserializationCluster {
3093
3116
public:
3094
- TypeDeserializationCluster () {}
3117
+ TypeDeserializationCluster ()
3118
+ : type_(AbstractType::Handle ()), instr_(Instructions::Handle ()) {}
3095
3119
virtual ~TypeDeserializationCluster () {}
3096
3120
3097
3121
void ReadAlloc (Deserializer* d) {
@@ -3126,6 +3150,12 @@ class TypeDeserializationCluster : public DeserializationCluster {
3126
3150
}
3127
3151
type->ptr ()->token_pos_ = d->ReadTokenPosition ();
3128
3152
type->ptr ()->type_state_ = d->Read <int8_t >();
3153
+ if (d->kind () == Snapshot::kFullAOT ) {
3154
+ const int32_t text_offset = d->Read <int32_t >();
3155
+ instr_ = d->GetInstructionsAt (text_offset);
3156
+ type_ = type;
3157
+ type_.SetTypeTestingStub (instr_);
3158
+ }
3129
3159
}
3130
3160
3131
3161
for (intptr_t id = start_index_; id < stop_index_; id++) {
@@ -3139,18 +3169,53 @@ class TypeDeserializationCluster : public DeserializationCluster {
3139
3169
}
3140
3170
type->ptr ()->token_pos_ = d->ReadTokenPosition ();
3141
3171
type->ptr ()->type_state_ = d->Read <int8_t >();
3172
+ if (d->kind () == Snapshot::kFullAOT ) {
3173
+ const int32_t text_offset = d->Read <int32_t >();
3174
+ instr_ = d->GetInstructionsAt (text_offset);
3175
+ type_ = type;
3176
+ type_.SetTypeTestingStub (instr_);
3177
+ }
3178
+ }
3179
+
3180
+ // The [Type::dynamic_type()] object is not serialized, so we manually send
3181
+ // the type testing stub for it.
3182
+ if (d->kind () == Snapshot::kFullAOT && d->for_vm_isolate ()) {
3183
+ const int32_t text_offset = d->Read <int32_t >();
3184
+ Dart::vm_isolate ()->heap ()->WriteProtect (false );
3185
+ instr_ = d->GetInstructionsAt (text_offset);
3186
+ Type::dynamic_type ().SetTypeTestingStub (instr_);
3187
+ Dart::vm_isolate ()->heap ()->WriteProtect (true );
3188
+ }
3189
+ }
3190
+
3191
+ void PostLoad (const Array& refs, Snapshot::Kind kind, Zone* zone) {
3192
+ if (kind != Snapshot::kFullAOT ) {
3193
+ for (intptr_t id = canonical_start_index_; id < canonical_stop_index_;
3194
+ id++) {
3195
+ type_ ^= refs.At (id);
3196
+ instr_ = TypeTestingStubGenerator::DefaultCodeForType (type_);
3197
+ type_.SetTypeTestingStub (instr_);
3198
+ }
3199
+ for (intptr_t id = start_index_; id < stop_index_; id++) {
3200
+ type_ ^= refs.At (id);
3201
+ instr_ = TypeTestingStubGenerator::DefaultCodeForType (type_);
3202
+ type_.SetTypeTestingStub (instr_);
3203
+ }
3142
3204
}
3143
3205
}
3144
3206
3145
3207
private:
3146
3208
intptr_t canonical_start_index_;
3147
3209
intptr_t canonical_stop_index_;
3210
+ AbstractType& type_;
3211
+ Instructions& instr_;
3148
3212
};
3149
3213
3150
3214
#if !defined(DART_PRECOMPILED_RUNTIME)
3151
3215
class TypeRefSerializationCluster : public SerializationCluster {
3152
3216
public:
3153
- TypeRefSerializationCluster () : SerializationCluster(" TypeRef" ) {}
3217
+ explicit TypeRefSerializationCluster (const TypeTestingStubFinder& ttsf)
3218
+ : SerializationCluster(" TypeRef" ), type_testing_stubs_(ttsf) {}
3154
3219
virtual ~TypeRefSerializationCluster () {}
3155
3220
3156
3221
void Trace (Serializer* s, RawObject* object) {
@@ -3183,17 +3248,25 @@ class TypeRefSerializationCluster : public SerializationCluster {
3183
3248
for (RawObject** p = from; p <= to; p++) {
3184
3249
s->WriteRef (*p);
3185
3250
}
3251
+ if (s->kind () == Snapshot::kFullAOT ) {
3252
+ RawInstructions* instr = type_testing_stubs_.LookupByAddresss (
3253
+ type->ptr ()->type_test_stub_entry_point_ );
3254
+ const int32_t text_offset = s->GetTextOffset (instr, Code::null ());
3255
+ s->Write <int32_t >(text_offset);
3256
+ }
3186
3257
}
3187
3258
}
3188
3259
3189
3260
private:
3190
3261
GrowableArray<RawTypeRef*> objects_;
3262
+ const TypeTestingStubFinder& type_testing_stubs_;
3191
3263
};
3192
3264
#endif // !DART_PRECOMPILED_RUNTIME
3193
3265
3194
3266
class TypeRefDeserializationCluster : public DeserializationCluster {
3195
3267
public:
3196
- TypeRefDeserializationCluster () {}
3268
+ TypeRefDeserializationCluster ()
3269
+ : type_(AbstractType::Handle ()), instr_(Instructions::Handle ()) {}
3197
3270
virtual ~TypeRefDeserializationCluster () {}
3198
3271
3199
3272
void ReadAlloc (Deserializer* d) {
@@ -3218,14 +3291,26 @@ class TypeRefDeserializationCluster : public DeserializationCluster {
3218
3291
for (RawObject** p = from; p <= to; p++) {
3219
3292
*p = d->ReadRef ();
3220
3293
}
3294
+ if (d->kind () == Snapshot::kFullAOT ) {
3295
+ const int32_t text_offset = d->Read <int32_t >();
3296
+ instr_ = d->GetInstructionsAt (text_offset);
3297
+ type_ = type;
3298
+ type_.SetTypeTestingStub (instr_);
3299
+ }
3221
3300
}
3222
3301
}
3302
+
3303
+ private:
3304
+ AbstractType& type_;
3305
+ Instructions& instr_;
3223
3306
};
3224
3307
3225
3308
#if !defined(DART_PRECOMPILED_RUNTIME)
3226
3309
class TypeParameterSerializationCluster : public SerializationCluster {
3227
3310
public:
3228
- TypeParameterSerializationCluster () : SerializationCluster(" TypeParameter" ) {}
3311
+ explicit TypeParameterSerializationCluster (const TypeTestingStubFinder& ttsf)
3312
+ : SerializationCluster(" TypeParameter" ), type_testing_stubs_(ttsf) {}
3313
+
3229
3314
virtual ~TypeParameterSerializationCluster () {}
3230
3315
3231
3316
void Trace (Serializer* s, RawObject* object) {
@@ -3263,17 +3348,25 @@ class TypeParameterSerializationCluster : public SerializationCluster {
3263
3348
s->WriteTokenPosition (type->ptr ()->token_pos_ );
3264
3349
s->Write <int16_t >(type->ptr ()->index_ );
3265
3350
s->Write <int8_t >(type->ptr ()->type_state_ );
3351
+ if (s->kind () == Snapshot::kFullAOT ) {
3352
+ RawInstructions* instr = type_testing_stubs_.LookupByAddresss (
3353
+ type->ptr ()->type_test_stub_entry_point_ );
3354
+ const int32_t text_offset = s->GetTextOffset (instr, Code::null ());
3355
+ s->Write <int32_t >(text_offset);
3356
+ }
3266
3357
}
3267
3358
}
3268
3359
3269
3360
private:
3270
3361
GrowableArray<RawTypeParameter*> objects_;
3362
+ const TypeTestingStubFinder& type_testing_stubs_;
3271
3363
};
3272
3364
#endif // !DART_PRECOMPILED_RUNTIME
3273
3365
3274
3366
class TypeParameterDeserializationCluster : public DeserializationCluster {
3275
3367
public:
3276
- TypeParameterDeserializationCluster () {}
3368
+ TypeParameterDeserializationCluster ()
3369
+ : type_(AbstractType::Handle ()), instr_(Instructions::Handle ()) {}
3277
3370
virtual ~TypeParameterDeserializationCluster () {}
3278
3371
3279
3372
void ReadAlloc (Deserializer* d) {
@@ -3303,8 +3396,28 @@ class TypeParameterDeserializationCluster : public DeserializationCluster {
3303
3396
type->ptr ()->token_pos_ = d->ReadTokenPosition ();
3304
3397
type->ptr ()->index_ = d->Read <int16_t >();
3305
3398
type->ptr ()->type_state_ = d->Read <int8_t >();
3399
+ if (d->kind () == Snapshot::kFullAOT ) {
3400
+ const int32_t text_offset = d->Read <int32_t >();
3401
+ instr_ = d->GetInstructionsAt (text_offset);
3402
+ type_ = type;
3403
+ type_.SetTypeTestingStub (instr_);
3404
+ }
3405
+ }
3406
+ }
3407
+
3408
+ void PostLoad (const Array& refs, Snapshot::Kind kind, Zone* zone) {
3409
+ if (kind != Snapshot::kFullAOT ) {
3410
+ for (intptr_t id = start_index_; id < stop_index_; id++) {
3411
+ type_ ^= refs.At (id);
3412
+ instr_ = TypeTestingStubGenerator::DefaultCodeForType (type_);
3413
+ type_.SetTypeTestingStub (instr_);
3414
+ }
3306
3415
}
3307
3416
}
3417
+
3418
+ private:
3419
+ AbstractType& type_;
3420
+ Instructions& instr_;
3308
3421
};
3309
3422
3310
3423
#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -4556,7 +4669,8 @@ Serializer::Serializer(Thread* thread,
4556
4669
uint8_t ** buffer,
4557
4670
ReAlloc alloc,
4558
4671
intptr_t initial_size,
4559
- ImageWriter* image_writer)
4672
+ ImageWriter* image_writer,
4673
+ bool vm_isolate)
4560
4674
: StackResource(thread),
4561
4675
heap_ (thread->isolate ()->heap()),
4562
4676
zone_(thread->zone ()),
@@ -4568,7 +4682,8 @@ Serializer::Serializer(Thread* thread,
4568
4682
num_cids_(0 ),
4569
4683
num_base_objects_(0 ),
4570
4684
num_written_objects_(0 ),
4571
- next_ref_index_(1 )
4685
+ next_ref_index_(1 ),
4686
+ vm_isolate_(vm_isolate)
4572
4687
#if defined(SNAPSHOT_BACKTRACE)
4573
4688
,
4574
4689
current_parent_ (Object::null()),
@@ -4668,11 +4783,11 @@ SerializationCluster* Serializer::NewClusterForClass(intptr_t cid) {
4668
4783
case kLibraryPrefixCid :
4669
4784
return new (Z) LibraryPrefixSerializationCluster ();
4670
4785
case kTypeCid :
4671
- return new (Z) TypeSerializationCluster ();
4786
+ return new (Z) TypeSerializationCluster (type_testing_stubs_ );
4672
4787
case kTypeRefCid :
4673
- return new (Z) TypeRefSerializationCluster ();
4788
+ return new (Z) TypeRefSerializationCluster (type_testing_stubs_ );
4674
4789
case kTypeParameterCid :
4675
- return new (Z) TypeParameterSerializationCluster ();
4790
+ return new (Z) TypeParameterSerializationCluster (type_testing_stubs_ );
4676
4791
case kBoundedTypeCid :
4677
4792
return new (Z) BoundedTypeSerializationCluster ();
4678
4793
case kClosureCid :
@@ -5120,7 +5235,8 @@ Deserializer::Deserializer(Thread* thread,
5120
5235
const uint8_t * buffer,
5121
5236
intptr_t size,
5122
5237
const uint8_t * instructions_buffer,
5123
- const uint8_t * data_buffer)
5238
+ const uint8_t * data_buffer,
5239
+ bool vm_isolate)
5124
5240
: StackResource(thread),
5125
5241
heap_(thread->isolate ()->heap()),
5126
5242
zone_(thread->zone ()),
@@ -5129,7 +5245,8 @@ Deserializer::Deserializer(Thread* thread,
5129
5245
image_reader_(NULL ),
5130
5246
refs_(NULL ),
5131
5247
next_ref_index_(1 ),
5132
- clusters_(NULL ) {
5248
+ clusters_(NULL ),
5249
+ vm_isolate_(vm_isolate) {
5133
5250
if (Snapshot::IncludesCode (kind)) {
5134
5251
ASSERT (instructions_buffer != NULL );
5135
5252
ASSERT (data_buffer != NULL );
@@ -5716,7 +5833,8 @@ intptr_t FullSnapshotWriter::WriteVMSnapshot() {
5716
5833
5717
5834
ASSERT (vm_snapshot_data_buffer_ != NULL );
5718
5835
Serializer serializer (thread (), kind_, vm_snapshot_data_buffer_, alloc_,
5719
- kInitialSize , vm_image_writer_);
5836
+ kInitialSize , vm_image_writer_,
5837
+ /* vm_isolate=*/ true );
5720
5838
5721
5839
serializer.ReserveHeader ();
5722
5840
serializer.WriteVersionAndFeatures (true );
@@ -5746,7 +5864,8 @@ void FullSnapshotWriter::WriteIsolateSnapshot(intptr_t num_base_objects) {
5746
5864
thread (), Timeline::GetIsolateStream (), " WriteIsolateSnapshot" ));
5747
5865
5748
5866
Serializer serializer (thread (), kind_, isolate_snapshot_data_buffer_, alloc_,
5749
- kInitialSize , isolate_image_writer_);
5867
+ kInitialSize , isolate_image_writer_,
5868
+ /* vm_isolate=*/ false );
5750
5869
ObjectStore* object_store = isolate ()->object_store ();
5751
5870
ASSERT (object_store != NULL );
5752
5871
@@ -5816,7 +5935,8 @@ FullSnapshotReader::FullSnapshotReader(const Snapshot* snapshot,
5816
5935
5817
5936
RawApiError* FullSnapshotReader::ReadVMSnapshot () {
5818
5937
Deserializer deserializer (thread_, kind_, buffer_, size_,
5819
- instructions_buffer_, data_buffer_);
5938
+ instructions_buffer_, data_buffer_,
5939
+ /* vm_isolate=*/ true );
5820
5940
5821
5941
RawApiError* error = deserializer.VerifyVersionAndFeatures (/* isolate=*/ NULL );
5822
5942
if (error != ApiError::null ()) {
@@ -5840,7 +5960,8 @@ RawApiError* FullSnapshotReader::ReadVMSnapshot() {
5840
5960
5841
5961
RawApiError* FullSnapshotReader::ReadIsolateSnapshot () {
5842
5962
Deserializer deserializer (thread_, kind_, buffer_, size_,
5843
- instructions_buffer_, data_buffer_);
5963
+ instructions_buffer_, data_buffer_,
5964
+ /* vm_isolate=*/ false );
5844
5965
5845
5966
RawApiError* error =
5846
5967
deserializer.VerifyVersionAndFeatures (thread_->isolate ());
0 commit comments