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

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

Issue 333773006: Removes open arrays (e.g. data[0]) from raw objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.cc ('k') | no next file » | 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/bigint_operations.h" 5 #include "vm/bigint_operations.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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 writer->Write<RawObject*>(ptr()->length_); 503 writer->Write<RawObject*>(ptr()->length_);
504 504
505 // Write out the instantiations field, but only in a full snapshot. 505 // Write out the instantiations field, but only in a full snapshot.
506 if (kind == Snapshot::kFull) { 506 if (kind == Snapshot::kFull) {
507 writer->WriteObjectImpl(ptr()->instantiations_); 507 writer->WriteObjectImpl(ptr()->instantiations_);
508 } 508 }
509 509
510 // Write out the individual types. 510 // Write out the individual types.
511 intptr_t len = Smi::Value(ptr()->length_); 511 intptr_t len = Smi::Value(ptr()->length_);
512 for (intptr_t i = 0; i < len; i++) { 512 for (intptr_t i = 0; i < len; i++) {
513 writer->WriteObjectImpl(ptr()->types_[i]); 513 writer->WriteObjectImpl(ptr()->types()[i]);
514 } 514 }
515 } 515 }
516 516
517 517
518 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, 518 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader,
519 intptr_t object_id, 519 intptr_t object_id,
520 intptr_t tags, 520 intptr_t tags,
521 Snapshot::Kind kind) { 521 Snapshot::Kind kind) {
522 ASSERT(reader != NULL); 522 ASSERT(reader != NULL);
523 ASSERT(((kind == Snapshot::kScript) && 523 ASSERT(((kind == Snapshot::kScript) &&
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 func.set_num_fixed_parameters(reader->Read<int16_t>()); 698 func.set_num_fixed_parameters(reader->Read<int16_t>());
699 func.set_num_optional_parameters(reader->Read<int16_t>()); 699 func.set_num_optional_parameters(reader->Read<int16_t>());
700 func.set_deoptimization_counter(reader->Read<int16_t>()); 700 func.set_deoptimization_counter(reader->Read<int16_t>());
701 func.set_kind_tag(reader->Read<uint16_t>()); 701 func.set_kind_tag(reader->Read<uint16_t>());
702 func.set_optimized_instruction_count(reader->Read<uint16_t>()); 702 func.set_optimized_instruction_count(reader->Read<uint16_t>());
703 func.set_optimized_call_site_count(reader->Read<uint16_t>()); 703 func.set_optimized_call_site_count(reader->Read<uint16_t>());
704 704
705 // Set all the object fields. 705 // Set all the object fields.
706 // TODO(5411462): Need to assert No GC can happen here, even though 706 // TODO(5411462): Need to assert No GC can happen here, even though
707 // allocations may happen. 707 // allocations may happen.
708 intptr_t num_flds = (func.raw()->to() - func.raw()->from()); 708 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from());
709 for (intptr_t i = 0; i <= num_flds; i++) { 709 for (intptr_t i = 0; i <= num_flds; i++) {
710 *(func.raw()->from() + i) = reader->ReadObjectRef(); 710 *(func.raw()->from() + i) = reader->ReadObjectRef();
711 } 711 }
712 712
713 // Set up code pointer with the lazy-compile-stub. 713 // Initialize all fields that are not part of the snapshot.
714 func.SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); 714 func.ClearCode();
715 715
716 return func.raw(); 716 return func.raw();
717 } 717 }
718 718
719 719
720 void RawFunction::WriteTo(SnapshotWriter* writer, 720 void RawFunction::WriteTo(SnapshotWriter* writer,
721 intptr_t object_id, 721 intptr_t object_id,
722 Snapshot::Kind kind) { 722 Snapshot::Kind kind) {
723 ASSERT(writer != NULL); 723 ASSERT(writer != NULL);
724 ASSERT(((kind == Snapshot::kScript) && 724 ASSERT(((kind == Snapshot::kScript) &&
(...skipping 13 matching lines...) Expand all
738 writer->Write<int32_t>(ptr()->usage_counter_); 738 writer->Write<int32_t>(ptr()->usage_counter_);
739 writer->Write<int16_t>(ptr()->num_fixed_parameters_); 739 writer->Write<int16_t>(ptr()->num_fixed_parameters_);
740 writer->Write<int16_t>(ptr()->num_optional_parameters_); 740 writer->Write<int16_t>(ptr()->num_optional_parameters_);
741 writer->Write<int16_t>(ptr()->deoptimization_counter_); 741 writer->Write<int16_t>(ptr()->deoptimization_counter_);
742 writer->Write<uint16_t>(ptr()->kind_tag_); 742 writer->Write<uint16_t>(ptr()->kind_tag_);
743 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); 743 writer->Write<uint16_t>(ptr()->optimized_instruction_count_);
744 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); 744 writer->Write<uint16_t>(ptr()->optimized_call_site_count_);
745 745
746 // Write out all the object pointer fields. 746 // Write out all the object pointer fields.
747 SnapshotWriterVisitor visitor(writer); 747 SnapshotWriterVisitor visitor(writer);
748 visitor.VisitPointers(from(), to_no_code()); 748 visitor.VisitPointers(from(), to_snapshot());
749
750 // Write null for the instructions and unoptimized code.
751 writer->WriteVMIsolateObject(kNullObject);
752 writer->WriteVMIsolateObject(kNullObject);
753 } 749 }
754 750
755 751
756 RawField* Field::ReadFrom(SnapshotReader* reader, 752 RawField* Field::ReadFrom(SnapshotReader* reader,
757 intptr_t object_id, 753 intptr_t object_id,
758 intptr_t tags, 754 intptr_t tags,
759 Snapshot::Kind kind) { 755 Snapshot::Kind kind) {
760 ASSERT(reader != NULL); 756 ASSERT(reader != NULL);
761 ASSERT(((kind == Snapshot::kScript) && 757 ASSERT(((kind == Snapshot::kScript) &&
762 !RawObject::IsCreatedFromSnapshot(tags)) || 758 !RawObject::IsCreatedFromSnapshot(tags)) ||
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 void RawOneByteString::WriteTo(SnapshotWriter* writer, 1970 void RawOneByteString::WriteTo(SnapshotWriter* writer,
1975 intptr_t object_id, 1971 intptr_t object_id,
1976 Snapshot::Kind kind) { 1972 Snapshot::Kind kind) {
1977 StringWriteTo(writer, 1973 StringWriteTo(writer,
1978 object_id, 1974 object_id,
1979 kind, 1975 kind,
1980 kOneByteStringCid, 1976 kOneByteStringCid,
1981 writer->GetObjectTags(this), 1977 writer->GetObjectTags(this),
1982 ptr()->length_, 1978 ptr()->length_,
1983 ptr()->hash_, 1979 ptr()->hash_,
1984 ptr()->data_); 1980 ptr()->data());
1985 } 1981 }
1986 1982
1987 1983
1988 void RawTwoByteString::WriteTo(SnapshotWriter* writer, 1984 void RawTwoByteString::WriteTo(SnapshotWriter* writer,
1989 intptr_t object_id, 1985 intptr_t object_id,
1990 Snapshot::Kind kind) { 1986 Snapshot::Kind kind) {
1991 StringWriteTo(writer, 1987 StringWriteTo(writer,
1992 object_id, 1988 object_id,
1993 kind, 1989 kind,
1994 kTwoByteStringCid, 1990 kTwoByteStringCid,
1995 writer->GetObjectTags(this), 1991 writer->GetObjectTags(this),
1996 ptr()->length_, 1992 ptr()->length_,
1997 ptr()->hash_, 1993 ptr()->hash_,
1998 ptr()->data_); 1994 ptr()->data());
1999 } 1995 }
2000 1996
2001 1997
2002 RawExternalOneByteString* ExternalOneByteString::ReadFrom( 1998 RawExternalOneByteString* ExternalOneByteString::ReadFrom(
2003 SnapshotReader* reader, 1999 SnapshotReader* reader,
2004 intptr_t object_id, 2000 intptr_t object_id,
2005 intptr_t tags, 2001 intptr_t tags,
2006 Snapshot::Kind kind) { 2002 Snapshot::Kind kind) {
2007 UNREACHABLE(); 2003 UNREACHABLE();
2008 return ExternalOneByteString::null(); 2004 return ExternalOneByteString::null();
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 Dart_WeakPersistentHandleFinalizer callback = 2384 Dart_WeakPersistentHandleFinalizer callback =
2389 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( 2385 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>(
2390 reader->ReadRawPointerValue()); 2386 reader->ReadRawPointerValue());
2391 obj.AddFinalizer(peer, callback); 2387 obj.AddFinalizer(peer, callback);
2392 return obj.raw(); 2388 return obj.raw();
2393 } 2389 }
2394 2390
2395 2391
2396 #define TYPED_DATA_WRITE(type) \ 2392 #define TYPED_DATA_WRITE(type) \
2397 { \ 2393 { \
2398 type* data = reinterpret_cast<type*>(ptr()->data_); \ 2394 type* data = reinterpret_cast<type*>(ptr()->data()); \
2399 for (intptr_t i = 0; i < len; i++) { \ 2395 for (intptr_t i = 0; i < len; i++) { \
2400 writer->Write(data[i]); \ 2396 writer->Write(data[i]); \
2401 } \ 2397 } \
2402 } \ 2398 } \
2403 2399
2404 2400
2405 void RawTypedData::WriteTo(SnapshotWriter* writer, 2401 void RawTypedData::WriteTo(SnapshotWriter* writer,
2406 intptr_t object_id, 2402 intptr_t object_id,
2407 Snapshot::Kind kind) { 2403 Snapshot::Kind kind) {
2408 ASSERT(writer != NULL); 2404 ASSERT(writer != NULL);
2409 intptr_t tags = writer->GetObjectTags(this); 2405 intptr_t tags = writer->GetObjectTags(this);
2410 intptr_t cid = ClassIdTag::decode(tags); 2406 intptr_t cid = ClassIdTag::decode(tags);
2411 intptr_t len = Smi::Value(ptr()->length_); 2407 intptr_t len = Smi::Value(ptr()->length_);
2412 2408
2413 // Write out the serialization header value for this object. 2409 // Write out the serialization header value for this object.
2414 writer->WriteInlinedObjectHeader(object_id); 2410 writer->WriteInlinedObjectHeader(object_id);
2415 2411
2416 // Write out the class and tags information. 2412 // Write out the class and tags information.
2417 writer->WriteIndexedObject(cid); 2413 writer->WriteIndexedObject(cid);
2418 writer->WriteIntptrValue(tags); 2414 writer->WriteIntptrValue(tags);
2419 2415
2420 // Write out the length field. 2416 // Write out the length field.
2421 writer->Write<RawObject*>(ptr()->length_); 2417 writer->Write<RawObject*>(ptr()->length_);
2422 2418
2423 // Write out the array elements. 2419 // Write out the array elements.
2424 switch (cid) { 2420 switch (cid) {
2425 case kTypedDataInt8ArrayCid: 2421 case kTypedDataInt8ArrayCid:
2426 case kTypedDataUint8ArrayCid: 2422 case kTypedDataUint8ArrayCid:
2427 case kTypedDataUint8ClampedArrayCid: { 2423 case kTypedDataUint8ClampedArrayCid: {
2428 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data_); 2424 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
2429 writer->WriteBytes(data, len); 2425 writer->WriteBytes(data, len);
2430 break; 2426 break;
2431 } 2427 }
2432 case kTypedDataInt16ArrayCid: 2428 case kTypedDataInt16ArrayCid:
2433 TYPED_DATA_WRITE(int16_t); 2429 TYPED_DATA_WRITE(int16_t);
2434 break; 2430 break;
2435 case kTypedDataUint16ArrayCid: 2431 case kTypedDataUint16ArrayCid:
2436 TYPED_DATA_WRITE(uint16_t); 2432 TYPED_DATA_WRITE(uint16_t);
2437 break; 2433 break;
2438 case kTypedDataInt32ArrayCid: 2434 case kTypedDataInt32ArrayCid:
(...skipping 13 matching lines...) Expand all
2452 break; 2448 break;
2453 case kTypedDataFloat64ArrayCid: 2449 case kTypedDataFloat64ArrayCid:
2454 TYPED_DATA_WRITE(double); // NOLINT. 2450 TYPED_DATA_WRITE(double); // NOLINT.
2455 break; 2451 break;
2456 default: 2452 default:
2457 UNREACHABLE(); 2453 UNREACHABLE();
2458 } 2454 }
2459 } 2455 }
2460 2456
2461 2457
2458 #define TYPED_EXT_DATA_WRITE(type) \
2459 { \
2460 type* data = reinterpret_cast<type*>(ptr()->data_); \
2461 for (intptr_t i = 0; i < len; i++) { \
2462 writer->Write(data[i]); \
2463 } \
2464 } \
2465
2466
2462 #define EXT_TYPED_DATA_WRITE(cid, type) \ 2467 #define EXT_TYPED_DATA_WRITE(cid, type) \
2463 writer->WriteIndexedObject(cid); \ 2468 writer->WriteIndexedObject(cid); \
2464 writer->WriteIntptrValue(RawObject::ClassIdTag::update(cid, tags)); \ 2469 writer->WriteIntptrValue(RawObject::ClassIdTag::update(cid, tags)); \
2465 writer->Write<RawObject*>(ptr()->length_); \ 2470 writer->Write<RawObject*>(ptr()->length_); \
2466 TYPED_DATA_WRITE(type) \ 2471 TYPED_EXT_DATA_WRITE(type) \
2467 2472
2468 2473
2469 void RawExternalTypedData::WriteTo(SnapshotWriter* writer, 2474 void RawExternalTypedData::WriteTo(SnapshotWriter* writer,
2470 intptr_t object_id, 2475 intptr_t object_id,
2471 Snapshot::Kind kind) { 2476 Snapshot::Kind kind) {
2472 ASSERT(writer != NULL); 2477 ASSERT(writer != NULL);
2473 intptr_t tags = writer->GetObjectTags(this); 2478 intptr_t tags = writer->GetObjectTags(this);
2474 intptr_t cid = ClassIdTag::decode(tags); 2479 intptr_t cid = ClassIdTag::decode(tags);
2475 intptr_t len = Smi::Value(ptr()->length_); 2480 intptr_t len = Smi::Value(ptr()->length_);
2476 2481
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 // We do not allow objects with native fields in an isolate message. 2788 // We do not allow objects with native fields in an isolate message.
2784 writer->SetWriteException(Exceptions::kArgument, 2789 writer->SetWriteException(Exceptions::kArgument,
2785 "Illegal argument in isolate message" 2790 "Illegal argument in isolate message"
2786 " : (object is a UserTag)"); 2791 " : (object is a UserTag)");
2787 } else { 2792 } else {
2788 UNREACHABLE(); 2793 UNREACHABLE();
2789 } 2794 }
2790 } 2795 }
2791 2796
2792 } // namespace dart 2797 } // namespace dart
OLDNEW
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698