| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 417 |
| 418 { | 418 { |
| 419 NoGCScope no_gc; | 419 NoGCScope no_gc; |
| 420 HeapLocker hl(isolate, old_space()); | 420 HeapLocker hl(isolate, old_space()); |
| 421 | 421 |
| 422 // First read the version string, and check that it matches. | 422 // First read the version string, and check that it matches. |
| 423 obj_ = ReadObject(); | 423 obj_ = ReadObject(); |
| 424 | 424 |
| 425 // If the version string doesn't match, return an error. | 425 // If the version string doesn't match, return an error. |
| 426 // NB: New things are allocated only if we're going to return an error. | 426 // NB: New things are allocated only if we're going to return an error. |
| 427 if (!obj_.IsString() || !String::Cast(obj_).Equals(Version::String())) { | 427 if (!obj_.IsString() || |
| 428 !String::Cast(obj_).Equals(Version::SnapshotString())) { |
| 428 const intptr_t kMessageBufferSize = 128; | 429 const intptr_t kMessageBufferSize = 128; |
| 429 char message_buffer[kMessageBufferSize]; | 430 char message_buffer[kMessageBufferSize]; |
| 430 OS::SNPrint(message_buffer, | 431 OS::SNPrint(message_buffer, |
| 431 kMessageBufferSize, | 432 kMessageBufferSize, |
| 432 "Wrong full snapshot version. Found %s expected %s", | 433 "Wrong full snapshot version. Found %s expected %s", |
| 433 obj_.ToCString(), | 434 obj_.ToCString(), |
| 434 Version::String()); | 435 Version::SnapshotString()); |
| 435 const String& msg = String::Handle(String::New(message_buffer)); | 436 const String& msg = String::Handle(String::New(message_buffer)); |
| 436 return ApiError::New(msg); | 437 return ApiError::New(msg); |
| 437 } | 438 } |
| 438 | 439 |
| 439 // The version string matches. Read the rest of the snapshot. | 440 // The version string matches. Read the rest of the snapshot. |
| 440 | 441 |
| 441 // Read in all the objects stored in the object store. | 442 // Read in all the objects stored in the object store. |
| 442 intptr_t num_flds = (object_store->to() - object_store->from()); | 443 intptr_t num_flds = (object_store->to() - object_store->from()); |
| 443 for (intptr_t i = 0; i <= num_flds; i++) { | 444 for (intptr_t i = 0; i <= num_flds; i++) { |
| 444 *(object_store->from() + i) = ReadObjectImpl(); | 445 *(object_store->from() + i) = ReadObjectImpl(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 463 | 464 |
| 464 | 465 |
| 465 RawObject* SnapshotReader::ReadScriptSnapshot() { | 466 RawObject* SnapshotReader::ReadScriptSnapshot() { |
| 466 ASSERT(kind_ == Snapshot::kScript); | 467 ASSERT(kind_ == Snapshot::kScript); |
| 467 | 468 |
| 468 // First read the version string, and check that it matches. | 469 // First read the version string, and check that it matches. |
| 469 obj_ = ReadObject(); | 470 obj_ = ReadObject(); |
| 470 | 471 |
| 471 // If the version string doesn't match, return an error. | 472 // If the version string doesn't match, return an error. |
| 472 // NB: New things are allocated only if we're going to return an error. | 473 // NB: New things are allocated only if we're going to return an error. |
| 473 if (!obj_.IsString() || !String::Cast(obj_).Equals(Version::String())) { | 474 if (!obj_.IsString() || |
| 475 !String::Cast(obj_).Equals(Version::SnapshotString())) { |
| 474 const intptr_t kMessageBufferSize = 256; | 476 const intptr_t kMessageBufferSize = 256; |
| 475 char message_buffer[kMessageBufferSize]; | 477 char message_buffer[kMessageBufferSize]; |
| 476 OS::SNPrint(message_buffer, | 478 OS::SNPrint(message_buffer, |
| 477 kMessageBufferSize, | 479 kMessageBufferSize, |
| 478 "Wrong script snapshot version. Found %s expected '%s'", | 480 "Wrong script snapshot version. Found %s expected '%s'", |
| 479 obj_.ToCString(), | 481 obj_.ToCString(), |
| 480 Version::String()); | 482 Version::SnapshotString()); |
| 481 const String& msg = String::Handle(String::New(message_buffer)); | 483 const String& msg = String::Handle(String::New(message_buffer)); |
| 482 return ApiError::New(msg); | 484 return ApiError::New(msg); |
| 483 } | 485 } |
| 484 | 486 |
| 485 // The version string matches. Read the rest of the snapshot. | 487 // The version string matches. Read the rest of the snapshot. |
| 486 obj_ = ReadObject(); | 488 obj_ = ReadObject(); |
| 487 if (!obj_.IsLibrary()) { | 489 if (!obj_.IsLibrary()) { |
| 488 if (!obj_.IsError()) { | 490 if (!obj_.IsError()) { |
| 489 const intptr_t kMessageBufferSize = 128; | 491 const intptr_t kMessageBufferSize = 128; |
| 490 char message_buffer[kMessageBufferSize]; | 492 char message_buffer[kMessageBufferSize]; |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 #endif | 1244 #endif |
| 1243 | 1245 |
| 1244 // Setup for long jump in case there is an exception while writing | 1246 // Setup for long jump in case there is an exception while writing |
| 1245 // the snapshot. | 1247 // the snapshot. |
| 1246 LongJumpScope jump; | 1248 LongJumpScope jump; |
| 1247 if (setjmp(*jump.Set()) == 0) { | 1249 if (setjmp(*jump.Set()) == 0) { |
| 1248 // Reserve space in the output buffer for a snapshot header. | 1250 // Reserve space in the output buffer for a snapshot header. |
| 1249 ReserveHeader(); | 1251 ReserveHeader(); |
| 1250 | 1252 |
| 1251 // Write out the version string. | 1253 // Write out the version string. |
| 1252 WriteObject(String::New(Version::String())); | 1254 WriteObject(String::New(Version::SnapshotString())); |
| 1253 | 1255 |
| 1254 // Write out the full snapshot. | 1256 // Write out the full snapshot. |
| 1255 { | 1257 { |
| 1256 NoGCScope no_gc; | 1258 NoGCScope no_gc; |
| 1257 | 1259 |
| 1258 // Write out all the objects in the object store of the isolate which | 1260 // Write out all the objects in the object store of the isolate which |
| 1259 // is the root set for all dart allocated objects at this point. | 1261 // is the root set for all dart allocated objects at this point. |
| 1260 SnapshotWriterVisitor visitor(this, false); | 1262 SnapshotWriterVisitor visitor(this, false); |
| 1261 object_store->VisitObjectPointers(&visitor); | 1263 object_store->VisitObjectPointers(&visitor); |
| 1262 | 1264 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1680 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 1679 | 1681 |
| 1680 // Setup for long jump in case there is an exception while writing | 1682 // Setup for long jump in case there is an exception while writing |
| 1681 // the snapshot. | 1683 // the snapshot. |
| 1682 LongJumpScope jump; | 1684 LongJumpScope jump; |
| 1683 if (setjmp(*jump.Set()) == 0) { | 1685 if (setjmp(*jump.Set()) == 0) { |
| 1684 // Reserve space in the output buffer for a snapshot header. | 1686 // Reserve space in the output buffer for a snapshot header. |
| 1685 ReserveHeader(); | 1687 ReserveHeader(); |
| 1686 | 1688 |
| 1687 // Write out the version string. | 1689 // Write out the version string. |
| 1688 WriteObject(String::New(Version::String())); | 1690 WriteObject(String::New(Version::SnapshotString())); |
| 1689 | 1691 |
| 1690 // Write out the library object. | 1692 // Write out the library object. |
| 1691 { | 1693 { |
| 1692 NoGCScope no_gc; | 1694 NoGCScope no_gc; |
| 1693 | 1695 |
| 1694 // Write out the library object. | 1696 // Write out the library object. |
| 1695 WriteObject(lib.raw()); | 1697 WriteObject(lib.raw()); |
| 1696 | 1698 |
| 1697 FillHeader(kind()); | 1699 FillHeader(kind()); |
| 1698 UnmarkAll(); | 1700 UnmarkAll(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1727 NoGCScope no_gc; | 1729 NoGCScope no_gc; |
| 1728 WriteObject(obj.raw()); | 1730 WriteObject(obj.raw()); |
| 1729 UnmarkAll(); | 1731 UnmarkAll(); |
| 1730 } else { | 1732 } else { |
| 1731 ThrowException(exception_type(), exception_msg()); | 1733 ThrowException(exception_type(), exception_msg()); |
| 1732 } | 1734 } |
| 1733 } | 1735 } |
| 1734 | 1736 |
| 1735 | 1737 |
| 1736 } // namespace dart | 1738 } // namespace dart |
| OLD | NEW |