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

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

Issue 2694103004: Cleanup app snapshots on isolate/vm exit. (Closed)
Patch Set: merge Created 3 years, 10 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/file_win.cc ('k') | runtime/bin/isolate_data.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1227
1228 1228
1229 static Dart_Isolate CreateServiceIsolate(const char* script_uri, 1229 static Dart_Isolate CreateServiceIsolate(const char* script_uri,
1230 const char* main, 1230 const char* main,
1231 const char* package_root, 1231 const char* package_root,
1232 const char* package_config, 1232 const char* package_config,
1233 Dart_IsolateFlags* flags, 1233 Dart_IsolateFlags* flags,
1234 void* data, 1234 void* data,
1235 char** error) { 1235 char** error) {
1236 IsolateData* isolate_data = 1236 IsolateData* isolate_data =
1237 new IsolateData(script_uri, package_root, package_config); 1237 new IsolateData(script_uri, package_root, package_config, NULL);
1238 Dart_Isolate isolate = NULL; 1238 Dart_Isolate isolate = NULL;
1239 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL, 1239 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL,
1240 NULL, isolate_data, error); 1240 NULL, isolate_data, error);
1241 1241
1242 if (isolate == NULL) { 1242 if (isolate == NULL) {
1243 Log::PrintErr("Error: Could not create service isolate\n"); 1243 Log::PrintErr("Error: Could not create service isolate\n");
1244 return NULL; 1244 return NULL;
1245 } 1245 }
1246 1246
1247 Dart_EnterScope(); 1247 Dart_EnterScope();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; 1323 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
1324 if (app_script_name != NULL) { 1324 if (app_script_name != NULL) {
1325 init_params.create = CreateServiceIsolate; 1325 init_params.create = CreateServiceIsolate;
1326 } 1326 }
1327 init_params.file_open = DartUtils::OpenFile; 1327 init_params.file_open = DartUtils::OpenFile;
1328 init_params.file_read = DartUtils::ReadFile; 1328 init_params.file_read = DartUtils::ReadFile;
1329 init_params.file_write = DartUtils::WriteFile; 1329 init_params.file_write = DartUtils::WriteFile;
1330 init_params.file_close = DartUtils::CloseFile; 1330 init_params.file_close = DartUtils::CloseFile;
1331 init_params.entropy_source = DartUtils::EntropySource; 1331 init_params.entropy_source = DartUtils::EntropySource;
1332 1332
1333 MappedMemory* mapped_vm_snapshot_data = NULL;
1334 MappedMemory* mapped_isolate_snapshot_data = NULL;
1333 if (snapshot_kind == kScript) { 1335 if (snapshot_kind == kScript) {
1334 File* file = File::Open(vm_snapshot_data_filename, File::kRead); 1336 File* file = File::Open(vm_snapshot_data_filename, File::kRead);
1335 if (file == NULL) { 1337 if (file == NULL) {
1336 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); 1338 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename);
1337 return kErrorExitCode; 1339 return kErrorExitCode;
1338 } 1340 }
1339 void* buffer = file->Map(File::kReadOnly, 0, file->Length()); 1341 mapped_vm_snapshot_data = file->Map(File::kReadOnly, 0, file->Length());
1340 if (buffer == NULL) { 1342 if (mapped_vm_snapshot_data == NULL) {
1341 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); 1343 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename);
1342 return kErrorExitCode; 1344 return kErrorExitCode;
1343 } 1345 }
1344 file->Close(); 1346 file->Close();
1345 init_params.vm_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); 1347 init_params.vm_snapshot_data =
1348 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address());
1346 1349
1347 file = File::Open(isolate_snapshot_data_filename, File::kRead); 1350 file = File::Open(isolate_snapshot_data_filename, File::kRead);
1348 if (file == NULL) { 1351 if (file == NULL) {
1349 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); 1352 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename);
1350 return kErrorExitCode; 1353 return kErrorExitCode;
1351 } 1354 }
1352 buffer = file->Map(File::kReadOnly, 0, file->Length()); 1355 mapped_isolate_snapshot_data =
1353 if (buffer == NULL) { 1356 file->Map(File::kReadOnly, 0, file->Length());
1357 if (mapped_isolate_snapshot_data == NULL) {
1354 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); 1358 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename);
1355 return kErrorExitCode; 1359 return kErrorExitCode;
1356 } 1360 }
1357 file->Close(); 1361 file->Close();
1358 isolate_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); 1362 isolate_snapshot_data = reinterpret_cast<const uint8_t*>(
1363 mapped_isolate_snapshot_data->address());
1359 } 1364 }
1360 1365
1361 char* error = Dart_Initialize(&init_params); 1366 char* error = Dart_Initialize(&init_params);
1362 if (error != NULL) { 1367 if (error != NULL) {
1363 Log::PrintErr("VM initialization failed: %s\n", error); 1368 Log::PrintErr("VM initialization failed: %s\n", error);
1364 free(error); 1369 free(error);
1365 return kErrorExitCode; 1370 return kErrorExitCode;
1366 } 1371 }
1367 1372
1368 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, 1373 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root,
1369 commandline_packages_file); 1374 commandline_packages_file, NULL);
1370 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, 1375 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data,
1371 NULL, NULL, isolate_data, &error); 1376 NULL, NULL, isolate_data, &error);
1372 if (isolate == NULL) { 1377 if (isolate == NULL) {
1373 Log::PrintErr("Error: %s\n", error); 1378 Log::PrintErr("Error: %s\n", error);
1374 free(error); 1379 free(error);
1375 exit(kErrorExitCode); 1380 exit(kErrorExitCode);
1376 } 1381 }
1377 1382
1378 Dart_Handle result; 1383 Dart_Handle result;
1379 Dart_Handle library; 1384 Dart_Handle library;
(...skipping 27 matching lines...) Expand all
1407 result = DartUtils::SetupPackageRoot(commandline_package_root, 1412 result = DartUtils::SetupPackageRoot(commandline_package_root,
1408 commandline_packages_file); 1413 commandline_packages_file);
1409 CHECK_RESULT(result); 1414 CHECK_RESULT(result);
1410 1415
1411 UriResolverIsolateScope::isolate = isolate; 1416 UriResolverIsolateScope::isolate = isolate;
1412 Dart_ExitScope(); 1417 Dart_ExitScope();
1413 Dart_ExitIsolate(); 1418 Dart_ExitIsolate();
1414 1419
1415 // Now we create an isolate into which we load all the code that needs to 1420 // Now we create an isolate into which we load all the code that needs to
1416 // be in the snapshot. 1421 // be in the snapshot.
1417 isolate_data = new IsolateData(NULL, NULL, NULL); 1422 isolate_data = new IsolateData(NULL, NULL, NULL, NULL);
1418 const uint8_t* kernel = NULL; 1423 const uint8_t* kernel = NULL;
1419 intptr_t kernel_length = 0; 1424 intptr_t kernel_length = 0;
1420 const bool is_kernel_file = 1425 const bool is_kernel_file =
1421 TryReadKernel(app_script_name, &kernel, &kernel_length); 1426 TryReadKernel(app_script_name, &kernel, &kernel_length);
1422 1427
1423 void* kernel_program = NULL; 1428 void* kernel_program = NULL;
1424 if (is_kernel_file) { 1429 if (is_kernel_file) {
1425 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); 1430 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length);
1426 free(const_cast<uint8_t*>(kernel)); 1431 free(const_cast<uint8_t*>(kernel));
1427 } 1432 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 1508
1504 Dart_ExitScope(); 1509 Dart_ExitScope();
1505 Dart_ShutdownIsolate(); 1510 Dart_ShutdownIsolate();
1506 } 1511 }
1507 error = Dart_Cleanup(); 1512 error = Dart_Cleanup();
1508 if (error != NULL) { 1513 if (error != NULL) {
1509 Log::PrintErr("VM cleanup failed: %s\n", error); 1514 Log::PrintErr("VM cleanup failed: %s\n", error);
1510 free(error); 1515 free(error);
1511 } 1516 }
1512 EventHandler::Stop(); 1517 EventHandler::Stop();
1518 delete mapped_vm_snapshot_data;
1519 delete mapped_isolate_snapshot_data;
1513 return 0; 1520 return 0;
1514 } 1521 }
1515 1522
1516 } // namespace bin 1523 } // namespace bin
1517 } // namespace dart 1524 } // namespace dart
1518 1525
1519 int main(int argc, char** argv) { 1526 int main(int argc, char** argv) {
1520 return dart::bin::main(argc, argv); 1527 return dart::bin::main(argc, argv);
1521 } 1528 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | runtime/bin/isolate_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698