Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 1965823002: Initial isolate reload support (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/native_entry.h" 5 #include "vm/native_entry.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/snapshot.h" 8 #include "vm/snapshot.h"
9 #include "vm/stub_code.h" 9 #include "vm/stub_code.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot); 232 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot);
233 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); 233 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization);
234 234
235 // Set all non object fields. 235 // Set all non object fields.
236 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 236 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
237 type.set_type_state(reader->Read<int8_t>()); 237 type.set_type_state(reader->Read<int8_t>());
238 238
239 // Set all the object fields. 239 // Set all the object fields.
240 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference); 240 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference);
241 241
242 // Read in the type class.
243 (*reader->ClassHandle()) =
244 Class::RawCast(reader->ReadObjectImpl(kAsReference));
245 type.set_type_class(*reader->ClassHandle());
246
242 // Set the canonical bit. 247 // Set the canonical bit.
243 if (!defer_canonicalization && is_canonical) { 248 if (!defer_canonicalization && is_canonical) {
244 type.SetCanonical(); 249 type.SetCanonical();
245 } 250 }
246 251
247 return type.raw(); 252 return type.raw();
248 } 253 }
249 254
250 255
251 void RawType::WriteTo(SnapshotWriter* writer, 256 void RawType::WriteTo(SnapshotWriter* writer,
252 intptr_t object_id, 257 intptr_t object_id,
253 Snapshot::Kind kind, 258 Snapshot::Kind kind,
254 bool as_reference) { 259 bool as_reference) {
255 ASSERT(writer != NULL); 260 ASSERT(writer != NULL);
256 261
257 // Only resolved and finalized types should be written to a snapshot. 262 // Only resolved and finalized types should be written to a snapshot.
258 ASSERT((ptr()->type_state_ == RawType::kFinalizedInstantiated) || 263 ASSERT((ptr()->type_state_ == RawType::kFinalizedInstantiated) ||
259 (ptr()->type_state_ == RawType::kFinalizedUninstantiated)); 264 (ptr()->type_state_ == RawType::kFinalizedUninstantiated));
260 ASSERT(ptr()->type_class_ != Object::null()); 265 ASSERT(ptr()->type_class_id_ != Object::null());
261 266
262 // Write out the serialization header value for this object. 267 // Write out the serialization header value for this object.
263 writer->WriteInlinedObjectHeader(object_id); 268 writer->WriteInlinedObjectHeader(object_id);
264 269
265 // Write out the class and tags information. 270 // Write out the class and tags information.
266 writer->WriteIndexedObject(kTypeCid); 271 writer->WriteIndexedObject(kTypeCid);
267 writer->WriteTags(writer->GetObjectTags(this)); 272 writer->WriteTags(writer->GetObjectTags(this));
268 273
274 // Lookup the type class.
275 RawSmi* raw_type_class_id = Smi::RawCast(ptr()->type_class_id_);
276 RawClass* type_class =
277 writer->isolate()->class_table()->At(Smi::Value(raw_type_class_id));
278
269 // Write out typeclass_is_in_fullsnapshot first as this will 279 // Write out typeclass_is_in_fullsnapshot first as this will
270 // help the reader decide on how to canonicalize the type object. 280 // help the reader decide on how to canonicalize the type object.
271 intptr_t tags = writer->GetObjectTags(ptr()->type_class_); 281 intptr_t tags = writer->GetObjectTags(type_class);
272 bool typeclass_is_in_fullsnapshot = 282 bool typeclass_is_in_fullsnapshot =
273 (ClassIdTag::decode(tags) == kClassCid) && 283 (ClassIdTag::decode(tags) == kClassCid) &&
274 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->type_class_)); 284 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(type_class));
275 writer->Write<bool>(typeclass_is_in_fullsnapshot); 285 writer->Write<bool>(typeclass_is_in_fullsnapshot);
276 286
277 // Write out all the non object pointer fields. 287 // Write out all the non object pointer fields.
278 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 288 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
279 writer->Write<int8_t>(ptr()->type_state_); 289 writer->Write<int8_t>(ptr()->type_state_);
280 290
281 // Write out all the object pointer fields. 291 // Write out all the object pointer fields.
282 ASSERT(ptr()->type_class_ != Object::null()); 292 ASSERT(ptr()->type_class_id_ != Object::null());
283 SnapshotWriterVisitor visitor(writer, kAsReference); 293 SnapshotWriterVisitor visitor(writer, kAsReference);
284 visitor.VisitPointers(from(), to()); 294 visitor.VisitPointers(from(), to());
295
296 // Write out the type class.
297 writer->WriteObjectImpl(type_class, kAsReference);
285 } 298 }
286 299
287 300
288 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, 301 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader,
289 intptr_t object_id, 302 intptr_t object_id,
290 intptr_t tags, 303 intptr_t tags,
291 Snapshot::Kind kind, 304 Snapshot::Kind kind,
292 bool as_reference) { 305 bool as_reference) {
293 ASSERT(reader != NULL); 306 ASSERT(reader != NULL);
294 307
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 type_parameter.set_token_pos( 354 type_parameter.set_token_pos(
342 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 355 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
343 type_parameter.set_index(reader->Read<int16_t>()); 356 type_parameter.set_index(reader->Read<int16_t>());
344 type_parameter.set_type_state(reader->Read<int8_t>()); 357 type_parameter.set_type_state(reader->Read<int8_t>());
345 358
346 // Set all the object fields. 359 // Set all the object fields.
347 READ_OBJECT_FIELDS(type_parameter, 360 READ_OBJECT_FIELDS(type_parameter,
348 type_parameter.raw()->from(), type_parameter.raw()->to(), 361 type_parameter.raw()->from(), type_parameter.raw()->to(),
349 kAsReference); 362 kAsReference);
350 363
364 // Read in the parameterized class.
365 (*reader->ClassHandle()) =
366 Class::RawCast(reader->ReadObjectImpl(kAsReference));
367 type_parameter.set_parameterized_class(*reader->ClassHandle());
368
351 return type_parameter.raw(); 369 return type_parameter.raw();
352 } 370 }
353 371
354 372
355 void RawTypeParameter::WriteTo(SnapshotWriter* writer, 373 void RawTypeParameter::WriteTo(SnapshotWriter* writer,
356 intptr_t object_id, 374 intptr_t object_id,
357 Snapshot::Kind kind, 375 Snapshot::Kind kind,
358 bool as_reference) { 376 bool as_reference) {
359 ASSERT(writer != NULL); 377 ASSERT(writer != NULL);
360 378
361 // Only finalized type parameters should be written to a snapshot. 379 // Only finalized type parameters should be written to a snapshot.
362 ASSERT(ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated); 380 ASSERT(ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated);
363 381
364 // Write out the serialization header value for this object. 382 // Write out the serialization header value for this object.
365 writer->WriteInlinedObjectHeader(object_id); 383 writer->WriteInlinedObjectHeader(object_id);
366 384
367 // Write out the class and tags information. 385 // Write out the class and tags information.
368 writer->WriteIndexedObject(kTypeParameterCid); 386 writer->WriteIndexedObject(kTypeParameterCid);
369 writer->WriteTags(writer->GetObjectTags(this)); 387 writer->WriteTags(writer->GetObjectTags(this));
370 388
371 // Write out all the non object pointer fields. 389 // Write out all the non object pointer fields.
372 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 390 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
373 writer->Write<int16_t>(ptr()->index_); 391 writer->Write<int16_t>(ptr()->index_);
374 writer->Write<int8_t>(ptr()->type_state_); 392 writer->Write<int8_t>(ptr()->type_state_);
375 393
376 // Write out all the object pointer fields. 394 // Write out all the object pointer fields.
377 SnapshotWriterVisitor visitor(writer, kAsReference); 395 SnapshotWriterVisitor visitor(writer, kAsReference);
378 visitor.VisitPointers(from(), to()); 396 visitor.VisitPointers(from(), to());
397
398 // Write out the parameterized class.
399 RawClass* param_class =
400 writer->isolate()->class_table()->At(ptr()->parameterized_class_id_);
401 writer->WriteObjectImpl(param_class, kAsReference);
379 } 402 }
380 403
381 404
382 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader, 405 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader,
383 intptr_t object_id, 406 intptr_t object_id,
384 intptr_t tags, 407 intptr_t tags,
385 Snapshot::Kind kind, 408 Snapshot::Kind kind,
386 bool as_reference) { 409 bool as_reference) {
387 ASSERT(reader != NULL); 410 ASSERT(reader != NULL);
388 411
(...skipping 3367 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 // We do not allow objects with native fields in an isolate message. 3779 // We do not allow objects with native fields in an isolate message.
3757 writer->SetWriteException(Exceptions::kArgument, 3780 writer->SetWriteException(Exceptions::kArgument,
3758 "Illegal argument in isolate message" 3781 "Illegal argument in isolate message"
3759 " : (object is a UserTag)"); 3782 " : (object is a UserTag)");
3760 } else { 3783 } else {
3761 UNREACHABLE(); 3784 UNREACHABLE();
3762 } 3785 }
3763 } 3786 }
3764 3787
3765 } // namespace dart 3788 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698