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

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"
11 #include "vm/visitor.h" 11 #include "vm/visitor.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DECLARE_FLAG(bool, remove_script_timestamps_for_test);
16
15 #define NEW_OBJECT(type) \ 17 #define NEW_OBJECT(type) \
16 ((Snapshot::IsFull(kind)) ? reader->New##type() : type::New()) 18 ((Snapshot::IsFull(kind)) ? reader->New##type() : type::New())
17 19
18 #define NEW_OBJECT_WITH_LEN(type, len) \ 20 #define NEW_OBJECT_WITH_LEN(type, len) \
19 ((Snapshot::IsFull(kind)) ? reader->New##type(len) : type::New(len)) 21 ((Snapshot::IsFull(kind)) ? reader->New##type(len) : type::New(len))
20 22
21 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ 23 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \
22 ((Snapshot::IsFull(kind)) ? \ 24 ((Snapshot::IsFull(kind)) ? \
23 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) 25 reader->New##type(len) : type::New(len, HEAP_SPACE(kind)))
24 26
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot); 234 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot);
233 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); 235 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization);
234 236
235 // Set all non object fields. 237 // Set all non object fields.
236 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 238 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
237 type.set_type_state(reader->Read<int8_t>()); 239 type.set_type_state(reader->Read<int8_t>());
238 240
239 // Set all the object fields. 241 // Set all the object fields.
240 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference); 242 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference);
241 243
244 // Read in the type class.
245 (*reader->ClassHandle()) =
246 Class::RawCast(reader->ReadObjectImpl(kAsReference));
247 type.set_type_class(*reader->ClassHandle());
248
242 // Set the canonical bit. 249 // Set the canonical bit.
243 if (!defer_canonicalization && is_canonical) { 250 if (!defer_canonicalization && is_canonical) {
244 type.SetCanonical(); 251 type.SetCanonical();
245 } 252 }
246 253
247 return type.raw(); 254 return type.raw();
248 } 255 }
249 256
250 257
251 void RawType::WriteTo(SnapshotWriter* writer, 258 void RawType::WriteTo(SnapshotWriter* writer,
252 intptr_t object_id, 259 intptr_t object_id,
253 Snapshot::Kind kind, 260 Snapshot::Kind kind,
254 bool as_reference) { 261 bool as_reference) {
255 ASSERT(writer != NULL); 262 ASSERT(writer != NULL);
256 263
257 // Only resolved and finalized types should be written to a snapshot. 264 // Only resolved and finalized types should be written to a snapshot.
258 ASSERT((ptr()->type_state_ == RawType::kFinalizedInstantiated) || 265 ASSERT((ptr()->type_state_ == RawType::kFinalizedInstantiated) ||
259 (ptr()->type_state_ == RawType::kFinalizedUninstantiated)); 266 (ptr()->type_state_ == RawType::kFinalizedUninstantiated));
260 ASSERT(ptr()->type_class_ != Object::null()); 267 ASSERT(ptr()->type_class_id_ != Object::null());
261 268
262 // Write out the serialization header value for this object. 269 // Write out the serialization header value for this object.
263 writer->WriteInlinedObjectHeader(object_id); 270 writer->WriteInlinedObjectHeader(object_id);
264 271
265 // Write out the class and tags information. 272 // Write out the class and tags information.
266 writer->WriteIndexedObject(kTypeCid); 273 writer->WriteIndexedObject(kTypeCid);
267 writer->WriteTags(writer->GetObjectTags(this)); 274 writer->WriteTags(writer->GetObjectTags(this));
268 275
276 // Lookup the type class.
277 RawSmi* raw_type_class_id = Smi::RawCast(ptr()->type_class_id_);
278 RawClass* type_class =
279 writer->isolate()->class_table()->At(Smi::Value(raw_type_class_id));
280
269 // Write out typeclass_is_in_fullsnapshot first as this will 281 // Write out typeclass_is_in_fullsnapshot first as this will
270 // help the reader decide on how to canonicalize the type object. 282 // help the reader decide on how to canonicalize the type object.
271 intptr_t tags = writer->GetObjectTags(ptr()->type_class_); 283 intptr_t tags = writer->GetObjectTags(type_class);
272 bool typeclass_is_in_fullsnapshot = 284 bool typeclass_is_in_fullsnapshot =
273 (ClassIdTag::decode(tags) == kClassCid) && 285 (ClassIdTag::decode(tags) == kClassCid) &&
274 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->type_class_)); 286 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(type_class));
275 writer->Write<bool>(typeclass_is_in_fullsnapshot); 287 writer->Write<bool>(typeclass_is_in_fullsnapshot);
276 288
277 // Write out all the non object pointer fields. 289 // Write out all the non object pointer fields.
278 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 290 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
279 writer->Write<int8_t>(ptr()->type_state_); 291 writer->Write<int8_t>(ptr()->type_state_);
280 292
281 // Write out all the object pointer fields. 293 // Write out all the object pointer fields.
282 ASSERT(ptr()->type_class_ != Object::null()); 294 ASSERT(ptr()->type_class_id_ != Object::null());
283 SnapshotWriterVisitor visitor(writer, kAsReference); 295 SnapshotWriterVisitor visitor(writer, kAsReference);
284 visitor.VisitPointers(from(), to()); 296 visitor.VisitPointers(from(), to());
297
298 // Write out the type class.
299 writer->WriteObjectImpl(type_class, kAsReference);
285 } 300 }
286 301
287 302
288 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, 303 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader,
289 intptr_t object_id, 304 intptr_t object_id,
290 intptr_t tags, 305 intptr_t tags,
291 Snapshot::Kind kind, 306 Snapshot::Kind kind,
292 bool as_reference) { 307 bool as_reference) {
293 ASSERT(reader != NULL); 308 ASSERT(reader != NULL);
294 309
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 type_parameter.set_token_pos( 356 type_parameter.set_token_pos(
342 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 357 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
343 type_parameter.set_index(reader->Read<int16_t>()); 358 type_parameter.set_index(reader->Read<int16_t>());
344 type_parameter.set_type_state(reader->Read<int8_t>()); 359 type_parameter.set_type_state(reader->Read<int8_t>());
345 360
346 // Set all the object fields. 361 // Set all the object fields.
347 READ_OBJECT_FIELDS(type_parameter, 362 READ_OBJECT_FIELDS(type_parameter,
348 type_parameter.raw()->from(), type_parameter.raw()->to(), 363 type_parameter.raw()->from(), type_parameter.raw()->to(),
349 kAsReference); 364 kAsReference);
350 365
366 // Read in the parameterized class.
367 (*reader->ClassHandle()) =
368 Class::RawCast(reader->ReadObjectImpl(kAsReference));
369 type_parameter.set_parameterized_class(*reader->ClassHandle());
370
351 return type_parameter.raw(); 371 return type_parameter.raw();
352 } 372 }
353 373
354 374
355 void RawTypeParameter::WriteTo(SnapshotWriter* writer, 375 void RawTypeParameter::WriteTo(SnapshotWriter* writer,
356 intptr_t object_id, 376 intptr_t object_id,
357 Snapshot::Kind kind, 377 Snapshot::Kind kind,
358 bool as_reference) { 378 bool as_reference) {
359 ASSERT(writer != NULL); 379 ASSERT(writer != NULL);
360 380
361 // Only finalized type parameters should be written to a snapshot. 381 // Only finalized type parameters should be written to a snapshot.
362 ASSERT(ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated); 382 ASSERT(ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated);
363 383
364 // Write out the serialization header value for this object. 384 // Write out the serialization header value for this object.
365 writer->WriteInlinedObjectHeader(object_id); 385 writer->WriteInlinedObjectHeader(object_id);
366 386
367 // Write out the class and tags information. 387 // Write out the class and tags information.
368 writer->WriteIndexedObject(kTypeParameterCid); 388 writer->WriteIndexedObject(kTypeParameterCid);
369 writer->WriteTags(writer->GetObjectTags(this)); 389 writer->WriteTags(writer->GetObjectTags(this));
370 390
371 // Write out all the non object pointer fields. 391 // Write out all the non object pointer fields.
372 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 392 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
373 writer->Write<int16_t>(ptr()->index_); 393 writer->Write<int16_t>(ptr()->index_);
374 writer->Write<int8_t>(ptr()->type_state_); 394 writer->Write<int8_t>(ptr()->type_state_);
375 395
376 // Write out all the object pointer fields. 396 // Write out all the object pointer fields.
377 SnapshotWriterVisitor visitor(writer, kAsReference); 397 SnapshotWriterVisitor visitor(writer, kAsReference);
378 visitor.VisitPointers(from(), to()); 398 visitor.VisitPointers(from(), to());
399
400 // Write out the parameterized class.
401 RawClass* param_class =
402 writer->isolate()->class_table()->At(ptr()->parameterized_class_id_);
403 writer->WriteObjectImpl(param_class, kAsReference);
379 } 404 }
380 405
381 406
382 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader, 407 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader,
383 intptr_t object_id, 408 intptr_t object_id,
384 intptr_t tags, 409 intptr_t tags,
385 Snapshot::Kind kind, 410 Snapshot::Kind kind,
386 bool as_reference) { 411 bool as_reference) {
387 ASSERT(reader != NULL); 412 ASSERT(reader != NULL);
388 413
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 // Set all the object fields. 1119 // Set all the object fields.
1095 // TODO(5411462): Need to assert No GC can happen here, even though 1120 // TODO(5411462): Need to assert No GC can happen here, even though
1096 // allocations may happen. 1121 // allocations may happen.
1097 intptr_t num_flds = (script.raw()->to_snapshot(kind) - script.raw()->from()); 1122 intptr_t num_flds = (script.raw()->to_snapshot(kind) - script.raw()->from());
1098 for (intptr_t i = 0; i <= num_flds; i++) { 1123 for (intptr_t i = 0; i <= num_flds; i++) {
1099 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); 1124 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1100 script.StorePointer((script.raw()->from() + i), 1125 script.StorePointer((script.raw()->from() + i),
1101 reader->PassiveObjectHandle()->raw()); 1126 reader->PassiveObjectHandle()->raw());
1102 } 1127 }
1103 1128
1129 script.set_load_timestamp(FLAG_remove_script_timestamps_for_test
1130 ? 0 : OS::GetCurrentTimeMillis());
1131
1104 return script.raw(); 1132 return script.raw();
1105 } 1133 }
1106 1134
1107 1135
1108 void RawScript::WriteTo(SnapshotWriter* writer, 1136 void RawScript::WriteTo(SnapshotWriter* writer,
1109 intptr_t object_id, 1137 intptr_t object_id,
1110 Snapshot::Kind kind, 1138 Snapshot::Kind kind,
1111 bool as_reference) { 1139 bool as_reference) {
1112 ASSERT(writer != NULL); 1140 ASSERT(writer != NULL);
1113 ASSERT(tokens_ != TokenStream::null()); 1141 ASSERT(tokens_ != TokenStream::null());
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 // We do not allow objects with native fields in an isolate message. 3784 // We do not allow objects with native fields in an isolate message.
3757 writer->SetWriteException(Exceptions::kArgument, 3785 writer->SetWriteException(Exceptions::kArgument,
3758 "Illegal argument in isolate message" 3786 "Illegal argument in isolate message"
3759 " : (object is a UserTag)"); 3787 " : (object is a UserTag)");
3760 } else { 3788 } else {
3761 UNREACHABLE(); 3789 UNREACHABLE();
3762 } 3790 }
3763 } 3791 }
3764 3792
3765 } // namespace dart 3793 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698