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

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

Issue 1584223006: Remove signature classes from the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 11 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
« no previous file with comments | « runtime/vm/raw_object.cc ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); 230 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization);
231 231
232 // Set all non object fields. 232 // Set all non object fields.
233 type.set_token_pos(reader->Read<int32_t>()); 233 type.set_token_pos(reader->Read<int32_t>());
234 type.set_type_state(reader->Read<int8_t>()); 234 type.set_type_state(reader->Read<int8_t>());
235 235
236 // Set all the object fields. 236 // Set all the object fields.
237 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference); 237 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference);
238 238
239 // Set the canonical bit. 239 // Set the canonical bit.
240 if (!defer_canonicalization && RawObject::IsCanonical(tags)) { 240 if (!defer_canonicalization && is_canonical) {
241 type.SetCanonical(); 241 type.SetCanonical();
242 } 242 }
243 243
244 return type.raw(); 244 return type.raw();
245 } 245 }
246 246
247 247
248 void RawType::WriteTo(SnapshotWriter* writer, 248 void RawType::WriteTo(SnapshotWriter* writer,
249 intptr_t object_id, 249 intptr_t object_id,
250 Snapshot::Kind kind, 250 Snapshot::Kind kind,
(...skipping 17 matching lines...) Expand all
268 intptr_t tags = writer->GetObjectTags(ptr()->type_class_); 268 intptr_t tags = writer->GetObjectTags(ptr()->type_class_);
269 bool typeclass_is_in_fullsnapshot = 269 bool typeclass_is_in_fullsnapshot =
270 (ClassIdTag::decode(tags) == kClassCid) && 270 (ClassIdTag::decode(tags) == kClassCid) &&
271 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->type_class_)); 271 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->type_class_));
272 writer->Write<bool>(typeclass_is_in_fullsnapshot); 272 writer->Write<bool>(typeclass_is_in_fullsnapshot);
273 273
274 // Write out all the non object pointer fields. 274 // Write out all the non object pointer fields.
275 writer->Write<int32_t>(ptr()->token_pos_); 275 writer->Write<int32_t>(ptr()->token_pos_);
276 writer->Write<int8_t>(ptr()->type_state_); 276 writer->Write<int8_t>(ptr()->type_state_);
277 277
278 // Write out all the object pointer fields. Since we will be canonicalizing 278 // Write out all the object pointer fields.
279 // the type object when reading it back we should write out all the fields
280 // inline and not as references.
281 ASSERT(ptr()->type_class_ != Object::null()); 279 ASSERT(ptr()->type_class_ != Object::null());
282 SnapshotWriterVisitor visitor(writer, kAsReference); 280 SnapshotWriterVisitor visitor(writer, kAsReference);
283 visitor.VisitPointers(from(), to()); 281 visitor.VisitPointers(from(), to());
284 } 282 }
285 283
286 284
285 RawFunctionType* FunctionType::ReadFrom(SnapshotReader* reader,
286 intptr_t object_id,
287 intptr_t tags,
288 Snapshot::Kind kind,
289 bool as_reference) {
290 ASSERT(reader != NULL);
291
292 // Determine if the scope class of this function type is in the full snapshot.
293 bool scopeclass_is_in_fullsnapshot = reader->Read<bool>();
294
295 // Allocate function type object.
296 FunctionType& function_type =
297 FunctionType::ZoneHandle(reader->zone(), NEW_OBJECT(FunctionType));
298 bool is_canonical = RawObject::IsCanonical(tags);
299 bool defer_canonicalization = is_canonical &&
300 (kind != Snapshot::kFull && scopeclass_is_in_fullsnapshot);
301 reader->AddBackRef(object_id,
302 &function_type,
303 kIsDeserialized,
304 defer_canonicalization);
305
306 // Set all non object fields.
307 function_type.set_token_pos(reader->Read<int32_t>());
308 function_type.set_type_state(reader->Read<int8_t>());
309
310 // Set all the object fields.
311 READ_OBJECT_FIELDS(function_type,
312 function_type.raw()->from(), function_type.raw()->to(),
313 kAsReference);
314
315 // Set the canonical bit.
316 if (!defer_canonicalization && is_canonical) {
317 function_type.SetCanonical();
318 }
319
320 return function_type.raw();
321 }
322
323
324 void RawFunctionType::WriteTo(SnapshotWriter* writer,
325 intptr_t object_id,
326 Snapshot::Kind kind,
327 bool as_reference) {
328 ASSERT(writer != NULL);
329
330 // Only resolved and finalized function types should be written to a snapshot.
331 ASSERT((ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) ||
332 (ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated));
333 ASSERT(ptr()->scope_class_ != Object::null());
334
335 // Write out the serialization header value for this object.
336 writer->WriteInlinedObjectHeader(object_id);
337
338 // Write out the class and tags information.
339 writer->WriteIndexedObject(kFunctionTypeCid);
340 writer->WriteTags(writer->GetObjectTags(this));
341
342 // Write out scopeclass_is_in_fullsnapshot first as this will
343 // help the reader decide on how to canonicalize the type object.
344 intptr_t tags = writer->GetObjectTags(ptr()->scope_class_);
345 bool scopeclass_is_in_fullsnapshot =
346 (ClassIdTag::decode(tags) == kClassCid) &&
347 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->scope_class_));
348 writer->Write<bool>(scopeclass_is_in_fullsnapshot);
349
350 // Write out all the non object pointer fields.
351 writer->Write<int32_t>(ptr()->token_pos_);
352 writer->Write<int8_t>(ptr()->type_state_);
353
354 // Write out all the object pointer fields.
355 ASSERT(ptr()->scope_class_ != Object::null());
356 SnapshotWriterVisitor visitor(writer, kAsReference);
357 visitor.VisitPointers(from(), to());
358 }
359
360
287 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, 361 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader,
288 intptr_t object_id, 362 intptr_t object_id,
289 intptr_t tags, 363 intptr_t tags,
290 Snapshot::Kind kind, 364 Snapshot::Kind kind,
291 bool as_reference) { 365 bool as_reference) {
292 ASSERT(reader != NULL); 366 ASSERT(reader != NULL);
293 367
294 // Allocate type ref object. 368 // Allocate type ref object.
295 TypeRef& type_ref = TypeRef::ZoneHandle( 369 TypeRef& type_ref = TypeRef::ZoneHandle(
296 reader->zone(), NEW_OBJECT(TypeRef)); 370 reader->zone(), NEW_OBJECT(TypeRef));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // Now set all the type fields. 539 // Now set all the type fields.
466 intptr_t offset = type_arguments.TypeAddr(0) - 540 intptr_t offset = type_arguments.TypeAddr(0) -
467 reinterpret_cast<RawAbstractType**>(type_arguments.raw()->ptr()); 541 reinterpret_cast<RawAbstractType**>(type_arguments.raw()->ptr());
468 for (intptr_t i = 0; i < len; i++) { 542 for (intptr_t i = 0; i < len; i++) {
469 *reader->TypeHandle() ^= 543 *reader->TypeHandle() ^=
470 reader->ReadObjectImpl(kAsReference, object_id, (i + offset)); 544 reader->ReadObjectImpl(kAsReference, object_id, (i + offset));
471 type_arguments.SetTypeAt(i, *reader->TypeHandle()); 545 type_arguments.SetTypeAt(i, *reader->TypeHandle());
472 } 546 }
473 547
474 // Set the canonical bit. 548 // Set the canonical bit.
475 if (!defer_canonicalization && RawObject::IsCanonical(tags)) { 549 if (!defer_canonicalization && is_canonical) {
476 type_arguments.SetCanonical(); 550 type_arguments.SetCanonical();
477 } 551 }
478 552
479 return type_arguments.raw(); 553 return type_arguments.raw();
480 } 554 }
481 555
482 556
483 void RawTypeArguments::WriteTo(SnapshotWriter* writer, 557 void RawTypeArguments::WriteTo(SnapshotWriter* writer,
484 intptr_t object_id, 558 intptr_t object_id,
485 Snapshot::Kind kind, 559 Snapshot::Kind kind,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 615
542 // Write out the class and tags information. 616 // Write out the class and tags information.
543 writer->WriteVMIsolateObject(kPatchClassCid); 617 writer->WriteVMIsolateObject(kPatchClassCid);
544 writer->WriteTags(writer->GetObjectTags(this)); 618 writer->WriteTags(writer->GetObjectTags(this));
545 // Write out all the object pointer fields. 619 // Write out all the object pointer fields.
546 SnapshotWriterVisitor visitor(writer, kAsReference); 620 SnapshotWriterVisitor visitor(writer, kAsReference);
547 visitor.VisitPointers(from(), to()); 621 visitor.VisitPointers(from(), to());
548 } 622 }
549 623
550 624
625 RawClosure* Closure::ReadFrom(SnapshotReader* reader,
626 intptr_t object_id,
627 intptr_t tags,
628 Snapshot::Kind kind,
629 bool as_reference) {
630 ASSERT(reader != NULL);
631 ASSERT(kind == Snapshot::kFull);
632
633 // Allocate closure object.
634 Closure& closure = Closure::ZoneHandle(
635 reader->zone(), NEW_OBJECT(Closure));
636 reader->AddBackRef(object_id, &closure, kIsDeserialized);
637
638 // Set all the object fields.
639 READ_OBJECT_FIELDS(closure,
640 closure.raw()->from(), closure.raw()->to(),
641 kAsReference);
642
643 return closure.raw();
644 }
645
646
647 void RawClosure::WriteTo(SnapshotWriter* writer,
648 intptr_t object_id,
649 Snapshot::Kind kind,
650 bool as_reference) {
651 ASSERT(writer != NULL);
652 if ((kind == Snapshot::kMessage) || (kind == Snapshot::kScript)) {
653 // Check if closure is serializable, throw an exception otherwise.
654 RawFunction* func = writer->IsSerializableClosure(this);
655 if (func != Function::null()) {
656 writer->WriteStaticImplicitClosure(object_id,
657 func,
658 writer->GetObjectTags(this));
659 return;
660 }
661 }
662
663 // Write out the serialization header value for this object.
664 writer->WriteInlinedObjectHeader(object_id);
665
666 // Write out the class and tags information.
667 writer->WriteIndexedObject(kClosureCid);
668 writer->WriteTags(writer->GetObjectTags(this));
669
670 // Write out all the object pointer fields.
671 SnapshotWriterVisitor visitor(writer, kAsReference);
672 visitor.VisitPointers(from(), to());
673 }
674
675
551 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, 676 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader,
552 intptr_t object_id, 677 intptr_t object_id,
553 intptr_t tags, 678 intptr_t tags,
554 Snapshot::Kind kind, 679 Snapshot::Kind kind,
555 bool as_reference) { 680 bool as_reference) {
556 ASSERT(reader != NULL); 681 ASSERT(reader != NULL);
557 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); 682 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull));
558 683
559 // Allocate closure data object. 684 // Allocate closure data object.
560 ClosureData& data = ClosureData::ZoneHandle( 685 ClosureData& data = ClosureData::ZoneHandle(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); 717 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject);
593 } else { 718 } else {
594 // We don't write non implicit context scopes in the snapshot. 719 // We don't write non implicit context scopes in the snapshot.
595 writer->WriteVMIsolateObject(kNullObject); 720 writer->WriteVMIsolateObject(kNullObject);
596 } 721 }
597 } 722 }
598 723
599 // Parent function. 724 // Parent function.
600 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); 725 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject);
601 726
602 // Signature class. 727 // Signature type.
603 writer->WriteObjectImpl(ptr()->signature_class_, kAsInlinedObject); 728 writer->WriteObjectImpl(ptr()->signature_type_, kAsInlinedObject);
604 729
605 // Static closure/Closure allocation stub. 730 // Static closure/Closure allocation stub.
606 // We don't write the closure or allocation stub in the snapshot. 731 // We don't write the closure or allocation stub in the snapshot.
607 writer->WriteVMIsolateObject(kNullObject); 732 writer->WriteVMIsolateObject(kNullObject);
608 } 733 }
609 734
610 735
611 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, 736 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader,
612 intptr_t object_id, 737 intptr_t object_id,
613 intptr_t tags, 738 intptr_t tags,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 841
717 842
718 void RawFunction::WriteTo(SnapshotWriter* writer, 843 void RawFunction::WriteTo(SnapshotWriter* writer,
719 intptr_t object_id, 844 intptr_t object_id,
720 Snapshot::Kind kind, 845 Snapshot::Kind kind,
721 bool as_reference) { 846 bool as_reference) {
722 ASSERT(writer != NULL); 847 ASSERT(writer != NULL);
723 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); 848 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull));
724 bool is_in_fullsnapshot = false; 849 bool is_in_fullsnapshot = false;
725 bool owner_is_class = false; 850 bool owner_is_class = false;
726 if (kind == Snapshot::kScript) { 851 if ((kind == Snapshot::kScript) && !Function::IsSignatureFunction(this)) {
727 intptr_t tags = writer->GetObjectTags(ptr()->owner_); 852 intptr_t tags = writer->GetObjectTags(ptr()->owner_);
728 intptr_t cid = ClassIdTag::decode(tags); 853 intptr_t cid = ClassIdTag::decode(tags);
729 owner_is_class = (cid == kClassCid); 854 owner_is_class = (cid == kClassCid);
730 is_in_fullsnapshot = owner_is_class ? 855 is_in_fullsnapshot = owner_is_class ?
731 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : 856 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) :
732 PatchClass::IsInFullSnapshot( 857 PatchClass::IsInFullSnapshot(
733 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); 858 reinterpret_cast<RawPatchClass*>(ptr()->owner_));
734 } 859 }
735 860
736 // Write out the serialization header value for this object. 861 // Write out the serialization header value for this object.
(...skipping 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after
3517 // We do not allow objects with native fields in an isolate message. 3642 // We do not allow objects with native fields in an isolate message.
3518 writer->SetWriteException(Exceptions::kArgument, 3643 writer->SetWriteException(Exceptions::kArgument,
3519 "Illegal argument in isolate message" 3644 "Illegal argument in isolate message"
3520 " : (object is a UserTag)"); 3645 " : (object is a UserTag)");
3521 } else { 3646 } else {
3522 UNREACHABLE(); 3647 UNREACHABLE();
3523 } 3648 }
3524 } 3649 }
3525 3650
3526 } // namespace dart 3651 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.cc ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698