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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // the same way as precompilation before main, then continue running in the | 90 // the same way as precompilation before main, then continue running in the |
91 // same process. | 91 // same process. |
92 // Always set this with dart_noopt. | 92 // Always set this with dart_noopt. |
93 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 93 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
94 static const bool is_noopt = true; | 94 static const bool is_noopt = true; |
95 #else | 95 #else |
96 static const bool is_noopt = false; | 96 static const bool is_noopt = false; |
97 #endif | 97 #endif |
98 | 98 |
99 | 99 |
100 extern const char* kPrecompiledVMIsolateSymbolName; | 100 extern const char* kPrecompiledLibraryName; |
101 extern const char* kPrecompiledIsolateSymbolName; | |
102 extern const char* kPrecompiledInstructionsSymbolName; | 101 extern const char* kPrecompiledInstructionsSymbolName; |
103 extern const char* kPrecompiledDataSymbolName; | 102 extern const char* kPrecompiledDataSymbolName; |
104 | 103 |
| 104 static const char* kVMIsolateSuffix = "snapshot.vmisolate"; |
| 105 static const char* kIsolateSuffix = "snapshot.isolate"; |
| 106 static const char* kAssemblySuffix = "snapshot.S"; |
| 107 static const char* kInstructionsSuffix = "snapshot.instructions"; |
| 108 static const char* kRODataSuffix = "snapshot.rodata"; |
| 109 |
105 | 110 |
106 // Global flag that is used to indicate that we want to trace resolution of | 111 // Global flag that is used to indicate that we want to trace resolution of |
107 // URIs and the loading of libraries, parts and scripts. | 112 // URIs and the loading of libraries, parts and scripts. |
108 static bool trace_loading = false; | 113 static bool trace_loading = false; |
109 | 114 |
110 | 115 |
111 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 116 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
112 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 117 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
113 // VM Service options. | 118 // VM Service options. |
114 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 119 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } else if (strcmp(kind, "app-after-run") == 0) { | 371 } else if (strcmp(kind, "app-after-run") == 0) { |
367 gen_snapshot_kind = kAppAfterRun; | 372 gen_snapshot_kind = kAppAfterRun; |
368 return true; | 373 return true; |
369 } | 374 } |
370 Log::PrintErr("Unrecognized snapshot kind: '%s'\nValid kinds are: " | 375 Log::PrintErr("Unrecognized snapshot kind: '%s'\nValid kinds are: " |
371 "script, app-aot, app-jit-after-run, app-after-run\n", kind); | 376 "script, app-aot, app-jit-after-run, app-after-run\n", kind); |
372 return false; | 377 return false; |
373 } | 378 } |
374 | 379 |
375 | 380 |
| 381 static bool ProcessRunAppSnapshotOption( |
| 382 const char* filename, CommandLineOptions* vm_options) { |
| 383 ASSERT(filename != NULL); |
| 384 snapshot_filename = filename; |
| 385 run_app_snapshot = true; |
| 386 return true; |
| 387 } |
| 388 |
| 389 |
376 static bool ProcessEnableVmServiceOption(const char* option_value, | 390 static bool ProcessEnableVmServiceOption(const char* option_value, |
377 CommandLineOptions* vm_options) { | 391 CommandLineOptions* vm_options) { |
378 ASSERT(option_value != NULL); | 392 ASSERT(option_value != NULL); |
379 | 393 |
380 if (!ExtractPortAndIP(option_value, | 394 if (!ExtractPortAndIP(option_value, |
381 &vm_service_server_port, | 395 &vm_service_server_port, |
382 &vm_service_server_ip, | 396 &vm_service_server_ip, |
383 DEFAULT_VM_SERVICE_SERVER_PORT, | 397 DEFAULT_VM_SERVICE_SERVER_PORT, |
384 DEFAULT_VM_SERVICE_SERVER_IP)) { | 398 DEFAULT_VM_SERVICE_SERVER_IP)) { |
385 Log::PrintErr("unrecognized --enable-vm-service option syntax. " | 399 Log::PrintErr("unrecognized --enable-vm-service option syntax. " |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 { "--version", ProcessVersionOption }, | 558 { "--version", ProcessVersionOption }, |
545 | 559 |
546 // VM specific options to the standalone dart program. | 560 // VM specific options to the standalone dart program. |
547 { "--compile_all", ProcessCompileAllOption }, | 561 { "--compile_all", ProcessCompileAllOption }, |
548 { "--parse_all", ProcessParseAllOption }, | 562 { "--parse_all", ProcessParseAllOption }, |
549 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 563 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
550 { "--disable-service-origin-check", ProcessDisableServiceOriginCheckOption }, | 564 { "--disable-service-origin-check", ProcessDisableServiceOriginCheckOption }, |
551 { "--observe", ProcessObserveOption }, | 565 { "--observe", ProcessObserveOption }, |
552 { "--snapshot=", ProcessSnapshotFilenameOption }, | 566 { "--snapshot=", ProcessSnapshotFilenameOption }, |
553 { "--snapshot-kind=", ProcessSnapshotKindOption }, | 567 { "--snapshot-kind=", ProcessSnapshotKindOption }, |
| 568 { "--run-app-snapshot=", ProcessRunAppSnapshotOption }, |
554 { "--use-blobs", ProcessUseBlobsOption }, | 569 { "--use-blobs", ProcessUseBlobsOption }, |
555 { "--trace-loading", ProcessTraceLoadingOption }, | 570 { "--trace-loading", ProcessTraceLoadingOption }, |
556 { "--hot-reload-test-mode", ProcessHotReloadTestModeOption }, | 571 { "--hot-reload-test-mode", ProcessHotReloadTestModeOption }, |
557 { "--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption }, | 572 { "--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption }, |
558 { "--short_socket_read", ProcessShortSocketReadOption }, | 573 { "--short_socket_read", ProcessShortSocketReadOption }, |
559 { "--short_socket_write", ProcessShortSocketWriteOption }, | 574 { "--short_socket_write", ProcessShortSocketWriteOption }, |
560 #if !defined(TARGET_OS_MACOS) | 575 #if !defined(TARGET_OS_MACOS) |
561 { "--root-certs-file=", ProcessRootCertsFileOption }, | 576 { "--root-certs-file=", ProcessRootCertsFileOption }, |
562 { "--root-certs-cache=", ProcessRootCertsCacheOption }, | 577 { "--root-certs-cache=", ProcessRootCertsCacheOption }, |
563 #endif // !defined(TARGET_OS_MACOS) | 578 #endif // !defined(TARGET_OS_MACOS) |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 "Unable to write file %s for writing snapshot\n", | 1200 "Unable to write file %s for writing snapshot\n", |
1186 qualified_filename); | 1201 qualified_filename); |
1187 } | 1202 } |
1188 file->Release(); | 1203 file->Release(); |
1189 if (concat != NULL) { | 1204 if (concat != NULL) { |
1190 delete concat; | 1205 delete concat; |
1191 } | 1206 } |
1192 } | 1207 } |
1193 | 1208 |
1194 | 1209 |
1195 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT | 1210 static void ReadSnapshotFile(const char* snapshot_directory, |
1196 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc; | 1211 const char* filename, |
1197 static const int64_t kAppSnapshotPageSize = 4 * KB; | 1212 const uint8_t** buffer) { |
1198 | 1213 char* concat = NULL; |
1199 | 1214 const char* qualified_filename; |
1200 static bool ReadAppSnapshotBlobs(const char* script_name, | 1215 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { |
1201 const uint8_t** vmisolate_buffer, | 1216 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
1202 const uint8_t** isolate_buffer, | 1217 concat = new char[len + 1]; |
1203 const uint8_t** instructions_buffer, | 1218 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
1204 const uint8_t** rodata_buffer) { | 1219 qualified_filename = concat; |
1205 File* file = File::Open(script_name, File::kRead); | 1220 } else { |
1206 if (file == NULL) { | 1221 qualified_filename = filename; |
1207 return false; | |
1208 } | |
1209 if (file->Length() < kAppSnapshotHeaderSize) { | |
1210 file->Release(); | |
1211 return false; | |
1212 } | |
1213 int64_t header[5]; | |
1214 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); | |
1215 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { | |
1216 file->Release(); | |
1217 return false; | |
1218 } | |
1219 if (header[0] != kAppSnapshotMagicNumber) { | |
1220 file->Release(); | |
1221 return false; | |
1222 } | 1222 } |
1223 | 1223 |
1224 int64_t vmisolate_position = | 1224 void* file = DartUtils::OpenFile(qualified_filename, false); |
1225 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); | 1225 if (file == NULL) { |
1226 int64_t isolate_position = | 1226 fprintf(stderr, |
1227 Utils::RoundUp(vmisolate_position + header[1], kAppSnapshotPageSize); | 1227 "Error: Unable to open file %s for reading snapshot\n", |
1228 int64_t rodata_position = | 1228 qualified_filename); |
1229 Utils::RoundUp(isolate_position + header[2], kAppSnapshotPageSize); | 1229 fflush(stderr); |
1230 int64_t instructions_position = | 1230 Platform::Exit(kErrorExitCode); |
1231 Utils::RoundUp(rodata_position + header[3], kAppSnapshotPageSize); | |
1232 | |
1233 void* read_only_buffer = | |
1234 file->Map(File::kReadOnly, vmisolate_position, | |
1235 instructions_position - vmisolate_position); | |
1236 if (read_only_buffer == NULL) { | |
1237 ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n"); | |
1238 } | 1231 } |
1239 | 1232 intptr_t len = -1; |
1240 *vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | 1233 DartUtils::ReadFile(buffer, &len, file); |
1241 + (vmisolate_position - vmisolate_position); | 1234 if ((*buffer == NULL) || (len == -1)) { |
1242 *isolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | 1235 fprintf(stderr, |
1243 + (isolate_position - vmisolate_position); | 1236 "Error: Unable to read snapshot file %s\n", qualified_filename); |
1244 if (header[3] == 0) { | 1237 fflush(stderr); |
1245 *rodata_buffer = NULL; | 1238 Platform::Exit(kErrorExitCode); |
1246 } else { | |
1247 *rodata_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | |
1248 + (rodata_position - vmisolate_position); | |
1249 } | 1239 } |
1250 | 1240 DartUtils::CloseFile(file); |
1251 if (header[4] == 0) { | 1241 if (concat != NULL) { |
1252 *instructions_buffer = NULL; | 1242 delete[] concat; |
1253 } else { | |
1254 *instructions_buffer = reinterpret_cast<const uint8_t*>( | |
1255 file->Map(File::kReadExecute, instructions_position, header[4])); | |
1256 if (*instructions_buffer == NULL) { | |
1257 ErrorExit(kErrorExitCode, "Failed to memory map snapshot2\n"); | |
1258 } | |
1259 } | 1243 } |
1260 | |
1261 file->Release(); | |
1262 return true; | |
1263 } | 1244 } |
1264 | 1245 |
1265 | 1246 |
1266 static bool ReadAppSnapshotDynamicLibrary(const char* script_name, | 1247 static void ReadExecutableSnapshotFile(const char* snapshot_directory, |
1267 const uint8_t** vmisolate_buffer, | 1248 const char* filename, |
1268 const uint8_t** isolate_buffer, | 1249 const uint8_t** buffer) { |
1269 const uint8_t** instructions_buffer, | 1250 char* concat = NULL; |
1270 const uint8_t** rodata_buffer) { | 1251 const char* qualified_filename; |
1271 void* library = Extensions::LoadExtensionLibrary(script_name); | 1252 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { |
1272 if (library == NULL) { | 1253 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
1273 return false; | 1254 concat = new char[len + 1]; |
| 1255 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1256 qualified_filename = concat; |
| 1257 } else { |
| 1258 qualified_filename = filename; |
1274 } | 1259 } |
1275 | 1260 |
1276 *vmisolate_buffer = reinterpret_cast<const uint8_t*>( | 1261 intptr_t len = -1; |
1277 Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName)); | 1262 *buffer = reinterpret_cast<uint8_t*>( |
1278 if (*vmisolate_buffer == NULL) { | 1263 DartUtils::MapExecutable(qualified_filename, &len)); |
1279 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | 1264 if ((*buffer == NULL) || (len == -1)) { |
1280 kPrecompiledVMIsolateSymbolName); | 1265 fprintf(stderr, |
| 1266 "Error: Unable to read snapshot file %s\n", qualified_filename); |
| 1267 fflush(stderr); |
| 1268 Platform::Exit(kErrorExitCode); |
1281 } | 1269 } |
1282 | 1270 if (concat != NULL) { |
1283 *isolate_buffer = reinterpret_cast<const uint8_t*>( | 1271 delete[] concat; |
1284 Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName)); | |
1285 if (*isolate_buffer == NULL) { | |
1286 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1287 kPrecompiledIsolateSymbolName); | |
1288 } | 1272 } |
1289 | |
1290 *instructions_buffer = reinterpret_cast<const uint8_t*>( | |
1291 Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName)); | |
1292 if (*instructions_buffer == NULL) { | |
1293 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1294 kPrecompiledInstructionsSymbolName); | |
1295 } | |
1296 | |
1297 *rodata_buffer = reinterpret_cast<const uint8_t*>( | |
1298 Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName)); | |
1299 if (*rodata_buffer == NULL) { | |
1300 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1301 kPrecompiledDataSymbolName); | |
1302 } | |
1303 | |
1304 return true; | |
1305 } | 1273 } |
1306 | 1274 |
1307 | 1275 |
1308 static bool ReadAppSnapshot(const char* script_name, | 1276 static void* LoadLibrarySymbol(const char* snapshot_directory, |
1309 const uint8_t** vmisolate_buffer, | 1277 const char* libname, |
1310 const uint8_t** isolate_buffer, | 1278 const char* symname) { |
1311 const uint8_t** instructions_buffer, | 1279 char* concat = NULL; |
1312 const uint8_t** rodata_buffer) { | 1280 const char* qualified_libname; |
1313 if (ReadAppSnapshotBlobs(script_name, | 1281 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { |
1314 vmisolate_buffer, | 1282 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); |
1315 isolate_buffer, | 1283 concat = new char[len + 1]; |
1316 instructions_buffer, | 1284 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); |
1317 rodata_buffer)) { | 1285 qualified_libname = concat; |
1318 return true; | 1286 } else { |
| 1287 qualified_libname = libname; |
1319 } | 1288 } |
1320 return ReadAppSnapshotDynamicLibrary(script_name, | 1289 void* library = Extensions::LoadExtensionLibrary(qualified_libname); |
1321 vmisolate_buffer, | 1290 if (concat != NULL) { |
1322 isolate_buffer, | 1291 delete concat; |
1323 instructions_buffer, | 1292 } |
1324 rodata_buffer); | 1293 if (library == NULL) { |
| 1294 return NULL; |
| 1295 } |
| 1296 return Extensions::ResolveSymbol(library, symname); |
1325 } | 1297 } |
1326 | 1298 |
1327 | 1299 |
1328 static bool WriteInt64(File* file, int64_t size) { | |
1329 return file->WriteFully(&size, sizeof(size)); | |
1330 } | |
1331 | |
1332 | |
1333 static void WriteAppSnapshot(const char* filename, | |
1334 uint8_t* vmisolate_buffer, | |
1335 intptr_t vmisolate_size, | |
1336 uint8_t* isolate_buffer, | |
1337 intptr_t isolate_size, | |
1338 uint8_t* instructions_buffer, | |
1339 intptr_t instructions_size, | |
1340 uint8_t* rodata_buffer, | |
1341 intptr_t rodata_size) { | |
1342 File* file = File::Open(filename, File::kWriteTruncate); | |
1343 if (file == NULL) { | |
1344 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); | |
1345 } | |
1346 | |
1347 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber)); | |
1348 WriteInt64(file, vmisolate_size); | |
1349 WriteInt64(file, isolate_size); | |
1350 WriteInt64(file, rodata_size); | |
1351 WriteInt64(file, instructions_size); | |
1352 ASSERT(file->Position() == kAppSnapshotHeaderSize); | |
1353 | |
1354 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); | |
1355 if (!file->WriteFully(vmisolate_buffer, vmisolate_size)) { | |
1356 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); | |
1357 } | |
1358 | |
1359 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); | |
1360 if (!file->WriteFully(isolate_buffer, isolate_size)) { | |
1361 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); | |
1362 } | |
1363 | |
1364 if (rodata_size != 0) { | |
1365 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); | |
1366 if (!file->WriteFully(rodata_buffer, rodata_size)) { | |
1367 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", | |
1368 filename); | |
1369 } | |
1370 } | |
1371 | |
1372 if (instructions_size != 0) { | |
1373 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); | |
1374 if (!file->WriteFully(instructions_buffer, instructions_size)) { | |
1375 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", | |
1376 filename); | |
1377 } | |
1378 } | |
1379 | |
1380 file->Flush(); | |
1381 file->Release(); | |
1382 } | |
1383 | |
1384 | |
1385 static void GenerateScriptSnapshot() { | 1300 static void GenerateScriptSnapshot() { |
1386 // First create a snapshot. | 1301 // First create a snapshot. |
1387 uint8_t* buffer = NULL; | 1302 uint8_t* buffer = NULL; |
1388 intptr_t size = 0; | 1303 intptr_t size = 0; |
1389 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1304 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
1390 if (Dart_IsError(result)) { | 1305 if (Dart_IsError(result)) { |
1391 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1306 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1392 } | 1307 } |
1393 | 1308 |
1394 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); | 1309 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); |
(...skipping 17 matching lines...) Expand all Loading... |
1412 &vm_isolate_buffer, | 1327 &vm_isolate_buffer, |
1413 &vm_isolate_size, | 1328 &vm_isolate_size, |
1414 &isolate_buffer, | 1329 &isolate_buffer, |
1415 &isolate_size, | 1330 &isolate_size, |
1416 &instructions_blob_buffer, | 1331 &instructions_blob_buffer, |
1417 &instructions_blob_size, | 1332 &instructions_blob_size, |
1418 &rodata_blob_buffer, | 1333 &rodata_blob_buffer, |
1419 &rodata_blob_size); | 1334 &rodata_blob_size); |
1420 } else { | 1335 } else { |
1421 result = Dart_CreatePrecompiledSnapshotAssembly( | 1336 result = Dart_CreatePrecompiledSnapshotAssembly( |
| 1337 &vm_isolate_buffer, |
| 1338 &vm_isolate_size, |
| 1339 &isolate_buffer, |
| 1340 &isolate_size, |
1422 &assembly_buffer, | 1341 &assembly_buffer, |
1423 &assembly_size); | 1342 &assembly_size); |
1424 } | 1343 } |
1425 if (Dart_IsError(result)) { | 1344 if (Dart_IsError(result)) { |
1426 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1345 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1427 } | 1346 } |
| 1347 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix, |
| 1348 false, |
| 1349 vm_isolate_buffer, |
| 1350 vm_isolate_size); |
| 1351 WriteSnapshotFile(snapshot_filename, kIsolateSuffix, |
| 1352 false, |
| 1353 isolate_buffer, |
| 1354 isolate_size); |
1428 if (use_blobs) { | 1355 if (use_blobs) { |
1429 WriteAppSnapshot(snapshot_filename, | 1356 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, |
1430 vm_isolate_buffer, | 1357 false, |
1431 vm_isolate_size, | 1358 instructions_blob_buffer, |
1432 isolate_buffer, | 1359 instructions_blob_size); |
1433 isolate_size, | 1360 WriteSnapshotFile(snapshot_filename, kRODataSuffix, |
1434 instructions_blob_buffer, | 1361 false, |
1435 instructions_blob_size, | 1362 rodata_blob_buffer, |
1436 rodata_blob_buffer, | 1363 rodata_blob_size); |
1437 rodata_blob_size); | |
1438 } else { | 1364 } else { |
1439 WriteSnapshotFile(NULL, snapshot_filename, | 1365 WriteSnapshotFile(snapshot_filename, kAssemblySuffix, |
1440 false, | 1366 false, |
1441 assembly_buffer, | 1367 assembly_buffer, |
1442 assembly_size); | 1368 assembly_size); |
1443 } | 1369 } |
1444 } | 1370 } |
1445 | 1371 |
1446 | 1372 |
1447 static void GeneratePrecompiledJITSnapshot() { | 1373 static void GeneratePrecompiledJITSnapshot() { |
| 1374 if (!use_blobs) { |
| 1375 ErrorExit(kErrorExitCode, |
| 1376 "Generating app JIT snapshots as assembly unimplemented\n"); |
| 1377 } |
1448 uint8_t* vm_isolate_buffer = NULL; | 1378 uint8_t* vm_isolate_buffer = NULL; |
1449 intptr_t vm_isolate_size = 0; | 1379 intptr_t vm_isolate_size = 0; |
1450 uint8_t* isolate_buffer = NULL; | 1380 uint8_t* isolate_buffer = NULL; |
1451 intptr_t isolate_size = 0; | 1381 intptr_t isolate_size = 0; |
1452 uint8_t* instructions_blob_buffer = NULL; | 1382 uint8_t* instructions_blob_buffer = NULL; |
1453 intptr_t instructions_blob_size = 0; | 1383 intptr_t instructions_blob_size = 0; |
1454 uint8_t* rodata_blob_buffer = NULL; | 1384 uint8_t* rodata_blob_buffer = NULL; |
1455 intptr_t rodata_blob_size = 0; | 1385 intptr_t rodata_blob_size = 0; |
1456 Dart_Handle result = Dart_CreateAppJITSnapshot( | 1386 Dart_Handle result = Dart_CreateAppJITSnapshot( |
1457 &vm_isolate_buffer, | 1387 &vm_isolate_buffer, |
1458 &vm_isolate_size, | 1388 &vm_isolate_size, |
1459 &isolate_buffer, | 1389 &isolate_buffer, |
1460 &isolate_size, | 1390 &isolate_size, |
1461 &instructions_blob_buffer, | 1391 &instructions_blob_buffer, |
1462 &instructions_blob_size, | 1392 &instructions_blob_size, |
1463 &rodata_blob_buffer, | 1393 &rodata_blob_buffer, |
1464 &rodata_blob_size); | 1394 &rodata_blob_size); |
1465 if (Dart_IsError(result)) { | 1395 if (Dart_IsError(result)) { |
1466 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1396 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1467 } | 1397 } |
1468 WriteAppSnapshot(snapshot_filename, | 1398 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix, |
1469 vm_isolate_buffer, | 1399 false, |
1470 vm_isolate_size, | 1400 vm_isolate_buffer, |
1471 isolate_buffer, | 1401 vm_isolate_size); |
1472 isolate_size, | 1402 WriteSnapshotFile(snapshot_filename, kIsolateSuffix, |
1473 instructions_blob_buffer, | 1403 false, |
1474 instructions_blob_size, | 1404 isolate_buffer, |
1475 rodata_blob_buffer, | 1405 isolate_size); |
1476 rodata_blob_size); | 1406 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, |
| 1407 false, |
| 1408 instructions_blob_buffer, |
| 1409 instructions_blob_size); |
| 1410 WriteSnapshotFile(snapshot_filename, kRODataSuffix, |
| 1411 false, |
| 1412 rodata_blob_buffer, |
| 1413 rodata_blob_size); |
1477 } | 1414 } |
1478 | 1415 |
1479 | 1416 |
1480 static void GenerateFullSnapshot() { | 1417 static void GenerateFullSnapshot() { |
1481 // Create a full snapshot of the script. | 1418 // Create a full snapshot of the script. |
1482 Dart_Handle result; | 1419 Dart_Handle result; |
1483 uint8_t* vm_isolate_buffer = NULL; | 1420 uint8_t* vm_isolate_buffer = NULL; |
1484 intptr_t vm_isolate_size = 0; | 1421 intptr_t vm_isolate_size = 0; |
1485 uint8_t* isolate_buffer = NULL; | 1422 uint8_t* isolate_buffer = NULL; |
1486 intptr_t isolate_size = 0; | 1423 intptr_t isolate_size = 0; |
1487 | 1424 |
1488 result = Dart_CreateSnapshot(&vm_isolate_buffer, | 1425 result = Dart_CreateSnapshot(&vm_isolate_buffer, |
1489 &vm_isolate_size, | 1426 &vm_isolate_size, |
1490 &isolate_buffer, | 1427 &isolate_buffer, |
1491 &isolate_size); | 1428 &isolate_size); |
1492 if (Dart_IsError(result)) { | 1429 if (Dart_IsError(result)) { |
1493 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1430 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1494 } | 1431 } |
1495 | 1432 |
1496 WriteAppSnapshot(snapshot_filename, | 1433 WriteSnapshotFile(snapshot_filename, |
1497 vm_isolate_buffer, | 1434 kVMIsolateSuffix, |
1498 vm_isolate_size, | 1435 false, |
1499 isolate_buffer, | 1436 vm_isolate_buffer, |
1500 isolate_size, | 1437 vm_isolate_size); |
1501 NULL, 0, NULL, 0); | 1438 WriteSnapshotFile(snapshot_filename, |
| 1439 kIsolateSuffix, |
| 1440 false, |
| 1441 isolate_buffer, |
| 1442 isolate_size); |
1502 } | 1443 } |
1503 | 1444 |
1504 | 1445 |
1505 #define CHECK_RESULT(result) \ | 1446 #define CHECK_RESULT(result) \ |
1506 if (Dart_IsError(result)) { \ | 1447 if (Dart_IsError(result)) { \ |
1507 if (Dart_IsVMRestartRequest(result)) { \ | 1448 if (Dart_IsVMRestartRequest(result)) { \ |
1508 Dart_ExitScope(); \ | 1449 Dart_ExitScope(); \ |
1509 Dart_ShutdownIsolate(); \ | 1450 Dart_ShutdownIsolate(); \ |
1510 return true; \ | 1451 return true; \ |
1511 } \ | 1452 } \ |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 | 1776 |
1836 Loader::InitOnce(); | 1777 Loader::InitOnce(); |
1837 | 1778 |
1838 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1779 if (!DartUtils::SetOriginalWorkingDirectory()) { |
1839 OSError err; | 1780 OSError err; |
1840 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1781 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
1841 fflush(stderr); | 1782 fflush(stderr); |
1842 Platform::Exit(kErrorExitCode); | 1783 Platform::Exit(kErrorExitCode); |
1843 } | 1784 } |
1844 | 1785 |
1845 const uint8_t* instructions_snapshot = NULL; | |
1846 const uint8_t* data_snapshot = NULL; | |
1847 | |
1848 if (ReadAppSnapshot(script_name, | |
1849 &vm_isolate_snapshot_buffer, | |
1850 &isolate_snapshot_buffer, | |
1851 &instructions_snapshot, | |
1852 &data_snapshot)) { | |
1853 run_app_snapshot = true; | |
1854 } | |
1855 | |
1856 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) | 1786 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
1857 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. | 1787 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. |
1858 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { | 1788 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { |
1859 vm_options.AddArgument("--load_deferred_eagerly"); | 1789 vm_options.AddArgument("--load_deferred_eagerly"); |
1860 } | 1790 } |
1861 #endif | 1791 #endif |
1862 | 1792 |
1863 if (gen_snapshot_kind == kAppJITAfterRun) { | 1793 if (gen_snapshot_kind == kAppJITAfterRun) { |
1864 vm_options.AddArgument("--fields_may_be_reset"); | 1794 vm_options.AddArgument("--fields_may_be_reset"); |
1865 } | 1795 } |
1866 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { | 1796 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { |
1867 vm_options.AddArgument("--precompilation"); | 1797 vm_options.AddArgument("--precompilation"); |
1868 } | 1798 } |
1869 #if defined(DART_PRECOMPILED_RUNTIME) | 1799 #if defined(DART_PRECOMPILED_RUNTIME) |
1870 vm_options.AddArgument("--precompilation"); | 1800 vm_options.AddArgument("--precompilation"); |
1871 #endif | 1801 #endif |
1872 | 1802 |
1873 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1803 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1874 | 1804 |
1875 // Start event handler. | 1805 // Start event handler. |
1876 TimerUtils::InitOnce(); | 1806 TimerUtils::InitOnce(); |
1877 EventHandler::Start(); | 1807 EventHandler::Start(); |
1878 | 1808 |
| 1809 const uint8_t* instructions_snapshot = NULL; |
| 1810 const uint8_t* data_snapshot = NULL; |
| 1811 if (run_app_snapshot) { |
| 1812 ReadSnapshotFile(snapshot_filename, kVMIsolateSuffix, |
| 1813 &vm_isolate_snapshot_buffer); |
| 1814 ReadSnapshotFile(snapshot_filename, kIsolateSuffix, |
| 1815 &isolate_snapshot_buffer); |
| 1816 if (use_blobs) { |
| 1817 ReadExecutableSnapshotFile(snapshot_filename, |
| 1818 kInstructionsSuffix, |
| 1819 &instructions_snapshot); |
| 1820 ReadSnapshotFile(snapshot_filename, kRODataSuffix, |
| 1821 &data_snapshot); |
| 1822 } else { |
| 1823 instructions_snapshot = reinterpret_cast<const uint8_t*>( |
| 1824 LoadLibrarySymbol(snapshot_filename, |
| 1825 kPrecompiledLibraryName, |
| 1826 kPrecompiledInstructionsSymbolName)); |
| 1827 data_snapshot = reinterpret_cast<const uint8_t*>( |
| 1828 LoadLibrarySymbol(snapshot_filename, |
| 1829 kPrecompiledLibraryName, |
| 1830 kPrecompiledDataSymbolName)); |
| 1831 } |
| 1832 } |
| 1833 |
1879 // Initialize the Dart VM. | 1834 // Initialize the Dart VM. |
1880 Dart_InitializeParams init_params; | 1835 Dart_InitializeParams init_params; |
1881 memset(&init_params, 0, sizeof(init_params)); | 1836 memset(&init_params, 0, sizeof(init_params)); |
1882 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1837 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
1883 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; | 1838 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; |
1884 init_params.instructions_snapshot = instructions_snapshot; | 1839 init_params.instructions_snapshot = instructions_snapshot; |
1885 init_params.data_snapshot = data_snapshot; | 1840 init_params.data_snapshot = data_snapshot; |
1886 init_params.create = CreateIsolateAndSetup; | 1841 init_params.create = CreateIsolateAndSetup; |
1887 init_params.shutdown = ShutdownIsolate; | 1842 init_params.shutdown = ShutdownIsolate; |
1888 init_params.file_open = DartUtils::OpenFile; | 1843 init_params.file_open = DartUtils::OpenFile; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 Platform::Exit(Process::GlobalExitCode()); | 1898 Platform::Exit(Process::GlobalExitCode()); |
1944 } | 1899 } |
1945 | 1900 |
1946 } // namespace bin | 1901 } // namespace bin |
1947 } // namespace dart | 1902 } // namespace dart |
1948 | 1903 |
1949 int main(int argc, char** argv) { | 1904 int main(int argc, char** argv) { |
1950 dart::bin::main(argc, argv); | 1905 dart::bin::main(argc, argv); |
1951 UNREACHABLE(); | 1906 UNREACHABLE(); |
1952 } | 1907 } |
OLD | NEW |