OLD | NEW |
---|---|
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 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2197 | 2197 |
2198 // Write out the used length field. | 2198 // Write out the used length field. |
2199 writer->Write<RawObject*>(ptr()->length_); | 2199 writer->Write<RawObject*>(ptr()->length_); |
2200 | 2200 |
2201 // Write out the Array object. | 2201 // Write out the Array object. |
2202 writer->WriteObjectImpl(ptr()->data_); | 2202 writer->WriteObjectImpl(ptr()->data_); |
2203 } | 2203 } |
2204 | 2204 |
2205 | 2205 |
2206 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, | 2206 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, |
2207 intptr_t object_id, | 2207 intptr_t object_id, |
2208 intptr_t tags, | 2208 intptr_t tags, |
2209 Snapshot::Kind kind) { | 2209 Snapshot::Kind kind) { |
2210 ASSERT(reader != NULL); | 2210 ASSERT(reader != NULL); |
2211 | 2211 |
2212 LinkedHashMap& map = LinkedHashMap::ZoneHandle( | 2212 LinkedHashMap& map = LinkedHashMap::ZoneHandle( |
2213 reader->zone(), LinkedHashMap::null()); | 2213 reader->zone(), LinkedHashMap::null()); |
2214 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { | 2214 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { |
2215 // The immutable maps that seed map literals are not yet VM-internal, so | 2215 // The immutable maps that seed map literals are not yet VM-internal, so |
2216 // we don't reach this. | 2216 // we don't reach this. |
2217 UNREACHABLE(); | 2217 UNREACHABLE(); |
2218 } else { | 2218 } else { |
2219 // Since the map might contain itself as a key or value, allocate first. | 2219 // Since the map might contain itself as a key or value, allocate first. |
2220 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); | 2220 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); |
2221 } | 2221 } |
2222 reader->AddBackRef(object_id, &map, kIsDeserialized); | 2222 reader->AddBackRef(object_id, &map, kIsDeserialized); |
2223 // Set the object tags. | 2223 // Set the object tags. |
2224 map.set_tags(tags); | 2224 map.set_tags(tags); |
2225 // Read and set the fields. | 2225 |
siva
2015/06/01 22:19:36
Maybe add comments here to match the comments on t
koda
2015/06/01 23:01:01
Done.
| |
2226 intptr_t num_flds = (map.raw()->to() - map.raw()->from()); | 2226 *reader->TypeArgumentsHandle() ^= reader->ReadObjectImpl(); |
2227 for (intptr_t i = 0; i <= num_flds; i++) { | 2227 map.SetTypeArguments(*reader->TypeArgumentsHandle()); |
2228 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); | 2228 |
2229 map.StorePointer((map.raw()->from() + i), | 2229 intptr_t len = reader->ReadSmiValue(); |
2230 reader->PassiveObjectHandle()->raw()); | 2230 intptr_t used_data = (len << 1); |
2231 map.SetUsedData(used_data); | |
2232 map.SetDeletedKeys(0); | |
2233 intptr_t index_size = Utils::Maximum(Utils::RoundUpToPowerOfTwo(used_data), | |
2234 static_cast<unsigned int>(16)); | |
2235 Array& data = *reader->ArrayHandle(); | |
2236 data = Array::New(index_size, HEAP_SPACE(kind)); | |
2237 map.SetData(data); | |
2238 // The index and hashMask is regenerated by the maps themselves on demand. | |
2239 // Thus, the index will probably be allocated in new space (unless it's huge). | |
2240 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and | |
2241 // in particular, if/when (const) maps are needed in the VM isolate snapshot. | |
siva
2015/06/01 22:19:36
We need an assertion to make sure we don't write t
koda
2015/06/01 23:01:01
Added an explicit assertion here, for documentatio
| |
2242 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback. | |
2243 | |
2244 // Read the keys and values. | |
2245 bool is_canonical = RawObject::IsCanonical(tags); | |
2246 for (intptr_t i = 0; i < used_data; i++) { | |
2247 *reader->PassiveObjectHandle() = | |
2248 is_canonical ? reader->ReadObjectImpl() : reader->ReadObjectRef(); | |
2249 data.SetAt(i, *reader->PassiveObjectHandle()); | |
2231 } | 2250 } |
2232 return map.raw(); | 2251 return map.raw(); |
2233 } | 2252 } |
2234 | 2253 |
2235 | 2254 |
2236 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, | 2255 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, |
2237 intptr_t object_id, | 2256 intptr_t object_id, |
2238 Snapshot::Kind kind) { | 2257 Snapshot::Kind kind) { |
2239 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { | 2258 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { |
2240 // The immutable maps that seed map literals are not yet VM-internal, so | 2259 // The immutable maps that seed map literals are not yet VM-internal, so |
2241 // we don't reach this. | 2260 // we don't reach this. |
2242 UNREACHABLE(); | 2261 UNREACHABLE(); |
2243 } | 2262 } |
2244 ASSERT(writer != NULL); | 2263 ASSERT(writer != NULL); |
2245 | 2264 |
2246 // Write out the serialization header value for this object. | 2265 // Write out the serialization header value for this object. |
2247 writer->WriteInlinedObjectHeader(object_id); | 2266 writer->WriteInlinedObjectHeader(object_id); |
2248 | 2267 |
2249 // Write out the class and tags information. | 2268 // Write out the class and tags information. |
2250 writer->WriteIndexedObject(kLinkedHashMapCid); | 2269 writer->WriteIndexedObject(kLinkedHashMapCid); |
2251 writer->WriteTags(writer->GetObjectTags(this)); | 2270 const uword tags = writer->GetObjectTags(this); |
2271 writer->WriteTags(tags); | |
2252 | 2272 |
2253 // Write out all the object pointer fields. | 2273 // Write out the type arguments. |
2254 // TODO(koda): Serialize only used parts of data_ (after compaction), to | 2274 writer->WriteObjectImpl(ptr()->type_arguments_); |
2255 // reduce space and support per-isolate salted hash codes. All allowed keys | 2275 |
2256 // have types for which we can rehash without running Dart code. | 2276 const intptr_t used_data = Smi::Value(ptr()->used_data_); |
2257 SnapshotWriterVisitor visitor(writer); | 2277 ASSERT((used_data & 1) == 0); // Keys + values, so must be even. |
2258 visitor.VisitPointers(from(), to()); | 2278 const intptr_t deleted_keys = Smi::Value(ptr()->deleted_keys_); |
2279 | |
2280 // Write out the number of (not deleted) key/value pairs that will follow. | |
2281 writer->Write<RawObject*>(Smi::New((used_data >> 1) - deleted_keys)); | |
2282 | |
2283 // Write out the keys and values. | |
2284 const bool is_canonical = RawObject::IsCanonical(tags); | |
2285 RawArray* data_array = ptr()->data_; | |
2286 RawObject** data_elements = data_array->ptr()->data(); | |
2287 ASSERT(used_data <= Smi::Value(data_array->ptr()->length_)); | |
2288 #if defined(DEBUG) | |
2289 intptr_t deleted_keys_found = 0; | |
2290 #endif // DEBUG | |
2291 for (intptr_t i = 0; i < used_data; i += 2) { | |
2292 RawObject* key = data_elements[i]; | |
2293 if (key == data_array) { | |
2294 #if defined(DEBUG) | |
2295 ++deleted_keys_found; | |
2296 #endif // DEBUG | |
2297 continue; | |
2298 } | |
2299 RawObject* value = data_elements[i + 1]; | |
2300 if (is_canonical) { | |
2301 writer->WriteObjectImpl(key); | |
2302 writer->WriteObjectImpl(value); | |
2303 } else { | |
2304 writer->WriteObjectRef(key); | |
2305 writer->WriteObjectRef(value); | |
2306 } | |
2307 } | |
2308 ASSERT(deleted_keys_found == deleted_keys); | |
2259 } | 2309 } |
2260 | 2310 |
2261 | 2311 |
2262 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, | 2312 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, |
2263 intptr_t object_id, | 2313 intptr_t object_id, |
2264 intptr_t tags, | 2314 intptr_t tags, |
2265 Snapshot::Kind kind) { | 2315 Snapshot::Kind kind) { |
2266 ASSERT(reader != NULL); | 2316 ASSERT(reader != NULL); |
2267 // Read the values. | 2317 // Read the values. |
2268 float value0 = reader->Read<float>(); | 2318 float value0 = reader->Read<float>(); |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2884 // We do not allow objects with native fields in an isolate message. | 2934 // We do not allow objects with native fields in an isolate message. |
2885 writer->SetWriteException(Exceptions::kArgument, | 2935 writer->SetWriteException(Exceptions::kArgument, |
2886 "Illegal argument in isolate message" | 2936 "Illegal argument in isolate message" |
2887 " : (object is a UserTag)"); | 2937 " : (object is a UserTag)"); |
2888 } else { | 2938 } else { |
2889 UNREACHABLE(); | 2939 UNREACHABLE(); |
2890 } | 2940 } |
2891 } | 2941 } |
2892 | 2942 |
2893 } // namespace dart | 2943 } // namespace dart |
OLD | NEW |