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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // If the raw length is negative or greater than what the local machine can | 175 // If the raw length is negative or greater than what the local machine can |
176 // handle, then signal an error. | 176 // handle, then signal an error. |
177 int64_t snapshot_length = ReadUnaligned(&snapshot->unaligned_length_); | 177 int64_t snapshot_length = ReadUnaligned(&snapshot->unaligned_length_); |
178 if ((snapshot_length < 0) || (snapshot_length > kIntptrMax)) { | 178 if ((snapshot_length < 0) || (snapshot_length > kIntptrMax)) { |
179 return NULL; | 179 return NULL; |
180 } | 180 } |
181 return snapshot; | 181 return snapshot; |
182 } | 182 } |
183 | 183 |
184 | 184 |
| 185 const char* Snapshot::FeaturesString(Kind kind) { |
| 186 TextBuffer buffer(64); |
| 187 |
| 188 // Different fields are included for DEBUG/RELEASE/PRODUCT. |
| 189 #if defined(DEBUG) |
| 190 buffer.AddString("debug"); |
| 191 #elif defined(PRODUCT) |
| 192 buffer.AddString("product"); |
| 193 #else |
| 194 buffer.AddString("release"); |
| 195 #endif |
| 196 |
| 197 if (Snapshot::IncludesCode(kind)) { |
| 198 // Checked mode affects deopt ids. |
| 199 Isolate* isolate = Isolate::Current(); |
| 200 buffer.AddString(isolate->asserts() ? " asserts" : " no-asserts"); |
| 201 buffer.AddString(isolate->type_checks() ? " type-checks" |
| 202 : " no-type-checks"); |
| 203 |
| 204 // Generated code must match the host architecture and ABI. |
| 205 #if defined(TARGET_ARCH_ARM) |
| 206 #if defined(TARGET_ABI_IOS) |
| 207 buffer.AddString(" arm-ios"); |
| 208 #elif defined(TARGET_ABI_EABI) |
| 209 buffer.AddString(" arm-eabi"); |
| 210 #else |
| 211 #error Unknown ABI |
| 212 #endif |
| 213 buffer.AddString(TargetCPUFeatures::hardfp_supported() ? " hardfp" |
| 214 : " softfp"); |
| 215 #elif defined(TARGET_ARCH_ARM64) |
| 216 buffer.AddString(" arm64"); |
| 217 #elif defined(TARGET_ARCH_MIPS) |
| 218 buffer.AddString(" mips"); |
| 219 #elif defined(TARGET_ARCH_IA32) |
| 220 buffer.AddString(" ia32"); |
| 221 #elif defined(TARGET_ARCH_X64) |
| 222 #if defined(_WIN64) |
| 223 buffer.AddString(" x64-win"); |
| 224 #else |
| 225 buffer.AddString(" x64-sysv"); |
| 226 #endif |
| 227 #elif defined(TARGET_ARCH_DBC) |
| 228 buffer.AddString(" dbc"); |
| 229 #elif defined(TARGET_ARCH_DBC64) |
| 230 buffer.AddString(" dbc64"); |
| 231 #endif |
| 232 } |
| 233 |
| 234 return buffer.Steal(); |
| 235 } |
| 236 |
| 237 |
185 RawSmi* BaseReader::ReadAsSmi() { | 238 RawSmi* BaseReader::ReadAsSmi() { |
186 intptr_t value = Read<int32_t>(); | 239 intptr_t value = Read<int32_t>(); |
187 ASSERT((value & kSmiTagMask) == kSmiTag); | 240 ASSERT((value & kSmiTagMask) == kSmiTag); |
188 return reinterpret_cast<RawSmi*>(value); | 241 return reinterpret_cast<RawSmi*>(value); |
189 } | 242 } |
190 | 243 |
191 | 244 |
192 intptr_t BaseReader::ReadSmiValue() { | 245 intptr_t BaseReader::ReadSmiValue() { |
193 return Smi::Value(ReadAsSmi()); | 246 return Smi::Value(ReadAsSmi()); |
194 } | 247 } |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version, | 685 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version, |
633 actual_version); | 686 actual_version); |
634 free(actual_version); | 687 free(actual_version); |
635 // This can also fail while bringing up the VM isolate, so make sure to | 688 // This can also fail while bringing up the VM isolate, so make sure to |
636 // allocate the error message in old space. | 689 // allocate the error message in old space. |
637 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld)); | 690 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld)); |
638 return ApiError::New(msg, Heap::kOld); | 691 return ApiError::New(msg, Heap::kOld); |
639 } | 692 } |
640 Advance(version_len); | 693 Advance(version_len); |
641 | 694 |
642 const char* expected_features = Dart::FeaturesString(kind_); | 695 const char* expected_features = Snapshot::FeaturesString(kind_); |
643 ASSERT(expected_features != NULL); | 696 ASSERT(expected_features != NULL); |
644 const intptr_t expected_len = strlen(expected_features); | 697 const intptr_t expected_len = strlen(expected_features); |
645 | 698 |
646 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress()); | 699 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress()); |
647 ASSERT(features != NULL); | 700 ASSERT(features != NULL); |
648 intptr_t buffer_len = OS::StrNLen(features, PendingBytes()); | 701 intptr_t buffer_len = OS::StrNLen(features, PendingBytes()); |
649 if ((buffer_len != expected_len) || | 702 if ((buffer_len != expected_len) || |
650 strncmp(features, expected_features, expected_len)) { | 703 strncmp(features, expected_features, expected_len)) { |
651 const intptr_t kMessageBufferSize = 256; | 704 const intptr_t kMessageBufferSize = 256; |
652 char message_buffer[kMessageBufferSize]; | 705 char message_buffer[kMessageBufferSize]; |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 UNREACHABLE(); | 1888 UNREACHABLE(); |
1836 } | 1889 } |
1837 | 1890 |
1838 | 1891 |
1839 void SnapshotWriter::WriteVersionAndFeatures() { | 1892 void SnapshotWriter::WriteVersionAndFeatures() { |
1840 const char* expected_version = Version::SnapshotString(); | 1893 const char* expected_version = Version::SnapshotString(); |
1841 ASSERT(expected_version != NULL); | 1894 ASSERT(expected_version != NULL); |
1842 const intptr_t version_len = strlen(expected_version); | 1895 const intptr_t version_len = strlen(expected_version); |
1843 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); | 1896 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); |
1844 | 1897 |
1845 const char* expected_features = Dart::FeaturesString(kind_); | 1898 const char* expected_features = Snapshot::FeaturesString(kind_); |
1846 ASSERT(expected_features != NULL); | 1899 ASSERT(expected_features != NULL); |
1847 const intptr_t features_len = strlen(expected_features); | 1900 const intptr_t features_len = strlen(expected_features); |
1848 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features), | 1901 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features), |
1849 features_len + 1); | 1902 features_len + 1); |
1850 free(const_cast<char*>(expected_features)); | 1903 free(const_cast<char*>(expected_features)); |
1851 } | 1904 } |
1852 | 1905 |
1853 | 1906 |
1854 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 1907 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
1855 : SnapshotWriter(Thread::Current(), | 1908 : SnapshotWriter(Thread::Current(), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 *buffer_len_ = BytesWritten(); | 1991 *buffer_len_ = BytesWritten(); |
1939 } | 1992 } |
1940 } else { | 1993 } else { |
1941 FreeBuffer(); | 1994 FreeBuffer(); |
1942 ThrowException(exception_type(), exception_msg()); | 1995 ThrowException(exception_type(), exception_msg()); |
1943 } | 1996 } |
1944 } | 1997 } |
1945 | 1998 |
1946 | 1999 |
1947 } // namespace dart | 2000 } // namespace dart |
OLD | NEW |