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" |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 SnapshotWriter::SnapshotWriter(Snapshot::Kind kind, | 853 SnapshotWriter::SnapshotWriter(Snapshot::Kind kind, |
854 uint8_t** buffer, | 854 uint8_t** buffer, |
855 ReAlloc alloc, | 855 ReAlloc alloc, |
856 intptr_t initial_size) | 856 intptr_t initial_size) |
857 : BaseWriter(buffer, alloc, initial_size), | 857 : BaseWriter(buffer, alloc, initial_size), |
858 kind_(kind), | 858 kind_(kind), |
859 object_store_(Isolate::Current()->object_store()), | 859 object_store_(Isolate::Current()->object_store()), |
860 class_table_(Isolate::Current()->class_table()), | 860 class_table_(Isolate::Current()->class_table()), |
861 forward_list_(), | 861 forward_list_(), |
862 exception_type_(Exceptions::kNone), | 862 exception_type_(Exceptions::kNone), |
863 exception_msg_(NULL), | 863 exception_msg_(NULL) { |
864 error_(LanguageError::Handle()) { | |
865 } | 864 } |
866 | 865 |
867 | 866 |
868 void SnapshotWriter::WriteObject(RawObject* rawobj) { | 867 void SnapshotWriter::WriteObject(RawObject* rawobj) { |
869 WriteObjectImpl(rawobj); | 868 WriteObjectImpl(rawobj); |
870 WriteForwardedObjects(); | 869 WriteForwardedObjects(); |
871 } | 870 } |
872 | 871 |
873 | 872 |
874 void SnapshotWriter::HandleVMIsolateObject(RawObject* rawobj) { | 873 void SnapshotWriter::HandleVMIsolateObject(RawObject* rawobj) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 ASSERT(isolate != NULL); | 1028 ASSERT(isolate != NULL); |
1030 ObjectStore* object_store = isolate->object_store(); | 1029 ObjectStore* object_store = isolate->object_store(); |
1031 ASSERT(object_store != NULL); | 1030 ASSERT(object_store != NULL); |
1032 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1031 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1033 | 1032 |
1034 // Setup for long jump in case there is an exception while writing | 1033 // Setup for long jump in case there is an exception while writing |
1035 // the snapshot. | 1034 // the snapshot. |
1036 LongJump* base = isolate->long_jump_base(); | 1035 LongJump* base = isolate->long_jump_base(); |
1037 LongJump jump; | 1036 LongJump jump; |
1038 isolate->set_long_jump_base(&jump); | 1037 isolate->set_long_jump_base(&jump); |
1039 // TODO(6726): Allocate these constant strings once in the VM isolate. | |
1040 *ErrorHandle() = LanguageError::New( | |
1041 String::Handle(String::New("Error while writing full snapshot"))); | |
1042 if (setjmp(*jump.Set()) == 0) { | 1038 if (setjmp(*jump.Set()) == 0) { |
1043 NoGCScope no_gc; | 1039 NoGCScope no_gc; |
1044 | 1040 |
1045 // Reserve space in the output buffer for a snapshot header. | 1041 // Reserve space in the output buffer for a snapshot header. |
1046 ReserveHeader(); | 1042 ReserveHeader(); |
1047 | 1043 |
1048 // Write out all the objects in the object store of the isolate which | 1044 // Write out all the objects in the object store of the isolate which |
1049 // is the root set for all dart allocated objects at this point. | 1045 // is the root set for all dart allocated objects at this point. |
1050 SnapshotWriterVisitor visitor(this, false); | 1046 SnapshotWriterVisitor visitor(this, false); |
1051 object_store->VisitObjectPointers(&visitor); | 1047 object_store->VisitObjectPointers(&visitor); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 SetWriteException(Exceptions::kArgument, | 1323 SetWriteException(Exceptions::kArgument, |
1328 "Illegal argument in isolate message" | 1324 "Illegal argument in isolate message" |
1329 " : (object extends NativeWrapper)"); | 1325 " : (object extends NativeWrapper)"); |
1330 } | 1326 } |
1331 } | 1327 } |
1332 | 1328 |
1333 | 1329 |
1334 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, | 1330 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, |
1335 const char* msg) { | 1331 const char* msg) { |
1336 set_exception_type(type); | 1332 set_exception_type(type); |
1337 // TODO(6726): Allocate these constant strings once in the VM isolate. | |
1338 set_exception_msg(msg); | 1333 set_exception_msg(msg); |
1339 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); | 1334 // The more specific error is set up in SnapshotWriter::ThrowException(). |
| 1335 Isolate::Current()->long_jump_base()-> |
| 1336 Jump(1, Object::snapshot_writer_error()); |
1340 } | 1337 } |
1341 | 1338 |
1342 | 1339 |
1343 void SnapshotWriter::WriteInstance(intptr_t object_id, | 1340 void SnapshotWriter::WriteInstance(intptr_t object_id, |
1344 RawObject* raw, | 1341 RawObject* raw, |
1345 RawClass* cls, | 1342 RawClass* cls, |
1346 intptr_t tags) { | 1343 intptr_t tags) { |
1347 // First check if object is a closure or has native fields. | 1344 // First check if object is a closure or has native fields. |
1348 CheckIfSerializable(cls); | 1345 CheckIfSerializable(cls); |
1349 | 1346 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 | 1390 |
1394 // Write out the class information for this object. | 1391 // Write out the class information for this object. |
1395 WriteObjectImpl(cls); | 1392 WriteObjectImpl(cls); |
1396 } | 1393 } |
1397 | 1394 |
1398 | 1395 |
1399 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, | 1396 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, |
1400 const char* msg) { | 1397 const char* msg) { |
1401 Isolate::Current()->object_store()->clear_sticky_error(); | 1398 Isolate::Current()->object_store()->clear_sticky_error(); |
1402 UnmarkAll(); | 1399 UnmarkAll(); |
1403 const String& msg_obj = String::Handle(String::New(msg)); | 1400 if (msg != NULL) { |
1404 const Array& args = Array::Handle(Array::New(1)); | 1401 const String& msg_obj = String::Handle(String::New(msg)); |
1405 args.SetAt(0, msg_obj); | 1402 const Array& args = Array::Handle(Array::New(1)); |
1406 Exceptions::ThrowByType(type, args); | 1403 args.SetAt(0, msg_obj); |
| 1404 Exceptions::ThrowByType(type, args); |
| 1405 } else { |
| 1406 Exceptions::ThrowByType(type, Object::empty_array()); |
| 1407 } |
1407 UNREACHABLE(); | 1408 UNREACHABLE(); |
1408 } | 1409 } |
1409 | 1410 |
1410 | 1411 |
1411 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { | 1412 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { |
1412 ASSERT(kind() == Snapshot::kScript); | 1413 ASSERT(kind() == Snapshot::kScript); |
1413 Isolate* isolate = Isolate::Current(); | 1414 Isolate* isolate = Isolate::Current(); |
1414 ASSERT(isolate != NULL); | 1415 ASSERT(isolate != NULL); |
1415 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1416 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1416 | 1417 |
1417 // Setup for long jump in case there is an exception while writing | 1418 // Setup for long jump in case there is an exception while writing |
1418 // the snapshot. | 1419 // the snapshot. |
1419 LongJump* base = isolate->long_jump_base(); | 1420 LongJump* base = isolate->long_jump_base(); |
1420 LongJump jump; | 1421 LongJump jump; |
1421 isolate->set_long_jump_base(&jump); | 1422 isolate->set_long_jump_base(&jump); |
1422 *ErrorHandle() = LanguageError::New( | |
1423 String::Handle(String::New("Error while writing script snapshot"))); | |
1424 if (setjmp(*jump.Set()) == 0) { | 1423 if (setjmp(*jump.Set()) == 0) { |
1425 // Write out the library object. | 1424 // Write out the library object. |
1426 NoGCScope no_gc; | 1425 NoGCScope no_gc; |
1427 ReserveHeader(); | 1426 ReserveHeader(); |
1428 WriteObject(lib.raw()); | 1427 WriteObject(lib.raw()); |
1429 FillHeader(kind()); | 1428 FillHeader(kind()); |
1430 UnmarkAll(); | 1429 UnmarkAll(); |
1431 isolate->set_long_jump_base(base); | 1430 isolate->set_long_jump_base(base); |
1432 } else { | 1431 } else { |
1433 isolate->set_long_jump_base(base); | 1432 isolate->set_long_jump_base(base); |
(...skipping 17 matching lines...) Expand all Loading... |
1451 void MessageWriter::WriteMessage(const Object& obj) { | 1450 void MessageWriter::WriteMessage(const Object& obj) { |
1452 ASSERT(kind() == Snapshot::kMessage); | 1451 ASSERT(kind() == Snapshot::kMessage); |
1453 Isolate* isolate = Isolate::Current(); | 1452 Isolate* isolate = Isolate::Current(); |
1454 ASSERT(isolate != NULL); | 1453 ASSERT(isolate != NULL); |
1455 | 1454 |
1456 // Setup for long jump in case there is an exception while writing | 1455 // Setup for long jump in case there is an exception while writing |
1457 // the message. | 1456 // the message. |
1458 LongJump* base = isolate->long_jump_base(); | 1457 LongJump* base = isolate->long_jump_base(); |
1459 LongJump jump; | 1458 LongJump jump; |
1460 isolate->set_long_jump_base(&jump); | 1459 isolate->set_long_jump_base(&jump); |
1461 *ErrorHandle() = LanguageError::New( | |
1462 String::Handle(String::New("Error while writing message"))); | |
1463 if (setjmp(*jump.Set()) == 0) { | 1460 if (setjmp(*jump.Set()) == 0) { |
1464 NoGCScope no_gc; | 1461 NoGCScope no_gc; |
1465 WriteObject(obj.raw()); | 1462 WriteObject(obj.raw()); |
1466 UnmarkAll(); | 1463 UnmarkAll(); |
1467 isolate->set_long_jump_base(base); | 1464 isolate->set_long_jump_base(base); |
1468 } else { | 1465 } else { |
1469 isolate->set_long_jump_base(base); | 1466 isolate->set_long_jump_base(base); |
1470 ThrowException(exception_type(), exception_msg()); | 1467 ThrowException(exception_type(), exception_msg()); |
1471 } | 1468 } |
1472 } | 1469 } |
1473 | 1470 |
1474 | 1471 |
1475 } // namespace dart | 1472 } // namespace dart |
OLD | NEW |