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/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 instructions_reader_ = new InstructionsReader(instructions_buffer); | 211 instructions_reader_ = new InstructionsReader(instructions_buffer); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 RawObject* SnapshotReader::ReadObject() { | 216 RawObject* SnapshotReader::ReadObject() { |
217 // Setup for long jump in case there is an exception while reading. | 217 // Setup for long jump in case there is an exception while reading. |
218 LongJumpScope jump; | 218 LongJumpScope jump; |
219 if (setjmp(*jump.Set()) == 0) { | 219 if (setjmp(*jump.Set()) == 0) { |
220 PassiveObject& obj = | 220 PassiveObject& obj = |
221 PassiveObject::Handle(isolate(), ReadObjectImpl(kAsInlinedObject)); | 221 PassiveObject::Handle(zone(), ReadObjectImpl(kAsInlinedObject)); |
222 for (intptr_t i = 0; i < backward_references_->length(); i++) { | 222 for (intptr_t i = 0; i < backward_references_->length(); i++) { |
223 if (!(*backward_references_)[i].is_deserialized()) { | 223 if (!(*backward_references_)[i].is_deserialized()) { |
224 ReadObjectImpl(kAsInlinedObject); | 224 ReadObjectImpl(kAsInlinedObject); |
225 (*backward_references_)[i].set_state(kIsDeserialized); | 225 (*backward_references_)[i].set_state(kIsDeserialized); |
226 } | 226 } |
227 } | 227 } |
228 if (kind() != Snapshot::kFull) { | 228 if (kind() != Snapshot::kFull) { |
229 ProcessDeferredCanonicalizations(); | 229 ProcessDeferredCanonicalizations(); |
230 } | 230 } |
231 return obj.raw(); | 231 return obj.raw(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 return func.raw(); | 301 return func.raw(); |
302 } | 302 } |
303 | 303 |
304 | 304 |
305 RawObject* SnapshotReader::ReadStaticImplicitClosure(intptr_t object_id, | 305 RawObject* SnapshotReader::ReadStaticImplicitClosure(intptr_t object_id, |
306 intptr_t class_header) { | 306 intptr_t class_header) { |
307 ASSERT(kind_ != Snapshot::kFull); | 307 ASSERT(kind_ != Snapshot::kFull); |
308 | 308 |
309 // First create a function object and associate it with the specified | 309 // First create a function object and associate it with the specified |
310 // 'object_id'. | 310 // 'object_id'. |
311 Function& func = Function::Handle(isolate(), Function::null()); | 311 Function& func = Function::Handle(zone(), Function::null()); |
312 Instance& obj = Instance::ZoneHandle(zone(), Instance::null()); | 312 Instance& obj = Instance::ZoneHandle(zone(), Instance::null()); |
313 AddBackRef(object_id, &obj, kIsDeserialized); | 313 AddBackRef(object_id, &obj, kIsDeserialized); |
314 | 314 |
315 // Read the library/class/function information and lookup the function. | 315 // Read the library/class/function information and lookup the function. |
316 str_ ^= ReadObjectImpl(kAsInlinedObject); | 316 str_ ^= ReadObjectImpl(kAsInlinedObject); |
317 library_ = Library::LookupLibrary(str_); | 317 library_ = Library::LookupLibrary(str_); |
318 if (library_.IsNull() || !library_.Loaded()) { | 318 if (library_.IsNull() || !library_.Loaded()) { |
319 SetReadException("Invalid Library object found in message."); | 319 SetReadException("Invalid Library object found in message."); |
320 } | 320 } |
321 str_ ^= ReadObjectImpl(kAsInlinedObject); | 321 str_ ^= ReadObjectImpl(kAsInlinedObject); |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 | 1817 |
1818 | 1818 |
1819 // An object visitor which will iterate over all the script objects in the heap | 1819 // An object visitor which will iterate over all the script objects in the heap |
1820 // and either count them or collect them into an array. This is used during | 1820 // and either count them or collect them into an array. This is used during |
1821 // full snapshot generation of the VM isolate to write out all script | 1821 // full snapshot generation of the VM isolate to write out all script |
1822 // objects and their accompanying token streams. | 1822 // objects and their accompanying token streams. |
1823 class ScriptVisitor : public ObjectVisitor { | 1823 class ScriptVisitor : public ObjectVisitor { |
1824 public: | 1824 public: |
1825 explicit ScriptVisitor(Isolate* isolate) : | 1825 explicit ScriptVisitor(Isolate* isolate) : |
1826 ObjectVisitor(isolate), | 1826 ObjectVisitor(isolate), |
1827 objHandle_(Object::Handle(isolate)), | 1827 objHandle_(Object::Handle(isolate->current_zone())), |
1828 count_(0), | 1828 count_(0), |
1829 scripts_(NULL) {} | 1829 scripts_(NULL) {} |
1830 | 1830 |
1831 ScriptVisitor(Isolate* isolate, const Array* scripts) : | 1831 ScriptVisitor(Isolate* isolate, const Array* scripts) : |
1832 ObjectVisitor(isolate), | 1832 ObjectVisitor(isolate), |
1833 objHandle_(Object::Handle(isolate)), | 1833 objHandle_(Object::Handle(isolate->current_zone())), |
1834 count_(0), | 1834 count_(0), |
1835 scripts_(scripts) {} | 1835 scripts_(scripts) {} |
1836 | 1836 |
1837 void VisitObject(RawObject* obj) { | 1837 void VisitObject(RawObject* obj) { |
1838 if (obj->IsScript()) { | 1838 if (obj->IsScript()) { |
1839 if (scripts_ != NULL) { | 1839 if (scripts_ != NULL) { |
1840 objHandle_ = obj; | 1840 objHandle_ = obj; |
1841 scripts_->SetAt(count_, objHandle_); | 1841 scripts_->SetAt(count_, objHandle_); |
1842 } | 1842 } |
1843 count_ += 1; | 1843 count_ += 1; |
(...skipping 18 matching lines...) Expand all Loading... |
1862 : isolate_(Isolate::Current()), | 1862 : isolate_(Isolate::Current()), |
1863 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer), | 1863 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer), |
1864 isolate_snapshot_buffer_(isolate_snapshot_buffer), | 1864 isolate_snapshot_buffer_(isolate_snapshot_buffer), |
1865 instructions_snapshot_buffer_(instructions_snapshot_buffer), | 1865 instructions_snapshot_buffer_(instructions_snapshot_buffer), |
1866 alloc_(alloc), | 1866 alloc_(alloc), |
1867 vm_isolate_snapshot_size_(0), | 1867 vm_isolate_snapshot_size_(0), |
1868 isolate_snapshot_size_(0), | 1868 isolate_snapshot_size_(0), |
1869 instructions_snapshot_size_(0), | 1869 instructions_snapshot_size_(0), |
1870 forward_list_(NULL), | 1870 forward_list_(NULL), |
1871 instructions_writer_(NULL), | 1871 instructions_writer_(NULL), |
1872 scripts_(Array::Handle(isolate_)), | 1872 scripts_(Array::Handle(isolate_->current_zone())), |
1873 symbol_table_(Array::Handle(isolate_)), | 1873 symbol_table_(Array::Handle(isolate_->current_zone())), |
1874 snapshot_code_(snapshot_code), | 1874 snapshot_code_(snapshot_code), |
1875 vm_isolate_is_symbolic_(vm_isolate_is_symbolic) { | 1875 vm_isolate_is_symbolic_(vm_isolate_is_symbolic) { |
1876 ASSERT(isolate_snapshot_buffer_ != NULL); | 1876 ASSERT(isolate_snapshot_buffer_ != NULL); |
1877 ASSERT(alloc_ != NULL); | 1877 ASSERT(alloc_ != NULL); |
1878 ASSERT(isolate_ != NULL); | 1878 ASSERT(isolate_ != NULL); |
1879 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1879 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1880 ObjectStore* object_store = isolate_->object_store(); | 1880 ObjectStore* object_store = isolate_->object_store(); |
1881 ASSERT(object_store != NULL); | 1881 ASSERT(object_store != NULL); |
1882 Heap* heap = isolate_->heap(); | 1882 Heap* heap = isolate_->heap(); |
1883 ASSERT(heap != NULL); | 1883 ASSERT(heap != NULL); |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 // We only allow closure of top level methods or static functions in a | 2469 // We only allow closure of top level methods or static functions in a |
2470 // class to be sent in isolate messages. | 2470 // class to be sent in isolate messages. |
2471 if (can_send_any_object() && | 2471 if (can_send_any_object() && |
2472 Function::IsImplicitStaticClosureFunction(func)) { | 2472 Function::IsImplicitStaticClosureFunction(func)) { |
2473 return func; | 2473 return func; |
2474 } | 2474 } |
2475 // Not a closure of a top level method or static function, throw an | 2475 // Not a closure of a top level method or static function, throw an |
2476 // exception as we do not allow these objects to be serialized. | 2476 // exception as we do not allow these objects to be serialized. |
2477 HANDLESCOPE(thread()); | 2477 HANDLESCOPE(thread()); |
2478 | 2478 |
2479 const Class& clazz = Class::Handle(isolate(), cls); | 2479 const Class& clazz = Class::Handle(zone(), cls); |
2480 const Function& errorFunc = Function::Handle(isolate(), func); | 2480 const Function& errorFunc = Function::Handle(zone(), func); |
2481 ASSERT(!errorFunc.IsNull()); | 2481 ASSERT(!errorFunc.IsNull()); |
2482 | 2482 |
2483 // All other closures are errors. | 2483 // All other closures are errors. |
2484 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2484 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
2485 char* chars = OS::SCreate(thread()->zone(), | 2485 char* chars = OS::SCreate(thread()->zone(), |
2486 "Illegal argument in isolate message : (object is a closure - %s %s)", | 2486 "Illegal argument in isolate message : (object is a closure - %s %s)", |
2487 clazz.ToCString(), errorFunc.ToCString()); | 2487 clazz.ToCString(), errorFunc.ToCString()); |
2488 SetWriteException(Exceptions::kArgument, chars); | 2488 SetWriteException(Exceptions::kArgument, chars); |
2489 } | 2489 } |
2490 return Function::null(); | 2490 return Function::null(); |
(...skipping 10 matching lines...) Expand all Loading... |
2501 ASSERT(class_id == kPatchClassCid); | 2501 ASSERT(class_id == kPatchClassCid); |
2502 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; | 2502 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; |
2503 } | 2503 } |
2504 | 2504 |
2505 | 2505 |
2506 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { | 2506 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { |
2507 if (cls->ptr()->num_native_fields_ != 0) { | 2507 if (cls->ptr()->num_native_fields_ != 0) { |
2508 // We do not allow objects with native fields in an isolate message. | 2508 // We do not allow objects with native fields in an isolate message. |
2509 HANDLESCOPE(thread()); | 2509 HANDLESCOPE(thread()); |
2510 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2510 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
2511 const Class& clazz = Class::Handle(isolate(), cls); | 2511 const Class& clazz = Class::Handle(zone(), cls); |
2512 char* chars = OS::SCreate(thread()->zone(), | 2512 char* chars = OS::SCreate(thread()->zone(), |
2513 "Illegal argument in isolate message" | 2513 "Illegal argument in isolate message" |
2514 " : (object extends NativeWrapper - %s)", | 2514 " : (object extends NativeWrapper - %s)", |
2515 clazz.ToCString()); | 2515 clazz.ToCString()); |
2516 SetWriteException(Exceptions::kArgument, chars); | 2516 SetWriteException(Exceptions::kArgument, chars); |
2517 } | 2517 } |
2518 } | 2518 } |
2519 | 2519 |
2520 | 2520 |
2521 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, | 2521 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2728 NoSafepointScope no_safepoint; | 2728 NoSafepointScope no_safepoint; |
2729 WriteObject(obj.raw()); | 2729 WriteObject(obj.raw()); |
2730 UnmarkAll(); | 2730 UnmarkAll(); |
2731 } else { | 2731 } else { |
2732 ThrowException(exception_type(), exception_msg()); | 2732 ThrowException(exception_type(), exception_msg()); |
2733 } | 2733 } |
2734 } | 2734 } |
2735 | 2735 |
2736 | 2736 |
2737 } // namespace dart | 2737 } // namespace dart |
OLD | NEW |