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 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1200 "Unable to write file %s for writing snapshot\n", | 1195 "Unable to write file %s for writing snapshot\n", |
1201 qualified_filename); | 1196 qualified_filename); |
1202 } | 1197 } |
1203 file->Release(); | 1198 file->Release(); |
1204 if (concat != NULL) { | 1199 if (concat != NULL) { |
1205 delete concat; | 1200 delete concat; |
1206 } | 1201 } |
1207 } | 1202 } |
1208 | 1203 |
1209 | 1204 |
1210 static void ReadSnapshotFile(const char* snapshot_directory, | 1205 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT |
1211 const char* filename, | 1206 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc; |
1212 const uint8_t** buffer) { | 1207 static const int64_t kAppSnapshotPageSize = 4 * KB; |
1213 char* concat = NULL; | 1208 |
1214 const char* qualified_filename; | 1209 |
1215 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { | 1210 static bool ReadAppSnapshotBlobs(const char* script_name, |
1216 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); | 1211 const uint8_t** vmisolate_buffer, |
1217 concat = new char[len + 1]; | 1212 const uint8_t** isolate_buffer, |
1218 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); | 1213 const uint8_t** instructions_buffer, |
1219 qualified_filename = concat; | 1214 const uint8_t** rodata_buffer) { |
1215 File* file = File::Open(script_name, File::kRead); | |
1216 if (file == NULL) { | |
1217 return false; | |
1218 } | |
1219 if (file->Length() < kAppSnapshotHeaderSize) { | |
1220 file->Release(); | |
1221 return false; | |
1222 } | |
1223 int64_t magic = 0; | |
1224 int64_t vmisolate_size = 0; | |
1225 int64_t isolate_size = 0; | |
1226 int64_t instructions_size = 0; | |
1227 int64_t rodata_size = 0; | |
1228 if (!file->ReadFully(&magic, sizeof(magic))) { | |
1229 file->Release(); | |
1230 return false; | |
1231 } | |
1232 if (magic != kAppSnapshotMagicNumber) { | |
1233 file->Release(); | |
1234 return false; | |
1235 } | |
1236 file->ReadFully(&vmisolate_size, sizeof(vmisolate_size)); | |
1237 file->ReadFully(&isolate_size, sizeof(isolate_size)); | |
1238 file->ReadFully(&instructions_size, sizeof(instructions_size)); | |
1239 file->ReadFully(&rodata_size, sizeof(rodata_size)); | |
1240 ASSERT(file->Position() == kAppSnapshotHeaderSize); | |
siva
2016/10/12 20:37:33
Instead of these individual reads of the magic num
rmacnak
2016/10/13 01:08:16
Done.
| |
1241 | |
1242 int64_t position = file->Position(); | |
1243 position = Utils::RoundUp(position, kAppSnapshotPageSize); | |
1244 *vmisolate_buffer = reinterpret_cast<const uint8_t*>( | |
1245 file->MapReadOnly(position, vmisolate_size)); | |
1246 if (*vmisolate_buffer == NULL) { | |
1247 ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n"); | |
1248 } | |
1249 position += vmisolate_size; | |
1250 | |
1251 position = Utils::RoundUp(position, kAppSnapshotPageSize); | |
1252 *isolate_buffer = reinterpret_cast<const uint8_t*>( | |
1253 file->MapReadOnly(position, isolate_size)); | |
1254 if (*isolate_buffer == NULL) { | |
1255 ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n"); | |
1256 } | |
1257 position += isolate_size; | |
1258 | |
1259 if (instructions_size == 0) { | |
1260 *instructions_buffer = NULL; | |
1220 } else { | 1261 } else { |
1221 qualified_filename = filename; | 1262 position = Utils::RoundUp(position, kAppSnapshotPageSize); |
1222 } | 1263 *instructions_buffer = reinterpret_cast<const uint8_t*>( |
1223 | 1264 file->MapReadExecute(position, instructions_size)); |
1224 void* file = DartUtils::OpenFile(qualified_filename, false); | 1265 if (*instructions_buffer == NULL) { |
1266 ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n"); | |
1267 } | |
1268 position += instructions_size; | |
1269 } | |
1270 | |
1271 if (rodata_size == 0) { | |
1272 *rodata_buffer = NULL; | |
1273 } else { | |
1274 position = Utils::RoundUp(position, kAppSnapshotPageSize); | |
1275 *rodata_buffer = reinterpret_cast<const uint8_t*>( | |
1276 file->MapReadOnly(position, rodata_size)); | |
1277 if (*rodata_buffer == NULL) { | |
1278 ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n"); | |
1279 } | |
1280 } | |
1281 | |
siva
2016/10/12 20:37:33
Can the order of rodata be swapped with instructio
rmacnak
2016/10/13 01:08:16
Done.
| |
1282 return true; | |
siva
2016/10/12 20:37:33
Missing file->Release() for the success case?
On L
rmacnak
2016/10/13 01:08:16
Done.
| |
1283 } | |
1284 | |
1285 | |
1286 static bool ReadAppSnapshotDynamicLibrary(const char* script_name, | |
1287 const uint8_t** vmisolate_buffer, | |
1288 const uint8_t** isolate_buffer, | |
1289 const uint8_t** instructions_buffer, | |
1290 const uint8_t** rodata_buffer) { | |
1291 void* library = Extensions::LoadExtensionLibrary(script_name); | |
siva
2016/10/12 20:37:33
Can you make sure that this will work for any name
rmacnak
2016/10/13 01:08:16
Done, using the same for both platforms in the tes
| |
1292 if (library == NULL) { | |
1293 return false; | |
1294 } | |
1295 | |
1296 *vmisolate_buffer = reinterpret_cast<const uint8_t*>( | |
1297 Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName)); | |
1298 if (*vmisolate_buffer == NULL) { | |
1299 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1300 kPrecompiledVMIsolateSymbolName); | |
1301 } | |
1302 | |
1303 *isolate_buffer = reinterpret_cast<const uint8_t*>( | |
1304 Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName)); | |
1305 if (*isolate_buffer == NULL) { | |
1306 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1307 kPrecompiledIsolateSymbolName); | |
1308 } | |
1309 | |
1310 *instructions_buffer = reinterpret_cast<const uint8_t*>( | |
1311 Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName)); | |
1312 if (*instructions_buffer == NULL) { | |
1313 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1314 kPrecompiledInstructionsSymbolName); | |
1315 } | |
1316 | |
1317 *rodata_buffer = reinterpret_cast<const uint8_t*>( | |
1318 Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName)); | |
1319 if (*rodata_buffer == NULL) { | |
1320 ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n", | |
1321 kPrecompiledDataSymbolName); | |
1322 } | |
1323 | |
1324 return true; | |
1325 } | |
1326 | |
1327 | |
1328 static bool ReadAppSnapshot(const char* script_name, | |
1329 const uint8_t** vmisolate_buffer, | |
1330 const uint8_t** isolate_buffer, | |
1331 const uint8_t** instructions_buffer, | |
1332 const uint8_t** rodata_buffer) { | |
1333 if (ReadAppSnapshotBlobs(script_name, | |
1334 vmisolate_buffer, | |
1335 isolate_buffer, | |
1336 instructions_buffer, | |
1337 rodata_buffer)) { | |
1338 return true; | |
1339 } | |
1340 return ReadAppSnapshotDynamicLibrary(script_name, | |
1341 vmisolate_buffer, | |
1342 isolate_buffer, | |
1343 instructions_buffer, | |
1344 rodata_buffer); | |
1345 } | |
1346 | |
1347 | |
1348 static bool WriteInt64(File* file, int64_t size) { | |
1349 return file->WriteFully(&size, sizeof(size)); | |
1350 } | |
1351 | |
1352 | |
1353 static void WriteAppSnapshot(const char* filename, | |
1354 uint8_t* vmisolate_buffer, | |
1355 intptr_t vmisolate_size, | |
1356 uint8_t* isolate_buffer, | |
1357 intptr_t isolate_size, | |
1358 uint8_t* instructions_buffer, | |
1359 intptr_t instructions_size, | |
1360 uint8_t* rodata_buffer, | |
1361 intptr_t rodata_size) { | |
1362 File* file = File::Open(filename, File::kWriteTruncate); | |
1225 if (file == NULL) { | 1363 if (file == NULL) { |
1226 fprintf(stderr, | 1364 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); |
1227 "Error: Unable to open file %s for reading snapshot\n", | 1365 } |
1228 qualified_filename); | 1366 |
1229 fflush(stderr); | 1367 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber)); |
1230 Platform::Exit(kErrorExitCode); | 1368 WriteInt64(file, vmisolate_size); |
1231 } | 1369 WriteInt64(file, isolate_size); |
1232 intptr_t len = -1; | 1370 WriteInt64(file, instructions_size); |
1233 DartUtils::ReadFile(buffer, &len, file); | 1371 WriteInt64(file, rodata_size); |
1234 if ((*buffer == NULL) || (len == -1)) { | 1372 ASSERT(file->Position() == kAppSnapshotHeaderSize); |
1235 fprintf(stderr, | 1373 |
1236 "Error: Unable to read snapshot file %s\n", qualified_filename); | 1374 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); |
1237 fflush(stderr); | 1375 if (!file->WriteFully(vmisolate_buffer, vmisolate_size)) { |
1238 Platform::Exit(kErrorExitCode); | 1376 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); |
1239 } | 1377 } |
1240 DartUtils::CloseFile(file); | 1378 |
1241 if (concat != NULL) { | 1379 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); |
1242 delete[] concat; | 1380 if (!file->WriteFully(isolate_buffer, isolate_size)) { |
1243 } | 1381 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); |
1244 } | 1382 } |
1245 | 1383 |
1246 | 1384 if (instructions_size != 0) { |
1247 static void ReadExecutableSnapshotFile(const char* snapshot_directory, | 1385 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); |
1248 const char* filename, | 1386 if (!file->WriteFully(instructions_buffer, instructions_size)) { |
1249 const uint8_t** buffer) { | 1387 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", |
1250 char* concat = NULL; | 1388 filename); |
1251 const char* qualified_filename; | 1389 } |
1252 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { | 1390 } |
1253 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); | 1391 |
1254 concat = new char[len + 1]; | 1392 if (rodata_size != 0) { |
1255 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); | 1393 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); |
1256 qualified_filename = concat; | 1394 if (!file->WriteFully(rodata_buffer, rodata_size)) { |
1257 } else { | 1395 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", |
1258 qualified_filename = filename; | 1396 filename); |
1259 } | 1397 } |
1260 | 1398 } |
1261 intptr_t len = -1; | 1399 |
1262 *buffer = reinterpret_cast<uint8_t*>( | 1400 file->Flush(); |
1263 DartUtils::MapExecutable(qualified_filename, &len)); | 1401 file->Release(); |
1264 if ((*buffer == NULL) || (len == -1)) { | 1402 } |
1265 fprintf(stderr, | 1403 |
1266 "Error: Unable to read snapshot file %s\n", qualified_filename); | 1404 |
1267 fflush(stderr); | |
1268 Platform::Exit(kErrorExitCode); | |
1269 } | |
1270 if (concat != NULL) { | |
1271 delete[] concat; | |
1272 } | |
1273 } | |
1274 | |
1275 | |
1276 static void* LoadLibrarySymbol(const char* snapshot_directory, | |
1277 const char* libname, | |
1278 const char* symname) { | |
1279 char* concat = NULL; | |
1280 const char* qualified_libname; | |
1281 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { | |
1282 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); | |
1283 concat = new char[len + 1]; | |
1284 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); | |
1285 qualified_libname = concat; | |
1286 } else { | |
1287 qualified_libname = libname; | |
1288 } | |
1289 void* library = Extensions::LoadExtensionLibrary(qualified_libname); | |
1290 if (concat != NULL) { | |
1291 delete concat; | |
1292 } | |
1293 if (library == NULL) { | |
1294 return NULL; | |
1295 } | |
1296 return Extensions::ResolveSymbol(library, symname); | |
1297 } | |
1298 | |
1299 | |
1300 static void GenerateScriptSnapshot() { | 1405 static void GenerateScriptSnapshot() { |
1301 // First create a snapshot. | 1406 // First create a snapshot. |
1302 uint8_t* buffer = NULL; | 1407 uint8_t* buffer = NULL; |
1303 intptr_t size = 0; | 1408 intptr_t size = 0; |
1304 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1409 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
1305 if (Dart_IsError(result)) { | 1410 if (Dart_IsError(result)) { |
1306 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1411 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1307 } | 1412 } |
1308 | 1413 |
1309 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); | 1414 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); |
(...skipping 17 matching lines...) Expand all Loading... | |
1327 &vm_isolate_buffer, | 1432 &vm_isolate_buffer, |
1328 &vm_isolate_size, | 1433 &vm_isolate_size, |
1329 &isolate_buffer, | 1434 &isolate_buffer, |
1330 &isolate_size, | 1435 &isolate_size, |
1331 &instructions_blob_buffer, | 1436 &instructions_blob_buffer, |
1332 &instructions_blob_size, | 1437 &instructions_blob_size, |
1333 &rodata_blob_buffer, | 1438 &rodata_blob_buffer, |
1334 &rodata_blob_size); | 1439 &rodata_blob_size); |
1335 } else { | 1440 } else { |
1336 result = Dart_CreatePrecompiledSnapshotAssembly( | 1441 result = Dart_CreatePrecompiledSnapshotAssembly( |
1337 &vm_isolate_buffer, | |
1338 &vm_isolate_size, | |
1339 &isolate_buffer, | |
1340 &isolate_size, | |
1341 &assembly_buffer, | 1442 &assembly_buffer, |
1342 &assembly_size); | 1443 &assembly_size); |
1343 } | 1444 } |
1344 if (Dart_IsError(result)) { | 1445 if (Dart_IsError(result)) { |
1345 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1446 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1346 } | 1447 } |
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) { | 1448 if (use_blobs) { |
1356 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, | 1449 WriteAppSnapshot(snapshot_filename, |
1357 false, | 1450 vm_isolate_buffer, |
1358 instructions_blob_buffer, | 1451 vm_isolate_size, |
1359 instructions_blob_size); | 1452 isolate_buffer, |
1360 WriteSnapshotFile(snapshot_filename, kRODataSuffix, | 1453 isolate_size, |
1361 false, | 1454 instructions_blob_buffer, |
1362 rodata_blob_buffer, | 1455 instructions_blob_size, |
1363 rodata_blob_size); | 1456 rodata_blob_buffer, |
1457 rodata_blob_size); | |
1364 } else { | 1458 } else { |
1365 WriteSnapshotFile(snapshot_filename, kAssemblySuffix, | 1459 WriteSnapshotFile(NULL, snapshot_filename, |
1366 false, | 1460 false, |
1367 assembly_buffer, | 1461 assembly_buffer, |
1368 assembly_size); | 1462 assembly_size); |
1369 } | 1463 } |
1370 } | 1464 } |
1371 | 1465 |
1372 | 1466 |
1373 static void GeneratePrecompiledJITSnapshot() { | 1467 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; | 1468 uint8_t* vm_isolate_buffer = NULL; |
1379 intptr_t vm_isolate_size = 0; | 1469 intptr_t vm_isolate_size = 0; |
1380 uint8_t* isolate_buffer = NULL; | 1470 uint8_t* isolate_buffer = NULL; |
1381 intptr_t isolate_size = 0; | 1471 intptr_t isolate_size = 0; |
1382 uint8_t* instructions_blob_buffer = NULL; | 1472 uint8_t* instructions_blob_buffer = NULL; |
1383 intptr_t instructions_blob_size = 0; | 1473 intptr_t instructions_blob_size = 0; |
1384 uint8_t* rodata_blob_buffer = NULL; | 1474 uint8_t* rodata_blob_buffer = NULL; |
1385 intptr_t rodata_blob_size = 0; | 1475 intptr_t rodata_blob_size = 0; |
1386 Dart_Handle result = Dart_CreateAppJITSnapshot( | 1476 Dart_Handle result = Dart_CreateAppJITSnapshot( |
1387 &vm_isolate_buffer, | 1477 &vm_isolate_buffer, |
1388 &vm_isolate_size, | 1478 &vm_isolate_size, |
1389 &isolate_buffer, | 1479 &isolate_buffer, |
1390 &isolate_size, | 1480 &isolate_size, |
1391 &instructions_blob_buffer, | 1481 &instructions_blob_buffer, |
1392 &instructions_blob_size, | 1482 &instructions_blob_size, |
1393 &rodata_blob_buffer, | 1483 &rodata_blob_buffer, |
1394 &rodata_blob_size); | 1484 &rodata_blob_size); |
1395 if (Dart_IsError(result)) { | 1485 if (Dart_IsError(result)) { |
1396 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1486 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1397 } | 1487 } |
1398 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix, | 1488 WriteAppSnapshot(snapshot_filename, |
1399 false, | 1489 vm_isolate_buffer, |
1400 vm_isolate_buffer, | 1490 vm_isolate_size, |
1401 vm_isolate_size); | 1491 isolate_buffer, |
1402 WriteSnapshotFile(snapshot_filename, kIsolateSuffix, | 1492 isolate_size, |
1403 false, | 1493 instructions_blob_buffer, |
1404 isolate_buffer, | 1494 instructions_blob_size, |
1405 isolate_size); | 1495 rodata_blob_buffer, |
1406 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix, | 1496 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 } | 1497 } |
1415 | 1498 |
1416 | 1499 |
1417 static void GenerateFullSnapshot() { | 1500 static void GenerateFullSnapshot() { |
1418 // Create a full snapshot of the script. | 1501 // Create a full snapshot of the script. |
1419 Dart_Handle result; | 1502 Dart_Handle result; |
1420 uint8_t* vm_isolate_buffer = NULL; | 1503 uint8_t* vm_isolate_buffer = NULL; |
1421 intptr_t vm_isolate_size = 0; | 1504 intptr_t vm_isolate_size = 0; |
1422 uint8_t* isolate_buffer = NULL; | 1505 uint8_t* isolate_buffer = NULL; |
1423 intptr_t isolate_size = 0; | 1506 intptr_t isolate_size = 0; |
1424 | 1507 |
1425 result = Dart_CreateSnapshot(&vm_isolate_buffer, | 1508 result = Dart_CreateSnapshot(&vm_isolate_buffer, |
1426 &vm_isolate_size, | 1509 &vm_isolate_size, |
1427 &isolate_buffer, | 1510 &isolate_buffer, |
1428 &isolate_size); | 1511 &isolate_size); |
1429 if (Dart_IsError(result)) { | 1512 if (Dart_IsError(result)) { |
1430 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1513 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
1431 } | 1514 } |
1432 | 1515 |
1433 WriteSnapshotFile(snapshot_filename, | 1516 WriteAppSnapshot(snapshot_filename, |
1434 kVMIsolateSuffix, | 1517 vm_isolate_buffer, |
1435 false, | 1518 vm_isolate_size, |
1436 vm_isolate_buffer, | 1519 isolate_buffer, |
1437 vm_isolate_size); | 1520 isolate_size, |
1438 WriteSnapshotFile(snapshot_filename, | 1521 NULL, 0, NULL, 0); |
1439 kIsolateSuffix, | |
1440 false, | |
1441 isolate_buffer, | |
1442 isolate_size); | |
1443 } | 1522 } |
1444 | 1523 |
1445 | 1524 |
1446 #define CHECK_RESULT(result) \ | 1525 #define CHECK_RESULT(result) \ |
1447 if (Dart_IsError(result)) { \ | 1526 if (Dart_IsError(result)) { \ |
1448 if (Dart_IsVMRestartRequest(result)) { \ | 1527 if (Dart_IsVMRestartRequest(result)) { \ |
1449 Dart_ExitScope(); \ | 1528 Dart_ExitScope(); \ |
1450 Dart_ShutdownIsolate(); \ | 1529 Dart_ShutdownIsolate(); \ |
1451 return true; \ | 1530 return true; \ |
1452 } \ | 1531 } \ |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1771 | 1850 |
1772 Loader::InitOnce(); | 1851 Loader::InitOnce(); |
1773 | 1852 |
1774 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1853 if (!DartUtils::SetOriginalWorkingDirectory()) { |
1775 OSError err; | 1854 OSError err; |
1776 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1855 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
1777 fflush(stderr); | 1856 fflush(stderr); |
1778 Platform::Exit(kErrorExitCode); | 1857 Platform::Exit(kErrorExitCode); |
1779 } | 1858 } |
1780 | 1859 |
1860 const uint8_t* instructions_snapshot = NULL; | |
1861 const uint8_t* data_snapshot = NULL; | |
1862 | |
1863 if (ReadAppSnapshot(script_name, | |
1864 &vm_isolate_snapshot_buffer, | |
1865 &isolate_snapshot_buffer, | |
1866 &instructions_snapshot, | |
1867 &data_snapshot)) { | |
1868 run_app_snapshot = true; | |
1869 } | |
1870 | |
1781 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) | 1871 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
1782 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. | 1872 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. |
1783 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { | 1873 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { |
1784 vm_options.AddArgument("--load_deferred_eagerly"); | 1874 vm_options.AddArgument("--load_deferred_eagerly"); |
1785 } | 1875 } |
1786 #endif | 1876 #endif |
1787 | 1877 |
1788 if (gen_snapshot_kind == kAppJITAfterRun) { | 1878 if (gen_snapshot_kind == kAppJITAfterRun) { |
1789 vm_options.AddArgument("--fields_may_be_reset"); | 1879 vm_options.AddArgument("--fields_may_be_reset"); |
1790 } | 1880 } |
1791 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { | 1881 if ((gen_snapshot_kind == kAppAOT) || is_noopt) { |
1792 vm_options.AddArgument("--precompilation"); | 1882 vm_options.AddArgument("--precompilation"); |
1793 } | 1883 } |
1794 #if defined(DART_PRECOMPILED_RUNTIME) | 1884 #if defined(DART_PRECOMPILED_RUNTIME) |
1795 vm_options.AddArgument("--precompilation"); | 1885 vm_options.AddArgument("--precompilation"); |
1796 #endif | 1886 #endif |
1797 | 1887 |
1798 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1888 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1799 | 1889 |
1800 // Start event handler. | 1890 // Start event handler. |
1801 TimerUtils::InitOnce(); | 1891 TimerUtils::InitOnce(); |
1802 EventHandler::Start(); | 1892 EventHandler::Start(); |
1803 | 1893 |
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. | 1894 // Initialize the Dart VM. |
1830 Dart_InitializeParams init_params; | 1895 Dart_InitializeParams init_params; |
1831 memset(&init_params, 0, sizeof(init_params)); | 1896 memset(&init_params, 0, sizeof(init_params)); |
1832 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1897 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
1833 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; | 1898 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; |
1834 init_params.instructions_snapshot = instructions_snapshot; | 1899 init_params.instructions_snapshot = instructions_snapshot; |
1835 init_params.data_snapshot = data_snapshot; | 1900 init_params.data_snapshot = data_snapshot; |
1836 init_params.create = CreateIsolateAndSetup; | 1901 init_params.create = CreateIsolateAndSetup; |
1837 init_params.shutdown = ShutdownIsolate; | 1902 init_params.shutdown = ShutdownIsolate; |
1838 init_params.file_open = DartUtils::OpenFile; | 1903 init_params.file_open = DartUtils::OpenFile; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1893 Platform::Exit(Process::GlobalExitCode()); | 1958 Platform::Exit(Process::GlobalExitCode()); |
1894 } | 1959 } |
1895 | 1960 |
1896 } // namespace bin | 1961 } // namespace bin |
1897 } // namespace dart | 1962 } // namespace dart |
1898 | 1963 |
1899 int main(int argc, char** argv) { | 1964 int main(int argc, char** argv) { |
1900 dart::bin::main(argc, argv); | 1965 dart::bin::main(argc, argv); |
1901 UNREACHABLE(); | 1966 UNREACHABLE(); |
1902 } | 1967 } |
OLD | NEW |