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

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, 4 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
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 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( 2135 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle(
2136 reader->isolate(), GrowableObjectArray::null()); 2136 reader->isolate(), GrowableObjectArray::null());
2137 if (kind == Snapshot::kFull) { 2137 if (kind == Snapshot::kFull) {
2138 array = reader->NewGrowableObjectArray(); 2138 array = reader->NewGrowableObjectArray();
2139 } else { 2139 } else {
2140 array = GrowableObjectArray::New(0, HEAP_SPACE(kind)); 2140 array = GrowableObjectArray::New(0, HEAP_SPACE(kind));
2141 } 2141 }
2142 reader->AddBackRef(object_id, &array, kIsDeserialized); 2142 reader->AddBackRef(object_id, &array, kIsDeserialized);
2143 intptr_t length = reader->ReadSmiValue(); 2143 intptr_t length = reader->ReadSmiValue();
2144 array.SetLength(length); 2144 array.SetLength(length);
2145 Array& contents = Array::Handle(); 2145 Array& contents = Array::Handle(reader->isolate());
2146 contents ^= reader->ReadObjectImpl(); 2146 contents ^= reader->ReadObjectImpl();
2147 array.SetData(contents); 2147 array.SetData(contents);
2148 const TypeArguments& type_arguments = 2148 const TypeArguments& type_arguments =
2149 TypeArguments::Handle(contents.GetTypeArguments()); 2149 TypeArguments::Handle(reader->isolate(), contents.GetTypeArguments());
2150 array.SetTypeArguments(type_arguments); 2150 array.SetTypeArguments(type_arguments);
2151 return array.raw(); 2151 return array.raw();
2152 } 2152 }
2153 2153
2154 2154
2155 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer, 2155 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer,
2156 intptr_t object_id, 2156 intptr_t object_id,
2157 Snapshot::Kind kind) { 2157 Snapshot::Kind kind) {
2158 ASSERT(writer != NULL); 2158 ASSERT(writer != NULL);
2159 2159
2160 // Write out the serialization header value for this object. 2160 // Write out the serialization header value for this object.
2161 writer->WriteInlinedObjectHeader(object_id); 2161 writer->WriteInlinedObjectHeader(object_id);
2162 2162
2163 // Write out the class and tags information. 2163 // Write out the class and tags information.
2164 writer->WriteIndexedObject(kGrowableObjectArrayCid); 2164 writer->WriteIndexedObject(kGrowableObjectArrayCid);
2165 writer->WriteTags(writer->GetObjectTags(this)); 2165 writer->WriteTags(writer->GetObjectTags(this));
2166 2166
2167 // Write out the used length field. 2167 // Write out the used length field.
2168 writer->Write<RawObject*>(ptr()->length_); 2168 writer->Write<RawObject*>(ptr()->length_);
2169 2169
2170 // Write out the Array object. 2170 // Write out the Array object.
2171 writer->WriteObjectImpl(ptr()->data_); 2171 writer->WriteObjectImpl(ptr()->data_);
2172 } 2172 }
2173 2173
2174 2174
2175 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
2176 intptr_t object_id,
2177 intptr_t tags,
2178 Snapshot::Kind kind) {
2179 ASSERT(reader != NULL);
2180
2181 LinkedHashMap& map = LinkedHashMap::ZoneHandle(
2182 reader->isolate(), LinkedHashMap::null());
2183 if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
2184 // The immutable maps that seed map literals are not yet VM-internal, so
2185 // we don't reach this.
2186 UNREACHABLE();
2187 } else {
2188 map = LinkedHashMap::New(HEAP_SPACE(kind));
2189 }
2190 reader->AddBackRef(object_id, &map, kIsDeserialized);
2191 Array& contents = Array::Handle(reader->isolate());
2192 contents ^= reader->ReadObjectImpl();
2193 map.SetData(contents);
2194 const TypeArguments& type_arguments =
2195 TypeArguments::Handle(reader->isolate(), contents.GetTypeArguments());
2196 map.SetTypeArguments(type_arguments);
2197 return map.raw();
2198 }
2199
2200
2201 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
2202 intptr_t object_id,
2203 Snapshot::Kind kind) {
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 }
2209 ASSERT(writer != NULL);
2210
2211 // Write out the serialization header value for this object.
2212 writer->WriteInlinedObjectHeader(object_id);
2213
2214 // Write out the class and tags information.
2215 writer->WriteIndexedObject(kLinkedHashMapCid);
2216 writer->WriteTags(writer->GetObjectTags(this));
2217
2218 // Write out the backing array.
2219 // TODO(koda): Serialize as pairs (like ToArray) instead, to reduce space and
2220 // support per-isolate salted hash codes.
2221 writer->WriteObjectImpl(ptr()->data_);
2222 }
2223
2224
2175 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, 2225 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader,
2176 intptr_t object_id, 2226 intptr_t object_id,
2177 intptr_t tags, 2227 intptr_t tags,
2178 Snapshot::Kind kind) { 2228 Snapshot::Kind kind) {
2179 ASSERT(reader != NULL); 2229 ASSERT(reader != NULL);
2180 // Read the values. 2230 // Read the values.
2181 float value0 = reader->Read<float>(); 2231 float value0 = reader->Read<float>();
2182 float value1 = reader->Read<float>(); 2232 float value1 = reader->Read<float>();
2183 float value2 = reader->Read<float>(); 2233 float value2 = reader->Read<float>();
2184 float value3 = reader->Read<float>(); 2234 float value3 = reader->Read<float>();
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 // We do not allow objects with native fields in an isolate message. 2849 // We do not allow objects with native fields in an isolate message.
2800 writer->SetWriteException(Exceptions::kArgument, 2850 writer->SetWriteException(Exceptions::kArgument,
2801 "Illegal argument in isolate message" 2851 "Illegal argument in isolate message"
2802 " : (object is a UserTag)"); 2852 " : (object is a UserTag)");
2803 } else { 2853 } else {
2804 UNREACHABLE(); 2854 UNREACHABLE();
2805 } 2855 }
2806 } 2856 }
2807 2857
2808 } // namespace dart 2858 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698