OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 "bin/snapshot_utils.h" | 5 #include "bin/snapshot_utils.h" |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/error_exit.h" | 8 #include "bin/error_exit.h" |
9 #include "bin/extensions.h" | 9 #include "bin/extensions.h" |
10 #include "bin/file.h" | 10 #include "bin/file.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 MappedMemory* vm_data_mapping_; | 68 MappedMemory* vm_data_mapping_; |
69 MappedMemory* vm_instructions_mapping_; | 69 MappedMemory* vm_instructions_mapping_; |
70 MappedMemory* isolate_data_mapping_; | 70 MappedMemory* isolate_data_mapping_; |
71 MappedMemory* isolate_instructions_mapping_; | 71 MappedMemory* isolate_instructions_mapping_; |
72 }; | 72 }; |
73 | 73 |
74 static AppSnapshot* TryReadAppSnapshotBlobs(const char* script_name) { | 74 static AppSnapshot* TryReadAppSnapshotBlobs(const char* script_name) { |
75 File* file = File::Open(script_name, File::kRead); | 75 File* file = File::Open(NULL, script_name, File::kRead); |
76 if (file == NULL) { | 76 if (file == NULL) { |
77 return NULL; | 77 return NULL; |
78 } | 78 } |
79 if (file->Length() < kAppSnapshotHeaderSize) { | 79 if (file->Length() < kAppSnapshotHeaderSize) { |
80 file->Release(); | 80 file->Release(); |
81 return NULL; | 81 return NULL; |
82 } | 82 } |
83 int64_t header[5]; | 83 int64_t header[5]; |
84 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); | 84 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); |
85 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { | 85 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 FATAL1("Failed to resolve symbol '%s'\n", | 219 FATAL1("Failed to resolve symbol '%s'\n", |
220 kIsolateSnapshotInstructionsSymbolName); | 220 kIsolateSnapshotInstructionsSymbolName); |
221 } | 221 } |
222 | 222 |
223 return new DylibAppSnapshot(library, vm_data_buffer, vm_instructions_buffer, | 223 return new DylibAppSnapshot(library, vm_data_buffer, vm_instructions_buffer, |
224 isolate_data_buffer, isolate_instructions_buffer); | 224 isolate_data_buffer, isolate_instructions_buffer); |
225 } | 225 } |
226 #endif // defined(DART_PRECOMPILED_RUNTIME) | 226 #endif // defined(DART_PRECOMPILED_RUNTIME) |
227 | 227 |
228 AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_name) { | 228 AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_name) { |
229 if (File::GetType(script_name, true) != File::kIsFile) { | 229 if (File::GetType(NULL, script_name, true) != File::kIsFile) { |
230 // If 'script_name' refers to a pipe, don't read to check for an app | 230 // If 'script_name' refers to a pipe, don't read to check for an app |
231 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in | 231 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in |
232 // anyway if it was). | 232 // anyway if it was). |
233 return NULL; | 233 return NULL; |
234 } | 234 } |
235 AppSnapshot* snapshot = TryReadAppSnapshotBlobs(script_name); | 235 AppSnapshot* snapshot = TryReadAppSnapshotBlobs(script_name); |
236 if (snapshot != NULL) { | 236 if (snapshot != NULL) { |
237 return snapshot; | 237 return snapshot; |
238 } | 238 } |
239 #if defined(DART_PRECOMPILED_RUNTIME) | 239 #if defined(DART_PRECOMPILED_RUNTIME) |
240 // For testing AOT with the standalone embedder, we also support loading | 240 // For testing AOT with the standalone embedder, we also support loading |
241 // from a dynamic library to simulate what happens on iOS. | 241 // from a dynamic library to simulate what happens on iOS. |
242 snapshot = TryReadAppSnapshotDynamicLibrary(script_name); | 242 snapshot = TryReadAppSnapshotDynamicLibrary(script_name); |
243 if (snapshot != NULL) { | 243 if (snapshot != NULL) { |
244 return snapshot; | 244 return snapshot; |
245 } | 245 } |
246 #endif // defined(DART_PRECOMPILED_RUNTIME) | 246 #endif // defined(DART_PRECOMPILED_RUNTIME) |
247 return NULL; | 247 return NULL; |
248 } | 248 } |
249 | 249 |
250 static void WriteSnapshotFile(const char* filename, | 250 static void WriteSnapshotFile(const char* filename, |
251 bool write_magic_number, | 251 bool write_magic_number, |
252 const uint8_t* buffer, | 252 const uint8_t* buffer, |
253 const intptr_t size) { | 253 const intptr_t size) { |
254 File* file = File::Open(filename, File::kWriteTruncate); | 254 File* file = File::Open(NULL, filename, File::kWriteTruncate); |
255 if (file == NULL) { | 255 if (file == NULL) { |
256 ErrorExit(kErrorExitCode, "Unable to open file %s for writing snapshot\n", | 256 ErrorExit(kErrorExitCode, "Unable to open file %s for writing snapshot\n", |
257 filename); | 257 filename); |
258 } | 258 } |
259 | 259 |
260 if (write_magic_number) { | 260 if (write_magic_number) { |
261 // Write the magic number to indicate file is a script snapshot. | 261 // Write the magic number to indicate file is a script snapshot. |
262 DartUtils::WriteSnapshotMagicNumber(file); | 262 DartUtils::WriteSnapshotMagicNumber(file); |
263 } | 263 } |
264 | 264 |
(...skipping 10 matching lines...) Expand all Loading... |
275 | 275 |
276 static void WriteAppSnapshot(const char* filename, | 276 static void WriteAppSnapshot(const char* filename, |
277 uint8_t* vm_data_buffer, | 277 uint8_t* vm_data_buffer, |
278 intptr_t vm_data_size, | 278 intptr_t vm_data_size, |
279 uint8_t* vm_instructions_buffer, | 279 uint8_t* vm_instructions_buffer, |
280 intptr_t vm_instructions_size, | 280 intptr_t vm_instructions_size, |
281 uint8_t* isolate_data_buffer, | 281 uint8_t* isolate_data_buffer, |
282 intptr_t isolate_data_size, | 282 intptr_t isolate_data_size, |
283 uint8_t* isolate_instructions_buffer, | 283 uint8_t* isolate_instructions_buffer, |
284 intptr_t isolate_instructions_size) { | 284 intptr_t isolate_instructions_size) { |
285 File* file = File::Open(filename, File::kWriteTruncate); | 285 File* file = File::Open(NULL, filename, File::kWriteTruncate); |
286 if (file == NULL) { | 286 if (file == NULL) { |
287 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); | 287 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); |
288 } | 288 } |
289 | 289 |
290 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber)); | 290 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber)); |
291 WriteInt64(file, vm_data_size); | 291 WriteInt64(file, vm_data_size); |
292 WriteInt64(file, vm_instructions_size); | 292 WriteInt64(file, vm_instructions_size); |
293 WriteInt64(file, isolate_data_size); | 293 WriteInt64(file, isolate_data_size); |
294 WriteInt64(file, isolate_instructions_size); | 294 WriteInt64(file, isolate_instructions_size); |
295 ASSERT(file->Position() == kAppSnapshotHeaderSize); | 295 ASSERT(file->Position() == kAppSnapshotHeaderSize); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 Dart_Handle result = | 396 Dart_Handle result = |
397 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); | 397 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); |
398 if (Dart_IsError(result)) { | 398 if (Dart_IsError(result)) { |
399 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 399 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
400 } | 400 } |
401 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); | 401 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); |
402 } | 402 } |
403 | 403 |
404 } // namespace bin | 404 } // namespace bin |
405 } // namespace dart | 405 } // namespace dart |
OLD | NEW |