Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: runtime/bin/main.cc

Issue 2405393002: Use a single file for app snapshots. (Closed)
Patch Set: gen_snapshot Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 (ReadAppSnapshotBlobs(script_name,
1282 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); 1314 vmisolate_buffer,
1283 concat = new char[len + 1]; 1315 isolate_buffer,
1284 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); 1316 instructions_buffer,
1285 qualified_libname = concat; 1317 rodata_buffer)) {
1286 } else { 1318 return true;
1287 qualified_libname = libname;
1288 } 1319 }
1289 void* library = Extensions::LoadExtensionLibrary(qualified_libname); 1320 return ReadAppSnapshotDynamicLibrary(script_name,
1290 if (concat != NULL) { 1321 vmisolate_buffer,
1291 delete concat; 1322 isolate_buffer,
1292 } 1323 instructions_buffer,
1293 if (library == NULL) { 1324 rodata_buffer);
1294 return NULL;
1295 }
1296 return Extensions::ResolveSymbol(library, symname);
1297 } 1325 }
1298 1326
1299 1327
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
1300 static void GenerateScriptSnapshot() { 1385 static void GenerateScriptSnapshot() {
1301 // First create a snapshot. 1386 // First create a snapshot.
1302 uint8_t* buffer = NULL; 1387 uint8_t* buffer = NULL;
1303 intptr_t size = 0; 1388 intptr_t size = 0;
1304 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); 1389 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size);
1305 if (Dart_IsError(result)) { 1390 if (Dart_IsError(result)) {
1306 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1391 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1307 } 1392 }
1308 1393
1309 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); 1394 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size);
(...skipping 17 matching lines...) Expand all
1327 &vm_isolate_buffer, 1412 &vm_isolate_buffer,
1328 &vm_isolate_size, 1413 &vm_isolate_size,
1329 &isolate_buffer, 1414 &isolate_buffer,
1330 &isolate_size, 1415 &isolate_size,
1331 &instructions_blob_buffer, 1416 &instructions_blob_buffer,
1332 &instructions_blob_size, 1417 &instructions_blob_size,
1333 &rodata_blob_buffer, 1418 &rodata_blob_buffer,
1334 &rodata_blob_size); 1419 &rodata_blob_size);
1335 } else { 1420 } else {
1336 result = Dart_CreatePrecompiledSnapshotAssembly( 1421 result = Dart_CreatePrecompiledSnapshotAssembly(
1337 &vm_isolate_buffer,
1338 &vm_isolate_size,
1339 &isolate_buffer,
1340 &isolate_size,
1341 &assembly_buffer, 1422 &assembly_buffer,
1342 &assembly_size); 1423 &assembly_size);
1343 } 1424 }
1344 if (Dart_IsError(result)) { 1425 if (Dart_IsError(result)) {
1345 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1426 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1346 } 1427 }
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) { 1428 if (use_blobs) {
1356 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, 1429 WriteAppSnapshot(snapshot_filename,
1357 false, 1430 vm_isolate_buffer,
1358 instructions_blob_buffer, 1431 vm_isolate_size,
1359 instructions_blob_size); 1432 isolate_buffer,
1360 WriteSnapshotFile(snapshot_filename, kRODataSuffix, 1433 isolate_size,
1361 false, 1434 instructions_blob_buffer,
1362 rodata_blob_buffer, 1435 instructions_blob_size,
1363 rodata_blob_size); 1436 rodata_blob_buffer,
1437 rodata_blob_size);
1364 } else { 1438 } else {
1365 WriteSnapshotFile(snapshot_filename, kAssemblySuffix, 1439 WriteSnapshotFile(NULL, snapshot_filename,
1366 false, 1440 false,
1367 assembly_buffer, 1441 assembly_buffer,
1368 assembly_size); 1442 assembly_size);
1369 } 1443 }
1370 } 1444 }
1371 1445
1372 1446
1373 static void GeneratePrecompiledJITSnapshot() { 1447 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; 1448 uint8_t* vm_isolate_buffer = NULL;
1379 intptr_t vm_isolate_size = 0; 1449 intptr_t vm_isolate_size = 0;
1380 uint8_t* isolate_buffer = NULL; 1450 uint8_t* isolate_buffer = NULL;
1381 intptr_t isolate_size = 0; 1451 intptr_t isolate_size = 0;
1382 uint8_t* instructions_blob_buffer = NULL; 1452 uint8_t* instructions_blob_buffer = NULL;
1383 intptr_t instructions_blob_size = 0; 1453 intptr_t instructions_blob_size = 0;
1384 uint8_t* rodata_blob_buffer = NULL; 1454 uint8_t* rodata_blob_buffer = NULL;
1385 intptr_t rodata_blob_size = 0; 1455 intptr_t rodata_blob_size = 0;
1386 Dart_Handle result = Dart_CreateAppJITSnapshot( 1456 Dart_Handle result = Dart_CreateAppJITSnapshot(
1387 &vm_isolate_buffer, 1457 &vm_isolate_buffer,
1388 &vm_isolate_size, 1458 &vm_isolate_size,
1389 &isolate_buffer, 1459 &isolate_buffer,
1390 &isolate_size, 1460 &isolate_size,
1391 &instructions_blob_buffer, 1461 &instructions_blob_buffer,
1392 &instructions_blob_size, 1462 &instructions_blob_size,
1393 &rodata_blob_buffer, 1463 &rodata_blob_buffer,
1394 &rodata_blob_size); 1464 &rodata_blob_size);
1395 if (Dart_IsError(result)) { 1465 if (Dart_IsError(result)) {
1396 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1466 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1397 } 1467 }
1398 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix, 1468 WriteAppSnapshot(snapshot_filename,
1399 false, 1469 vm_isolate_buffer,
1400 vm_isolate_buffer, 1470 vm_isolate_size,
1401 vm_isolate_size); 1471 isolate_buffer,
1402 WriteSnapshotFile(snapshot_filename, kIsolateSuffix, 1472 isolate_size,
1403 false, 1473 instructions_blob_buffer,
1404 isolate_buffer, 1474 instructions_blob_size,
1405 isolate_size); 1475 rodata_blob_buffer,
1406 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, 1476 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 } 1477 }
1415 1478
1416 1479
1417 static void GenerateFullSnapshot() { 1480 static void GenerateFullSnapshot() {
1418 // Create a full snapshot of the script. 1481 // Create a full snapshot of the script.
1419 Dart_Handle result; 1482 Dart_Handle result;
1420 uint8_t* vm_isolate_buffer = NULL; 1483 uint8_t* vm_isolate_buffer = NULL;
1421 intptr_t vm_isolate_size = 0; 1484 intptr_t vm_isolate_size = 0;
1422 uint8_t* isolate_buffer = NULL; 1485 uint8_t* isolate_buffer = NULL;
1423 intptr_t isolate_size = 0; 1486 intptr_t isolate_size = 0;
1424 1487
1425 result = Dart_CreateSnapshot(&vm_isolate_buffer, 1488 result = Dart_CreateSnapshot(&vm_isolate_buffer,
1426 &vm_isolate_size, 1489 &vm_isolate_size,
1427 &isolate_buffer, 1490 &isolate_buffer,
1428 &isolate_size); 1491 &isolate_size);
1429 if (Dart_IsError(result)) { 1492 if (Dart_IsError(result)) {
1430 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1493 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1431 } 1494 }
1432 1495
1433 WriteSnapshotFile(snapshot_filename, 1496 WriteAppSnapshot(snapshot_filename,
1434 kVMIsolateSuffix, 1497 vm_isolate_buffer,
1435 false, 1498 vm_isolate_size,
1436 vm_isolate_buffer, 1499 isolate_buffer,
1437 vm_isolate_size); 1500 isolate_size,
1438 WriteSnapshotFile(snapshot_filename, 1501 NULL, 0, NULL, 0);
1439 kIsolateSuffix,
1440 false,
1441 isolate_buffer,
1442 isolate_size);
1443 } 1502 }
1444 1503
1445 1504
1446 #define CHECK_RESULT(result) \ 1505 #define CHECK_RESULT(result) \
1447 if (Dart_IsError(result)) { \ 1506 if (Dart_IsError(result)) { \
1448 if (Dart_IsVMRestartRequest(result)) { \ 1507 if (Dart_IsVMRestartRequest(result)) { \
1449 Dart_ExitScope(); \ 1508 Dart_ExitScope(); \
1450 Dart_ShutdownIsolate(); \ 1509 Dart_ShutdownIsolate(); \
1451 return true; \ 1510 return true; \
1452 } \ 1511 } \
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 1830
1772 Loader::InitOnce(); 1831 Loader::InitOnce();
1773 1832
1774 if (!DartUtils::SetOriginalWorkingDirectory()) { 1833 if (!DartUtils::SetOriginalWorkingDirectory()) {
1775 OSError err; 1834 OSError err;
1776 fprintf(stderr, "Error determining current directory: %s\n", err.message()); 1835 fprintf(stderr, "Error determining current directory: %s\n", err.message());
1777 fflush(stderr); 1836 fflush(stderr);
1778 Platform::Exit(kErrorExitCode); 1837 Platform::Exit(kErrorExitCode);
1779 } 1838 }
1780 1839
1840 const uint8_t* instructions_snapshot = NULL;
1841 const uint8_t* data_snapshot = NULL;
1842
1843 if (ReadAppSnapshot(script_name,
1844 &vm_isolate_snapshot_buffer,
1845 &isolate_snapshot_buffer,
1846 &instructions_snapshot,
1847 &data_snapshot)) {
1848 run_app_snapshot = true;
1849 }
1850
1781 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) 1851 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1782 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. 1852 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME.
1783 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { 1853 if ((gen_snapshot_kind != kNone) || run_app_snapshot) {
1784 vm_options.AddArgument("--load_deferred_eagerly"); 1854 vm_options.AddArgument("--load_deferred_eagerly");
1785 } 1855 }
1786 #endif 1856 #endif
1787 1857
1788 if (gen_snapshot_kind == kAppJITAfterRun) { 1858 if (gen_snapshot_kind == kAppJITAfterRun) {
1789 vm_options.AddArgument("--fields_may_be_reset"); 1859 vm_options.AddArgument("--fields_may_be_reset");
1790 } 1860 }
1791 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { 1861 if ((gen_snapshot_kind == kAppAOT) || is_noopt) {
1792 vm_options.AddArgument("--precompilation"); 1862 vm_options.AddArgument("--precompilation");
1793 } 1863 }
1794 #if defined(DART_PRECOMPILED_RUNTIME) 1864 #if defined(DART_PRECOMPILED_RUNTIME)
1795 vm_options.AddArgument("--precompilation"); 1865 vm_options.AddArgument("--precompilation");
1796 #endif 1866 #endif
1797 1867
1798 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1868 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1799 1869
1800 // Start event handler. 1870 // Start event handler.
1801 TimerUtils::InitOnce(); 1871 TimerUtils::InitOnce();
1802 EventHandler::Start(); 1872 EventHandler::Start();
1803 1873
1804 const uint8_t* instructions_snapshot = NULL;
1805 const uint8_t* data_snapshot = NULL;
1806 if (run_app_snapshot) {
1807 ReadSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1808 &vm_isolate_snapshot_buffer);
1809 ReadSnapshotFile(snapshot_filename, kIsolateSuffix,
1810 &isolate_snapshot_buffer);
1811 if (use_blobs) {
1812 ReadExecutableSnapshotFile(snapshot_filename,
1813 kInstructionsSuffix,
1814 &instructions_snapshot);
1815 ReadSnapshotFile(snapshot_filename, kRODataSuffix,
1816 &data_snapshot);
1817 } else {
1818 instructions_snapshot = reinterpret_cast<const uint8_t*>(
1819 LoadLibrarySymbol(snapshot_filename,
1820 kPrecompiledLibraryName,
1821 kPrecompiledInstructionsSymbolName));
1822 data_snapshot = reinterpret_cast<const uint8_t*>(
1823 LoadLibrarySymbol(snapshot_filename,
1824 kPrecompiledLibraryName,
1825 kPrecompiledDataSymbolName));
1826 }
1827 }
1828
1829 // Initialize the Dart VM. 1874 // Initialize the Dart VM.
1830 Dart_InitializeParams init_params; 1875 Dart_InitializeParams init_params;
1831 memset(&init_params, 0, sizeof(init_params)); 1876 memset(&init_params, 0, sizeof(init_params));
1832 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; 1877 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
1833 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; 1878 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer;
1834 init_params.instructions_snapshot = instructions_snapshot; 1879 init_params.instructions_snapshot = instructions_snapshot;
1835 init_params.data_snapshot = data_snapshot; 1880 init_params.data_snapshot = data_snapshot;
1836 init_params.create = CreateIsolateAndSetup; 1881 init_params.create = CreateIsolateAndSetup;
1837 init_params.shutdown = ShutdownIsolate; 1882 init_params.shutdown = ShutdownIsolate;
1838 init_params.file_open = DartUtils::OpenFile; 1883 init_params.file_open = DartUtils::OpenFile;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 Platform::Exit(Process::GlobalExitCode()); 1938 Platform::Exit(Process::GlobalExitCode());
1894 } 1939 }
1895 1940
1896 } // namespace bin 1941 } // namespace bin
1897 } // namespace dart 1942 } // namespace dart
1898 1943
1899 int main(int argc, char** argv) { 1944 int main(int argc, char** argv) {
1900 dart::bin::main(argc, argv); 1945 dart::bin::main(argc, argv);
1901 UNREACHABLE(); 1946 UNREACHABLE();
1902 } 1947 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698