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 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 | 1177 |
1178 // The version string matches. Read the rest of the snapshot. | 1178 // The version string matches. Read the rest of the snapshot. |
1179 | 1179 |
1180 { | 1180 { |
1181 NoSafepointScope no_safepoint; | 1181 NoSafepointScope no_safepoint; |
1182 HeapLocker hl(isolate, old_space()); | 1182 HeapLocker hl(isolate, old_space()); |
1183 | 1183 |
1184 // Read in the symbol table. | 1184 // Read in the symbol table. |
1185 object_store->symbol_table_ = reinterpret_cast<RawArray*>(ReadObject()); | 1185 object_store->symbol_table_ = reinterpret_cast<RawArray*>(ReadObject()); |
1186 | 1186 |
1187 Symbols::InitOnceFromSnapshot(isolate); | |
1188 | |
1189 // Read in all the script objects and the accompanying token streams | |
1190 // for bootstrap libraries so that they are in the VM isolate's read | |
1191 // only memory. | |
1192 *(ArrayHandle()) ^= ReadObject(); | |
1193 | |
1187 // Validate the class table. | 1194 // Validate the class table. |
1188 #if defined(DEBUG) | 1195 #if defined(DEBUG) |
1189 isolate->ValidateClassTable(); | 1196 isolate->ValidateClassTable(); |
1190 #endif | 1197 #endif |
1191 | 1198 |
1192 return ApiError::null(); | 1199 return ApiError::null(); |
1193 } | 1200 } |
1194 } | 1201 } |
1195 | 1202 |
1196 | 1203 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 isolate_snapshot_buffer_(isolate_snapshot_buffer), | 1466 isolate_snapshot_buffer_(isolate_snapshot_buffer), |
1460 alloc_(alloc), | 1467 alloc_(alloc), |
1461 vm_isolate_snapshot_size_(0), | 1468 vm_isolate_snapshot_size_(0), |
1462 isolate_snapshot_size_(0), | 1469 isolate_snapshot_size_(0), |
1463 forward_list_(SnapshotWriter::FirstObjectId()) { | 1470 forward_list_(SnapshotWriter::FirstObjectId()) { |
1464 ASSERT(isolate_snapshot_buffer_ != NULL); | 1471 ASSERT(isolate_snapshot_buffer_ != NULL); |
1465 ASSERT(alloc_ != NULL); | 1472 ASSERT(alloc_ != NULL); |
1466 } | 1473 } |
1467 | 1474 |
1468 | 1475 |
1476 // An object visitor which will serialize all . This is used to | |
hausner
2015/05/21 20:37:13
missing word after "serialize all"?
Lower case S i
siva
2015/05/22 18:09:27
Done.
| |
1477 // Serialize all the script objects into the VM isolate heap. | |
1478 class ScriptVisitor : public ObjectVisitor { | |
1479 public: | |
1480 explicit ScriptVisitor(Isolate* isolate) : | |
1481 ObjectVisitor(isolate), | |
1482 objHandle_(Object::Handle(isolate)), | |
1483 count_(0), | |
1484 scripts_(NULL) {} | |
1485 | |
1486 ScriptVisitor(Isolate* isolate, const Array* scripts) : | |
1487 ObjectVisitor(isolate), | |
1488 objHandle_(Object::Handle(isolate)), | |
1489 count_(0), | |
1490 scripts_(scripts) {} | |
1491 | |
1492 void VisitObject(RawObject* obj) { | |
1493 if (obj->IsScript()) { | |
1494 if (scripts_ != NULL) { | |
1495 objHandle_ = obj; | |
1496 scripts_->SetAt(count_, objHandle_); | |
1497 } | |
1498 count_ += 1; | |
1499 } | |
1500 } | |
1501 | |
1502 intptr_t count() const { return count_; } | |
1503 | |
1504 private: | |
1505 Object& objHandle_; | |
1506 intptr_t count_; | |
1507 const Array* scripts_; | |
1508 }; | |
1509 | |
1510 | |
1469 void FullSnapshotWriter::WriteVmIsolateSnapshot() { | 1511 void FullSnapshotWriter::WriteVmIsolateSnapshot() { |
1470 ASSERT(vm_isolate_snapshot_buffer_ != NULL); | 1512 ASSERT(vm_isolate_snapshot_buffer_ != NULL); |
1471 SnapshotWriter writer(Snapshot::kFull, | 1513 SnapshotWriter writer(Snapshot::kFull, |
1472 vm_isolate_snapshot_buffer_, | 1514 vm_isolate_snapshot_buffer_, |
1473 alloc_, | 1515 alloc_, |
1474 kInitialSize, | 1516 kInitialSize, |
1475 &forward_list_, | 1517 &forward_list_, |
1476 true); // Can send any kind of object. | 1518 true); // Can send any kind of object. |
1477 Isolate* isolate = writer.isolate(); | 1519 Isolate* isolate = writer.isolate(); |
1478 ASSERT(isolate != NULL); | 1520 ASSERT(isolate != NULL); |
1479 ObjectStore* object_store = isolate->object_store(); | 1521 ObjectStore* object_store = isolate->object_store(); |
1480 ASSERT(object_store != NULL); | 1522 ASSERT(object_store != NULL); |
1481 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1523 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1482 | 1524 |
1483 // Ensure the class table is valid. | 1525 // Ensure the class table is valid. |
1484 #if defined(DEBUG) | 1526 #if defined(DEBUG) |
1485 isolate->ValidateClassTable(); | 1527 isolate->ValidateClassTable(); |
1486 #endif | 1528 #endif |
1487 | 1529 |
1488 // Write full snapshot for a regular isolate. | 1530 // Collect all the script objects and their accompanying token stream objects |
1531 // into an array so that we can write it out as part of the VM isolate | |
1532 // snapshot. We first count the number of script objects, allocate an array | |
1533 // and then fill it up with the script objects. | |
1534 ScriptVisitor scripts_counter(isolate); | |
1535 isolate->heap()->old_space()->VisitObjects(&scripts_counter); | |
1536 intptr_t count = scripts_counter.count(); | |
1537 const Array& scripts = Array::Handle(isolate, Array::New(count, Heap::kOld)); | |
1538 ScriptVisitor script_visitor(isolate, &scripts); | |
1539 isolate->heap()->old_space()->VisitObjects(&script_visitor); | |
1540 | |
1541 // Write full snapshot for the VM isolate. | |
1489 // Setup for long jump in case there is an exception while writing | 1542 // Setup for long jump in case there is an exception while writing |
1490 // the snapshot. | 1543 // the snapshot. |
1491 LongJumpScope jump; | 1544 LongJumpScope jump; |
1492 if (setjmp(*jump.Set()) == 0) { | 1545 if (setjmp(*jump.Set()) == 0) { |
1493 // Reserve space in the output buffer for a snapshot header. | 1546 // Reserve space in the output buffer for a snapshot header. |
1494 writer.ReserveHeader(); | 1547 writer.ReserveHeader(); |
1495 | 1548 |
1496 // Write out the version string. | 1549 // Write out the version string. |
1497 writer.WriteVersion(); | 1550 writer.WriteVersion(); |
1498 | 1551 |
1499 // Write out the symbol table. | 1552 // Write out the symbol table. |
1500 { | 1553 { |
1501 NoSafepointScope no_safepoint; | 1554 NoSafepointScope no_safepoint; |
1502 | 1555 |
1503 // Write out the symbol table and reset the symbol table for the | 1556 // Write out the symbol table and reset the symbol table for the |
1504 // regular isolate so that we do not write these symbols into the | 1557 // regular isolate so that we do not write these symbols into the |
1505 // snapshot of a regular dart isolate. | 1558 // snapshot of a regular dart isolate. |
1506 writer.WriteObject(object_store->symbol_table()); | 1559 writer.WriteObject(object_store->symbol_table()); |
1507 | 1560 |
1561 // Write out all the script objects and the accompanying token streams | |
1562 // for the bootstrap libraries so that they are in the VM isolate | |
1563 // read only memory. | |
1564 writer.WriteObject(scripts.raw()); | |
1565 | |
1566 // Write out all forwarded objects. | |
1567 writer.WriteForwardedObjects(); | |
1568 | |
1508 writer.FillHeader(writer.kind()); | 1569 writer.FillHeader(writer.kind()); |
1509 } | 1570 } |
1510 vm_isolate_snapshot_size_ = writer.BytesWritten(); | 1571 vm_isolate_snapshot_size_ = writer.BytesWritten(); |
1511 // Reset the symbol table for the regular isolate so that we do not | 1572 // Reset the symbol table for the regular isolate so that we do not |
1512 // write these symbols into the snapshot of a regular dart isolate. | 1573 // write these symbols into the snapshot of a regular dart isolate. |
1513 Symbols::SetupSymbolTable(isolate); | 1574 Symbols::SetupSymbolTable(isolate); |
1514 } else { | 1575 } else { |
1515 writer.ThrowException(writer.exception_type(), writer.exception_msg()); | 1576 writer.ThrowException(writer.exception_type(), writer.exception_msg()); |
1516 } | 1577 } |
1517 } | 1578 } |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2223 NoSafepointScope no_safepoint; | 2284 NoSafepointScope no_safepoint; |
2224 WriteObject(obj.raw()); | 2285 WriteObject(obj.raw()); |
2225 UnmarkAll(); | 2286 UnmarkAll(); |
2226 } else { | 2287 } else { |
2227 ThrowException(exception_type(), exception_msg()); | 2288 ThrowException(exception_type(), exception_msg()); |
2228 } | 2289 } |
2229 } | 2290 } |
2230 | 2291 |
2231 | 2292 |
2232 } // namespace dart | 2293 } // namespace dart |
OLD | NEW |