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/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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
11 #include "vm/exceptions.h" | 11 #include "vm/exceptions.h" |
12 #include "vm/heap.h" | 12 #include "vm/heap.h" |
13 #include "vm/longjump.h" | 13 #include "vm/longjump.h" |
14 #include "vm/object.h" | 14 #include "vm/object.h" |
15 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
16 #include "vm/snapshot_ids.h" | 16 #include "vm/snapshot_ids.h" |
17 #include "vm/symbols.h" | 17 #include "vm/symbols.h" |
18 | 18 |
19 namespace dart { | 19 namespace dart { |
20 | 20 |
21 #define I (isolate()) | |
siva
2014/06/06 18:10:33
Is this still needed?
zra
2014/06/06 18:30:57
No. I've removed it.
| |
22 | |
21 static const int kNumInitialReferencesInFullSnapshot = 160 * KB; | 23 static const int kNumInitialReferencesInFullSnapshot = 160 * KB; |
22 static const int kNumInitialReferences = 64; | 24 static const int kNumInitialReferences = 64; |
23 | 25 |
24 | 26 |
25 static bool IsSingletonClassId(intptr_t class_id) { | 27 static bool IsSingletonClassId(intptr_t class_id) { |
26 // Check if this is a singleton object class which is shared by all isolates. | 28 // Check if this is a singleton object class which is shared by all isolates. |
27 return ((class_id >= kClassCid && class_id <= kUnwindErrorCid) || | 29 return ((class_id >= kClassCid && class_id <= kUnwindErrorCid) || |
28 (class_id >= kNullCid && class_id <= kVoidCid)); | 30 (class_id >= kNullCid && class_id <= kVoidCid)); |
29 } | 31 } |
30 | 32 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 169 |
168 | 170 |
169 RawObject* SnapshotReader::ReadObject() { | 171 RawObject* SnapshotReader::ReadObject() { |
170 const Instance& null_object = Instance::Handle(); | 172 const Instance& null_object = Instance::Handle(); |
171 *ErrorHandle() = UnhandledException::New(null_object, null_object); | 173 *ErrorHandle() = UnhandledException::New(null_object, null_object); |
172 // Setup for long jump in case there is an exception while reading. | 174 // Setup for long jump in case there is an exception while reading. |
173 LongJumpScope jump; | 175 LongJumpScope jump; |
174 if (setjmp(*jump.Set()) == 0) { | 176 if (setjmp(*jump.Set()) == 0) { |
175 Object& obj = Object::Handle(ReadObjectImpl()); | 177 Object& obj = Object::Handle(ReadObjectImpl()); |
176 for (intptr_t i = 0; i < backward_references_.length(); i++) { | 178 for (intptr_t i = 0; i < backward_references_.length(); i++) { |
177 if (!backward_references_[i]->is_deserialized()) { | 179 if (!backward_references_[i].is_deserialized()) { |
178 ReadObjectImpl(); | 180 ReadObjectImpl(); |
179 backward_references_[i]->set_state(kIsDeserialized); | 181 backward_references_[i].set_state(kIsDeserialized); |
180 } | 182 } |
181 } | 183 } |
182 return obj.raw(); | 184 return obj.raw(); |
183 } else { | 185 } else { |
184 // An error occurred while reading, return the error object. | 186 // An error occurred while reading, return the error object. |
185 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); | 187 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); |
186 isolate()->object_store()->clear_sticky_error(); | 188 isolate()->object_store()->clear_sticky_error(); |
187 return err.raw(); | 189 return err.raw(); |
188 } | 190 } |
189 } | 191 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 } | 336 } |
335 return obj_.raw(); | 337 return obj_.raw(); |
336 } | 338 } |
337 | 339 |
338 | 340 |
339 void SnapshotReader::AddBackRef(intptr_t id, | 341 void SnapshotReader::AddBackRef(intptr_t id, |
340 Object* obj, | 342 Object* obj, |
341 DeserializeState state) { | 343 DeserializeState state) { |
342 intptr_t index = (id - kMaxPredefinedObjectIds); | 344 intptr_t index = (id - kMaxPredefinedObjectIds); |
343 ASSERT(index == backward_references_.length()); | 345 ASSERT(index == backward_references_.length()); |
344 BackRefNode* node = new BackRefNode(obj, state); | 346 BackRefNode node(obj, state); |
345 ASSERT(node != NULL); | |
346 backward_references_.Add(node); | 347 backward_references_.Add(node); |
347 } | 348 } |
348 | 349 |
349 | 350 |
350 Object* SnapshotReader::GetBackRef(intptr_t id) { | 351 Object* SnapshotReader::GetBackRef(intptr_t id) { |
351 ASSERT(id >= kMaxPredefinedObjectIds); | 352 ASSERT(id >= kMaxPredefinedObjectIds); |
352 intptr_t index = (id - kMaxPredefinedObjectIds); | 353 intptr_t index = (id - kMaxPredefinedObjectIds); |
353 if (index < backward_references_.length()) { | 354 if (index < backward_references_.length()) { |
354 return backward_references_[index]->reference(); | 355 return backward_references_[index].reference(); |
355 } | 356 } |
356 return NULL; | 357 return NULL; |
357 } | 358 } |
358 | 359 |
359 | 360 |
360 void SnapshotReader::ReadFullSnapshot() { | 361 void SnapshotReader::ReadFullSnapshot() { |
361 ASSERT(kind_ == Snapshot::kFull); | 362 ASSERT(kind_ == Snapshot::kFull); |
362 Isolate* isolate = Isolate::Current(); | 363 Isolate* isolate = Isolate::Current(); |
363 ASSERT(isolate != NULL); | 364 ASSERT(isolate != NULL); |
364 ObjectStore* object_store = isolate->object_store(); | 365 ObjectStore* object_store = isolate->object_store(); |
365 ASSERT(object_store != NULL); | 366 ASSERT(object_store != NULL); |
366 NoGCScope no_gc; | 367 NoGCScope no_gc; |
367 | 368 |
368 // TODO(asiva): Add a check here to ensure we have the right heap | 369 // TODO(asiva): Add a check here to ensure we have the right heap |
369 // size for the full snapshot being read. | 370 // size for the full snapshot being read. |
370 | 371 |
371 // Read in all the objects stored in the object store. | 372 // Read in all the objects stored in the object store. |
372 intptr_t num_flds = (object_store->to() - object_store->from()); | 373 intptr_t num_flds = (object_store->to() - object_store->from()); |
373 for (intptr_t i = 0; i <= num_flds; i++) { | 374 for (intptr_t i = 0; i <= num_flds; i++) { |
374 *(object_store->from() + i) = ReadObjectImpl(); | 375 *(object_store->from() + i) = ReadObjectImpl(); |
375 } | 376 } |
376 for (intptr_t i = 0; i < backward_references_.length(); i++) { | 377 for (intptr_t i = 0; i < backward_references_.length(); i++) { |
377 if (!backward_references_[i]->is_deserialized()) { | 378 if (!backward_references_[i].is_deserialized()) { |
378 ReadObjectImpl(); | 379 ReadObjectImpl(); |
379 backward_references_[i]->set_state(kIsDeserialized); | 380 backward_references_[i].set_state(kIsDeserialized); |
380 } | 381 } |
381 } | 382 } |
382 | 383 |
383 // Validate the class table. | 384 // Validate the class table. |
384 #if defined(DEBUG) | 385 #if defined(DEBUG) |
385 isolate->ValidateClassTable(); | 386 isolate->ValidateClassTable(); |
386 #endif | 387 #endif |
387 | 388 |
388 // Setup native resolver for bootstrap impl. | 389 // Setup native resolver for bootstrap impl. |
389 Bootstrap::SetupNativeResolver(); | 390 Bootstrap::SetupNativeResolver(); |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1573 NoGCScope no_gc; | 1574 NoGCScope no_gc; |
1574 WriteObject(obj.raw()); | 1575 WriteObject(obj.raw()); |
1575 UnmarkAll(); | 1576 UnmarkAll(); |
1576 } else { | 1577 } else { |
1577 ThrowException(exception_type(), exception_msg()); | 1578 ThrowException(exception_type(), exception_msg()); |
1578 } | 1579 } |
1579 } | 1580 } |
1580 | 1581 |
1581 | 1582 |
1582 } // namespace dart | 1583 } // namespace dart |
OLD | NEW |