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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 stream_(TokenStream::Handle()), | 160 stream_(TokenStream::Handle()), |
161 data_(ExternalTypedData::Handle()), | 161 data_(ExternalTypedData::Handle()), |
162 error_(UnhandledException::Handle()), | 162 error_(UnhandledException::Handle()), |
163 backward_references_((kind == Snapshot::kFull) ? | 163 backward_references_((kind == Snapshot::kFull) ? |
164 kNumInitialReferencesInFullSnapshot : | 164 kNumInitialReferencesInFullSnapshot : |
165 kNumInitialReferences) { | 165 kNumInitialReferences) { |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 RawObject* SnapshotReader::ReadObject() { | 169 RawObject* SnapshotReader::ReadObject() { |
170 // Setup for long jump in case there is an exception while reading. | |
171 LongJump* base = isolate()->long_jump_base(); | |
172 LongJump jump; | |
173 isolate()->set_long_jump_base(&jump); | |
174 const Instance& null_object = Instance::Handle(); | 170 const Instance& null_object = Instance::Handle(); |
175 *ErrorHandle() = UnhandledException::New(null_object, null_object); | 171 *ErrorHandle() = UnhandledException::New(null_object, null_object); |
| 172 // Setup for long jump in case there is an exception while reading. |
| 173 LongJumpScope jump; |
176 if (setjmp(*jump.Set()) == 0) { | 174 if (setjmp(*jump.Set()) == 0) { |
177 Object& obj = Object::Handle(ReadObjectImpl()); | 175 Object& obj = Object::Handle(ReadObjectImpl()); |
178 for (intptr_t i = 0; i < backward_references_.length(); i++) { | 176 for (intptr_t i = 0; i < backward_references_.length(); i++) { |
179 if (!backward_references_[i]->is_deserialized()) { | 177 if (!backward_references_[i]->is_deserialized()) { |
180 ReadObjectImpl(); | 178 ReadObjectImpl(); |
181 backward_references_[i]->set_state(kIsDeserialized); | 179 backward_references_[i]->set_state(kIsDeserialized); |
182 } | 180 } |
183 } | 181 } |
184 isolate()->set_long_jump_base(base); | |
185 return obj.raw(); | 182 return obj.raw(); |
186 } else { | 183 } else { |
187 // An error occurred while reading, return the error object. | 184 // An error occurred while reading, return the error object. |
188 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); | 185 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); |
189 isolate()->object_store()->clear_sticky_error(); | 186 isolate()->object_store()->clear_sticky_error(); |
190 isolate()->set_long_jump_base(base); | |
191 return err.raw(); | 187 return err.raw(); |
192 } | 188 } |
193 } | 189 } |
194 | 190 |
195 | 191 |
196 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { | 192 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { |
197 ASSERT(kind_ != Snapshot::kFull); | 193 ASSERT(kind_ != Snapshot::kFull); |
198 // Read the class header information and lookup the class. | 194 // Read the class header information and lookup the class. |
199 intptr_t class_header = ReadIntptrValue(); | 195 intptr_t class_header = ReadIntptrValue(); |
200 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 196 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 | 1071 |
1076 void FullSnapshotWriter::WriteFullSnapshot() { | 1072 void FullSnapshotWriter::WriteFullSnapshot() { |
1077 Isolate* isolate = Isolate::Current(); | 1073 Isolate* isolate = Isolate::Current(); |
1078 ASSERT(isolate != NULL); | 1074 ASSERT(isolate != NULL); |
1079 ObjectStore* object_store = isolate->object_store(); | 1075 ObjectStore* object_store = isolate->object_store(); |
1080 ASSERT(object_store != NULL); | 1076 ASSERT(object_store != NULL); |
1081 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1077 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1082 | 1078 |
1083 // Setup for long jump in case there is an exception while writing | 1079 // Setup for long jump in case there is an exception while writing |
1084 // the snapshot. | 1080 // the snapshot. |
1085 LongJump* base = isolate->long_jump_base(); | 1081 LongJumpScope jump; |
1086 LongJump jump; | |
1087 isolate->set_long_jump_base(&jump); | |
1088 if (setjmp(*jump.Set()) == 0) { | 1082 if (setjmp(*jump.Set()) == 0) { |
1089 NoGCScope no_gc; | 1083 NoGCScope no_gc; |
1090 | 1084 |
1091 // Reserve space in the output buffer for a snapshot header. | 1085 // Reserve space in the output buffer for a snapshot header. |
1092 ReserveHeader(); | 1086 ReserveHeader(); |
1093 | 1087 |
1094 // Write out all the objects in the object store of the isolate which | 1088 // Write out all the objects in the object store of the isolate which |
1095 // is the root set for all dart allocated objects at this point. | 1089 // is the root set for all dart allocated objects at this point. |
1096 SnapshotWriterVisitor visitor(this, false); | 1090 SnapshotWriterVisitor visitor(this, false); |
1097 object_store->VisitObjectPointers(&visitor); | 1091 object_store->VisitObjectPointers(&visitor); |
1098 | 1092 |
1099 // Write out all forwarded objects. | 1093 // Write out all forwarded objects. |
1100 WriteForwardedObjects(); | 1094 WriteForwardedObjects(); |
1101 | 1095 |
1102 FillHeader(kind()); | 1096 FillHeader(kind()); |
1103 UnmarkAll(); | 1097 UnmarkAll(); |
1104 | |
1105 isolate->set_long_jump_base(base); | |
1106 } else { | 1098 } else { |
1107 isolate->set_long_jump_base(base); | |
1108 ThrowException(exception_type(), exception_msg()); | 1099 ThrowException(exception_type(), exception_msg()); |
1109 } | 1100 } |
1110 } | 1101 } |
1111 | 1102 |
1112 | 1103 |
1113 uword SnapshotWriter::GetObjectTags(RawObject* raw) { | 1104 uword SnapshotWriter::GetObjectTags(RawObject* raw) { |
1114 uword tags = raw->ptr()->tags_; | 1105 uword tags = raw->ptr()->tags_; |
1115 if (SerializedHeaderTag::decode(tags) == kObjectId) { | 1106 if (SerializedHeaderTag::decode(tags) == kObjectId) { |
1116 intptr_t id = SerializedHeaderData::decode(tags); | 1107 intptr_t id = SerializedHeaderData::decode(tags); |
1117 return forward_list_[id - kMaxPredefinedObjectIds]->tags(); | 1108 return forward_list_[id - kMaxPredefinedObjectIds]->tags(); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1459 |
1469 | 1460 |
1470 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { | 1461 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { |
1471 ASSERT(kind() == Snapshot::kScript); | 1462 ASSERT(kind() == Snapshot::kScript); |
1472 Isolate* isolate = Isolate::Current(); | 1463 Isolate* isolate = Isolate::Current(); |
1473 ASSERT(isolate != NULL); | 1464 ASSERT(isolate != NULL); |
1474 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1465 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1475 | 1466 |
1476 // Setup for long jump in case there is an exception while writing | 1467 // Setup for long jump in case there is an exception while writing |
1477 // the snapshot. | 1468 // the snapshot. |
1478 LongJump* base = isolate->long_jump_base(); | 1469 LongJumpScope jump; |
1479 LongJump jump; | |
1480 isolate->set_long_jump_base(&jump); | |
1481 if (setjmp(*jump.Set()) == 0) { | 1470 if (setjmp(*jump.Set()) == 0) { |
1482 // Write out the library object. | 1471 // Write out the library object. |
1483 NoGCScope no_gc; | 1472 NoGCScope no_gc; |
1484 ReserveHeader(); | 1473 ReserveHeader(); |
1485 WriteObject(lib.raw()); | 1474 WriteObject(lib.raw()); |
1486 FillHeader(kind()); | 1475 FillHeader(kind()); |
1487 UnmarkAll(); | 1476 UnmarkAll(); |
1488 isolate->set_long_jump_base(base); | |
1489 } else { | 1477 } else { |
1490 isolate->set_long_jump_base(base); | |
1491 ThrowException(exception_type(), exception_msg()); | 1478 ThrowException(exception_type(), exception_msg()); |
1492 } | 1479 } |
1493 } | 1480 } |
1494 | 1481 |
1495 | 1482 |
1496 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 1483 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
1497 for (RawObject** current = first; current <= last; current++) { | 1484 for (RawObject** current = first; current <= last; current++) { |
1498 RawObject* raw_obj = *current; | 1485 RawObject* raw_obj = *current; |
1499 if (as_references_) { | 1486 if (as_references_) { |
1500 writer_->WriteObjectRef(raw_obj); | 1487 writer_->WriteObjectRef(raw_obj); |
1501 } else { | 1488 } else { |
1502 writer_->WriteObjectImpl(raw_obj); | 1489 writer_->WriteObjectImpl(raw_obj); |
1503 } | 1490 } |
1504 } | 1491 } |
1505 } | 1492 } |
1506 | 1493 |
1507 | 1494 |
1508 void MessageWriter::WriteMessage(const Object& obj) { | 1495 void MessageWriter::WriteMessage(const Object& obj) { |
1509 ASSERT(kind() == Snapshot::kMessage); | 1496 ASSERT(kind() == Snapshot::kMessage); |
1510 Isolate* isolate = Isolate::Current(); | 1497 Isolate* isolate = Isolate::Current(); |
1511 ASSERT(isolate != NULL); | 1498 ASSERT(isolate != NULL); |
1512 | 1499 |
1513 // Setup for long jump in case there is an exception while writing | 1500 // Setup for long jump in case there is an exception while writing |
1514 // the message. | 1501 // the message. |
1515 LongJump* base = isolate->long_jump_base(); | 1502 LongJumpScope jump; |
1516 LongJump jump; | |
1517 isolate->set_long_jump_base(&jump); | |
1518 if (setjmp(*jump.Set()) == 0) { | 1503 if (setjmp(*jump.Set()) == 0) { |
1519 NoGCScope no_gc; | 1504 NoGCScope no_gc; |
1520 WriteObject(obj.raw()); | 1505 WriteObject(obj.raw()); |
1521 UnmarkAll(); | 1506 UnmarkAll(); |
1522 isolate->set_long_jump_base(base); | |
1523 } else { | 1507 } else { |
1524 isolate->set_long_jump_base(base); | |
1525 ThrowException(exception_type(), exception_msg()); | 1508 ThrowException(exception_type(), exception_msg()); |
1526 } | 1509 } |
1527 } | 1510 } |
1528 | 1511 |
1529 | 1512 |
1530 } // namespace dart | 1513 } // namespace dart |
OLD | NEW |