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 iterate over all the script objects in the heap |
| 1477 // and either count them or collect them into an array. This is used during |
| 1478 // full snapshot generation of the VM isolate to write out all script |
| 1479 // objects and their accompanying token streams. |
| 1480 class ScriptVisitor : public ObjectVisitor { |
| 1481 public: |
| 1482 explicit ScriptVisitor(Isolate* isolate) : |
| 1483 ObjectVisitor(isolate), |
| 1484 objHandle_(Object::Handle(isolate)), |
| 1485 count_(0), |
| 1486 scripts_(NULL) {} |
| 1487 |
| 1488 ScriptVisitor(Isolate* isolate, const Array* scripts) : |
| 1489 ObjectVisitor(isolate), |
| 1490 objHandle_(Object::Handle(isolate)), |
| 1491 count_(0), |
| 1492 scripts_(scripts) {} |
| 1493 |
| 1494 void VisitObject(RawObject* obj) { |
| 1495 if (obj->IsScript()) { |
| 1496 if (scripts_ != NULL) { |
| 1497 objHandle_ = obj; |
| 1498 scripts_->SetAt(count_, objHandle_); |
| 1499 } |
| 1500 count_ += 1; |
| 1501 } |
| 1502 } |
| 1503 |
| 1504 intptr_t count() const { return count_; } |
| 1505 |
| 1506 private: |
| 1507 Object& objHandle_; |
| 1508 intptr_t count_; |
| 1509 const Array* scripts_; |
| 1510 }; |
| 1511 |
| 1512 |
1469 void FullSnapshotWriter::WriteVmIsolateSnapshot() { | 1513 void FullSnapshotWriter::WriteVmIsolateSnapshot() { |
1470 ASSERT(vm_isolate_snapshot_buffer_ != NULL); | 1514 ASSERT(vm_isolate_snapshot_buffer_ != NULL); |
1471 SnapshotWriter writer(Snapshot::kFull, | 1515 SnapshotWriter writer(Snapshot::kFull, |
1472 vm_isolate_snapshot_buffer_, | 1516 vm_isolate_snapshot_buffer_, |
1473 alloc_, | 1517 alloc_, |
1474 kInitialSize, | 1518 kInitialSize, |
1475 &forward_list_, | 1519 &forward_list_, |
1476 true); // Can send any kind of object. | 1520 true); // Can send any kind of object. |
1477 Isolate* isolate = writer.isolate(); | 1521 Isolate* isolate = writer.isolate(); |
1478 ASSERT(isolate != NULL); | 1522 ASSERT(isolate != NULL); |
1479 ObjectStore* object_store = isolate->object_store(); | 1523 ObjectStore* object_store = isolate->object_store(); |
1480 ASSERT(object_store != NULL); | 1524 ASSERT(object_store != NULL); |
1481 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1525 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1482 | 1526 |
1483 // Ensure the class table is valid. | 1527 // Ensure the class table is valid. |
1484 #if defined(DEBUG) | 1528 #if defined(DEBUG) |
1485 isolate->ValidateClassTable(); | 1529 isolate->ValidateClassTable(); |
1486 #endif | 1530 #endif |
1487 | 1531 |
1488 // Write full snapshot for a regular isolate. | 1532 // Collect all the script objects and their accompanying token stream objects |
| 1533 // into an array so that we can write it out as part of the VM isolate |
| 1534 // snapshot. We first count the number of script objects, allocate an array |
| 1535 // and then fill it up with the script objects. |
| 1536 ScriptVisitor scripts_counter(isolate); |
| 1537 isolate->heap()->old_space()->VisitObjects(&scripts_counter); |
| 1538 intptr_t count = scripts_counter.count(); |
| 1539 const Array& scripts = Array::Handle(isolate, Array::New(count, Heap::kOld)); |
| 1540 ScriptVisitor script_visitor(isolate, &scripts); |
| 1541 isolate->heap()->old_space()->VisitObjects(&script_visitor); |
| 1542 |
| 1543 // Write full snapshot for the VM isolate. |
1489 // Setup for long jump in case there is an exception while writing | 1544 // Setup for long jump in case there is an exception while writing |
1490 // the snapshot. | 1545 // the snapshot. |
1491 LongJumpScope jump; | 1546 LongJumpScope jump; |
1492 if (setjmp(*jump.Set()) == 0) { | 1547 if (setjmp(*jump.Set()) == 0) { |
1493 // Reserve space in the output buffer for a snapshot header. | 1548 // Reserve space in the output buffer for a snapshot header. |
1494 writer.ReserveHeader(); | 1549 writer.ReserveHeader(); |
1495 | 1550 |
1496 // Write out the version string. | 1551 // Write out the version string. |
1497 writer.WriteVersion(); | 1552 writer.WriteVersion(); |
1498 | 1553 |
1499 // Write out the symbol table. | 1554 /* |
| 1555 * Now Write out the following |
| 1556 * - the symbol table |
| 1557 * - all the scripts and token streams for these scripts |
| 1558 * |
| 1559 **/ |
1500 { | 1560 { |
1501 NoSafepointScope no_safepoint; | 1561 NoSafepointScope no_safepoint; |
1502 | 1562 |
1503 // Write out the symbol table and reset the symbol table for the | 1563 // 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 | 1564 // regular isolate so that we do not write these symbols into the |
1505 // snapshot of a regular dart isolate. | 1565 // snapshot of a regular dart isolate. |
1506 writer.WriteObject(object_store->symbol_table()); | 1566 writer.WriteObject(object_store->symbol_table()); |
1507 | 1567 |
| 1568 // Write out all the script objects and the accompanying token streams |
| 1569 // for the bootstrap libraries so that they are in the VM isolate |
| 1570 // read only memory. |
| 1571 writer.WriteObject(scripts.raw()); |
| 1572 |
| 1573 // Write out all forwarded objects. |
| 1574 writer.WriteForwardedObjects(); |
| 1575 |
1508 writer.FillHeader(writer.kind()); | 1576 writer.FillHeader(writer.kind()); |
1509 } | 1577 } |
1510 vm_isolate_snapshot_size_ = writer.BytesWritten(); | 1578 vm_isolate_snapshot_size_ = writer.BytesWritten(); |
1511 // Reset the symbol table for the regular isolate so that we do not | 1579 // 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. | 1580 // write these symbols into the snapshot of a regular dart isolate. |
1513 Symbols::SetupSymbolTable(isolate); | 1581 Symbols::SetupSymbolTable(isolate); |
1514 } else { | 1582 } else { |
1515 writer.ThrowException(writer.exception_type(), writer.exception_msg()); | 1583 writer.ThrowException(writer.exception_type(), writer.exception_msg()); |
1516 } | 1584 } |
1517 } | 1585 } |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 NoSafepointScope no_safepoint; | 2291 NoSafepointScope no_safepoint; |
2224 WriteObject(obj.raw()); | 2292 WriteObject(obj.raw()); |
2225 UnmarkAll(); | 2293 UnmarkAll(); |
2226 } else { | 2294 } else { |
2227 ThrowException(exception_type(), exception_msg()); | 2295 ThrowException(exception_type(), exception_msg()); |
2228 } | 2296 } |
2229 } | 2297 } |
2230 | 2298 |
2231 | 2299 |
2232 } // namespace dart | 2300 } // namespace dart |
OLD | NEW |