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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 573 |
574 private: | 574 private: |
575 PageSpace* page_space_; | 575 PageSpace* page_space_; |
576 }; | 576 }; |
577 | 577 |
578 | 578 |
579 RawObject* SnapshotReader::ReadScriptSnapshot() { | 579 RawObject* SnapshotReader::ReadScriptSnapshot() { |
580 ASSERT(kind_ == Snapshot::kScript); | 580 ASSERT(kind_ == Snapshot::kScript); |
581 | 581 |
582 // First read the version string, and check that it matches. | 582 // First read the version string, and check that it matches. |
583 RawApiError* error = VerifyVersionAndFeatures(); | 583 RawApiError* error = VerifyVersionAndFeatures(Isolate::Current()); |
584 if (error != ApiError::null()) { | 584 if (error != ApiError::null()) { |
585 return error; | 585 return error; |
586 } | 586 } |
587 | 587 |
588 // The version string matches. Read the rest of the snapshot. | 588 // The version string matches. Read the rest of the snapshot. |
589 obj_ = ReadObject(); | 589 obj_ = ReadObject(); |
590 if (!obj_.IsLibrary()) { | 590 if (!obj_.IsLibrary()) { |
591 if (!obj_.IsError()) { | 591 if (!obj_.IsError()) { |
592 const intptr_t kMessageBufferSize = 128; | 592 const intptr_t kMessageBufferSize = 128; |
593 char message_buffer[kMessageBufferSize]; | 593 char message_buffer[kMessageBufferSize]; |
594 OS::SNPrint(message_buffer, kMessageBufferSize, | 594 OS::SNPrint(message_buffer, kMessageBufferSize, |
595 "Invalid object %s found in script snapshot", | 595 "Invalid object %s found in script snapshot", |
596 obj_.ToCString()); | 596 obj_.ToCString()); |
597 const String& msg = String::Handle(String::New(message_buffer)); | 597 const String& msg = String::Handle(String::New(message_buffer)); |
598 obj_ = ApiError::New(msg); | 598 obj_ = ApiError::New(msg); |
599 } | 599 } |
600 } | 600 } |
601 return obj_.raw(); | 601 return obj_.raw(); |
602 } | 602 } |
603 | 603 |
604 | 604 |
605 RawApiError* SnapshotReader::VerifyVersionAndFeatures() { | 605 RawApiError* SnapshotReader::VerifyVersionAndFeatures(Isolate* isolate) { |
606 // If the version string doesn't match, return an error. | 606 // If the version string doesn't match, return an error. |
607 // Note: New things are allocated only if we're going to return an error. | 607 // Note: New things are allocated only if we're going to return an error. |
608 | 608 |
609 const char* expected_version = Version::SnapshotString(); | 609 const char* expected_version = Version::SnapshotString(); |
610 ASSERT(expected_version != NULL); | 610 ASSERT(expected_version != NULL); |
611 const intptr_t version_len = strlen(expected_version); | 611 const intptr_t version_len = strlen(expected_version); |
612 if (PendingBytes() < version_len) { | 612 if (PendingBytes() < version_len) { |
613 const intptr_t kMessageBufferSize = 128; | 613 const intptr_t kMessageBufferSize = 128; |
614 char message_buffer[kMessageBufferSize]; | 614 char message_buffer[kMessageBufferSize]; |
615 OS::SNPrint(message_buffer, kMessageBufferSize, | 615 OS::SNPrint(message_buffer, kMessageBufferSize, |
(...skipping 16 matching lines...) Expand all Loading... |
632 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version, | 632 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version, |
633 actual_version); | 633 actual_version); |
634 free(actual_version); | 634 free(actual_version); |
635 // This can also fail while bringing up the VM isolate, so make sure to | 635 // This can also fail while bringing up the VM isolate, so make sure to |
636 // allocate the error message in old space. | 636 // allocate the error message in old space. |
637 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld)); | 637 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld)); |
638 return ApiError::New(msg, Heap::kOld); | 638 return ApiError::New(msg, Heap::kOld); |
639 } | 639 } |
640 Advance(version_len); | 640 Advance(version_len); |
641 | 641 |
642 const char* expected_features = Dart::FeaturesString(kind_); | 642 const char* expected_features = Dart::FeaturesString(isolate, kind_); |
643 ASSERT(expected_features != NULL); | 643 ASSERT(expected_features != NULL); |
644 const intptr_t expected_len = strlen(expected_features); | 644 const intptr_t expected_len = strlen(expected_features); |
645 | 645 |
646 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress()); | 646 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress()); |
647 ASSERT(features != NULL); | 647 ASSERT(features != NULL); |
648 intptr_t buffer_len = OS::StrNLen(features, PendingBytes()); | 648 intptr_t buffer_len = OS::StrNLen(features, PendingBytes()); |
649 if ((buffer_len != expected_len) || | 649 if ((buffer_len != expected_len) || |
650 strncmp(features, expected_features, expected_len)) { | 650 strncmp(features, expected_features, expected_len)) { |
651 const intptr_t kMessageBufferSize = 256; | 651 const intptr_t kMessageBufferSize = 256; |
652 char message_buffer[kMessageBufferSize]; | 652 char message_buffer[kMessageBufferSize]; |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 UNREACHABLE(); | 1835 UNREACHABLE(); |
1836 } | 1836 } |
1837 | 1837 |
1838 | 1838 |
1839 void SnapshotWriter::WriteVersionAndFeatures() { | 1839 void SnapshotWriter::WriteVersionAndFeatures() { |
1840 const char* expected_version = Version::SnapshotString(); | 1840 const char* expected_version = Version::SnapshotString(); |
1841 ASSERT(expected_version != NULL); | 1841 ASSERT(expected_version != NULL); |
1842 const intptr_t version_len = strlen(expected_version); | 1842 const intptr_t version_len = strlen(expected_version); |
1843 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); | 1843 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); |
1844 | 1844 |
1845 const char* expected_features = Dart::FeaturesString(kind_); | 1845 const char* expected_features = |
| 1846 Dart::FeaturesString(Isolate::Current(), kind_); |
1846 ASSERT(expected_features != NULL); | 1847 ASSERT(expected_features != NULL); |
1847 const intptr_t features_len = strlen(expected_features); | 1848 const intptr_t features_len = strlen(expected_features); |
1848 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features), | 1849 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features), |
1849 features_len + 1); | 1850 features_len + 1); |
1850 free(const_cast<char*>(expected_features)); | 1851 free(const_cast<char*>(expected_features)); |
1851 } | 1852 } |
1852 | 1853 |
1853 | 1854 |
1854 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 1855 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
1855 : SnapshotWriter(Thread::Current(), | 1856 : SnapshotWriter(Thread::Current(), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 *buffer_len_ = BytesWritten(); | 1939 *buffer_len_ = BytesWritten(); |
1939 } | 1940 } |
1940 } else { | 1941 } else { |
1941 FreeBuffer(); | 1942 FreeBuffer(); |
1942 ThrowException(exception_type(), exception_msg()); | 1943 ThrowException(exception_type(), exception_msg()); |
1943 } | 1944 } |
1944 } | 1945 } |
1945 | 1946 |
1946 | 1947 |
1947 } // namespace dart | 1948 } // namespace dart |
OLD | NEW |