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