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

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

Issue 745203002: - Make array immutable first, then canonicalize it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/snapshot.cc » ('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/object.h" 5 #include "vm/object.h"
6 #include "vm/object_store.h" 6 #include "vm/object_store.h"
7 #include "vm/snapshot.h" 7 #include "vm/snapshot.h"
8 #include "vm/stub_code.h" 8 #include "vm/stub_code.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 #include "vm/visitor.h" 10 #include "vm/visitor.h"
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1749
1750 // Allocate bigint object. 1750 // Allocate bigint object.
1751 Bigint& obj = Bigint::ZoneHandle(reader->isolate(), NEW_OBJECT(Bigint)); 1751 Bigint& obj = Bigint::ZoneHandle(reader->isolate(), NEW_OBJECT(Bigint));
1752 reader->AddBackRef(object_id, &obj, kIsDeserialized); 1752 reader->AddBackRef(object_id, &obj, kIsDeserialized);
1753 1753
1754 // Set all the object fields. 1754 // Set all the object fields.
1755 // TODO(5411462): Need to assert No GC can happen here, even though 1755 // TODO(5411462): Need to assert No GC can happen here, even though
1756 // allocations may happen. 1756 // allocations may happen.
1757 intptr_t num_flds = (obj.raw()->to() - obj.raw()->from()); 1757 intptr_t num_flds = (obj.raw()->to() - obj.raw()->from());
1758 for (intptr_t i = 0; i <= num_flds; i++) { 1758 for (intptr_t i = 0; i <= num_flds; i++) {
1759 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 1759 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl();
1760 obj.StorePointer(obj.raw()->from() + i, 1760 obj.StorePointer(obj.raw()->from() + i,
1761 reader->PassiveObjectHandle()->raw()); 1761 reader->PassiveObjectHandle()->raw());
1762 } 1762 }
1763 1763
1764 // If it is a canonical constant make it one. 1764 // If it is a canonical constant make it one.
1765 // When reading a full snapshot we don't need to canonicalize the object 1765 // When reading a full snapshot we don't need to canonicalize the object
1766 // as it would already be a canonical object. 1766 // as it would already be a canonical object.
1767 // When reading a script snapshot we need to canonicalize only those object 1767 // When reading a script snapshot we need to canonicalize only those object
1768 // references that are objects from the core library (loaded from a 1768 // references that are objects from the core library (loaded from a
1769 // full snapshot). Objects that are only in the script need not be 1769 // full snapshot). Objects that are only in the script need not be
(...skipping 19 matching lines...) Expand all
1789 ASSERT(writer != NULL); 1789 ASSERT(writer != NULL);
1790 1790
1791 // Write out the serialization header value for this object. 1791 // Write out the serialization header value for this object.
1792 writer->WriteInlinedObjectHeader(object_id); 1792 writer->WriteInlinedObjectHeader(object_id);
1793 1793
1794 // Write out the class and tags information. 1794 // Write out the class and tags information.
1795 writer->WriteIndexedObject(kBigintCid); 1795 writer->WriteIndexedObject(kBigintCid);
1796 writer->WriteTags(writer->GetObjectTags(this)); 1796 writer->WriteTags(writer->GetObjectTags(this));
1797 1797
1798 // Write out all the object pointer fields. 1798 // Write out all the object pointer fields.
1799 SnapshotWriterVisitor visitor(writer); 1799 SnapshotWriterVisitor visitor(writer, false);
1800 visitor.VisitPointers(from(), to()); 1800 visitor.VisitPointers(from(), to());
1801 } 1801 }
1802 1802
1803 1803
1804 RawDouble* Double::ReadFrom(SnapshotReader* reader, 1804 RawDouble* Double::ReadFrom(SnapshotReader* reader,
1805 intptr_t object_id, 1805 intptr_t object_id,
1806 intptr_t tags, 1806 intptr_t tags,
1807 Snapshot::Kind kind) { 1807 Snapshot::Kind kind) {
1808 ASSERT(reader != NULL); 1808 ASSERT(reader != NULL);
1809 ASSERT(kind != Snapshot::kMessage); 1809 ASSERT(kind != Snapshot::kMessage);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 2101
2102 // Read the length so that we can determine instance size to allocate. 2102 // Read the length so that we can determine instance size to allocate.
2103 intptr_t len = reader->ReadSmiValue(); 2103 intptr_t len = reader->ReadSmiValue();
2104 Array* array = reinterpret_cast<Array*>( 2104 Array* array = reinterpret_cast<Array*>(
2105 reader->GetBackRef(object_id)); 2105 reader->GetBackRef(object_id));
2106 if (array == NULL) { 2106 if (array == NULL) {
2107 array = &(Array::ZoneHandle(reader->isolate(), 2107 array = &(Array::ZoneHandle(reader->isolate(),
2108 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); 2108 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind)));
2109 reader->AddBackRef(object_id, array, kIsDeserialized); 2109 reader->AddBackRef(object_id, array, kIsDeserialized);
2110 } 2110 }
2111 ASSERT(!RawObject::IsCanonical(tags));
2111 reader->ArrayReadFrom(*array, len, tags); 2112 reader->ArrayReadFrom(*array, len, tags);
2112 return array->raw(); 2113 return array->raw();
2113 } 2114 }
2114 2115
2115 2116
2116 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, 2117 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader,
2117 intptr_t object_id, 2118 intptr_t object_id,
2118 intptr_t tags, 2119 intptr_t tags,
2119 Snapshot::Kind kind) { 2120 Snapshot::Kind kind) {
2120 ASSERT(reader != NULL); 2121 ASSERT(reader != NULL);
2121 2122
2122 // Read the length so that we can determine instance size to allocate. 2123 // Read the length so that we can determine instance size to allocate.
2123 intptr_t len = reader->ReadSmiValue(); 2124 intptr_t len = reader->ReadSmiValue();
2124 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); 2125 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id));
2125 if (array == NULL) { 2126 if (array == NULL) {
2126 array = &(Array::ZoneHandle( 2127 array = &(Array::ZoneHandle(
2127 reader->isolate(), 2128 reader->isolate(),
2128 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); 2129 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind)));
2129 reader->AddBackRef(object_id, array, kIsDeserialized); 2130 reader->AddBackRef(object_id, array, kIsDeserialized);
2130 } 2131 }
2131 reader->ArrayReadFrom(*array, len, tags); 2132 reader->ArrayReadFrom(*array, len, tags);
2133 if (RawObject::IsCanonical(tags)) {
2134 *array ^= array->CheckAndCanonicalize(NULL);
2135 }
2132 return raw(*array); 2136 return raw(*array);
2133 } 2137 }
2134 2138
2135 2139
2136 void RawArray::WriteTo(SnapshotWriter* writer, 2140 void RawArray::WriteTo(SnapshotWriter* writer,
2137 intptr_t object_id, 2141 intptr_t object_id,
2138 Snapshot::Kind kind) { 2142 Snapshot::Kind kind) {
2143 ASSERT(!RawObject::IsCanonical(writer->GetObjectTags(this)));
2139 writer->ArrayWriteTo(object_id, 2144 writer->ArrayWriteTo(object_id,
2140 kArrayCid, 2145 kArrayCid,
2141 writer->GetObjectTags(this), 2146 writer->GetObjectTags(this),
2142 ptr()->length_, 2147 ptr()->length_,
2143 ptr()->type_arguments_, 2148 ptr()->type_arguments_,
2144 ptr()->data()); 2149 ptr()->data());
2145 } 2150 }
2146 2151
2147 2152
2148 void RawImmutableArray::WriteTo(SnapshotWriter* writer, 2153 void RawImmutableArray::WriteTo(SnapshotWriter* writer,
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 // We do not allow objects with native fields in an isolate message. 2887 // We do not allow objects with native fields in an isolate message.
2883 writer->SetWriteException(Exceptions::kArgument, 2888 writer->SetWriteException(Exceptions::kArgument,
2884 "Illegal argument in isolate message" 2889 "Illegal argument in isolate message"
2885 " : (object is a UserTag)"); 2890 " : (object is a UserTag)");
2886 } else { 2891 } else {
2887 UNREACHABLE(); 2892 UNREACHABLE();
2888 } 2893 }
2889 } 2894 }
2890 2895
2891 } // namespace dart 2896 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698