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

Side by Side Diff: src/d8.cc

Issue 315033002: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix build issue by making sure the target is empty (as opposed to not the chain of depedencies) whe… Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/d8.h ('k') | src/flag-definitions.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 } 1313 }
1314 #ifdef V8_SHARED 1314 #ifdef V8_SHARED
1315 else if (strcmp(argv[i], "--dump-counters") == 0) { 1315 else if (strcmp(argv[i], "--dump-counters") == 0) {
1316 printf("D8 with shared library does not include counters\n"); 1316 printf("D8 with shared library does not include counters\n");
1317 return false; 1317 return false;
1318 } else if (strcmp(argv[i], "--debugger") == 0) { 1318 } else if (strcmp(argv[i], "--debugger") == 0) {
1319 printf("Javascript debugger not included\n"); 1319 printf("Javascript debugger not included\n");
1320 return false; 1320 return false;
1321 } 1321 }
1322 #endif // V8_SHARED 1322 #endif // V8_SHARED
1323 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1324 else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
1325 options.natives_blob = argv[i] + 15;
1326 argv[i] = NULL;
1327 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) {
1328 options.snapshot_blob = argv[i] + 16;
1329 argv[i] = NULL;
1330 }
1331 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1323 } 1332 }
1324 1333
1325 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 1334 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1326 1335
1327 // Set up isolated source groups. 1336 // Set up isolated source groups.
1328 options.isolate_sources = new SourceGroup[options.num_isolates]; 1337 options.isolate_sources = new SourceGroup[options.num_isolates];
1329 SourceGroup* current = options.isolate_sources; 1338 SourceGroup* current = options.isolate_sources;
1330 current->Begin(argv, 1); 1339 current->Begin(argv, 1);
1331 for (int i = 1; i < argc; i++) { 1340 for (int i = 1; i < argc; i++) {
1332 const char* str = argv[i]; 1341 const char* str = argv[i];
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 } 1479 }
1471 virtual void* AllocateUninitialized(size_t length) V8_OVERRIDE { 1480 virtual void* AllocateUninitialized(size_t length) V8_OVERRIDE {
1472 return malloc(0); 1481 return malloc(0);
1473 } 1482 }
1474 virtual void Free(void* p, size_t) V8_OVERRIDE { 1483 virtual void Free(void* p, size_t) V8_OVERRIDE {
1475 free(p); 1484 free(p);
1476 } 1485 }
1477 }; 1486 };
1478 1487
1479 1488
1489 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1490 class StartupDataHandler {
1491 public:
1492 StartupDataHandler(const char* natives_blob,
1493 const char* snapshot_blob) {
1494 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
1495 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
1496 }
1497
1498 ~StartupDataHandler() {
1499 delete[] natives_.data;
1500 delete[] snapshot_.data;
1501 }
1502
1503 private:
1504 void Load(const char* blob_file,
1505 v8::StartupData* startup_data,
1506 void (*setter_fn)(v8::StartupData*)) {
1507 startup_data->data = NULL;
1508 startup_data->compressed_size = 0;
1509 startup_data->raw_size = 0;
1510
1511 if (!blob_file)
1512 return;
1513
1514 FILE* file = fopen(blob_file, "rb");
1515 if (!file)
1516 return;
1517
1518 fseek(file, 0, SEEK_END);
1519 startup_data->raw_size = ftell(file);
1520 rewind(file);
1521
1522 startup_data->data = new char[startup_data->raw_size];
1523 startup_data->compressed_size = fread(
1524 const_cast<char*>(startup_data->data), 1, startup_data->raw_size,
1525 file);
1526 fclose(file);
1527
1528 if (startup_data->raw_size == startup_data->compressed_size)
1529 (*setter_fn)(startup_data);
1530 }
1531
1532 v8::StartupData natives_;
1533 v8::StartupData snapshot_;
1534
1535 // Disallow copy & assign.
1536 StartupDataHandler(const StartupDataHandler& other);
1537 void operator=(const StartupDataHandler& other);
1538 };
1539 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1540
1541
1480 int Shell::Main(int argc, char* argv[]) { 1542 int Shell::Main(int argc, char* argv[]) {
1481 if (!SetOptions(argc, argv)) return 1; 1543 if (!SetOptions(argc, argv)) return 1;
1482 v8::V8::InitializeICU(options.icu_data_file); 1544 v8::V8::InitializeICU(options.icu_data_file);
1545 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1546 StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
1547 #endif
1483 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); 1548 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
1484 SetFlagsFromString("--redirect-code-traces-to=code.asm"); 1549 SetFlagsFromString("--redirect-code-traces-to=code.asm");
1485 ShellArrayBufferAllocator array_buffer_allocator; 1550 ShellArrayBufferAllocator array_buffer_allocator;
1486 MockArrayBufferAllocator mock_arraybuffer_allocator; 1551 MockArrayBufferAllocator mock_arraybuffer_allocator;
1487 if (options.mock_arraybuffer_allocator) { 1552 if (options.mock_arraybuffer_allocator) {
1488 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); 1553 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator);
1489 } else { 1554 } else {
1490 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); 1555 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
1491 } 1556 }
1492 int result = 0; 1557 int result = 0;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 } 1626 }
1562 1627
1563 } // namespace v8 1628 } // namespace v8
1564 1629
1565 1630
1566 #ifndef GOOGLE3 1631 #ifndef GOOGLE3
1567 int main(int argc, char* argv[]) { 1632 int main(int argc, char* argv[]) {
1568 return v8::Shell::Main(argc, argv); 1633 return v8::Shell::Main(argc, argv);
1569 } 1634 }
1570 #endif 1635 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698