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

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

Issue 380333002: Add VM class for Map/LinkedHashMap. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 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
« 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/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 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( 2156 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle(
2157 reader->isolate(), GrowableObjectArray::null()); 2157 reader->isolate(), GrowableObjectArray::null());
2158 if (kind == Snapshot::kFull) { 2158 if (kind == Snapshot::kFull) {
2159 array = reader->NewGrowableObjectArray(); 2159 array = reader->NewGrowableObjectArray();
2160 } else { 2160 } else {
2161 array = GrowableObjectArray::New(0, HEAP_SPACE(kind)); 2161 array = GrowableObjectArray::New(0, HEAP_SPACE(kind));
2162 } 2162 }
2163 reader->AddBackRef(object_id, &array, kIsDeserialized); 2163 reader->AddBackRef(object_id, &array, kIsDeserialized);
2164 intptr_t length = reader->ReadSmiValue(); 2164 intptr_t length = reader->ReadSmiValue();
2165 array.SetLength(length); 2165 array.SetLength(length);
2166 Array& contents = Array::Handle(); 2166 Array& contents = Array::Handle(reader->isolate());
2167 contents ^= reader->ReadObjectImpl(); 2167 contents ^= reader->ReadObjectImpl();
2168 array.SetData(contents); 2168 array.SetData(contents);
2169 const TypeArguments& type_arguments = 2169 const TypeArguments& type_arguments =
2170 TypeArguments::Handle(contents.GetTypeArguments()); 2170 TypeArguments::Handle(reader->isolate(), contents.GetTypeArguments());
2171 array.SetTypeArguments(type_arguments); 2171 array.SetTypeArguments(type_arguments);
2172 return array.raw(); 2172 return array.raw();
2173 } 2173 }
2174 2174
2175 2175
2176 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer, 2176 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer,
2177 intptr_t object_id, 2177 intptr_t object_id,
2178 Snapshot::Kind kind) { 2178 Snapshot::Kind kind) {
2179 ASSERT(writer != NULL); 2179 ASSERT(writer != NULL);
2180 2180
2181 // Write out the serialization header value for this object. 2181 // Write out the serialization header value for this object.
2182 writer->WriteInlinedObjectHeader(object_id); 2182 writer->WriteInlinedObjectHeader(object_id);
2183 2183
2184 // Write out the class and tags information. 2184 // Write out the class and tags information.
2185 writer->WriteIndexedObject(kGrowableObjectArrayCid); 2185 writer->WriteIndexedObject(kGrowableObjectArrayCid);
2186 writer->WriteTags(writer->GetObjectTags(this)); 2186 writer->WriteTags(writer->GetObjectTags(this));
2187 2187
2188 // Write out the used length field. 2188 // Write out the used length field.
2189 writer->Write<RawObject*>(ptr()->length_); 2189 writer->Write<RawObject*>(ptr()->length_);
2190 2190
2191 // Write out the Array object. 2191 // Write out the Array object.
2192 writer->WriteObjectImpl(ptr()->data_); 2192 writer->WriteObjectImpl(ptr()->data_);
2193 } 2193 }
2194 2194
2195 2195
2196 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
2197 intptr_t object_id,
2198 intptr_t tags,
2199 Snapshot::Kind kind) {
2200 ASSERT(reader != NULL);
2201
2202 LinkedHashMap& map = LinkedHashMap::ZoneHandle(
2203 reader->isolate(), LinkedHashMap::null());
2204 if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
2205 // The immutable maps that seed map literals are not yet VM-internal, so
2206 // we don't reach this.
2207 UNREACHABLE();
2208 } else {
2209 map = LinkedHashMap::New(HEAP_SPACE(kind));
2210 }
2211 reader->AddBackRef(object_id, &map, kIsDeserialized);
2212 Array& contents = Array::Handle(reader->isolate());
2213 contents ^= reader->ReadObjectImpl();
2214 map.SetData(contents);
2215 const TypeArguments& type_arguments =
2216 TypeArguments::Handle(reader->isolate(), contents.GetTypeArguments());
2217 map.SetTypeArguments(type_arguments);
2218 return map.raw();
2219 }
2220
2221
2222 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
2223 intptr_t object_id,
2224 Snapshot::Kind kind) {
2225 if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
2226 // The immutable maps that seed map literals are not yet VM-internal, so
2227 // we don't reach this.
2228 UNREACHABLE();
2229 }
2230 ASSERT(writer != NULL);
2231
2232 // Write out the serialization header value for this object.
2233 writer->WriteInlinedObjectHeader(object_id);
2234
2235 // Write out the class and tags information.
2236 writer->WriteIndexedObject(kLinkedHashMapCid);
2237 writer->WriteTags(writer->GetObjectTags(this));
2238
2239 // Write out the backing array.
2240 // TODO(koda): Serialize as pairs (like ToArray) instead, to reduce space and
2241 // support per-isolate salted hash codes.
2242 writer->WriteObjectImpl(ptr()->data_);
2243 }
2244
2245
2196 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, 2246 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader,
2197 intptr_t object_id, 2247 intptr_t object_id,
2198 intptr_t tags, 2248 intptr_t tags,
2199 Snapshot::Kind kind) { 2249 Snapshot::Kind kind) {
2200 ASSERT(reader != NULL); 2250 ASSERT(reader != NULL);
2201 // Read the values. 2251 // Read the values.
2202 float value0 = reader->Read<float>(); 2252 float value0 = reader->Read<float>();
2203 float value1 = reader->Read<float>(); 2253 float value1 = reader->Read<float>();
2204 float value2 = reader->Read<float>(); 2254 float value2 = reader->Read<float>();
2205 float value3 = reader->Read<float>(); 2255 float value3 = reader->Read<float>();
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 // We do not allow objects with native fields in an isolate message. 2870 // We do not allow objects with native fields in an isolate message.
2821 writer->SetWriteException(Exceptions::kArgument, 2871 writer->SetWriteException(Exceptions::kArgument,
2822 "Illegal argument in isolate message" 2872 "Illegal argument in isolate message"
2823 " : (object is a UserTag)"); 2873 " : (object is a UserTag)");
2824 } else { 2874 } else {
2825 UNREACHABLE(); 2875 UNREACHABLE();
2826 } 2876 }
2827 } 2877 }
2828 2878
2829 } // namespace dart 2879 } // 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