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

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

Issue 10867046: Use Heap::kOld when allocating objects for script snapshots. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return kStringInterface; 107 return kStringInterface;
108 } else if (raw_type == object_store->list_interface()) { 108 } else if (raw_type == object_store->list_interface()) {
109 return kListInterface; 109 return kListInterface;
110 } else if (raw_type == object_store->byte_array_interface()) { 110 } else if (raw_type == object_store->byte_array_interface()) {
111 return kByteArrayInterface; 111 return kByteArrayInterface;
112 } 112 }
113 return kInvalidIndex; 113 return kInvalidIndex;
114 } 114 }
115 115
116 116
117 static Heap::Space space(Snapshot::Kind kind) {
cshapiro 2012/08/25 03:30:11 Is this change missing heap.h or am I confused? L
siva 2012/08/27 17:15:21 I would have preferred to put this in snapshot.h b
118 return (kind == Snapshot::kMessage) ? Heap::kNew : Heap::kOld;
119 }
120
121
117 // TODO(5411462): Temporary setup of snapshot for testing purposes, 122 // TODO(5411462): Temporary setup of snapshot for testing purposes,
118 // the actual creation of a snapshot maybe done differently. 123 // the actual creation of a snapshot maybe done differently.
119 const Snapshot* Snapshot::SetupFromBuffer(const void* raw_memory) { 124 const Snapshot* Snapshot::SetupFromBuffer(const void* raw_memory) {
120 ASSERT(raw_memory != NULL); 125 ASSERT(raw_memory != NULL);
121 ASSERT(kHeaderSize == sizeof(Snapshot)); 126 ASSERT(kHeaderSize == sizeof(Snapshot));
122 ASSERT(kLengthIndex == length_offset()); 127 ASSERT(kLengthIndex == length_offset());
123 ASSERT((kSnapshotFlagIndex * sizeof(int32_t)) == kind_offset()); 128 ASSERT((kSnapshotFlagIndex * sizeof(int32_t)) == kind_offset());
124 ASSERT((kHeapObjectTag & kInlined)); 129 ASSERT((kHeapObjectTag & kInlined));
125 // No object can have kFreeBit and kMarkBit set simultaneously. If kFreeBit 130 // No object can have kFreeBit and kMarkBit set simultaneously. If kFreeBit
126 // is set then the rest of tags is a pointer to the next FreeListElement which 131 // is set then the rest of tags is a pointer to the next FreeListElement which
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 cls = library_.LookupClass(str_); 196 cls = library_.LookupClass(str_);
192 } 197 }
193 ASSERT(!cls.IsNull()); 198 ASSERT(!cls.IsNull());
194 return cls.raw(); 199 return cls.raw();
195 } 200 }
196 201
197 202
198 RawObject* SnapshotReader::ReadObjectImpl() { 203 RawObject* SnapshotReader::ReadObjectImpl() {
199 int64_t value = Read<int64_t>(); 204 int64_t value = Read<int64_t>();
200 if ((value & kSmiTagMask) == 0) { 205 if ((value & kSmiTagMask) == 0) {
201 return Integer::New((value >> kSmiTagShift)); 206 return Integer::New((value >> kSmiTagShift), space(kind_));
202 } 207 }
203 return ReadObjectImpl(value); 208 return ReadObjectImpl(value);
204 } 209 }
205 210
206 211
207 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) { 212 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) {
208 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin)); 213 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin));
209 if (IsVMIsolateObject(header_value)) { 214 if (IsVMIsolateObject(header_value)) {
210 return ReadVMIsolateObject(header_value); 215 return ReadVMIsolateObject(header_value);
211 } else { 216 } else {
212 if (SerializedHeaderTag::decode(header_value) == kObjectId) { 217 if (SerializedHeaderTag::decode(header_value) == kObjectId) {
213 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); 218 return ReadIndexedObject(SerializedHeaderData::decode(header_value));
214 } 219 }
215 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); 220 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined);
216 return ReadInlinedObject(SerializedHeaderData::decode(header_value)); 221 return ReadInlinedObject(SerializedHeaderData::decode(header_value));
217 } 222 }
218 } 223 }
219 224
220 225
221 RawObject* SnapshotReader::ReadObjectRef() { 226 RawObject* SnapshotReader::ReadObjectRef() {
222 int64_t header_value = Read<int64_t>(); 227 int64_t header_value = Read<int64_t>();
223 if ((header_value & kSmiTagMask) == 0) { 228 if ((header_value & kSmiTagMask) == 0) {
224 return Integer::New((header_value >> kSmiTagShift)); 229 return Integer::New((header_value >> kSmiTagShift), space(kind_));
225 } 230 }
226 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin)); 231 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin));
227 if (IsVMIsolateObject(header_value)) { 232 if (IsVMIsolateObject(header_value)) {
228 return ReadVMIsolateObject(header_value); 233 return ReadVMIsolateObject(header_value);
229 } else if (SerializedHeaderTag::decode(header_value) == kObjectId) { 234 } else if (SerializedHeaderTag::decode(header_value) == kObjectId) {
230 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); 235 return ReadIndexedObject(SerializedHeaderData::decode(header_value));
231 } 236 }
232 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); 237 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined);
233 intptr_t object_id = SerializedHeaderData::decode(header_value); 238 intptr_t object_id = SerializedHeaderData::decode(header_value);
234 ASSERT(GetBackRef(object_id) == NULL); 239 ASSERT(GetBackRef(object_id) == NULL);
235 240
236 // Read the class header information and lookup the class. 241 // Read the class header information and lookup the class.
237 intptr_t class_header = ReadIntptrValue(); 242 intptr_t class_header = ReadIntptrValue();
238 243
239 // Since we are only reading an object reference, If it is an instance kind 244 // Since we are only reading an object reference, If it is an instance kind
240 // then we only need to figure out the class of the object and allocate an 245 // then we only need to figure out the class of the object and allocate an
241 // instance of it. The individual fields will be read later. 246 // instance of it. The individual fields will be read later.
242 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { 247 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) {
243 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); 248 Instance& result = Instance::ZoneHandle(isolate(), Instance::null());
244 AddBackRef(object_id, &result, kIsNotDeserialized); 249 AddBackRef(object_id, &result, kIsNotDeserialized);
245 250
246 cls_ ^= ReadObjectImpl(); // Read class information. 251 cls_ ^= ReadObjectImpl(); // Read class information.
247 ASSERT(!cls_.IsNull()); 252 ASSERT(!cls_.IsNull());
248 intptr_t instance_size = cls_.instance_size(); 253 intptr_t instance_size = cls_.instance_size();
249 ASSERT(instance_size > 0); 254 ASSERT(instance_size > 0);
250 if (kind_ == Snapshot::kFull) { 255 if (kind_ == Snapshot::kFull) {
251 result ^= AllocateUninitialized(cls_, instance_size); 256 result ^= AllocateUninitialized(cls_, instance_size);
252 } else { 257 } else {
253 result ^= Object::Allocate(cls_.id(), instance_size, Heap::kNew); 258 result ^= Object::Allocate(cls_.id(), instance_size, space(kind_));
254 } 259 }
255 return result.raw(); 260 return result.raw();
256 } 261 }
257 ASSERT((class_header & kSmiTagMask) != 0); 262 ASSERT((class_header & kSmiTagMask) != 0);
258 cls_ = LookupInternalClass(class_header); 263 cls_ = LookupInternalClass(class_header);
259 ASSERT(!cls_.IsNull()); 264 ASSERT(!cls_.IsNull());
260 265
261 // Similarly Array and ImmutableArray objects are also similarly only 266 // Similarly Array and ImmutableArray objects are also similarly only
262 // allocated here, the individual array elements are read later. 267 // allocated here, the individual array elements are read later.
263 intptr_t class_id = cls_.id(); 268 intptr_t class_id = cls_.id();
264 if (class_id == kArrayCid) { 269 if (class_id == kArrayCid) {
265 // Read the length and allocate an object based on the len. 270 // Read the length and allocate an object based on the len.
266 intptr_t len = ReadSmiValue(); 271 intptr_t len = ReadSmiValue();
267 Array& array = Array::ZoneHandle( 272 Array& array = Array::ZoneHandle(
268 isolate(), 273 isolate(),
269 (kind_ == Snapshot::kFull) ? NewArray(len) : Array::New(len)); 274 ((kind_ == Snapshot::kFull) ?
275 NewArray(len) : Array::New(len, space(kind_))));
270 AddBackRef(object_id, &array, kIsNotDeserialized); 276 AddBackRef(object_id, &array, kIsNotDeserialized);
271 277
272 return array.raw(); 278 return array.raw();
273 } 279 }
274 if (class_id == kImmutableArrayCid) { 280 if (class_id == kImmutableArrayCid) {
275 // Read the length and allocate an object based on the len. 281 // Read the length and allocate an object based on the len.
276 intptr_t len = ReadSmiValue(); 282 intptr_t len = ReadSmiValue();
277 ImmutableArray& array = ImmutableArray::ZoneHandle( 283 ImmutableArray& array = ImmutableArray::ZoneHandle(
278 isolate(), 284 isolate(),
279 (kind_ == Snapshot::kFull) ? 285 (kind_ == Snapshot::kFull) ?
280 NewImmutableArray(len) : ImmutableArray::New(len)); 286 NewImmutableArray(len) : ImmutableArray::New(len, space(kind_)));
281 AddBackRef(object_id, &array, kIsNotDeserialized); 287 AddBackRef(object_id, &array, kIsNotDeserialized);
282 288
283 return array.raw(); 289 return array.raw();
284 } 290 }
285 291
286 // For all other internal VM classes we read the object inline. 292 // For all other internal VM classes we read the object inline.
287 intptr_t tags = ReadIntptrValue(); 293 intptr_t tags = ReadIntptrValue();
288 switch (class_id) { 294 switch (class_id) {
289 #define SNAPSHOT_READ(clazz) \ 295 #define SNAPSHOT_READ(clazz) \
290 case clazz::kClassId: { \ 296 case clazz::kClassId: { \
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 result = &(Instance::ZoneHandle(isolate(), Instance::null())); 660 result = &(Instance::ZoneHandle(isolate(), Instance::null()));
655 AddBackRef(object_id, result, kIsDeserialized); 661 AddBackRef(object_id, result, kIsDeserialized);
656 cls_ ^= ReadObjectImpl(); 662 cls_ ^= ReadObjectImpl();
657 ASSERT(!cls_.IsNull()); 663 ASSERT(!cls_.IsNull());
658 instance_size = cls_.instance_size(); 664 instance_size = cls_.instance_size();
659 ASSERT(instance_size > 0); 665 ASSERT(instance_size > 0);
660 // Allocate the instance and read in all the fields for the object. 666 // Allocate the instance and read in all the fields for the object.
661 if (kind_ == Snapshot::kFull) { 667 if (kind_ == Snapshot::kFull) {
662 *result ^= AllocateUninitialized(cls_, instance_size); 668 *result ^= AllocateUninitialized(cls_, instance_size);
663 } else { 669 } else {
664 *result ^= Object::Allocate(cls_.id(), instance_size, Heap::kNew); 670 *result ^= Object::Allocate(cls_.id(), instance_size, space(kind_));
665 } 671 }
666 } else { 672 } else {
667 cls_ ^= ReadObjectImpl(); 673 cls_ ^= ReadObjectImpl();
668 ASSERT(!cls_.IsNull()); 674 ASSERT(!cls_.IsNull());
669 instance_size = cls_.instance_size(); 675 instance_size = cls_.instance_size();
670 } 676 }
671 intptr_t offset = Object::InstanceSize(); 677 intptr_t offset = Object::InstanceSize();
672 while (offset < instance_size) { 678 while (offset < instance_size) {
673 obj_ = ReadObjectRef(); 679 obj_ = ReadObjectRef();
674 result->SetFieldAtOffset(offset, obj_); 680 result->SetFieldAtOffset(offset, obj_);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 RawObject* raw_obj = *current; 1146 RawObject* raw_obj = *current;
1141 if (as_references_) { 1147 if (as_references_) {
1142 writer_->WriteObjectRef(raw_obj); 1148 writer_->WriteObjectRef(raw_obj);
1143 } else { 1149 } else {
1144 writer_->WriteObjectImpl(raw_obj); 1150 writer_->WriteObjectImpl(raw_obj);
1145 } 1151 }
1146 } 1152 }
1147 } 1153 }
1148 1154
1149 } // namespace dart 1155 } // namespace dart
OLDNEW
« runtime/vm/raw_object_snapshot.cc ('K') | « runtime/vm/raw_object_snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698