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

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

Issue 1151523002: VM-internalize the default Map implementation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix fingerprints. Created 5 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
« no previous file with comments | « runtime/vm/raw_object.h ('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/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 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 Snapshot::Kind kind) { 2211 Snapshot::Kind kind) {
2212 ASSERT(reader != NULL); 2212 ASSERT(reader != NULL);
2213 2213
2214 LinkedHashMap& map = LinkedHashMap::ZoneHandle( 2214 LinkedHashMap& map = LinkedHashMap::ZoneHandle(
2215 reader->zone(), LinkedHashMap::null()); 2215 reader->zone(), LinkedHashMap::null());
2216 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { 2216 if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
2217 // The immutable maps that seed map literals are not yet VM-internal, so 2217 // The immutable maps that seed map literals are not yet VM-internal, so
2218 // we don't reach this. 2218 // we don't reach this.
2219 UNREACHABLE(); 2219 UNREACHABLE();
2220 } else { 2220 } else {
2221 map = LinkedHashMap::New(HEAP_SPACE(kind)); 2221 // Since the map might contain itself as a key or value, allocate first.
2222 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
2222 } 2223 }
2223 reader->AddBackRef(object_id, &map, kIsDeserialized); 2224 reader->AddBackRef(object_id, &map, kIsDeserialized);
2224 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(); 2225 // Set the object tags.
2225 map.SetData(*(reader->ArrayHandle())); 2226 map.set_tags(tags);
2226 *(reader->TypeArgumentsHandle()) = reader->ArrayHandle()->GetTypeArguments(); 2227 // Read and set the fields.
2227 map.SetTypeArguments(*(reader->TypeArgumentsHandle())); 2228 intptr_t num_flds = (map.raw()->to() - map.raw()->from());
2229 for (intptr_t i = 0; i <= num_flds; i++) {
2230 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef();
2231 map.StorePointer((map.raw()->from() + i),
2232 reader->PassiveObjectHandle()->raw());
2233 }
2228 return map.raw(); 2234 return map.raw();
2229 } 2235 }
2230 2236
2231 2237
2232 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, 2238 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
2233 intptr_t object_id, 2239 intptr_t object_id,
2234 Snapshot::Kind kind) { 2240 Snapshot::Kind kind) {
2235 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { 2241 if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
2236 // The immutable maps that seed map literals are not yet VM-internal, so 2242 // The immutable maps that seed map literals are not yet VM-internal, so
2237 // we don't reach this. 2243 // we don't reach this.
2238 UNREACHABLE(); 2244 UNREACHABLE();
2239 } 2245 }
2240 ASSERT(writer != NULL); 2246 ASSERT(writer != NULL);
2241 2247
2242 // Write out the serialization header value for this object. 2248 // Write out the serialization header value for this object.
2243 writer->WriteInlinedObjectHeader(object_id); 2249 writer->WriteInlinedObjectHeader(object_id);
2244 2250
2245 // Write out the class and tags information. 2251 // Write out the class and tags information.
2246 writer->WriteIndexedObject(kLinkedHashMapCid); 2252 writer->WriteIndexedObject(kLinkedHashMapCid);
2247 writer->WriteTags(writer->GetObjectTags(this)); 2253 writer->WriteTags(writer->GetObjectTags(this));
2248 2254
2249 // Write out the backing array. 2255 // Write out all the object pointer fields.
2250 // TODO(koda): Serialize as pairs (like ToArray) instead, to reduce space and 2256 // TODO(koda): Serialize only used parts of data_ (after compaction), to
2251 // support per-isolate salted hash codes. 2257 // reduce space and support per-isolate salted hash codes. All allowed keys
2252 writer->WriteObjectImpl(ptr()->data_); 2258 // have types for which we can rehash without running Dart code.
2259 SnapshotWriterVisitor visitor(writer);
2260 visitor.VisitPointers(from(), to());
2253 } 2261 }
2254 2262
2255 2263
2256 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, 2264 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader,
2257 intptr_t object_id, 2265 intptr_t object_id,
2258 intptr_t tags, 2266 intptr_t tags,
2259 Snapshot::Kind kind) { 2267 Snapshot::Kind kind) {
2260 ASSERT(reader != NULL); 2268 ASSERT(reader != NULL);
2261 // Read the values. 2269 // Read the values.
2262 float value0 = reader->Read<float>(); 2270 float value0 = reader->Read<float>();
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 // We do not allow objects with native fields in an isolate message. 2886 // We do not allow objects with native fields in an isolate message.
2879 writer->SetWriteException(Exceptions::kArgument, 2887 writer->SetWriteException(Exceptions::kArgument,
2880 "Illegal argument in isolate message" 2888 "Illegal argument in isolate message"
2881 " : (object is a UserTag)"); 2889 " : (object is a UserTag)");
2882 } else { 2890 } else {
2883 UNREACHABLE(); 2891 UNREACHABLE();
2884 } 2892 }
2885 } 2893 }
2886 2894
2887 } // namespace dart 2895 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698